Skip to main content
Glama

Wikidata SPARQL Query

wikidata_sparql_query
Read-only

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 ?Label, ?Description, or ?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

NameRequiredDescriptionDefault
queryYesSPARQL 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
timeoutNoClient-side timeout in seconds (1–55). Capped at 55s — the Wikidata server hard limit is 60s.
languageNoWikidata 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

NameRequiredDescriptionDefault
errorNoPresent when the call failed. Absent on success.
noticeNoPresent 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).
resultsNoResult 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.
truncatedNoTrue 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.
variablesNoVariable names returned by the SELECT clause.
totalCountNoNumber of rows the query produced, before any response-budget cut.
returnedCountNoNumber of rows in results — fewer than totalCount when the 64,000-byte response budget cut the result.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed10 schema fields changed
    • changedInput schema / properties / language / description
      Previous value: -"Language for the wikibase:label SERVICE (e.g., \"en\", \"de\"). Controls the language of ?<var>Label variables. Set to \"\" to suppress label SERVICE injection."New value: +"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\"."
    • addedInput schema / properties / language / pattern
      Added value: +"^\\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*)?$"
    • changedInput schema / properties / query / description
      Previous value: -"SPARQL SELECT query. Must be a SELECT query (not CONSTRUCT/DESCRIBE/ASK). Standard prefixes (wd:, wdt:, p:, ps:, pq:, wikibase:, bd:) are injected automatically. Example: SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146. } LIMIT 10"New value: +"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"
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `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."New value: +"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."
    • changedOutput schema / properties / error / properties / data / properties / reason / examples
      Previous value: -[
      -  "parse_error",
      -  "timeout",
      -  "throttled"
      -]New value: +[
      +  "not_select_query",
      +  "parse_error",
      +  "timeout",
      +  "throttled"
      +]
    • changedOutput schema / properties / notice / description
      Previous value: -"Recovery hint when no results returned — suggests checking query logic or broadening filters. Absent on non-empty results."New value: +"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)."
    • changedOutput schema / properties / results / description
      Previous value: -"Array of result bindings. Each row maps variable names to binding objects with { type, value, \"xml:lang\"?, datatype? } fields."New value: +"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."
    • addedOutput schema / properties / returnedCount
      Added value: +{
      +  "description": "Number of rows in results — fewer than totalCount when the 64,000-byte response budget cut the result.",
      +  "type": "number"
      +}
    • changedOutput schema / properties / totalCount / description
      Previous value: -"Number of result rows returned."New value: +"Number of rows the query produced, before any response-budget cut."
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when the row count equals 10,000 — the Wikidata/Blazegraph server-side cap — indicating the result set was likely truncated. False otherwise. Add a LIMIT clause to avoid hitting the cap. Note: the SPARQL endpoint does not expose an explicit truncation flag; this is an inferred signal."New value: +"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."
  2. Changed6 schema fields changed
    • changedInput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedInput schema / additionalProperties
      Added value: +false
    • changedOutput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedOutput schema / anyOf
      Added value: +[
      +  {
      +    "not": {
      +      "required": [
      +        "error"
      +      ]
      +    },
      +    "required": [
      +      "results",
      +      "variables",
      +      "truncated",
      +      "totalCount"
      +    ]
      +  },
      +  {
      +    "required": [
      +      "error"
      +    ]
      +  }
      +]
    • addedOutput schema / properties / error
      Added value: +{
      +  "additionalProperties": {},
      +  "description": "Present when the call failed. Absent on success.",
      +  "properties": {
      +    "code": {
      +      "description": "JSON-RPC error code for this failure.",
      +      "maximum": 9007199254740991,
      +      "minimum": -9007199254740991,
      +      "type": "integer"
      +    },
      +    "data": {
      +      "additionalProperties": {},
      +      "properties": {
      +        "reason": {
      +          "description": "Machine-readable failure mode. Declared by this tool: `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": [
      +            "parse_error",
      +            "timeout",
      +            "throttled"
      +          ],
      +          "type": "string"
      +        },
      +        "recovery": {
      +          "additionalProperties": {},
      +          "description": "Actionable next step for the caller.",
      +          "properties": {
      +            "hint": {
      +              "type": "string"
      +            }
      +          },
      +          "required": [
      +            "hint"
      +          ],
      +          "type": "object"
      +        },
      +        "retryable": {
      +          "description": "Whether retrying may succeed.",
      +          "type": "boolean"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "message": {
      +      "description": "Human-readable description of what went wrong.",
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "code",
      +    "message"
      +  ],
      +  "type": "object"
      +}
    • removedOutput schema / required
      Removed value: -[
      -  "results",
      -  "variables",
      -  "truncated",
      -  "totalCount"
      -]
  3. Changed1 schema field changed
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when the endpoint returned a partial result set due to server-side memory limits. False when the full result was returned. Add a LIMIT clause to avoid truncation on large queries."New value: +"True when the row count equals 10,000 — the Wikidata/Blazegraph server-side cap — indicating the result set was likely truncated. False otherwise. Add a LIMIT clause to avoid hitting the cap. Note: the SPARQL endpoint does not expose an explicit truncation flag; this is an inferred signal."
  4. Changed4 schema fields changed
    • addedOutput schema / properties / notice
      Added value: +{
      +  "description": "Recovery hint when no results returned — suggests checking query logic or broadening filters. Absent on non-empty results.",
      +  "type": "string"
      +}
    • removedOutput schema / properties / rowCount
      Removed value: -{
      -  "description": "Number of result rows.",
      -  "type": "number"
      -}
    • addedOutput schema / properties / totalCount
      Added value: +{
      +  "description": "Number of result rows returned.",
      +  "type": "number"
      +}
    • changedOutput schema / required
      Previous value: -[
      -  "results",
      -  "variables",
      -  "rowCount",
      -  "truncated"
      -]New value: +[
      +  "results",
      +  "variables",
      +  "truncated",
      +  "totalCount"
      +]
  5. First observed

TDQS

A4.4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only assert readOnly and openWorld; the description goes well beyond them by disclosing auto-injected prefixes, conditional wikibase:label SERVICE injection rules, a 60s server hard timeout, and the 64,000-byte response cap with its truncation contract (whole rows, returnedCount/totalCount, notice). This is exactly the behavioral detail an agent needs to avoid surprising failures.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the purpose and capability envelope, then constraints and pagination, then the pointer to wikidata_get_labels. Dense and mostly waste-free, though the label-SERVICE injection sentence is long and the response-format sentence borders on output-schema territory.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex, high-variance tool this covers the failure modes an agent would otherwise discover by trial: rejected non-SELECT forms, timeout ceiling, truncation and how to page, and an output schema exists to carry the return contract. Nothing material is missing for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% and all three parameters are documented in the schema, so the baseline is 3. The description largely restates that documentation (prefix injection, 60s cap, label language) rather than adding new syntax or format semantics, so it does not clearly exceed the schema's contribution.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Execute a SPARQL SELECT query against the Wikidata Query Service') and immediately scopes it against its siblings by naming the kind of work only this tool does (multi-hop traversal, aggregation, subqueries). An agent can distinguish it from wikidata_get_entity or wikidata_get_statements without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete usage direction ('use LIMIT to keep queries fast', page with ORDER BY plus LIMIT/OFFSET, and 'Use wikidata_get_labels to humanize QID results from this tool'), which explicitly routes one downstream task to a sibling. It stops short of stating when NOT to reach for SPARQL versus the simpler sibling tools (get_entity, get_statements), so the exclusion side is inferred rather than declared.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.