Skip to content

MCP server overview

Spongram exposes one MCP endpoint, /mcp, over streamable HTTP. This page covers how a client authenticates, which protocol versions are accepted, how a call travels through the service, what a result looks like and how errors are reported. The tools themselves are in the tools reference.

Endpoint

URL https://spongram.example.com/mcp (no trailing slash)
Transport MCP streamable HTTP
Methods POST for every JSON-RPC message, DELETE to close a session
Authentication Authorization: Bearer spt_brain_xxx
Request body One JSON-RPC 2.0 message per POST

GET /mcp is not implemented: Spongram does not open a server-to-client stream, and every answer comes back in the response to the POST that asked for it.

Clients never talk to the Graphiti MCP server directly. In a server deployment it listens on an internal port only, and spongram is the single entry point: it authenticates the caller, pins the call to the caller's brain, and post-processes the answer.

Three deployment shapes

The behaviour of /mcp differs in a few places depending on how Spongram runs. The pages of this section use these names:

Name Setting What changes on /mcp
Server SPONGRAM_EDITION=cloud, the default. Docker Compose or Swarm, self-hosted. Brain keys, anti-tampering, rate limit, uuid ownership checks.
Cloud control plane A server with SPONGRAM_CLOUD_CONTROL_ENABLED=true and brains in enforce access mode. Adds per-key permissions and a tools/list filtered by them.
Desktop edition SPONGRAM_EDITION=local. Embedded engine, one brain. No key, no rate limit, no anti-tampering refusal.

Authentication

Every request to /mcp on a server carries a brain key:

Authorization: Bearer spt_brain_xxx
  • A brain key is spt_brain_ followed by 32 hexadecimal characters (42 characters in all). One key identifies one brain (an instance) and therefore one group_id in the graph.
  • Spongram stores the SHA-256 hash of the key and its first 18 characters (for lookup), never the key itself. The clear value is shown once, when the brain is created or its key is regenerated. A lost key cannot be recovered: regenerate it, which revokes the previous one.
  • A missing header, a token that does not start with spt_brain_ or has another length answers HTTP 401 Missing or malformed Bearer spt_brain_ token.
  • An unknown, expired, revoked or deactivated key, or a key whose brain is not active, answers HTTP 401 Invalid, expired, revoked, or suspended key.
  • A successful lookup is cached in the process for SPONGRAM_AUTH_CACHE_TTL seconds (300 by default). The Cloud control plane does not cache: key, principal, grant and organisation are read on every request.

The desktop edition does not authenticate /mcp: it serves its single brain to the local user and ignores the Authorization header.

Keys are created and regenerated in the admin UI or through the admin API. The security model is described in security.

Optional request headers

Header Effect
X-Spongram-Client claude-code or codex. Selects the persona variant sent on initialize and the client= tag added to writes. It never authorises anything. See client contract.
Mcp-Session-Id The session id returned by initialize. See sessions.
MCP-Protocol-Version The negotiated protocol version. See below.
litellm-api-key Selects the inference credential for this request. Accepted only by a server whose inference provider is LiteLLM; any other deployment answers HTTP 400. See inference providers.

Spongram does not forward Authorization, cookies or the litellm-api-key header to Graphiti.

Protocol versions

A server accepts the handshake era of MCP: a client calls initialize, receives a session, then calls tools. The accepted protocol versions are:

2024-11-05   2025-03-26   2025-06-18   2025-11-25

The session-less era of the protocol (server/discover followed by direct tools/call) is refused with HTTP 400 and a JSON-RPC error -32600:

{
  "jsonrpc": "2.0",
  "id": "server-error",
  "error": {
    "code": -32600,
    "message": "Bad Request: Unsupported protocol version: <offending value>. Supported versions: 2024-11-05, 2025-03-26, 2025-06-18, 2025-11-25"
  }
}

The refusal is triggered by any of these: an MCP-Protocol-Version header outside the list, a version outside the list announced in params._meta["io.modelcontextprotocol/protocolVersion"], or the method server/discover.

Why: initialize is the one place where Spongram hands the client its behavioural contract, the active persona and the topic rules. A client that skipped it would work without any of them. MCP clients fall back to initialize when they receive this answer.

The desktop edition answers initialize itself with protocol version 2025-06-18 and does not apply this check.

Sessions

