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.
- Merge adapter.tools, whose default names include intent_runtime_, into the original tools/list response and check every final name for duplicates.
- 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. attachIntentTools is the helper provided in full as attach.mjs below; it checks merged names before creating a session. Resources/prompts handlers remain unchanged.
Map original to the handlers that existed before attachment. attached is a Promise: on connection cleanup, await it and call close() on the successfully created helper to close its session/adapter. Dispose the caller-owned Intent on service shutdown and preserve existing cleanup. Keep a separate attached helper/session for each logical client. Existing HTTP servers retain their own ports and transports.
The sketch and complete example reuse the same collision checks and call forwarding. The complete example below adds lifecycle handling. JavaScript supports ESM .js/.mjs; TypeScript uses the same API with included public types.
Coexist with capability-graph and other modules
In this example, original.listTools() and the forwarding helper's listTools() return an array of tool definitions. Each definition has name and inputSchema, usually includes description, and may declare outputSchema; other modules' definitions remain intact. The SDK handler wraps the array in a tools/list response shaped as {tools: [...]}. Clients read definitions from the response's tools property to display tools and prepare calls. tools/call returns the actual invocation result.
If your existing server already includes capability-graph, original.listTools retains its actual definitions and original.callTool retains its actual handlers. MCP does not automatically isolate tools by module. This module supplies default names containing intent_runtime_, so ordinary integrations need no prefix configuration. Keep capability-graph's actual names and parameters; every name in the final merged list must be unique.
This table explains routing; the actual tools/list contains full definitions, not just an array of names. Executor mode adds intent_runtime_parse instead of the three host tools.
One adapter may contain multiple instances, selected by instance, sharing the tool set above. Use an additional toolPrefix only when the same Server needs multiple adapters or already has a matching tool name. For example, toolPrefix: 'orders_' produces orders_intent_runtime_prepare (and corresponding accept/cancel names). Default names still require collision checks; repeated attachment does not automatically number tools or overwrite existing ones.
Keep one shared handler for tools/list and one for tools/call on the Server, dispatching by exact tool name. Do not let two modules replace the same handler independently. Forward to original only when the Intent session returns undefined. A matched tool's isError=true reply remains its error; do not try another module.
The helper below checks all merged names on attachment, on each listing and before each call, including duplicates within the original tool list. A conflict reports its name; fix the name or choose a distinct prefix before attaching again. Dynamic additions use the same checks; a call rejected by this check does not reach a business tool's execution handler. This merges tool definitions and routing; each module retains its own parameters and handlers.
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 default intent_runtime_ 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, intent_runtime_prepare, intent_runtime_accept, intent_runtime_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.
Local result lifecycle
Forward both request shapes. For host prepare, branch on structuredContent.kind before calling the model. local_result completes the call. Forward the real AbortSignal and close the logical session when its client disconnects to cancel in-flight local validation.