Wikidata Mcp Server

io.github.cyanheads由 GitHub 账号 cyanheads 发布v0.3.0更新于 Oct 29, 2026

Search and fetch Wikidata entities, execute SPARQL queries, and resolve external identifiers.

已验证Streamable HTTP可网页运行知识与记忆数据与分析

概览

AI 生成的概览

查询 Wikidata 知识图谱:搜索与获取实体、读取声明与站点链接、执行 SPARQL,并把 DOI、ORCID 等外部标识解析为条目。

可以做什么
  • 按文本搜索条目与属性,返回带标签和匹配信息的 QID/PID
  • 按 QID 或 PID 获取实体,可筛选字段与语言,并批量解析最多 50 个 ID 的标签
  • 读取带限定符和参考文献的属性声明,获取维基百科及其他维基媒体项目的条目链接
  • 对 Wikidata 查询服务执行 SPARQL SELECT,自动注入前缀与标签服务
  • 把 DOI、PMID、ORCID、OpenAlex、IMDb 等外部标识解析为 Wikidata 条目
  • 通过 wikidata://entity/{id} 资源读取实体的精简 Markdown 摘要
适用场景
适合需要人物、地点、作品或概念的事实性、可溯源背景信息,或需要把学术、影视类标识关联到 Wikidata 条目的场景。也适合需要对 Wikidata 做图遍历或聚合的研究与数据任务。
运行要求
可使用托管的 Streamable HTTP 端点,或通过 npx 在本地运行(需 Node.js 24 及以上;源码构建需 Bun 1.4+)。无需 API 密钥或账号。可选环境变量涵盖传输方式、端口、认证模式、日志级别、REST 与 SPARQL 超时,以及必填的描述性 WIKIDATA_USER_AGENT。需要访问维基媒体服务的网络连接。
安装前请注意
所有工具都是对公开维基媒体数据的只读查询,但查询内容和标识会发送到维基媒体服务器;若使用托管端点,也会发送给该第三方。SPARQL 有速率限制(每分钟 60 次请求、每 IP 5 个并发),单次响应上限 64,000 字节,超出时只返回前若干行。外部标识查不到结果并不代表不存在,因为查询服务落后于线上维基。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Wikidata Mcp Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。

交给智能体安装

把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。

阅读 https://sourceweft.com/mcp/io.github.cyanheads%2Fwikidata-mcp-server/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。

查看智能体所依据的安装指南

其他 MCP 客户端

把它添加到你客户端的 mcpServers 配置中。

{
  "mcpServers": {
    "wikidata": {
      "type": "http",
      "url": "https://wikidata.caseyjhand.com/mcp"
    }
  }
}

README

@cyanheads/wikidata-mcp-server

Search and fetch Wikidata entities, execute SPARQL queries, and resolve external identifiers via MCP. STDIO or Streamable HTTP.

7 Tools • 1 Resource • 1 Skill

Public Hosted Server: https://wikidata.caseyjhand.com/mcp


Overview

Wikidata'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.

Tools

ToolDescription
wikidata_search_entitiesSearch for items or properties by text query, returning QIDs/PIDs with labels, descriptions, and match metadata
wikidata_get_entityFetch a full entity by QID or PID with optional field and language filtering
wikidata_get_labelsBatch-resolve up to 50 QIDs or PIDs to human-readable labels and descriptions
wikidata_get_statementsFetch property claims for an entity with qualifier detail and QID label resolution
wikidata_get_sitelinksFetch Wikipedia and Wikimedia project article URLs for a Wikidata item
wikidata_sparql_queryExecute a SPARQL SELECT query against the Wikidata Query Service
wikidata_resolve_external_idLook up a Wikidata entity by an external identifier (DOI, PubMed ID, ORCID, OpenAlex ID, etc.)

Resources

ResourceDescription
wikidata://entity/{id}Compact markdown summary of a Wikidata entity — labels, English description, instance-of, Wikipedia link, image, and statement count

All resource data is also reachable via tools.

The published wikidata-guide covers entity disambiguation, qualified statements, external identifiers, and SPARQL. It is included in plugin installs and served over MCP as skill://wikidata-guide/SKILL.md.

