Powered by Zoomin Software. For more details please contactZoomin

MarkLogic MCP Server

Retrieve SQL endpoint

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

The POST /v1/retrieve/sql endpoint runs one read-only SQL query against MarkLogic Server and returns the result as columns and rows. The query runs in the security context of the calling user, so the result contains only data that the user is authorized to see.

Overview

The SQL endpoint queries existing Template Driven Extraction (TDE) views in your database. It does not create or maintain them.

Call the Retrieve SQL Metadata endpoint first to discover the schema, table, and column names that you can query.

The endpoint requires the mra-sql role, which includes the mra-reader role. A user who has mra-reader without mra-sql receives a 403 response.

Basic usage

This example submits a query:

curl -X POST http://localhost:8003/v1/retrieve/sql \
  -H "Content-Type: application/json" \
  --digest -u <username>:<password> \
  -d '{
    "query": "SELECT name FROM sys_tables ORDER BY name"
  }'

A HEAD request to the same path checks whether the endpoint is available.

Parameters

query (string)

Required. A single read-only SQL statement.

The query must meet these requirements:

  • Start with SELECT or WITH
  • Contain one statement, with no semicolon outside quoted text, including a trailing semicolon
  • Contain no SQL comments (-- or /* */)
  • Contain no write or administrative keywords, even inside a string literal: INSERT, UPDATE, DELETE, MERGE, UPSERT, CREATE, DROP, ALTER, TRUNCATE, GRANT, or REVOKE
  • Contain no script-injection content, such as javascript, xquery, declare, import module, xdmp:, fn:, eval(, or invoke(
  • Produce unique result column names; use AS aliases when joined tables share column names
  • Contain 10,000 characters or fewer

The endpoint rejects a request body that has any other field, a query value that is not a string, and an empty query.

These examples show valid and invalid queries:

Query Result
SELECT 1 AS one Accepted
SELECT 'a;b' AS value Accepted, because the semicolon is inside a string literal
SELECT name FROM sys_tables; Rejected because of the trailing semicolon
SELECT 1 -- comment Rejected because it contains a comment
SELECT 'update' AS note Rejected because it contains a prohibited keyword
DELETE FROM sys_tables Rejected because it is a write statement

Response format

Success response

HTTP status: 200 OK

This table describes the fields in the response:

Field Type Description
columns array of strings Column names in result order
rows array of objects Result rows, each keyed by column name
rowCount integer Number of rows in this response
maxRows integer Effective row cap for the response
truncated boolean Present and true when the result was capped at maxRows

This example shows a response:

{
  "columns": ["name"],
  "rows": [
    { "name": "Orders" },
    { "name": "Customers" }
  ],
  "rowCount": 2,
  "maxRows": 500
}

Row limit and truncation

The endpoint returns at most sqlQueryMaxRows rows. The default is 500. You can change the limit in retrieveConfig.json.

When the result exceeds the limit, the response contains only the number of rows specified in sqlQueryMaxRows and sets truncated to true. To reduce the result's row count, narrow the query with a WHERE clause or use aggregates. To get an exact total, run a COUNT(*) query.

The limit caps the number of rows that the endpoint returns, not the length or computational cost of the query. The endpoint does not support pagination.

Error responses

Error responses that the endpoint formats use this format:

{
  "errorResponse": {
    "statusCode": 400,
    "status": "Bad Request",
    "message": "Invalid parameter format"
  }
}

Authentication and MarkLogic Server-level failures can use the MarkLogic Server error format instead.

This table lists the status codes that this endpoint returns:

Status Message Meaning
400
  • Invalid parameter format
  • Only a single SQL statement is allowed; semicolons are not permitted
  • Only read-only SQL queries are allowed; write/admin statements are not supported
  • Only plain read-only SQL queries starting with SELECT or WITH are supported
  • Query contains unsupported or potentially unsafe content
  • Query produced duplicate result column name(s): <name>. Use unique column aliases.
  • Query produced ambiguous result columns. Use unique column aliases for all selected fields.
  • Underlying MarkLogic Server SQL syntax error message; varies by query
The query is invalid, malformed, or unsupported
401 Varies by authentication failure Authentication is required
403 Caller is not authorized to execute SQL queries. The mra-sql role is required. The caller does not have SQL execute privilege
404 Varies by module-loading error The endpoint module cannot be loaded
405 Method <method> is not supported The HTTP method is not allowed
500 Varies by MarkLogic Server error A MarkLogic Server error occurred

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

This example shows the response for a query that contains an unquoted semicolon:

{
  "errorResponse": {
    "statusCode": 400,
    "status": "Bad Request",
    "message": "Only a single SQL statement is allowed; semicolons are not permitted"
  }
}
Alert