Powered by Zoomin Software. For more details please contactZoomin

MarkLogic MCP Server

Retrieve SPARQL endpoint

  • Last Updated: December 3, 2026
  • 3 minute read
    • Documentation

The POST /v1/retrieve/sparql endpoint executes one read-only SPARQL SELECT or ASK query in the calling identity's MarkLogic Server security context. It returns SPARQL 1.1 Query Results JSON.

Overview

Use the Retrieve SPARQL metadata endpoint to discover visible prefixes and graph IRIs before constructing a query. Query results contain only data that the calling identity can read.

The endpoint executes sem.sparql() and does not execute SPARQL Update.

Basic usage

This example submits a query directly to MarkLogic Retrieval API (MRA):

curl --digest -u "<ML_USER>:<ML_PASSWORD>" -H "Content-Type: application/json" -X POST "http://<ML_HOST>:<REST_PORT>/v1/retrieve/sparql" -d '{"query":"SELECT (1 AS ?one) WHERE {}"}'

Request parameters

The request body must be a JSON object with exactly one field, query. Its value must be a non-empty string containing one complete query.

The endpoint supports SELECT and ASK, optionally preceded by PREFIX or BASE. Use FROM or GRAPH in the query to scope graphs. Separate bindings and graph-scope request parameters are not supported.

The endpoint parses the complete query before execution. SPARQL comments, declarations, literals, IRIs, and valid semicolons within SPARQL syntax are supported. Do not send a trailing statement terminator or multiple queries. The endpoint rejects malformed queries, multiple queries, CONSTRUCT, DESCRIBE, and all SPARQL Update forms, including INSERT, DELETE, LOAD, CLEAR, CREATE, DROP, COPY, MOVE, and ADD.

The endpoint does not impose a query-character limit. MarkLogic Server or transport limits may still apply.

These examples show valid and invalid query forms:

Query Result
SELECT (1 AS ?one) WHERE {} Accepted
ASK {} Accepted
PREFIX ex: <urn:example:> SELECT ?s WHERE { ?s ?p ?o } Accepted
A query with a legal semicolon-separated property list Accepted
CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o } Rejected because the query form is not supported
DELETE WHERE { ?s ?p ?o } Rejected because SPARQL Update is not supported
SELECT * {} ASK {} Rejected because the request contains multiple queries

Response format

SELECT success response

HTTP status: 200 OK

This example shows a representative response. The binding values depend on the query and the caller's permissions:

{
  "head": { "vars": ["one"] },
  "results": {
    "bindings": [
      {
        "one": {
          "type": "literal",
          "value": "1",
          "datatype": "http://www.w3.org/2001/XMLSchema#integer"
        }
      }
    ]
  },
  "maxRows": 500
}

ASK success response

An ASK response contains head and a boolean boolean field. It does not contain maxRows or truncated.

Row limit and truncation

The endpoint returns at most sparqlQueryMaxRows solutions for a SELECT query. The default is 500. Set this property in retrieveConfig.json. The property must be a positive safe integer; otherwise, the endpoint uses 500.

The response always includes maxRows. It includes truncated: true only when an additional solution exists beyond the limit. The endpoint does not return a total-result count. The row limit does not bound query cost for joins, sorting, or aggregation.

Error responses

The endpoint returns HTTP errors for invalid requests, authorization failures, and MarkLogic Server failures. This table summarizes the documented outcomes:

Status Cause
400 The body is invalid, the query is empty or malformed, the request has extra fields, or the query form is unsupported.
401 MarkLogic Server credentials are missing or invalid, or the MCP request has no required bearer token.
403 The identity lacks the SPARQL privilege required by the endpoint.
404 An MRA endpoint module is unavailable to the caller or is not deployed.
405 The HTTP method is not allowed.
500 An unexpected MarkLogic Server-side failure occurred.
504 MarkLogic Server recognized a MarkLogic REST app server execution timeout or cancellation.

See SPARQL tool issues in "Troubleshoot MarkLogic MCP Server" for remedies.

Alert