Skip to main content

Module mcp

Module mcp 

Source
Expand description

Model Context Protocol (MCP) HTTP handlers.

Exposes Materialize data products to AI agents via JSON-RPC 2.0 over HTTP POST.

Β§Endpoints

  • /api/mcp/agents - User data products for customer AI agents
  • /api/mcp/observatory - System catalog (mz_*) for troubleshooting

Β§Tools

Agents: get_data_products, get_data_product_details, query Observatory: query_system_catalog

Data products are discovered via mz_internal.mz_mcp_data_products system view.

ModulesΒ§

error_codes πŸ”’
JSON-RPC 2.0 error codes.

StructsΒ§

Capabilities πŸ”’
ClientInfo πŸ”’
ContentBlock πŸ”’
GetDataProductDetailsParams πŸ”’
InitializeParams πŸ”’
InitializeResult πŸ”’
McpError πŸ”’
McpRequest πŸ”’
JSON-RPC 2.0 request. Requests have id; notifications don’t.
McpResponse πŸ”’
QueryParams πŸ”’
QuerySystemCatalogParams πŸ”’
ReadDataProductParams πŸ”’
ServerInfo πŸ”’
TableReferenceCollector πŸ”’
Collects table references from SQL AST with their schema qualification.
ToolAnnotations πŸ”’
MCP 2025-11-25 tool annotations that describe tool behavior. These hints help clients make trust and safety decisions.
ToolContentResult πŸ”’
ToolDefinition πŸ”’
ToolsListResult πŸ”’

EnumsΒ§

McpEndpointType πŸ”’
McpMethod πŸ”’
MCP method variants with their associated parameters.
McpRequestError πŸ”’
MCP request errors, mapped to JSON-RPC error codes.
McpResult πŸ”’
Typed MCP response results.
ToolsCallParams πŸ”’
Tool call parameters, deserialized via adjacently tagged enum. Serde maps name to the variant and arguments to the variant’s data.

ConstantsΒ§

DETAILS_QUERY_PREFIX πŸ”’
DISCOVERY_QUERY πŸ”’
JSONRPC_VERSION πŸ”’
JSON-RPC protocol version used in all MCP requests and responses.
MAX_READ_LIMIT πŸ”’
Maximum number of rows that can be returned by read_data_product.
MCP_PROTOCOL_VERSION πŸ”’
MCP protocol version returned in the initialize response. Spec: https://modelcontextprotocol.io/specification/2025-11-25
MCP_REQUEST_TIMEOUT πŸ”’
Maximum time an MCP tool call can run before the HTTP response is returned. Note: this returns a clean JSON-RPC error to the caller, but the underlying query may continue running on the cluster until it completes or is cancelled separately (see database-issues#9947 for SELECT timeout gaps).
READ_ONLY_ANNOTATIONS πŸ”’
Annotations for all MCP tools: read-only, non-destructive, idempotent.

FunctionsΒ§

default_read_limit πŸ”’
execute_query πŸ”’
execute_sql πŸ”’
Execute SQL via execute_request from sql.rs.
format_rows_response πŸ”’
Serialize rows to JSON and enforce the response size cap.
get_data_product_details πŸ”’
get_data_products πŸ”’
handle_initialize πŸ”’
handle_mcp_agents
Agents endpoint: exposes user data products.
handle_mcp_method πŸ”’
handle_mcp_method_not_allowed
MCP 2025-11-25 requires servers to return 405 for GET requests on endpoints that only support POST.
handle_mcp_observatory
Observatory endpoint: exposes system catalog (mz_*) only.
handle_mcp_request πŸ”’
handle_mcp_request_inner πŸ”’
handle_tools_call πŸ”’
handle_tools_list πŸ”’
query_system_catalog πŸ”’
read_data_product πŸ”’
Read rows from a data product. Issues a single read-only query.
safe_data_product_name πŸ”’
Parses a data product name and returns it safely quoted for SQL interpolation.
validate_origin πŸ”’
Validates the Origin header to prevent DNS rebinding attacks (MCP 2025-11-25). Returns Some(403) if the Origin is present but doesn’t match the Host. Returns None if the Origin is absent (non-browser client) or valid.
validate_readonly_query πŸ”’
Validates query is a single SELECT, SHOW, or EXPLAIN statement.
validate_system_catalog_query πŸ”’
Validates that a query only references system catalog tables.