Capability reference

wikidata_search_entities tool

  • Searches labels, aliases, and descriptions; type="item" for people, places, and works, type="property" for P-IDs
  • Takes a Wikidata language code (en, de, pt-br; case-insensitive); offset pagination, up to 50 results per call
  • Each hit includes match metadata saying whether it matched a label or alias

wikidata_get_entity tool

  • 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)
  • languages filters multilingual maps to the given language codes
  • 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

wikidata_get_labels tool

  • Up to 50 IDs per call via the MediaWiki wbgetentities API, with one or more language codes per request
  • Reports a found count and notFound IDs for partial results
  • Meant to follow a SPARQL query: run it, then humanize the QIDs

wikidata_get_statements tool

  • 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
  • References stay grouped by source; unknown or absent values come back as somevalue / novalue
  • 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

wikidata_get_sitelinks tool

  • Maps site codes (e.g. enwiki) to article titles and URLs; sites filters to specific codes
  • wikis_only=true keeps only Wikipedia links (drops Wiktionary, Wikiquote, Wikisource, etc.)
  • Q-IDs only; P-IDs are not supported

wikidata_sparql_query tool

  • Runs SELECT queries against the Wikidata Query Service (Blazegraph); ASK, CONSTRUCT, DESCRIBE, updates, and plain search text are rejected before the request is sent
  • 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
  • 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
  • Client timeout is 1–55s (server hard limit 60s); rate limit is 60 requests/min and 5 concurrent requests per IP

wikidata_resolve_external_id tool

  • 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
  • The property must have data type external-id; item-valued or media properties (e.g. P31, P18) are rejected
  • 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

wikidata://entity/{id} resource

  • Compact markdown summary — labels (all languages), English description, instance-of (P31), enwiki Wikipedia link, image (P18), and statement count
  • Returned as text/markdown; for full entity data, use wikidata_get_entity
  • id is a Q-ID or P-ID, the same identifiers the tools take

Features

Built on @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.

Wikidata-specific:

  • Wikidata REST API v1 for entity and statement fetches — no SPARQL overhead for lookup operations
  • MediaWiki wbgetentities API for efficient batch label resolution
  • Wikidata Query Service (Blazegraph) for SPARQL with auto-injected prefix headers and label SERVICE
  • Configurable User-Agent per Wikimedia policy (WIKIDATA_USER_AGENT)
  • Separate timeout configuration for REST and SPARQL endpoints (WIKIDATA_REST_TIMEOUT_MS, WIKIDATA_SPARQL_TIMEOUT_MS)

Agent-friendly output:

  • All tools echo relevant input parameters in the response for traceability
  • wikidata_get_labels designed to follow SPARQL result sets — run the query, then humanize in one call
  • wikidata_resolve_external_id returns multipleMatches instead of a false null when a Wikidata data-integrity issue puts duplicate claims on one external ID
  • 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

Getting started

Connect to the hosted instance, no install:

sh
claude mcp add --transport http wikidata-mcp-server https://wikidata.caseyjhand.com/mcp

Or run it locally:

sh
claude mcp add wikidata-mcp-server -- npx -y @cyanheads/wikidata-mcp-server

For other clients, add this to the MCP config file:

json
{  "mcpServers": {    "wikidata-mcp-server": {      "command": "npx",      "args": ["-y", "@cyanheads/wikidata-mcp-server"]    }  }}

For Docker or a source build, see Running the server.

Configuration

All configuration is validated at startup via Zod schemas. Key environment variables:

