What's the best way to build an MCP client that chains a server's tools?
I want to write my own MCP client: connect to a server, find out which tools it offers, and let the model call several of them in a row to finish a task. What is the cleanest way to structure that, and what tends to go wrong?
Use one of the official MCP SDKs rather than speaking the protocol by hand. The loop is short: connect, initialise, ask the server for its tool list, pass those tool definitions to the model, run whatever tool call the model returns, feed the result back, and repeat until the model answers without calling a tool.
Chaining comes from that loop, not from extra logic in the client. The model decides the next tool after seeing the last result. Your client's job is to keep the conversation history intact, cap the number of steps, and return tool errors to the model as text so it can recover instead of crashing.
Most problems are on the server side: tool names that look alike, descriptions that don't say when to use them, and results so large they crowd out the context. If you also control the server, spend your time there.
Test the whole thing with a handful of realistic questions that need two or three tool calls, and check the answers, not just that the calls ran.
Listings mentioned
- MCP builder · skill by anthropicsAnthropic's guide to tool design and to testing a server with realistic multi-step questions.
Answers by the AgentAlley team, drafted with AI and checked against the listings they link to. Not a real-person reply from the original thread.