initialize returns an Mcp-Session-Id response header. Send it back on every later request, and send notifications/initialized once after initialize, as the protocol requires.

  • Recovery. Graphiti keeps sessions in memory and forgets one after 30 idle minutes or when it restarts. It then answers 404 to the stale id, and the call was not executed. Spongram opens a new session, replays the call once, and returns the new id in the Mcp-Session-Id response header. Adopt the id you receive. initialize and notifications/* are never replayed.
  • Calls that need no upstream session. add_memory, the synthetic tools and, on a server, get_episodes are answered by Spongram and do not depend on the Graphiti session being alive.
  • Closing. DELETE /mcp with the Mcp-Session-Id header closes the session; Spongram relays Graphiti's answer. Without the header the answer is HTTP 400.

Rate limit

A server limits each brain to SPONGRAM_RATE_LIMIT_PER_MIN requests per minute (100 by default, 0 disables the limit), with a token bucket that refills continuously. A request over the limit answers HTTP 429 with a Retry-After header in seconds.

The handshake is free: initialize, ping, tools/list, prompts/list, resources/list, resources/templates/list and every notifications/* message consume no token. Many clients reconnecting at once on the same key therefore cannot exhaust the bucket before they do any work.

The desktop edition has no rate limit.

How a call flows

A tools/call goes through these steps, in this order. A step that answers ends the call.

  1. Authentication. The brain key resolves to one brain and its group_id (HTTP 401 otherwise).
  2. Protocol era. A session-less request is refused (HTTP 400, server only).
  3. Permission. With the Cloud control plane, the tool's action is checked against the key (HTTP 403).
  4. Rate limit. One token is consumed (HTTP 429, server only).
  5. Closed surface. A Graphiti tool Spongram does not expose is answered Unknown tool.
  6. Synthetic tools. Persona, project-alias, skill and code-map tools are answered by Spongram. reflect_on_failure is rewritten into an add_memory.
  7. Search cache. With SPONGRAM_HOT_CACHE_ENABLED on, an identical recent search is answered from the cache.
  8. group_id injection. Spongram writes the brain's group_id and group_ids into the arguments. A server refuses a call that already carries another value (HTTP 403 group_id mismatch — anti-tampering). On add_memory, unknown arguments are removed and the client=, project= and persona= tags are completed or validated (tagging and scope). On searches, the scope argument is read and removed.
  9. Queue. add_memory is stored in the durable ingestion queue and acknowledged at once. It is forwarded to Graphiti later by a background worker (ingestion).
  10. Uuid ownership. For get_entity_edge, delete_entity_edge and delete_episode, a server checks that the uuid belongs to the brain before forwarding.
  11. Forwarding. Every other call goes to Graphiti (or to the embedded engine in the desktop edition). Reads are retried up to twice on a transient network failure or a 502, 503 or 504; delete_episode is sent once.
  12. Post-processing. Search results go through the search pipeline (search). Delete tools clear the brain's search cache.

Two handshake answers are also rewritten on the way back:

  • tools/list: the descriptions of add_memory, search_nodes and search_memory_facts are replaced by Spongram's proactive wording, the closed tools and arguments are removed, and the synthetic tools are added.
  • initialize: Spongram's behavioural contract is appended to instructions (client contract).

Result shape

A tool result is a JSON-RPC response whose result follows the MCP tool-result shape:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "content": [{"type": "text", "text": "{\"message\": \"Facts retrieved successfully\", \"facts\": []}"}],
    "structuredContent": {"result": {"message": "Facts retrieved successfully", "facts": []}},
    "isError": false
  }
}
  • content[0].text holds the payload as a JSON string (plain text for a few tools).
  • structuredContent holds the same payload already parsed, wrapped under result. The add_memory acknowledgement carries it, and so do search results and get_episodes on a server. Synthetic tools do not, nor do the other answers of the desktop edition.
  • The two are kept in sync. Every transformation Spongram applies to a search result (read scoping, hiding superseded facts, re-ranking, truncation, code-map enrichment) is written to content[0].text, then copied into structuredContent as the last step before the answer leaves. Some clients read one field and some read the other; both see the same list.

Response framing

The Content-Type of a response depends on who produced it:

Produced by Content-Type Body
Graphiti, forwarded text/event-stream One SSE event: event: message, then data: <JSON-RPC response>
Spongram itself (queue acknowledgement, synthetic tools, refusals) application/json The JSON-RPC response
Desktop edition application/json The JSON-RPC response

A client must accept both, which the streamable HTTP transport already requires: send Accept: application/json, text/event-stream. Spongram reads Graphiti's answer completely before it replies, so the SSE body arrives in one piece, never as a progressive stream.

The _spongram metadata block

Search payloads can carry a _spongram object next to nodes or facts. It reports what Spongram removed or reordered, so that nothing is dropped silently.

{
  "message": "Facts retrieved successfully",
  "facts": ["..."],
  "_spongram": {
    "filtered": 2,
    "scope": {"project": "my-project", "all": false, "persona": null, "aliases": ["old-name"]},
    "hidden_invalid": 1,
    "promoted": 1
  }
}
Field Set by Meaning
filtered Read scoping (SPONGRAM_READ_SCOPING_ENABLED) Number of results dropped because they belong to another project or another persona. Present, possibly 0, whenever the stage ran.
scope Read scoping The scope that was applied: project, all, the active persona, and aliases when the project has some.
hidden_invalid search_memory_facts, SPONGRAM_HIDE_INVALID_FACTS (on by default) Number of superseded facts removed. Present only when at least one was removed.
promoted search_memory_facts, SPONGRAM_CORROBORATION_RANKING_ENABLED Number of corroborated facts that gained places. Present only when at least one moved.

The block is absent when the upstream list is empty or when no stage had anything to report. An agent should read filtered: a value above zero with no useful result means a cross-project search (scope.all) may find what it is looking for.

Errors

Spongram reports errors in three ways. Which one applies depends on where the call stopped.

HTTP errors, with a JSON body {"detail": ...} (the protocol-era refusal carries the JSON-RPC error shown above instead):

Status Cause
400 Session-less protocol era; DELETE /mcp without Mcp-Session-Id; reserved _meta key in the request; litellm-api-key on a deployment that does not accept it.
401 Missing, malformed, unknown, expired or revoked brain key, or suspended brain.
402 Desktop edition with a locked licence, on add_memory, record_skill and reflect_on_failure; reads and deletes stay allowed. Cloud control plane without a valid licence (license_restricted, license_feature_missing), on writes, configuration tools, search_nodes, search_memory_facts and recall_skill; other reads and deletes stay allowed.
403 group_id or group_ids that is not the brain's own; missing permission with the Cloud control plane.
409 Cloud control plane: a delete tool on a brain that holds versioned sources.
422 add_memory rejected by the optional source policy (SPONGRAM_CONSTITUTION_ENABLED).
429 Rate limit, with Retry-After.
503 Graph driver not initialised (skill and code-map tools); Cloud control plane unable to admit an episode, with Retry-After.

Tool results with isError: true, in an HTTP 200:

  • Unknown tool: <name> for a tool that does not exist or that Spongram keeps closed;
  • Episode <uuid> not found or Entity edge <uuid> not found for a uuid that is not in the brain, whether it belongs to another brain or to none;
  • Ownership check unavailable, please retry. when the graph could not be read for that check. Nothing was forwarded;
  • A memory of this brain is being written; nothing was deleted, retry in a moment when a delete waited longer than SPONGRAM_DELETE_LOCK_WAIT_SECONDS (45 by default) behind an episode being extracted for the same brain. Deletes and extraction never write to one brain at the same time.

JSON-RPC error objects, in an HTTP 200, from the synthetic tools: -32602 for an invalid argument (unknown persona slug, invalid alias, missing skill name), -32603 for a storage failure.

Warning

Graphiti reports some of its own failures as a successful tool result whose payload is {"error": "..."}, with isError: false. Check the payload of a delete or a search for an error key rather than relying on isError alone.

Minimal example

The handshake, then a tool list and a search. Replace the host and the key with your own.

BASE=https://spongram.example.com
KEY=spt_brain_xxx

# 1. initialize, and keep the session id returned in the response headers
SID=$(curl -s -D - -o /dev/null -X POST "$BASE/mcp" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}' \
  | grep -i '^mcp-session-id:' | sed -E 's/^[^:]*: *//; s/\r$//')

# 2. confirm the handshake
curl -s -X POST "$BASE/mcp" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Mcp-Session-Id: $SID" \
  -d '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}'

# 3. list the tools
curl -s -X POST "$BASE/mcp" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Mcp-Session-Id: $SID" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'

# 4. call a tool
curl -s -X POST "$BASE/mcp" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Mcp-Session-Id: $SID" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_nodes","arguments":{"query":"deployment policy","max_nodes":5}}}'

Steps 3 and 4 answer with Content-Type: text/event-stream: the JSON-RPC response is on the line that starts with data:. To read the instructions Spongram sends to a client, print the body of step 1 instead of discarding it and look at result.instructions.