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

TableJSON 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

TableJSON 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

Score is being calculated.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.