{"id":"33f14490-817e-4fe0-ba06-bd5863845646","slug":"wikidata-mcp-server","kind":"mcp","name":"wikidata-mcp-server","summary":"Search and fetch Wikidata entities, execute SPARQL queries, and resolve external identifiers via MCP. STDIO or Streamable HTTP.","owner":"cyanheads","repoUrl":"https://github.com/cyanheads/wikidata-mcp-server","license":"Apache-2.0","licenseTier":"permissive","trust":"community","stars":3,"match":null,"fewStars":true,"format":"mcp","createdAt":"2026-05-23T17:00:24.000Z","addedAt":"2026-10-14T05:32:42.168Z","logoUrl":"https://avatars.githubusercontent.com/u/10339515?u=4c01abceabee90f9b5a4a4861cc791a239241fa3&v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["cloud-infra","memory-knowledge","browser-web"],"tags":["bun","knowledge-graph","linked-data","sparql","typescript","wikibase","wikidata","ai-agent"],"runtime":"node","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-17T15:20:50.865Z","sample":false,"url":"https://conduits.dev/tools/wikidata-mcp-server","language":"TypeScript","transports":["stdio"],"install":{"npm":"@cyanheads/wikidata-mcp-server"},"requirements":{"env":[{"name":"WIKIDATA_USER_AGENT","secret":false,"required":false,"description":"User-Agent string for Wikimedia requests. Wikimedia policy requires a descriptive value."},{"name":"WIKIDATA_SPARQL_TIMEOUT_MS","secret":false,"required":false,"description":"Max time to wait for a SPARQL response in milliseconds."},{"name":"WIKIDATA_REST_TIMEOUT_MS","secret":false,"required":false,"description":"Max time to wait for REST API responses in milliseconds."},{"name":"MCP_LOG_LEVEL","secret":false,"required":false,"description":"Sets the minimum log level for output (e.g., 'debug', 'info', 'warn')."}],"upstreamMayCharge":false},"tools":null,"readme":"<div align=\"center\">\n  <h1>@cyanheads/wikidata-mcp-server</h1>\n  <p><b>Search and fetch Wikidata entities, execute SPARQL queries, and resolve external identifiers via MCP. STDIO or Streamable HTTP.</b>\n  <div>7 Tools • 1 Resource</div>\n  </p>\n</div>\n\n<div align=\"center\">\n\n[![Version](https://img.shields.io/badge/Version-0.2.0-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/wikidata-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.3.1-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/wikidata-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/wikidata-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.3%2B-blueviolet.svg?style=flat-square)](https://bun.sh/)\n\n</div>\n\n<div align=\"center\">\n\n[![Install in Claude Desktop](https://img.shields.io/badge/Install_in-Claude_Desktop-D97757?style=for-the-badge&logo=anthropic&logoColor=white)](https://github.com/cyanheads/wikidata-mcp-server/releases/latest/download/wikidata-mcp-server.mcpb) [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=wikidata-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvd2lraWRhdGEtbWNwLXNlcnZlciJdfQ==) [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22wikidata-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fwikidata-mcp-server%22%5D%7D)\n\n[![Framework](https://img.shields.io/badge/Built%20on-@cyanheads/mcp--ts--core-67E8F9?style=flat-square)](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)\n\n</div>\n\n<div align=\"center\">\n\n**Public Hosted Server:** [https://wikidata.caseyjhand.com/mcp](https://wikidata.caseyjhand.com/mcp)\n\n</div>\n\n---\n\n## Overview\n\nWikidata's knowledge graph. Search and fetch entities, traverse the graph with SPARQL, and resolve external identifiers like DOI, PMID, ORCID, OpenAlex, and IMDb to their Wikidata items. No API key required.\n\n### Tools\n\n| Tool | Description |\n|:---|:---|\n| `wikidata_search_entities` | Search for items or properties by text query, returning QIDs/PIDs with labels, descriptions, and match metadata |\n| `wikidata_get_entity` | Fetch a full entity by QID or PID with optional field and language filtering |\n| `wikidata_get_labels` | Batch-resolve up to 50 QIDs or PIDs to human-readable labels and descriptions |\n| `wikidata_get_statements` | Fetch property claims for an entity with qualifier detail and QID label resolution |\n| `wikidata_get_sitelinks` | Fetch Wikipedia and Wikimedia project article URLs for a Wikidata item |\n| `wikidata_sparql_query` | Execute a SPARQL SELECT query against the Wikidata Query Service |\n| `wikidata_resolve_external_id` | Look up a Wikidata entity by an external identifier (DOI, PubMed ID, ORCID, OpenAlex ID, etc.) |\n\n### Resources\n\n| Resource | Description |\n|:---|:---|\n| `wikidata://entity/{id}` | Compact markdown summary of a Wikidata entity — labels, English description, instance-of, Wikipedia link, image, and statement count |\n\nAll resource data is also reachable via tools.\n\n## Capability reference\n\n### `wikidata_search_entities` <sub>tool</sub>\n\n- Searches labels, aliases, and descriptions; `type=\"item\"` for people, places, and works, `type=\"property\"` for P-IDs\n- Takes a Wikidata language code (`en`, `de`, `pt-br`; case-insensitive); offset pagination, up to 50 results per call\n- Each hit includes match metadata saying whether it matched a label or alias\n\n---\n\n### `wikidata_get_entity` <sub>tool</sub>\n\n- Q-IDs (e.g. `Q76`) fetch items and P-IDs (e.g. `P31`) fetch properties; `fields` selects `labels`, `descriptions`, `aliases`, `statements`, or `sitelinks`, and narrows the upstream fetch (Q76 is 344,114 bytes whole, 6,703 for `labels` alone)\n- `languages` filters multilingual maps to the given language codes\n- An entity too large to inline returns an outline of field categories with byte sizes; its `retrieval_notice` names a `fields` set that fits and points oversized statements or sitelinks to the tool that can narrow them\n\n---\n\n### `wikidata_get_labels` <sub>tool</sub>\n\n- Up to 50 IDs per call via the MediaWiki `wbgetentities` API, with one or more language codes per request\n- Reports a `found` count and `notFound` IDs for partial results\n- Meant to follow a SPARQL query: run it, then humanize the QIDs\n\n---\n\n### `wikidata_get_statements` <sub>tool</sub>\n\n- `properties` limits the fetch to specific P-IDs (omit for all); item QIDs and quantity units in values, qualifiers, and references are resolved to labels unless `resolve_labels=false`\n- References stay grouped by source; unknown or absent values come back as `somevalue` / `novalue`\n- A statement set too large to inline returns an outline of P-IDs with byte sizes, largest first (unfiltered, Q30 carries 467 properties across 1,717 statements); re-call with `properties` whose sizes sum to 24,000 or less, as the `retrieval_notice` suggests\n\n---\n\n### `wikidata_get_sitelinks` <sub>tool</sub>\n\n- Maps site codes (e.g. `enwiki`) to article titles and URLs; `sites` filters to specific codes\n- `wikis_only=true` keeps only Wikipedia links (drops Wiktionary, Wikiquote, Wikisource, etc.)\n- Q-IDs only; P-IDs are not supported\n\n---\n\n### `wikidata_sparql_query` <sub>tool</sub>\n\n- Runs SELECT queries against the Wikidata Query Service (Blazegraph); ASK, CONSTRUCT, DESCRIBE, updates, and plain search text are rejected before the request is sent\n- Standard prefixes (`wd:`, `wdt:`, `p:`, `ps:`, `pq:`, `wikibase:`, `bd:`) and the `wikibase:label` SERVICE (when the query uses a `?<var>Label`, `?<var>Description`, or `?<var>AltLabel` variable) are added automatically; `language` takes one code or a fallback list like `fr,en`\n- Results are SPARQL 1.1 JSON bindings, capped at 64,000 bytes per response and cut between whole rows; a larger result returns its leading rows with `returnedCount`, `totalCount`, and a notice to page with `ORDER BY` plus `LIMIT`/`OFFSET` or to aggregate\n- Client `timeout` is 1–55s (server hard limit 60s); rate limit is 60 requests/min and 5 concurrent requests per IP\n\n---\n\n### `wikidata_resolve_external_id` <sub>tool</sub>\n\n- Resolves DOI (P356), PMID (P698), ORCID (P496), OpenAlex ID (P10283), IMDb ID (P345), and other external IDs to a QID; whitespace and resolver URL prefixes are stripped, and DOIs, PMIDs, and ORCIDs are normalized\n- The property must have data type `external-id`; item-valued or media properties (e.g. `P31`, `P18`) are rejected\n- Returns `match=null` when not found (the Query Service lags the live wiki, so null is not proof of absence) and `multipleMatches` when more than one entity claims the same ID; the label uses the requested `language`, falling back to `mul`\n\n---\n\n### `wikidata://entity/{id}` <sub>resource</sub>\n\n- Compact markdown summary — labels (all languages), English description, instance-of (`P31`), enwiki Wikipedia link, image (`P18`), and statement count\n- Returned as `text/markdown`; for full entity data, use `wikidata_get_entity`\n- `id` is a Q-ID or P-ID, the same identifiers the tools take\n\n## Features\n\nBuilt on [`@cyanheads/mcp-ts-core`](https://github.com/cyanheads/mcp-ts-core): stdio and Streamable HTTP transports, pluggable auth (`none` / `jwt` / `oauth`), swappable storage (`in-memory`, `filesystem`, `Supabase`, `Cloudflare KV/R2/D1`), structured logging with optional OpenTelemetry tracing.\n\nWikidata-specific:\n\n- Wikidata REST API v1 for entity and statement fetches — no SPARQL overhead for lookup operations\n- MediaWiki `wbgetentities` API for efficient batch label resolution\n- Wikidata Query Service (Blazegraph) for SPARQL with auto-injected prefix headers and label SERVICE\n- Configurable `User-Agent` per Wikimedia policy (`WIKIDATA_USER_AGENT`)\n- Separate timeout configuration for REST and SPARQL endpoints (`WIKIDATA_REST_TIMEOUT_MS`, `WIKIDATA_SPARQL_TIMEOUT_MS`)\n\nAgent-friendly output:\n\n- All tools echo relevant input parameters in the response for traceability\n- `wikidata_get_labels` designed to follow SPARQL result sets — run the query, then humanize in one call\n- `wikidata_resolve_external_id` returns `multipleMatches` instead of a false null when a Wikidata data-integrity issue puts duplicate claims on one external ID\n- Oversized entities and statement sets return a `kind: \"outline\"` payload — field/property sizes plus a `retrieval_notice` naming the exact re-call — instead of a truncated or oversized response\n\n## Getting started\n\n### Public Hosted Instance\n\nA public instance is available at `https://wikidata.caseyjhand.com/mcp` — no installation required. Point any MCP client at it via Streamable HTTP:\n\n```json\n{\n  \"mcpServers\": {\n    \"wikidata-mcp-server\": {\n      \"type\": \"streamable-http\",\n      \"url\": \"https://wikidata.caseyjhand.com/mcp\"\n    }\n  }\n}\n```\n\n### Self-Hosted / Local\n\nAdd the following to your MCP client configuration file.\n\n```json\n{\n  \"mcpServers\": {\n    \"wikidata-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"bunx\",\n      \"args\": [\"@cyanheads/wikidata-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\"\n      }\n    }\n  }\n}\n```\n\nOr with npx (no Bun required):\n\n```json\n{\n  \"mcpServers\": {\n    \"wikidata-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@cyanheads/wikidata-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\"\n      }\n    }\n  }\n}\n```\n\nOr with Docker:\n\n```json\n{\n  \"mcpServers\": {\n    \"wikidata-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"docker\",\n      \"args\": [\"run\", \"-i\", \"--rm\", \"-e\", \"MCP_TRANSPORT_TYPE=stdio\", \"ghcr.io/cyanheads/wikidata-mcp-server:latest\"]\n    }\n  }\n}\n```\n\nFor Streamable HTTP, set the transport and start the server:\n\n```sh\nMCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http\n# Server listens at http://localhost:3010/mcp\n```\n\n### Prerequisites\n\n- [Bun v1.4.0](https://bun.sh/) or higher (or Node.js ≥ 24.0.0).\n\n### Installation\n\n1. **Clone the repository:**\n\n```sh\ngit clone https://github.com/cyanheads/wikidata-mcp-server.git\n```\n\n2. **Navigate into the directory:**\n\n```sh\ncd wikidata-mcp-server\n```\n\n3. **Install dependencies:**\n\n```sh\nbun install\n```\n\n4. **Configure environment:**\n\n```sh\ncp .env.example .env\n# edit .env and set any overrides\n```\n\n## Configuration\n\nAll configuration is validated at startup via Zod schemas. Key environment variables:\n\n| Variable | Description | Default |\n|:---|:---|:---|\n| `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http` | `stdio` |\n| `MCP_HTTP_PORT` | HTTP server port | `3010` |\n| `MCP_HTTP_ENDPOINT_PATH` | HTTP endpoint path where the MCP server is mounted | `/mcp` |\n| `MCP_PUBLIC_URL` | Public origin override for TLS-terminating reverse-proxy deployments | none |\n| `MCP_AUTH_MODE` | Authentication: `none`, `jwt`, or `oauth` | `none` |\n| `MCP_SESSION_MODE` | HTTP session mode: `stateful`, `stateless`, or `auto` | `stateless` |\n| `MCP_LOG_LEVEL` | Log level (`debug`, `info`, `notice`, `warning`, `error`) | `info` |\n| `MCP_GC_PRESSURE_INTERVAL_MS` | Opt-in forced-GC interval in ms (Bun only) | `0` (disabled) |\n| `LOGS_DIR` | Directory for log files (Node.js only) | `<project-root>/logs` |\n| `STORAGE_PROVIDER_TYPE` | Storage backend: `in-memory`, `filesystem`, `supabase`, `cloudflare-kv/r2/d1` | `in-memory` |\n| `WIKIDATA_USER_AGENT` | User-Agent string for Wikimedia requests (policy requires a descriptive value) | `wikidata-mcp-server/0.1 (https://github.com/cyanheads/wikidata-mcp-server)` |\n| `WIKIDATA_SPARQL_TIMEOUT_MS` | Max wait for a SPARQL response in ms | `55000` |\n| `WIKIDATA_REST_TIMEOUT_MS` | Max wait for REST API responses in ms | `10000` |\n| `OTEL_ENABLED` | Enable OpenTelemetry | `false` |\n\nSee [`.env.example`](./.env.example) for the full list of optional overrides.\n\n## Running the server\n\n### Local development\n\n- **Build and run the production version**:\n\n  ```sh\n  # One-time build\n  bun run rebuild\n\n  # Run the built server\n  bun run start:http\n  # or\n  bun run start:stdio\n  ```\n\n- **Run checks and tests**:\n  ```sh\n  bun run devcheck  # Lints, formats, type-checks, and more\n  bun run test      # Runs the test suite\n  ```\n\n### Docker\n\n```sh\ndocker build -t wikidata-mcp-server .\ndocker run --rm -p 3010:3010 wikidata-mcp-server\n```\n\nThe Dockerfile defaults to HTTP transport, stateless session mode, and logs to `/var/log/wikidata-mcp-server`. OpenTelemetry peer dependencies are installed by default — build with `--build-arg OTEL_ENABLED=false` to omit them.\n\n## Project structure\n\n| Directory | Purpose |\n|:---|:---|\n| `src/index.ts` | `createApp()` entry point — registers tools and resources, inits services. |\n| `src/mcp-server/tools` | Tool definitions (`*.tool.ts`). Seven tools for entity lookup, statements, sitelinks, SPARQL, and external ID resolution. |\n| `src/mcp-server/resources` | Resource definitions. Entity summary resource. |\n| `src/services/wikidata` | Wikidata service layer — REST API client, SPARQL client, statement normalization, types. |\n| `src/config` | Server-specific environment variable parsing and validation with Zod. |\n| `tests/` | Unit and integration tests, mirroring the `src/` structure. |\n\n## Development guide\n\nSee [`CLAUDE.md`](./CLAUDE.md) for development guidelines and architectural rules. The short version:\n\n- Handlers throw, framework catches — no `try/catch` in tool logic\n- Use `ctx.log` for logging, `ctx.state` for storage\n- Register new tools and resources in the `createApp()` arrays\n- Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields\n\n## Contributing\n\nIssues are welcome. Run checks and tests before submitting:\n\n```sh\nbun run devcheck\nbun run test\n```\n\n## License\n\nApache-2.0 — see [LICENSE](./LICENSE) for details.\n"}