feat(examples): multi-server chatbot with tool routing (closes #740)#2148
Open
Nishant-Chaudhary5338 wants to merge 1 commit into
Open
Conversation
…protocol#740) Adds three files demonstrating how one Anthropic-powered chatbot can connect to multiple MCP servers simultaneously and route tool calls to the correct server using a Map<toolName, Client> routing table. - examples/server/src/weatherServer.ts — stateless Streamable HTTP server on :3001 with get_weather and get_forecast tools - examples/server/src/mathServer.ts — stateless Streamable HTTP server on :3002 with add, multiply, and convert_temperature tools - examples/client/src/multiServerChatbot.ts — connects to both servers, builds the routing table, runs an interactive Anthropic SDK chat loop, and dispatches parallel tool calls to the correct server Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a runnable multi-server chatbot example showing how one MCP client connects to multiple servers simultaneously and routes Claude's tool calls to the correct server.
Closes #740
What this adds
examples/server/src/weatherServer.ts— stateless Streamable HTTP server on:3001withget_weatherandget_forecasttoolsexamples/server/src/mathServer.ts— stateless Streamable HTTP server on:3002withadd,multiply, andconvert_temperaturetoolsexamples/client/src/multiServerChatbot.ts— connects to both servers, builds aMap<toolName, Client>routing table, runs an interactive Anthropic SDK agentic chat loop, and dispatches parallel tool calls to the correct serverHow it works
listTools()on each server and populates the routing tabletool_useblock, the client looks up the owning server in the map and dispatches the call — no hardcoded routing, no tool-name prefixes neededPromise.allHow to run
Terminal 1:
pnpm --filter @modelcontextprotocol/examples-server exec tsx src/weatherServer.tsTerminal 2:
pnpm --filter @modelcontextprotocol/examples-server exec tsx src/mathServer.tsTerminal 3:
ANTHROPIC_API_KEY=sk-... \ pnpm --filter @modelcontextprotocol/examples-client exec tsx src/multiServerChatbot.tsTry these prompts to exercise both servers in one turn:
Testing
pnpm --filter @modelcontextprotocol/examples-client run check(typecheck + lint + prettier) passedpnpm --filter @modelcontextprotocol/examples-server run checkpassedisError: true