Files
servers/src/everything/docs/startup.md
cliffhall 1b8f376b90 Demonstrate registration of tools conditioned upon client capability support. Also, obviated need for clientConnected callback to pass sessionId because we defer initial fetching of roots happens when you run the get-roots-list tool.
* In how-it-works.md,
  - added a section on conditional tool registration

* In server/index.ts
  - import registerConditionalTools
  - in an oninitialized handler for the server, call registerConditionalTools
  - removed clientConnected from ServerFactoryResponse and all mentions in docs

* In tools/index.ts
  - export a registerConditionalTools function
  - refactor/move calls to registerGetRootsListTool, registerTriggerElicitationRequestTool, and registerTriggerSamplingRequestTool out of registerTools and into registerConditionalTools

* In server/roots.ts
  - only act if client supports roots
  - remove setInterval from call to requestRoots. It isn't happening during the initialze handshake anymore, so it doesn't interfere with that process if called immediaately

* In get-roots-list.ts, trigger-elicitation-request.ts, and trigger-sampling-request.ts,
  - only register tool if client supports capability

* Throughout the rest of the files, removing all references to `clientConnected`
2025-12-15 17:51:30 -05:00

2.8 KiB
Raw Blame History

Everything Server - Startup Process

Architecture | Project Structure | Startup Process | Server Features | Extension Points | How It Works

1. Everything Server Launcher

  • Usage node dist/index.js [stdio|sse|streamableHttp]
  • Runs the specified transport manager to handle client connections.
  • Specify transport type on command line (default stdio)
    • stdiotransports/stdio.js
    • ssetransports/sse.js
    • streamableHttptransports/streamableHttp.js

2. The Transport Manager

  • Creates a server instance using createServer() from server/index.ts
    • Connects it to the chosen transport type from the MCP SDK.
  • Handles communication according to the MCP specs for the chosen transport.
    • STDIO:
      • One simple, processbound connection.
      • CallsclientConnect() upon connection.
      • Closes and calls cleanup() on SIGINT.
    • SSE:
      • Supports multiple client connections.
      • Client transports are mapped to sessionId;
      • Calls clientConnect(sessionId) upon connection.
      • Hooks servers onclose to clean and remove session.
      • Exposes
        • /sse GET (SSE stream)
        • /message POST (JSONRPC messages)
    • Streamable HTTP:
      • Supports multiple client connections.
      • Client transports are mapped to sessionId;
      • Calls clientConnect(sessionId) upon connection.
      • Exposes /mcp for
        • POST (JSONRPC messages)
        • GET (SSE stream)
        • DELETE (termination)
      • Uses an event store for resumability and stores transports by sessionId.
      • Calls cleanup(sessionId) on DELETE.

3. The Server Factory

  • Invoke createServer() from server/index.ts
  • Creates a new McpServer instance with
    • Capabilities:
      • tools: {}
      • logging: {}
      • prompts: {}
      • resources: { subscribe: true }
    • Server Instructions
      • Loaded from the docs folder (server-instructions.md).
    • Registrations
      • Registers tools via registerTools(server).
      • Registers resources via registerResources(server).
      • Registers prompts via registerPrompts(server).
    • Other Request Handlers
      • Sets up resource subscription handlers via setSubscriptionHandlers(server).
      • Roots list change handler is added post-connection via
    • Returns
      • The McpServer instance
      • A clientConnect(sessionId) callback that enables post-connection setup
      • A cleanup(sessionId?) callback that stops any active intervals and removes any sessionscoped state

Enabling Multiple Clients

Some of the transport managers defined in the transports folder can support multiple clients. In order to do so, they must map certain data to a session identifier.