wikidata-mcp-server
Search and fetch Wikidata entities, execute SPARQL queries, and resolve external identifiers.
Should I use this
Quality & Safety
Findings (2)
- HIGH
- MEDIUMin wikidata_resolve_external_id
Based on automated analysis of tool definitions and protocol compliance.
Context Cost
This is the approximate number of tokens consumed each time the server's tools are loaded into a model's context. Higher counts reduce the attention available for other tasks.
Install
One-Click Install
Add this to your `claude_desktop_config.json` file:
{
"mcpServers": {
"wikidata-mcp-server": {
"command": "npx",
"args": [
"@cyanheads/wikidata-mcp-server"
]
}
}
}Runnable packages
0.3.0streamable-httpRemote endpoints
https://wikidata.caseyjhand.com/mcpstreamable-httpWhat it can do
Tool inventory
Tools (7)
🟢wikidata_search_entities(query, type, language, limit, offset)
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.
Input Schema
{
"type": "object",
"properties": {
"query": {
"type": "string",
"minLength": 1,
"description": "Search terms to match against entity labels, aliases, and descriptions."
},
"type": {
"default": "item",
"description": "Entity type to search. Use \"item\" for Q-IDs (people, places, concepts) or \"property\" for P-IDs (predicates).",
"type": "string",
"enum": [
"item",
"property"
]
},
"language": {
"default": "en",
"description": "Wikidata language code for returned labels and descriptions (e.g., \"en\", \"de\", \"zh-hant\"). Case-insensitive; \"_\" is read as \"-\"; blank means \"en\".",
"type": "string",
"pattern": "^\\s*(?:[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*\\s*)?$"
},
"limit": {
"default": 10,
"description": "Maximum number of results to return. Range: 1–50.",
"type": "integer",
"minimum": 1,
"maximum": 50
},
"offset": {
"default": 0,
"description": "Pagination offset. Start at 0; increment by limit to page through results.",
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"query"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Q-ID (e.g., \"Q76\") or P-ID (e.g., \"P31\") of the entity."
},
"label": {
"type": "string",
"description": "Display label in the requested language, or empty string if unavailable."
},
"description": {
"type": "string",
"description": "Short description in the requested language, or empty string if unavailable."
},
"match": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "Match type: \"label\" for a direct label hit, \"alias\" for an alias hit."
},
"language": {
"type": "string",
"description": "Language of the matched string."
}
},
"required": [
"type",
"language"
],
"additionalProperties": false,
"description": "Metadata about how this result matched the query."
}
},
"required": [
"id",
"label",
"description",
"match"
],
"additionalProperties": false,
"description": "A single search result with entity ID, label, description, and match metadata."
},
"description": "Ranked list of matching entities. Empty when no results found."
},
"effectiveQuery": {
"type": "string",
"description": "The search query that was executed."
},
"searchType": {
"type": "string",
"description": "The entity type that was searched (\"item\" or \"property\")."
},
"language": {
"type": "string",
"description": "The language used for label and description display."
},
"shown": {
"type": "number",
"description": "Number of results returned on this page."
},
"cap": {
"type": "number",
"description": "The limit parameter in effect."
},
"truncated": {
"description": "True when results were capped at the limit. The Wikidata search API returns no total count — use offset pagination to retrieve more.",
"type": "boolean"
},
"notice": {
"description": "Recovery hint when results are empty — echoes filters and suggests how to broaden. Absent when results are present.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `invalid_search_parameter`: The search endpoint refused a request parameter, in practice a language it does not search in such as \"mul\". Other values are possible when a failure originates below the handler.",
"examples": [
"invalid_search_parameter"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"results",
"effectiveQuery",
"searchType",
"language",
"shown",
"cap"
]
},
{
"required": [
"error"
]
}
]
}🟢wikidata_get_entity(id, fields, languages)
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.
Input Schema
{
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 1,
"description": "Q-ID (e.g., \"Q76\") or P-ID (e.g., \"P31\"). Case-insensitive — normalized to uppercase."
},
"fields": {
"description": "Fields to include. Options: \"labels\", \"descriptions\", \"aliases\", \"statements\", \"sitelinks\". Narrows the upstream fetch as well as the response, so a narrow selection is markedly cheaper. Omit for all fields.",
"type": "array",
"items": {
"type": "string",
"enum": [
"labels",
"descriptions",
"aliases",
"statements",
"sitelinks"
]
}
},
"languages": {
"description": "Wikidata language codes to include in labels, descriptions, and aliases (e.g., [\"en\", \"de\"]). Case-insensitive; \"_\" is read as \"-\"; blank entries are dropped. A requested language with no label of its own falls back to the entity's multilingual (\"mul\") value, returned under the requested code. Omit, or send an empty list, to return all available languages.",
"type": "array",
"items": {
"type": "string",
"pattern": "^\\s*(?:[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*\\s*)?$"
}
}
},
"required": [
"id"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Normalized entity ID (e.g., \"Q76\" or \"P31\")."
},
"type": {
"type": "string",
"description": "Entity type: \"item\" or \"property\"."
},
"kind": {
"type": "string",
"enum": [
"full",
"outline"
],
"description": "full — the requested field categories carry their data. outline — the entity overflowed the inline byte budget, so sections lists the categories with their byte sizes instead, and retrieval_notice names how to fetch each one. The id and type are present either way."
},
"data_type": {
"description": "Property data type (e.g., \"wikibase-item\", \"external-id\"). Present on properties only.",
"type": "string"
},
"labels": {
"description": "Map of language code to label string (e.g., {\"en\": \"Barack Obama\", \"de\": \"Barack Obama\"}).",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string"
}
},
"descriptions": {
"description": "Map of language code to description string (e.g., {\"en\": \"44th President of the United States\"}).",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string"
}
},
"aliases": {
"description": "Map of language code to list of alias strings (e.g., {\"en\": [\"Barack H. Obama\", \"President Obama\"]}).",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
"statements": {
"description": "Map of property ID to array of raw statement objects. Use wikidata_get_statements for resolved claims with label resolution, and whenever this entity's statements are large — its properties parameter selects individual P-IDs, granularity fields does not carry.",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {},
"additionalProperties": {}
}
}
},
"sitelinks": {
"description": "Map of site code (e.g., \"enwiki\") to sitelink metadata with title, url, and badges fields.",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "object",
"properties": {},
"additionalProperties": {}
}
},
"fieldsReturned": {
"type": "array",
"items": {
"type": "string"
},
"description": "Which fields were requested. In outline mode these are the categories the outline covers, not data returned."
},
"sections": {
"description": "Present when kind = outline: the entity's field categories, largest first, each with its byte size. Sizes are additive — a set of categories is only retrievable together if their total fits the budget, so follow retrieval_notice rather than requesting every name listed here.",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Section identifier — pass in `sections` to retrieve it"
},
"bytes": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991,
"description": "Serialized byte size of the section"
}
},
"required": [
"name",
"bytes"
],
"additionalProperties": false,
"description": "An available field category — its name and the serialized byte size of its data."
}
},
"retrieval_notice": {
"description": "Present when kind = outline: the next call to make, and the authoritative one to follow. It names a literal fields set already measured to fit the budget, defers any category that would not fit alongside it, and for a category too large for fields to deliver at all names the sibling tool (wikidata_get_statements, wikidata_get_sitelinks) or the languages parameter that can narrow it.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `entity_not_found`: No entity exists at this ID — either unassigned (resource-not-found) or out of range (invalid-path-parameter). `invalid_id`: ID format is not recognized as a Q-ID or P-ID. Other values are possible when a failure originates below the handler.",
"examples": [
"entity_not_found",
"invalid_id"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"id",
"type",
"kind",
"fieldsReturned"
]
},
{
"required": [
"error"
]
}
]
}🟢wikidata_get_labels(ids, languages)
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.
Input Schema
{
"type": "object",
"properties": {
"ids": {
"minItems": 1,
"maxItems": 50,
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"description": "Q-IDs (e.g., \"Q76\") or P-IDs (e.g., \"P31\") to resolve. 1–50 IDs per call."
},
"languages": {
"default": [
"en"
],
"description": "Wikidata language codes for returned labels and descriptions (e.g., [\"en\", \"de\", \"fr\"]). Case-insensitive; \"_\" is read as \"-\"; blank entries are dropped, and an empty list means [\"en\"]. A language with no label of its own falls back to the entity's multilingual (\"mul\") value, returned under the requested code.",
"type": "array",
"items": {
"type": "string",
"pattern": "^\\s*(?:[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*\\s*)?$"
}
}
},
"required": [
"ids"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"entities": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "object",
"properties": {
"labels": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string"
},
"description": "Map of language code to label string. Keys match the requested languages that have data."
},
"descriptions": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string"
},
"description": "Map of language code to description string. Keys match the requested languages that have data."
}
},
"required": [
"labels",
"descriptions"
],
"additionalProperties": false
},
"description": "Map of entity ID to labels and descriptions. IDs that were not found are absent."
},
"found": {
"type": "number",
"description": "Count of IDs that returned data."
},
"notFound": {
"type": "array",
"items": {
"type": "string"
},
"description": "IDs from the request that did not return data (not found or invalid)."
},
"languages": {
"type": "array",
"items": {
"type": "string"
},
"description": "The language codes that were requested."
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `invalid_ids`: One or more IDs in the array are not valid Q-IDs or P-IDs. Other values are possible when a failure originates below the handler.",
"examples": [
"invalid_ids"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"entities",
"found",
"notFound",
"languages"
]
},
{
"required": [
"error"
]
}
]
}🟢wikidata_get_statements(id, properties, language, resolve_labels)
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 statements are the most current values.
Input Schema
{
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 1,
"description": "Q-ID (e.g., \"Q76\") or P-ID of the entity to fetch statements for."
},
"properties": {
"description": "P-IDs to fetch (e.g., [\"P31\", \"P569\", \"P27\"]). Omit to return all properties (may be large for major items).",
"type": "array",
"items": {
"type": "string",
"minLength": 1
}
},
"language": {
"default": "en",
"description": "Wikidata language code for label resolution of QID values (e.g., \"en\", \"de\"). Case-insensitive; \"_\" is read as \"-\"; blank means \"en\".",
"type": "string",
"pattern": "^\\s*(?:[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*\\s*)?$"
},
"resolve_labels": {
"default": true,
"description": "Resolve item QIDs (label) and quantity unit QIDs (unitLabel) to human-readable labels via one batched label call, covering main values, qualifiers, and reference parts. Set to false to skip label resolution and return raw QIDs only (faster, smaller payload).",
"type": "boolean"
}
},
"required": [
"id"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The entity ID whose statements were fetched."
},
"kind": {
"type": "string",
"enum": [
"full",
"outline"
],
"description": "full — statements carries the claims. outline — the statement set overflowed the inline byte budget, so sections lists the P-IDs available instead; re-call with properties:[...] to retrieve specific ones. The counts below are reported either way."
},
"statements": {
"description": "Map of property ID to array of normalized statements. Each statement has id, rank, property, value (with type-specific fields), optional qualifiers ([{ property, value }]), and optional references — one entry per source in upstream order, each { parts: [{ property, value }] }. Present in full mode; omitted in outline mode.",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {},
"additionalProperties": {}
}
}
},
"sections": {
"description": "Present when kind = outline: the P-IDs this entity carries statements for, largest first, each sized as the UTF-8 bytes it adds to a response before labels. Sizes add up: copy names whose sizes sum to 24,000 or less into the properties input to retrieve them.",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Section identifier — pass in `sections` to retrieve it"
},
"bytes": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991,
"description": "Serialized byte size of the section"
}
},
"required": [
"name",
"bytes"
],
"additionalProperties": false,
"description": "An available property — its P-ID and the serialized byte size of its statements."
}
},
"retrieval_notice": {
"description": "Present when kind = outline: how to re-call for specific properties.",
"type": "string"
},
"propertyCount": {
"type": "number",
"description": "Number of distinct properties — those returned in full mode, those offered as sections in outline mode."
},
"statementCount": {
"type": "number",
"description": "Total number of statement objects across all properties. Counted before any overflow, so it reports the entity's full statement volume in both modes."
},
"labelsResolved": {
"type": "boolean",
"description": "True when the returned statements had labels resolved: resolve_labels was true and kind is full, so every item QID and quantity unit that resolved carries its label. False when resolve_labels was false, and on an outline, which carries no statements and makes no label lookup."
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `entity_not_found`: No entity exists at this ID — either unassigned or out of range. `invalid_id`: ID is not a valid Q-ID or P-ID format. `invalid_property`: A properties entry is not a valid P-ID format. Other values are possible when a failure originates below the handler.",
"examples": [
"entity_not_found",
"invalid_id",
"invalid_property"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"id",
"kind",
"propertyCount",
"statementCount",
"labelsResolved"
]
},
{
"required": [
"error"
]
}
]
}🟢wikidata_get_sitelinks(id, sites, wikis_only)
Fetch Wikipedia and Wikimedia project article URLs for a Wikidata item. A sitelink maps a site code (e.g., "enwiki") to a Wikipedia article title and URL. Major items can have 300+ sitelinks across languages. Use sites to filter to specific language editions, or wikis_only to return only Wikipedia links. Only Q-IDs (items) have sitelinks — properties (P-IDs) do not.
Input Schema
{
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 1,
"description": "Q-ID of the item (e.g., \"Q76\"). Only items have sitelinks; properties (P-IDs) are not supported."
},
"sites": {
"description": "Optional filter to specific site codes (e.g., [\"enwiki\", \"frwiki\", \"dewiki\"]). Omit to return all sitelinks.",
"type": "array",
"items": {
"type": "string",
"minLength": 1
}
},
"wikis_only": {
"default": false,
"description": "When true, return only Wikipedia sitelinks (site codes ending in \"wiki\", e.g., \"enwiki\", \"dewiki\"). Excludes Wikisource, Wiktionary, Wikiquote, etc.",
"type": "boolean"
}
},
"required": [
"id"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The Q-ID whose sitelinks were fetched."
},
"sitelinks": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Article title on that wiki."
},
"url": {
"description": "Full URL to the article. Omitted when unavailable.",
"type": "string"
},
"badges": {
"description": "Quality badge QIDs (e.g., \"Q17437798\" = featured article).",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"title"
],
"additionalProperties": false
},
"description": "Map of site code to sitelink metadata. Empty when the entity has no matching sitelinks."
},
"count": {
"type": "number",
"description": "Number of sitelinks returned."
},
"message": {
"description": "Informational note when no sitelinks were found. Absent when sitelinks are present.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `entity_not_found`: No item exists at this Q-ID — either unassigned or out of range. `not_an_item`: A P-ID was supplied — only items (Q-IDs) have sitelinks. Other values are possible when a failure originates below the handler.",
"examples": [
"entity_not_found",
"not_an_item"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"id",
"sitelinks",
"count"
]
},
{
"required": [
"error"
]
}
]
}🟢wikidata_sparql_query(query, language, timeout)
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.
Input Schema
{
"type": "object",
"properties": {
"query": {
"type": "string",
"minLength": 1,
"description": "SPARQL SELECT query. Any other form — ASK, CONSTRUCT, DESCRIBE, an update, or plain search text — is rejected before it is sent. Standard prefixes (wd:, wdt:, p:, ps:, pq:, wikibase:, bd:, rdfs:, schema:) are injected automatically. Example: SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146. } LIMIT 10"
},
"language": {
"default": "en",
"description": "Wikidata language code, or a comma-separated fallback list tried in order (e.g., \"en\", \"de\", \"fr,en\"), for the injected wikibase:label SERVICE — the language of ?<var>Label, ?<var>Description, and ?<var>AltLabel variables. The list falls back to the multilingual (\"mul\") label last unless it already names mul. Case-insensitive; \"_\" is read as \"-\"; blank means \"en\".",
"type": "string",
"pattern": "^\\s*(?:[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*(?:\\s*,\\s*[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*)*\\s*)?$"
},
"timeout": {
"default": 30,
"description": "Client-side timeout in seconds (1–55). Capped at 55s — the Wikidata server hard limit is 60s.",
"type": "integer",
"minimum": 1,
"maximum": 55
}
},
"required": [
"query"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "object",
"properties": {},
"additionalProperties": {}
}
},
"description": "Result bindings: every row when the result fits the 64,000-byte response budget, otherwise the leading rows that fit (returnedCount of totalCount). Each row maps variable names to binding objects with { type, value, \"xml:lang\"?, datatype? } fields."
},
"variables": {
"type": "array",
"items": {
"type": "string"
},
"description": "Variable names returned by the SELECT clause."
},
"truncated": {
"type": "boolean",
"description": "True when the query produced 10,000 rows (totalCount) — the Wikidata/Blazegraph server-side cap — indicating the result set was likely truncated upstream. False otherwise. Add a LIMIT clause to avoid hitting the cap. Independent of the response-budget cut, which returnedCount reports. Note: the SPARQL endpoint does not expose an explicit truncation flag; this is an inferred signal."
},
"totalCount": {
"type": "number",
"description": "Number of rows the query produced, before any response-budget cut."
},
"returnedCount": {
"description": "Number of rows in results — fewer than totalCount when the 64,000-byte response budget cut the result.",
"type": "number"
},
"notice": {
"description": "Present when the result was cut to fit the response budget (how to page or aggregate for the rest), or when no rows matched (check query logic or broaden filters).",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `not_select_query`: The query is not a SELECT query: an ASK, CONSTRUCT, DESCRIBE, or update form, or plain text. `parse_error`: SPARQL syntax error — the query could not be parsed. `timeout`: Query exceeded the client-side timeout. `throttled`: Wikidata SPARQL endpoint is rate-limited (60 req/min, 5 concurrent per IP). Other values are possible when a failure originates below the handler.",
"examples": [
"not_select_query",
"parse_error",
"timeout",
"throttled"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"results",
"variables",
"truncated",
"totalCount"
]
},
{
"required": [
"error"
]
}
]
}🟢wikidata_resolve_external_id(property, value, language)
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.
Input Schema
{
"type": "object",
"properties": {
"property": {
"type": "string",
"minLength": 1,
"description": "P-ID of the external identifier property, whose Wikidata data type must be external-id (e.g., \"P356\" for DOI, \"P698\" for PubMed ID, \"P496\" for ORCID, \"P10283\" for OpenAlex ID, \"P345\" for IMDb ID). Properties of any other data type are rejected — check an unfamiliar P-ID's data type with wikidata_get_entity."
},
"value": {
"type": "string",
"minLength": 1,
"description": "The external identifier value to look up (e.g., \"10.1038/nature01234\" for a DOI, \"32283226\" for a PubMed ID, \"0000-0002-1825-0097\" for an ORCID). A resolver URL is accepted for DOI, PubMed, and ORCID — the prefix is stripped before lookup."
},
"language": {
"default": "en",
"description": "Wikidata language code for the label and description in the response (e.g., \"en\", \"de\"). Case-insensitive; \"_\" is read as \"-\"; blank means \"en\". An entity with no label in this language returns its multilingual (\"mul\") label.",
"type": "string",
"pattern": "^\\s*(?:[A-Za-z]{2,8}(?:[-_][A-Za-z0-9]{1,9})*\\s*)?$"
}
},
"required": [
"property",
"value"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Output Schema
{
"type": "object",
"properties": {
"match": {
"anyOf": [
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Wikidata Q-ID of the matching entity (e.g., \"Q12345\")."
},
"label": {
"type": "string",
"description": "Display label in the requested language, else the multilingual (\"mul\") label, or empty string if neither exists."
},
"description": {
"type": "string",
"description": "Short description in the requested language, or empty string if unavailable."
},
"url": {
"type": "string",
"description": "Wikidata entity page URL (e.g., \"https://www.wikidata.org/wiki/Q12345\")."
}
},
"required": [
"id",
"label",
"description",
"url"
],
"additionalProperties": false
},
{
"type": "null"
}
],
"description": "Matching entity, or null when no Wikidata entity claims this external identifier (including the case where multipleMatches is populated). A null match is not proof of absence — the Query Service backing this lookup lags the live wiki, so a recently added identifier may not be indexed yet."
},
"property": {
"type": "string",
"description": "The P-ID used for the lookup."
},
"value": {
"type": "string",
"description": "The normalized value that was searched (may differ from input due to canonicalization)."
},
"multipleMatches": {
"description": "Present when more than one Wikidata entity claims this external ID (data integrity issue). match is null when this field is present. Inspect the list and select the correct QID manually.",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Q-ID of a matching entity."
},
"label": {
"type": "string",
"description": "Display label of this match."
}
},
"required": [
"id",
"label"
],
"additionalProperties": false,
"description": "One of the entities that claims this external identifier."
}
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `invalid_property`: Property ID is not in P+digits format. `not_external_id_property`: Property does not exist on Wikidata, or its data type is not external-id. Other values are possible when a failure originates below the handler.",
"examples": [
"invalid_property",
"not_external_id_property"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"match",
"property",
"value"
]
},
{
"required": [
"error"
]
}
]
}Community
Evidence