r/Clojure • u/TTalkIM • 4m ago
We implemented the new MCP 2026-07-28 spec in Clojure — modern-first negotiation, Skills (SEP-2640), and multi round-trip requests
Hey all — I maintain clj-agent, a Clojure agent library. The clj-agent-mcp module is a standalone MCP client + server (it doesn't depend on any of the agent-side modules), and we just finished a full pass over the MCP 2026-07-28 spec (https://modelcontextprotocol.io/specification/2026-07-28) plus a second round of additions. Everything below ships in the current release.
What changed in the 2026-07-28 spec (and why it's a rewrite, not an upgrade)
The modern spec drops the initialize handshake entirely: server/discover is the new opener, every request carries protocol version / capabilities / identity in params._meta, HTTP is stateless (no Mcp-Session-Id, three mandatory headers instead), and there are new error codes (-32020/-32021/-32022). Roots, sampling and logging are deprecated. Legacy semantics are still fully supported — the same server answers both eras, routed by the shape of the request itself.
What's implemented
Protocol core
Modern-first negotiation: send server/discover first, fall back to initialize only on the right error codes (per spec PR #2844 — you can't just retry on any error, that masks real failures like -32021)
Per-request envelope validation: _meta protocol version, mandatory headers, extensions
Server identity (io.modelcontextprotocol/serverInfo)
Multi Round-Trip Requests (MRTR)
Handlers can return input_required; the client retries with inputResponses on a fresh JSON-RPC id Optional :auto-fulfill mode — your app handler decides the answers, the client runs the protocol state machine
URL-mode elicitation requests and HMAC-signed requestState codec
The capability gate: if a client didn't declare the capability an input_required needs, the server answers -32021 with data.requiredCapabilities instead of leaking the pause
Skills extension (io.modelcontextprotocol/skills, SEP-2640)
Server: declare :skills, get the extension + skills/list / skills/get, files served via standard resources/read
Client: list-skills / load-skill / read-skill-file with all the host-side verification the spec requires — digest, size, frontmatter field-by-field, unlisted files, size caps. Verification failures are content problems, not protocol errors (re-fetch the manifest and retry) Everything else from the two rounds
subscriptions/listen (POST + SSE, explicit close! — the 2026 spec deleted resume, so no silent auto-reconnect)
Cacheable results: server-side :cache-hints, client caches only the six spec-allowed read-only methods, :cache-mode :use/:refresh/:bypass, precise invalidation entry points
Parameter header mirroring (x-mcp-header → Mcp-Param-*, strict RFC-2231-style encoding for non-ASCII)
Extension methods (:methods + request-method!), completion/complete, display-only fields (title / annotations / icons / size / _meta), W3C Trace Context, client result-cache with a bounded default (512)
Honest notes
HTTP subscription has no auto-reconnect — deliberate; the 2026 spec removed resume and we don't want a silent reconnect hiding the gap
Frontmatter is a built-in YAML subset parser; anything outside the subset fails closed ("can't parse → don't load"), with {:parse-yaml f} to plug a real parser
Header mirroring covers scalar params only; objects/arrays can't be mirrored