Architecture | Project Structure | Startup Process | Server Features | Extension Points | How It Works
- Some tools require client support for the capability they demonstrate. These are:
get-roots-listtrigger-elicitation-requesttrigger-multi-step-elicitationtrigger-sampling-requesttrigger-url-elicitation
- 2025 era: client capabilities aren't known until the initialization handshake is complete, so these tools are registered by
registerConditionalTools(server, context), invoked from anoninitializedhandler, for a client that declared the capability. - 2026-07-28: there is no handshake, and each request carries the client's capabilities in
_meta, soregisterModernTools(server, context)registers them up front. The SDK refuses a call whose embedded request the client did not declare (-32021).
- A tool that needs client input returns
inputRequired({ inputRequests })instead of a result. A 2026-07-28 client fulfils the embedded requests and retries the call withinputResponses; for a 2025-era client the SDK's legacy shim sends realelicitation/create,sampling/createMessageorroots/listrequests and re-enters the handler with the answers. Each handler is written once. - The handler reads the answers with
inputResponse(...)(any kind, including a decline) oracceptedContent(..., schema)(a validated form answer). - A flow of several rounds carries what it has learned in
requestState.trigger-multi-step-elicitationmints it withroundStateCodec(HMAC-signed, ten-minute expiry, process-wide key), passed to the server asrequestState.verify, so a tampered or expired state is refused with-32602before the handler runs.
- Serves the tasks extension (
io.modelcontextprotocol/tasks) on 2026-07-28:tasks/get,tasks/updateandtasks/cancel, with explicit schemas. createTask(behavior, options)stores a task under a minted UUID and returns thetools/callresult that hands its handle to the client (resultType: "task"). A task'sbehaviorworks out its state from the clock (stateAt) and takes the client's answers (receive), so nothing runs in the background. Tasks past their TTL are dropped when the store is next touched.
- 2025 era:
setSubscriptionHandlers(server, subscribed)processes subscribe/unsubscribe requests, keeping the instance's set of subscribed URIs. - Updates are started/stopped on demand by the
toggle-subscriber-updatestool, which callsbeginSimulatedResourceUpdates(server, subscribed)and keeps the stop function it returns; the instance'scleanup()stops it too. - 2026-07-28: the serving entry handles
subscriptions/listenitself. The context's publisher (server/context.ts) sends changes from the instance on stdio, whereserveStdioroutes them onto the open streams, and through the handler's bus over Streamable HTTP.
getSessionResourceURI(name: string): Builds a session resource URI:demo://resource/session/<name>.registerSessionResource(server, resource, type, payload): Registers a resource with the givenuri,name, andmimeType, returning aresource_link. The content is served from memory for the life of the session only. Supportstype: "text" | "blob"and returns data in the corresponding field.mintBlobResource(name, mimeType, blob): on 2026-07-28, where an instance may not outlive the request, stores the resource process-wide underdemo://resource/minted/<uuid>/<name>for ten minutes and returns aresource_link;registerMintedResources(server)serves the store through one template.- Intended usage: tools can create and expose artifacts without persisting them. For example,
tools/gzip-file-as-resource.tscompresses fetched content and returns either aresource_linkto a session or minted resource, by era, or an inlineresource, based onoutputType.
- 2025 era:
beginSimulatedLogging(server)periodically sends randomized log messages at different levels, and returns the function that stops it.toggle-simulated-loggingstarts and stops it; the instance'scleanup()stops it too. It usesserver.sendLoggingMessage(params, sessionId)so that the level the client set withlogging/setLevelis respected by the SDK. - Both eras:
trigger-log-messagessends one message per level withctx.mcpReq.log(...), which the SDK filters by the request's_metalog level on 2026-07-28 and by the session level on the 2025 era.