Discover and Call Tools as an MCP Client
Write an MCP client: the piece that talks to both the model and the server.
Implement mcp_answer(llm, server, question). The server exposes one method, handle(request), taking a JSON-RPC dict and returning the response dict (or None for a notification). In order:
initialize: the handshake.notifications/initialized: a notification, so noid, and no reply to wait for.tools/list: discover what the server offers.- Give the model the discovered tools (names, descriptions,
inputSchema) and ask which one to call with what arguments, as JSON{"name": ..., "arguments": {...}}. tools/callwith what the model chose.- Return the text of the first content block in the result.
If the model names a tool the server does not have, do not send it; return the model's raw reply so the failure is visible.
The server records every method in server.log, and the tests check the order: a client that calls tools before initializing is rejected by any real server. They also check the model is asked once.