Skip to content

MCP

xmemory exposes a Model Context Protocol server over Streamable HTTP. Any MCP-compatible client — Claude Desktop, Cursor, Windsurf, pydantic-ai, LangChain, Mastra, or a plain SDK call — can connect and get access to xmemory’s read and write tools with no custom code.

The MCP server supports two authentication paths:

  • OAuth2 flow for interactive browser-based connectors.
  • Direct fixed API-key flow for headless agents, CI, evals, and scripts.

Video tutorial coming soon — we’re putting together a step-by-step video walkthrough showing how to connect xmemory via MCP to products like Claude Code, ChatGPT, and Codex using their native MCP connectors. Stay tuned!


API key: To use xmemory APIs or integrations (including MCP), you need an API key. Please register your interest at https://xmemory.ai and we will reach out to give access. Copy and securely store the key. Never share your API key publicly.

Point your client to https://mcp.xmemory.ai/ and complete the OAuth2 login flow. The client receives an opaque MCP token (format: xmem_mcp_...) and uses it as a Bearer token.

Authorization: Bearer <xmemory_mcp_token>

For OAuth-issued MCP sessions, binding metadata (instance/admin/status) is stored server-side.

Headless clients can skip OAuth and send an account API key directly as the Bearer token on MCP shortcut paths:

Authorization: Bearer <your xmemory API key>

In this mode, session type is determined by the URL path, and the API key is revalidated on every request.

An example of adding an xmemory instance to Claude Code using the direct API key method:

Terminal window
claude mcp add --transport http xmemory https://mcp.xmemory.ai/instance/8c94edfb703645b587fd7d8c2f41b74d --header "Authorization: Bearer <xmemory API key>"

URLhttps://mcp.xmemory.ai/
TransportStreamable HTTP
AuthBearer token in the Authorization header

Use root MCP URL and OAuth discovery/login:

{
"mcpServers": {
"xmemory": {
"url": "https://mcp.xmemory.ai/",
"headers": {
"Authorization": "Bearer <xmemory_mcp_token>"
}
}
}
}

Direct API-key connection pattern (headless)

Section titled “Direct API-key connection pattern (headless)”

Use an MCP shortcut URL and pass the fixed API key:

{
"mcpServers": {
"xmemory": {
"url": "https://mcp.xmemory.ai/instance/<instance_id>",
"headers": {
"Authorization": "Bearer <xmemory_api_key>"
}
}
}
}

Supported shortcut paths:

  • /instance/<instance_id> - instance tools bound to that instance.
  • /admin - admin tools, initially disconnected.
  • /admin/<instance_id> - admin tools, pre-connected to that instance.
  • /status - status-only tool.

For framework-specific setup, see the integration guides: Pydantic, LangChain, Mastra AI.


The xmemory MCP server exposes 14 tools to instance connections: 9 bound tools that operate on the instance bound at login, and 5 explicit-instance tools that take an instance_id parameter for multi-instance access.

For direct API-key usage, /instance/<instance_id> creates the same instance-scoped tool surface, while /admin and /admin/<instance_id> switch to admin tools.

Tool descriptions are dynamic — on each list_tools() call, the server fetches your instance’s schema and appends a summary of its object types and relations to each tool description. This means the LLM sees tool descriptions tailored to your specific instance, making it more likely to use the tools correctly.

Returns the instance ID bound to the current session (e.g. "inst_abc123").

Parameters: none.

Useful for display, logging, or confirming which instance the agent is operating on.

Returns the full instance schema as a JSON string — object types with their fields, relations, deduplication keys, and descriptions.

Parameters: none.

The LLM can call this to understand what kinds of data the instance stores, which helps it formulate better write and read calls.

Extracts structured entities from free-form text and persists them. Synchronous — blocks until the data is fully committed.

ParameterTypeDescription
textstringFree-form text containing facts to extract and remember
session_idstring | nullOptional session ID for tracing (e.g. claude-qwxhjkmrtz)

Returns {"status": "ok", "write_id": "<uuid>"} on success.

Internally, the server runs a two-phase pipeline: an LLM extracts structured objects according to your instance’s schema, then a diff engine compares them against existing data and applies inserts, updates, and deletes.

Because write blocks until committed, you can call read immediately after and get consistent results.

Same as write, but enqueues the operation and returns immediately with a write_id.

ParameterTypeDescription
textstringFree-form text containing facts to extract and remember
session_idstring | nullOptional session ID for tracing

Returns {"status": "ok", "write_id": "<uuid>"}.

Important: do not call read immediately after write_async — the data may not be committed yet. Use write_status to poll, or use write (synchronous) when you need to read right after.

Checks the status of an async write previously submitted via write_async.

ParameterTypeDescription
write_idstringThe write ID returned by write_async

Returns:

{
"status": "ok",
"write_id": "<uuid>",
"write_status": "queued | processing | completed | failed | not_found",
"error_detail": "<string or null>",
"completed_at": "<ISO timestamp or null>"
}
write_statusMeaning
queuedWaiting to be picked up
processingCurrently being extracted and applied
completedSuccessfully committed — safe to read
failedExtraction or persistence failed; see error_detail
not_foundNo write with this ID exists

