Extend an MCP server
Add intent tools while keeping the existing connection, tools, resources, and prompts. This page uses Server from @modelcontextprotocol/server 2.3.1. Other SDKs can use the same tool-list and call forwarding. For a standalone service, use the stdio / HTTP commands.
Install into the existing server project:
Keep your existing compatible MCP SDK; adding tools does not require rebuilding the service or installing a duplicate SDK. Host mode below reuses the client's current model without another API key.
Four integration points
- Create an Intent and adapter; declare fields if needed.
- Include adapter.tools in your original tools/list response.
- Forward tools/call through its session; when it returns undefined, use the original handler.
- Close the session when its connection ends; close the adapter and caller-created Intent when the service stops.
This sketch shows where to integrate. original.listTools/original.callTool are your existing handlers, not SDK methods. server is your existing SDK Server. Resources/prompts handlers remain unchanged.
Map original to your handlers. Add session?.close() to connection cleanup; call adapter.close() and intent.dispose() on service shutdown without losing existing cleanup. Use toolPrefix to avoid collisions. Keep a separate session for each logical client. Existing HTTP servers retain their own ports and transports.
The complete example below adds collision checks, lifecycle handling, and preservation of original capabilities. JavaScript supports ESM .js/.mjs; TypeScript uses the same API with included public types.
Complete runnable example
Two files and startup instructions
Save both files in one directory and run node server-en.mjs. stdout carries MCP only; application logs go to stderr. The client should discover ping and the three ir_ intent tools; the existing resource and prompt remain usable.
Requests follow client → SDK → logical session → core. Close session/adapter with the connection and dispose caller-owned Intent at process end. Do not create separate sessions for prepare and accept.
Complete forwarding helper
SDK attachment
This example uses stdio; do not print application logs on stdout. Connect a client and check ping, ir_intent_prepare, ir_intent_accept, ir_intent_cancel. For recognition use instance=orders and fields=['orderId'], following the host handoff.
See Adapter reference for negotiation, ownership and error envelopes. An existing HTTP service keeps its listener and session management.