This document describes the high-level architecture and data flow of the Wikipedia MCP server.
- CLI (
wikipedia_mcp/__main__.py): Parses runtime configuration, validates auth/transport options, configures logging, and launches the server. - Auth Config (
wikipedia_mcp/auth_config.py): Validates--auth-*options and environment fallbacks into a transport auth config. - Server (
wikipedia_mcp/server.py): BuildsFastMCP, wires tool/resource handlers, configures JWT auth provider, and exposes static bearer middleware for network transports. - Schemas (
wikipedia_mcp/schemas.py): Pydantic output models used to generate explicit MCPoutputSchemadefinitions. - Wikipedia Client (
wikipedia_mcp/wikipedia_client.py): Handles Wikipedia API interaction, language/country mapping, variants, retries, and JSON/error normalization. - Tests (
tests/): Coverage for CLI behavior, tool schemas, auth modes, language/country handling, and compatibility contracts.
- A request arrives through MCP tool invocation or resource read.
- FastMCP dispatches to a registered handler in
server.py. - Handler calls
WikipediaClientmethods. - Client performs API/library operations and normalizes errors.
- Handler returns structured output aligned with explicit
outputSchema.
stdio(default): local integrations and desktop clients.http/streamable-http: preferred network deployment transport (endpoint path default/mcp).sse: legacy compatibility transport.
Auth is only applied to network transports:
none: no request auth.static: exact bearer token enforced by ASGI middleware.jwt: FastMCPBearerAuthProvidervalidates JWT using public key or JWKS.
This is separate from --access-token, which is used for outbound Wikipedia API requests.
- Canonical tools are preserved (
search_wikipedia,get_article, etc.). - Each canonical tool also has a discoverability alias prefixed with
wikipedia_. - Tools include MCP annotations (
readOnlyHint,idempotentHint,openWorldHint,destructiveHint).
- HTTP calls to Wikipedia use bounded retry/backoff on retryable failures.
- Non-JSON or malformed responses are normalized into actionable error payloads.
- Connectivity/search/coordinates surface safe fallback outputs instead of uncaught exceptions.
- For exposed network transports, prefer
http+--auth-mode static|jwtand private-network/reverse-proxy controls. - Avoid logging secrets or bearer tokens.
- Add new MCP tools in
server.pyand register matching alias + annotations. - Add/extend output models in
schemas.pyto keep contracts explicit. - Extend
WikipediaClientwith focused methods and keep protocol-facing adaptation in server handlers.