VariableDescriptionDefault
MCP_TRANSPORT_TYPETransport: stdio or httpstdio
MCP_HTTP_PORTHTTP server port3010
MCP_HTTP_ENDPOINT_PATHHTTP endpoint path where the MCP server is mounted/mcp
MCP_PUBLIC_URLPublic origin override for TLS-terminating reverse-proxy deploymentsnone
MCP_AUTH_MODEAuthentication: none, jwt, or oauthnone
MCP_SESSION_MODEHTTP session mode: stateful, stateless, or autostateless
MCP_LOG_LEVELLog level (debug, info, notice, warning, error)info
MCP_GC_PRESSURE_INTERVAL_MSOpt-in forced-GC interval in ms (Bun only)0 (disabled)
LOGS_DIRDirectory for log files (Node.js only)<project-root>/logs
STORAGE_PROVIDER_TYPEStorage backend: in-memory, filesystem, supabase, cloudflare-kv/r2/d1in-memory
WIKIDATA_USER_AGENTUser-Agent string for Wikimedia requests (policy requires a descriptive value)wikidata-mcp-server/0.1 (https://github.com/cyanheads/wikidata-mcp-server)
WIKIDATA_SPARQL_TIMEOUT_MSMax wait for a SPARQL response in ms55000
WIKIDATA_REST_TIMEOUT_MSMax wait for REST API responses in ms10000
OTEL_ENABLEDEnable OpenTelemetryfalse

See .env.example for the full list of optional overrides.

Running the server

Local development

Requires Bun v1.4.0 or higher (or Node.js ≥24.0.0).

sh
git clone https://github.com/cyanheads/wikidata-mcp-server.gitcd wikidata-mcp-serverbun installcp .env.example .env
  • Build and run the production version:

    sh
    # One-time buildbun run rebuild
    # Run the built serverbun run start:http# orbun run start:stdio
  • Run checks and tests:

    sh
    bun run devcheck  # Lints, formats, type-checks, and morebun run test      # Runs the test suite

Docker

sh
docker run --rm -p 3010:3010 ghcr.io/cyanheads/wikidata-mcp-server:latest

The image defaults to HTTP transport, stateless session mode, and logs to /var/log/wikidata-mcp-server. For stdio client configuration, use "command": "docker" with "args": ["run", "-i", "--rm", "-e", "MCP_TRANSPORT_TYPE=stdio", "ghcr.io/cyanheads/wikidata-mcp-server:latest"]. Build locally with docker build -t wikidata-mcp-server .; OpenTelemetry peers are installed by default (--build-arg OTEL_ENABLED=false omits them).

Project structure

DirectoryPurpose
src/index.tscreateApp() entry point — registers tools and resources, inits services.
src/mcp-server/toolsTool definitions (*.tool.ts). Seven tools for entity lookup, statements, sitelinks, SPARQL, and external ID resolution.
src/mcp-server/resourcesResource definitions. Entity summary resource.
src/services/wikidataWikidata service layer — REST API client, SPARQL client, statement normalization, types.
src/configServer-specific environment variable parsing and validation with Zod.
tests/Unit and integration tests, mirroring the src/ structure.
skills/wikidata-guide/Published guide for entity resolution, statements, and SPARQL workflows.

Development guide

See CLAUDE.md for development guidelines and architectural rules. The short version:

  • Handlers throw, framework catches — no try/catch in tool logic
  • Use ctx.log for logging, ctx.state for storage
  • Register new tools and resources in the createApp() arrays
  • Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields

Contributing

Issues are welcome. Run checks and tests before submitting:

sh
bun run devcheckbun run test

License

Apache-2.0 — see LICENSE for details.

来源:README.md,提交 88a0b07

工具

7

wikidata_search_entities

Search Wikidata Entities

Search Wikidata for items or properties by text query. Returns QIDs or PIDs with labels, descriptions, and match metadata indicating whether the hit was on a label or alias. Use type="item" for real-world concepts (people, places, works) and type="property" to find predicate P-IDs. The API returns no total count — pagination is offset-based with no result ceiling indicator.

输入参数typelimitquery必填offsetlanguage

wikidata_get_entity

Get Wikidata Entity

Fetch a Wikidata entity (item or property) by QID or PID. The fields parameter narrows the upstream fetch, not just the response — asking for labels alone costs a fraction of the whole entity, so name the fields you need. Omit fields for all data; a well-connected item is large enough to overflow, and an oversized entity returns kind: "outline" — the field categories with their byte sizes — instead of the data. Follow its retrieval_notice literally rather than picking from sections yourself — it names a fields set already measured to fit, since category sizes are additive and requesting them all would overflow again; for a category too large to deliver whole (statements or sitelinks on a major item) it names the sibling tool that can narrow it. Q-IDs (e.g. Q76) fetch items; P-IDs (e.g. P31) fetch properties from the correct endpoint automatically. Use wikidata_get_statements for deep claim traversal with label resolution, and whenever an entity's statements are large — its properties parameter selects individual P-IDs, granularity fields does not carry.

输入参数id必填fieldslanguages

wikidata_get_labels

Get Wikidata Labels

Resolve one or more QIDs or PIDs to their human-readable labels and descriptions. Lightweight — returns no claim data. Supports up to 50 IDs per call (batched automatically). Designed for the common agent pattern: receive QIDs from a SPARQL query, then humanize them.

输入参数ids必填languages

wikidata_get_statements

Get Wikidata Statements

Fetch property claims for a Wikidata entity with qualifier and reference detail. Item QIDs and quantity units — in values, qualifiers, and references — are resolved to human-readable labels by default. Use the properties parameter to fetch only specific P-IDs — omitting it returns every statement, and a well-connected item (a country, a major city) carries hundreds of properties: more than fits inline. A set over 24,000 bytes before labels comes back as kind: "outline" — every available P-ID with its byte size, largest first — instead of the statements; re-call with the same id plus properties:[...] naming P-IDs whose sizes sum to 24,000 or less (the retrieval_notice names one such set). Labels are added after that check, so a returned set can run past 24,000 bytes by their size, and a property requested alone is always returned whole — on a major item one property can run to hundreds of kilobytes. Designed for fact verification: "what does Wikidata say about this entity's {property}?". Preferred rank marks the favored statements for a property; check qualifiers and references for temporal scope and evidence.

输入参数id必填languagepropertiesresolve_labels

wikidata_sparql_query

Wikidata SPARQL Query

Execute a SPARQL SELECT query against the Wikidata Query Service. Full graph power: multi-hop traversals, aggregations, subqueries, OPTIONAL, FILTER, UNION, BIND. Standard Wikidata prefixes (wd:, wdt:, p:, ps:, pq:, wikibase:, bd:, rdfs:, schema:) are auto-injected. The wikibase:label SERVICE is also auto-injected when the query references a ?<var>Label, ?<var>Description, or ?<var>AltLabel variable and declares no label SERVICE of its own — so you can use ?itemLabel without writing the boilerplate. Hard server timeout is 60s; use LIMIT to keep queries fast. Bindings use the SPARQL 1.1 JSON format: each value is { type, value, "xml:lang"?, datatype? }. Each response is held to 64,000 bytes, cut between whole rows: a larger result returns its leading rows with returnedCount and totalCount and a notice — page with ORDER BY plus LIMIT/OFFSET, or aggregate in the query. Use wikidata_get_labels to humanize QID results from this tool.

输入参数query必填timeoutlanguage

wikidata_resolve_external_id

Resolve Wikidata External ID

Look up a Wikidata entity by an external identifier such as a DOI, PubMed ID, ORCID iD, or OpenAlex ID. Returns match=<entity> on success, match=null when not found, and match=null with multipleMatches populated when a Wikidata data integrity issue causes more than one entity to claim the same external ID. Common cross-server join use cases: CrossRef DOI → Wikidata paper QID (P356), PubMed PMID → Wikidata paper QID (P698), ORCID → author QID (P496), OpenAlex ID → entity QID (P10283). The property must be one whose Wikidata data type is external-id — item-valued or media properties (e.g. P31 instance-of, P18 image) are rejected rather than returning an empty match. Known value normalization is applied automatically: surrounding whitespace is trimmed, identifier-resolver URL prefixes are stripped (https://doi.org/, https://pubmed.ncbi.nlm.nih.gov/, https://orcid.org/), DOIs are uppercased, PMID prefixes stripped, ORCID hyphens normalized.

输入参数value必填languageproperty必填

版本历史

6
  1. v0.3.0最新Oct 29, 2026
  2. v0.2.1Oct 25, 2026
  3. v0.2.0Oct 13, 2026
  4. v0.1.20Oct 9, 2026
  5. v0.1.19Sep 20, 2026
  6. v0.1.18Sep 16, 2026

评分

已满足适用检查项的 100%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通必需25 分
  • 已声明认证方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分