Wikidata SPARQL Query
wikidata_sparql_queryExecute 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 ?Label, ?Description, or ?AltLabel variable and declares no label SERVICE of its own — so you can use ?itemLabel without writing the boilerplate. Scholarly articles, and every triple they own (DOI, PMID, authorship), live in a separate graph reachable only inside SERVICE wdsubgraph:scholarly_articles { … } (wdsubgraph: is predeclared). The injected label SERVICE runs on the main graph, so read a scholarly article's label inside that block, with BIND(?paperLabel AS ?paperLabel) and a label SERVICE there; a query that writes a label SERVICE gets none injected, so add a top-level one for main-graph labels. Hard server timeout is 60s; use LIMIT to keep queries fast. Each call returns at most 4,000 rows; a larger result returns its first rows with truncated, shown, and cap in place of totalCount — narrow the WHERE clause or aggregate in the query, or, for a result not much larger than that, page with ORDER BY plus LIMIT and OFFSET. Bindings use the SPARQL 1.1 JSON format: each value is { type, value, "xml:lang"?, datatype? }. Use wikidata_get_labels to humanize QID results from this tool.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"query": "<query>"
},
"name": "wikidata_sparql_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 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 | |
| timeout | No | Client-side timeout in seconds (1–55). Capped at 55s — the Wikidata server hard limit is 60s. | |
| language | No | 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". | en |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cap | No | The row ceiling that truncated the result. | |
| error | No | Present when the call failed. Absent on success. | |
| shown | No | Number of rows returned when truncated. | |
| notice | No | Present when truncated (how to page or aggregate for the rest) or when no rows matched (where else to look). | |
| results | No | Result bindings in query order: every row, or the first 4,000 when the result has more (truncated). Each row maps variable names to binding objects with { type, value, "xml:lang"?, datatype? } fields. | |
| truncated | No | True when the result had more than 4,000 rows: only the first 4,000 were read and returned. | |
| variables | No | Variable names returned by the SELECT clause. | |
| totalCount | No | Number of rows the query produced. Present only when the whole result was read: absent when truncated. |