Model Context Protocol server development
Target protocol revision 2026-07-28. It is stateless: there is no initialize handshake and no session. Every request carries its own protocol version and client capabilities, and the server answers each request independently.
The vendored spec and docs in resources/auto/ are the source of truth. Files prefixed specification-2026-07-28- and docs-2026-07-28- describe the current revision; files for 2024-11-05 through 2025-11-25 describe legacy revisions, and -draft- files describe unreleased work. Read a current file before answering from memory, because most pre-2026 MCP knowledge (handshake, sessions, GET streams, server-initiated requests) is now wrong.
Lookup protocol
- Start with
resources/auto/specification-2026-07-28-changelog.mdandresources/auto/specification-2026-07-28-deprecated.mdwhenever a question touches lifecycle, transports, notifications, or a feature you remember from an older revision. - Open the page for the area in question:
| Topic | File in resources/auto/ |
|---|---|
Messages, _meta keys, error codes, statelessness, JSON Schema rules | specification-2026-07-28-basic-index.md |
| Version negotiation, extensions, legacy compatibility matrix | specification-2026-07-28-basic-versioning.md |
server/discover | specification-2026-07-28-server-discover.md |
| stdio framing, cancellation, shutdown, legacy probe | specification-2026-07-28-basic-transports-stdio.md |
| Streamable HTTP headers, validation, status codes | specification-2026-07-28-basic-transports-streamable-http.md |
| Multi round-trip requests (elicitation, sampling, roots) | specification-2026-07-28-basic-patterns-mrtr.md |
subscriptions/listen change notifications | specification-2026-07-28-basic-patterns-subscriptions.md |
| Progress and cancellation | specification-2026-07-28-basic-patterns-progress.md, specification-2026-07-28-basic-patterns-cancellation.md |
Tools, results, errors, x-mcp-header, stateful handles | specification-2026-07-28-server-tools.md |
| Resources, templates, URI schemes | specification-2026-07-28-server-resources.md |
| Prompts, completion, pagination | specification-2026-07-28-server-prompts.md, specification-2026-07-28-server-utilities-completion.md, specification-2026-07-28-server-utilities-pagination.md |
ttlMs and cacheScope | specification-2026-07-28-server-utilities-caching.md |
| Elicitation | specification-2026-07-28-client-elicitation.md |
| Authorization (HTTP only) | specification-2026-07-28-basic-authorization-*.md, docs-2026-07-28-tutorials-security-authorization.md |
| Exact type definitions | specification-2026-07-28-schema.md |
| SDK quickstarts (TypeScript, Python, Java, Kotlin, C#) | docs-2026-07-28-develop-build-server.md |
| Inspector usage | docs-2026-07-28-tools-inspector*.md |
| Extensions (Tasks, Apps, Skills) | extensions-*.md, seps-2663-tasks-extension.md |
- Search with grep across
resources/auto/specification-2026-07-28-*for a method name,_metakey, or error name rather than guessing. Useresources/auto/llms.txtto find a page not listed above. - When a vendored page and an SDK disagree, trust the page for wire behavior and the SDK’s own README or changelog for its API, and tell the user which one you followed.
Protocol rules
- Per-request metadata. Every client request carries
_metawithio.modelcontextprotocol/protocolVersion(required),io.modelcontextprotocol/clientCapabilities(required), and optionallyio.modelcontextprotocol/clientInfoandio.modelcontextprotocol/logLevel. A request missing a required field is rejected with-32602(HTTP400). - Server identity. Include
io.modelcontextprotocol/serverInfoin every result’s_meta. TreatclientInfoas display data only, never as a security or behavior switch. - Discovery. Implement
server/discover, returningsupportedVersions,capabilities, optionalinstructions, and caching hints. Clients may call it first or skip it. - Version mismatch. Answer an unsupported version with
UnsupportedProtocolVersionError(-32022) whosedata.supportedlists the versions you serve. - Capabilities per request. Read client capabilities from the request being handled. If a request needs one the client did not declare (for example elicitation), return
MissingRequiredClientCapabilityError(-32021) listingdata.requiredCapabilities. - Results. Every result carries
resultType:"complete"for final results,"input_required"for MRTR interim results. - Server-to-client input uses MRTR. To elicit, sample, or list roots, return an
InputRequiredResultwithinputRequests(and an opaquerequestStateif you need to correlate). The client retries the original request with a new JSON-RPCidplusinputResponses. Servers never send JSON-RPC requests to the client. - Cross-call state uses handles. Return an explicit, opaque, high-entropy handle from a creation tool and accept it as an argument on later calls. Authorize the caller against the handle on every call, state its lifetime in the tool description, and return a tool execution error for expired handles. Connection or process identity is never a session.
- Change notifications. List changes and resource updates go only to clients that opened
subscriptions/listenwith a matching filter. Sendnotifications/subscriptions/acknowledgedfirst, and tag every notification withio.modelcontextprotocol/subscriptionId. Progress and log notifications stay on the response stream of the request they belong to. - Caching hints.
server/discover,tools/list,prompts/list,resources/list,resources/templates/list, andresources/readresults includettlMs(integer,>= 0) andcacheScope("public"or"private"). Returntools/listin a deterministic order, and do not vary list results per connection. - Error codes. Use
-32602for unknown tools, malformed params, and resource not found (not-32002). Use-32603for internal errors. New application codes go outside-32768to-32000;-32020to-32099is reserved for the spec. - Observability. Propagate OpenTelemetry context through the
traceparent,tracestate, andbaggage_metakeys.
Server design rules
- Tools. Name tools with 1 to 128 ASCII letters, digits,
_,-, or.. WriteinputSchemaas JSON Schema 2020-12; for no parameters use{ "type": "object", "additionalProperties": false }. AddoutputSchemawhen you returnstructuredContent, and also return the serialized JSON as a text block. - Two error channels. Report API failures, input validation failures, and business-rule failures as a tool result with
isError: trueand a message the model can act on. Reserve JSON-RPC errors for unknown tools, malformed requests, and server faults. - Inputs and outputs. Validate every argument, resolve file paths against an allowlist, rate limit calls, bound output size, and keep secrets out of errors and content. Never auto-dereference a network
$refin a schema. - Resources. Expose stable URIs (
https://,file://,git://, or a custom scheme) and templates for parameterized data. Prefer resource links in tool results over embedding large payloads. - Annotations. Use tool annotations (read-only, destructive, idempotent hints) to describe behavior, knowing clients treat them as untrusted unless the server is trusted.
Transports
stdio. One newline-delimited JSON-RPC message per line on stdout, nothing else. Log to stderr only (console.error in Node, the logging module in Python). Cancellation arrives as notifications/cancelled. Exit promptly when stdin closes.
Streamable HTTP. One endpoint (for example /mcp) that accepts POST only. Each request is its own POST answered with application/json or a request-scoped text/event-stream. Then:
- Require
MCP-Protocol-Version,Mcp-Method, andMcp-Name(fortools/call,resources/read,prompts/get). Reject header and body mismatches with400andHeaderMismatch(-32020). - Answer an unknown method with
404and-32601; answer a notification POST with202. - Treat a closed response stream as cancellation. Streams are not resumable;
Last-Event-IDis ignored. - Answer GET or DELETE with
405, and ignore anyMcp-Session-Idheader. - Validate
Origin(403when invalid), bind to127.0.0.1when local, and sendX-Accel-Buffering: noon SSE responses. - Follow the authorization spec for remote servers; stdio servers read credentials from the environment instead.
Deprecations and legacy compatibility
Check resources/auto/specification-2026-07-28-deprecated.md and resources/auto/specification-2026-07-28-changelog.md for the complete tables of deprecated features (Roots, Sampling, notifications/message logging, HTTP+SSE, OAuth DCR) and outright removals (initialize/notifications/initialized, ping, logging/setLevel, resources/subscribe, Mcp-Session-Id, HTTP GET streams, and core-protocol tasks, now the io.modelcontextprotocol/tasks extension).
Legacy compatibility. A server that must also serve 2025-11-25 or earlier clients can be dual-era: answer initialize with legacy semantics scoped to that process or session, and serve requests carrying modern _meta statelessly. A modern-only server names its supported versions in the error it returns to initialize. See the compatibility matrix in resources/auto/specification-2026-07-28-basic-versioning.md.
Minimal servers and SDK gotchas
Read resources/auto/docs-2026-07-28-develop-build-server.md for full TypeScript, Python, Java, Kotlin, and C# starter servers (and each SDK’s own docs for resource/prompt registration and HTTP hosting). Watch these two high-signal SDK pitfalls:
- TypeScript (
@modelcontextprotocol/server, ESM"type": "module"): Pass a factory function toserveStdio(createServer, ...)so each instance gets a freshMcpServerand serves both2026-07-28and legacyinitializeclients. Wiringserver.connect(new StdioServerTransport())by hand serves only legacy clients. - Python (MCP SDK 2.0.0+,
uv add "mcp[cli]"): ImportMCPServerfrommcp.server(it replaces the 1.xFastMCPimport and builds tool schemas from type hints and docstrings). Log throughloggingtostderr, neverprint().
Testing with MCP Inspector
The Inspector (@modelcontextprotocol/inspector, Node 22.19.0 or newer) has web, --cli, and --tui clients. It defaults to the legacy protocol era, so pass --protocol-era modern to exercise 2026-07-28 behavior, and repeat with --protocol-era legacy if the server is dual-era.
# Modern era over stdio
npx @modelcontextprotocol/inspector --cli node build/index.js --protocol-era modern --method tools/list
npx @modelcontextprotocol/inspector --cli node build/index.js --protocol-era modern \
--method tools/call --tool-name get_alerts --tool-arg state=CA
# Remote Streamable HTTP server
npx @modelcontextprotocol/inspector --cli https://example.com/mcp --transport http \
--protocol-era modern --method tools/list --strict
# Interactive web UI
npx @modelcontextprotocol/inspector node build/index.js
CLI exit codes: 0 success, 3 auth required, 4 unreachable, 5 tool error or tool not found, 6 --strict schema portability failure. On failure a single JSON error line goes to stderr. Full flag and method reference: resources/auto/docs-2026-07-28-tools-inspector-cli.md; era-specific behavior (logging, subscriptions, tasks): resources/auto/docs-2026-07-28-tools-inspector-protocol-eras.md.
Completion criteria
The server work is done when all of these hold:
--protocol-era modern --method tools/listexits0and lists every tool with its schema;--strictalso exits0.- Each tool called with valid arguments exits
0, and with invalid arguments returnsisError: truewith an actionable message (exit5), not a JSON-RPC error. - A stdio server writes only JSON-RPC to
stdout; all diagnostics appear onstderr. - No code path depends on
initialize,ping,logging/setLevel,resources/subscribe, session IDs, a GET stream, or server-sent JSON-RPC requests, except an explicit legacy branch of a dual-era server. - Cross-call state flows through explicit handles, and user input or LLM calls flow through MRTR
InputRequiredResult. - List and read results carry
ttlMsandcacheScope, and results carryresultTypeandserverInfo(verify in the Inspector’s raw JSON-RPC view if the SDK sets them for you). - A dual-era server also passes
tools/listwith--protocol-era legacy. - Every spec claim made to the user cites the
resources/auto/specification-2026-07-28-*page it came from (or, when localresources/auto/is absent, the corresponding page fetched fromhttps://modelcontextprotocol.io/llms.txt).