Queries the instance and returns a natural-language answer.

ParameterTypeDescription
querystringA natural-language question about the stored data
session_idstring | nullOptional session ID for tracing

Returns a JSON string with an answer field — a human-readable response synthesized from the structured data.

Internally, the server translates the question into SQL against the instance’s knowledge graph, executes it with automatic retry and empty-result verification, and formats the result into a plain-text answer.

xmemory learns from reads that couldn’t be fully answered and, on demand, surfaces a single rolling proposal of schema improvements for the bound instance. The flow is three tools — review → decide → apply — and a change is only applied when you call apply_pending_decisions. These tools require API-key authentication (not a plain instance token).

ToolParametersDescription
review_suggestionsoptional session_idReturn the consolidated proposal and a proposal_version token. May report evolution_in_progress if a migration is already running.
decide_suggestionsproposal_version, decisions, optional session_idRecord an accept / reject / defer per item, in bulk. Returns a next_proposal_version.
apply_pending_decisionsproposal_version, optional session_idCommit accepted decisions as one migration.

Always confirm with the user before deciding or applying. Rejecting an item suppresses that exact suggestion in future proposals.

These take instance_id as a parameter so a single connection can operate across multiple instances.

ToolParametersDescription
extractinstance_id, textExtract structured data from text. Extraction only — does not persist.
write_toinstance_id, textSynchronous write to a specific instance.
write_to_asyncinstance_id, textAsync write to a specific instance; returns write_id.
write_to_statusinstance_id, write_idPoll the status of an async write.
read_frominstance_id, queryQuery a specific instance.

Selecting the admin connection type at login switches the tool surface to schema generation and instance lifecycle management. All admin tools are prefixed admin_. The admin connection is stateful — it tracks whether you are currently connected to a specific instance, and several tools require that connection.

Important: never hand-write YAML schemas. Always use admin_generate_schema or admin_enhance_schema to produce a valid schema, then pass the result to admin_create_instance or admin_update_instance_schema.

Schema management

ToolParametersDescription
admin_generate_schemaschema_descriptionGenerate a YAML schema from a free-form description.
admin_enhance_schemaschema_description, schema_to_improveImprove an existing YAML schema. Returns the new YAML and a structured migration plan for applying non-additive changes safely.

Stateful instance lifecycle (operate on the connected instance, or change connection state)

ToolParametersDescription
admin_create_instanceschema_yaml, optional cluster_id, name, description, instance_configCreate a new instance. Requires being disconnected.
admin_connect_instanceinstance_idConnect to an existing instance. Fails if already connected.
admin_disconnect_instanceDisconnect from the current instance.
admin_get_instance_idReturn the connected instance ID (empty string if disconnected).
admin_get_instance_schemaReturn the YAML schema of the connected instance.
admin_update_instance_schemaschema_yaml, optional migration_plan, confirm_destructiveUpdate the connected instance’s schema. Pass migration_plan (from admin_enhance_schema) for non-additive changes; confirm_destructive authorises ops that drop data.
admin_update_instance_configinstance_configUpdate per-instance model config overrides.

Schema evolution (operate on the connected instance)

ToolParametersDescription
admin_dry_run_migrationschema_yaml, optional migration_plan, confirm_destructivePreview the DDL a migration would run, without applying it.
admin_list_migrationsoptional limit (1–200, default 50), before_id, include_yamlList applied migrations, newest first.
admin_get_migrationmigration_id, optional include_yamlGet a single migration record.

Cluster and instance management (require API key)

ToolParametersDescription
admin_list_clustersList clusters accessible to the API key.
admin_get_clustercluster_idGet a single cluster by ID.
admin_list_instancescluster_id, optional verboseList instances in a cluster.
admin_list_own_instancesoptional verboseList all instances across linked clusters.
admin_get_instance_by_idinstance_idGet instance metadata.
admin_delete_instance_by_idinstance_idDelete an instance.
admin_get_instance_schema_by_idinstance_idGet schema by instance ID.
admin_update_instance_schema_by_idinstance_id, schema_yml or schema_jsonUpdate schema by instance ID.
admin_update_instance_metadata_by_idinstance_id, name, optional descriptionReplace instance name/description.
admin_patch_instance_metadata_by_idinstance_id, optional name, descriptionPartially update instance metadata.

Use write when you need to read the data back immediately — it blocks until committed, guaranteeing consistency.

Use write_async + write_status when throughput matters more than immediate consistency — the client isn’t blocked, and you can poll for completion later.


All tools return {"error": "<message>"} as a JSON string on failure rather than raising exceptions, so the MCP client always gets a parseable response. Common errors:

ErrorCause
"no instance bound to this session"Token is invalid or not linked to an instance
"text size (N bytes) exceeds maximum (M bytes)"Write payload too large (limit: 1 MB)
"write queue not ready"Background processor hasn’t started
"write failed: <detail>"Extraction or persistence failure