### Pseudo-code for AI application discovery Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Shows how an AI application connects to an MCP server and registers it if tools are supported, then marks the server as ready. ```python # Pseudo Code async with Client(stdio_client(server_config)) as client: if client.server_capabilities.tools: app.register_mcp_server(client, supports_tools=True) app.set_server_ready(client) ``` -------------------------------- ### Tools List Request Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture A JSON-RPC request to list available tools. Includes standard _meta fields and optional cursor for pagination (omitted here). ```json { "jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": { "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": { "name": "example-client", "version": "1.0.0" }, "io.modelcontextprotocol/clientCapabilities": { "elicitation": {} } } } } ``` -------------------------------- ### Discover Request Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture JSON-RPC 2.0 request sent by a client to the server to discover supported capabilities and versions. Includes protocol version, client info, and client capabilities in the _meta field. ```json { "jsonrpc": "2.0", "id": 1, "method": "server/discover", "params": { "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": { "name": "example-client", "version": "1.0.0" }, "io.modelcontextprotocol/clientCapabilities": { "elicitation": {} } } } } ``` -------------------------------- ### Pseudo-code for AI application tool discovery Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Fetches available tools from all connected MCP clients and registers them with the conversation. Uses the MCP Python SDK pattern with `list_tools()`. ```python # Pseudo-code using MCP Python SDK patterns available_tools = [] for client in app.mcp_clients(): tools_response = await client.list_tools() available_tools.extend(tools_response.tools) conversation.register_available_tools(available_tools) ``` -------------------------------- ### Client Response: tools/list Request Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Client request to refresh the tool list after receiving a change notification, using the same _meta fields as the listen request. ```json { "jsonrpc": "2.0", "id": 5, "method": "tools/list", "params": { "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": { "name": "example-client", "version": "1.0.0" }, "io.modelcontextprotocol/clientCapabilities": { "elicitation": {} } } } } ``` -------------------------------- ### Listen Request: subscriptions/listen Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Client request to subscribe to tool list change notifications. Includes protocol version, client info, and capabilities in _meta, with a notifications filter requesting toolsListChanged. ```json { "jsonrpc": "2.0", "id": 4, "method": "subscriptions/listen", "params": { "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": { "name": "example-client", "version": "1.0.0" }, "io.modelcontextprotocol/clientCapabilities": { "elicitation": {} } }, "notifications": { "toolsListChanged": true } } } ``` -------------------------------- ### Pseudo-code for AI application tool execution Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Handles a tool call by finding the appropriate MCP client and invoking `call_tool`, then adds the result content to the conversation. ```python # Pseudo-code for AI application tool execution async def handle_tool_call(conversation, tool_name, arguments): client = app.find_mcp_client_for_tool(tool_name) result = await client.call_tool(tool_name, arguments) conversation.add_tool_result(result.content) ``` -------------------------------- ### Tool Call Request (JSON-RPC) Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture A `tools/call` request using the proper tool name `weather_current` with arguments for location and units. Includes `_meta` with protocol version and client info. ```json { "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "weather_current", "arguments": { "location": "San Francisco", "units": "imperial" }, "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": { "name": "example-client", "version": "1.0.0" }, "io.modelcontextprotocol/clientCapabilities": { "elicitation": {} } } } } ``` -------------------------------- ### Tools List Response Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture A JSON-RPC response containing a tools array with metadata for each tool, including name, title, description, and inputSchema. Includes caching fields ttlMs and cacheScope. ```json { "jsonrpc": "2.0", "id": 2, "result": { "resultType": "complete", "tools": [ { "name": "calculator_arithmetic", "title": "Calculator", "description": "Perform mathematical calculations including basic arithmetic, trigonometric functions, and algebraic operations", "inputSchema": { "type": "object", "properties": { "expression": { "type": "string", "description": "Mathematical expression to evaluate (e.g., '2 + 3 * 4', 'sin(30)', 'sqrt(16)')" } }, "required": ["expression"] } }, { "name": "weather_current", "title": "Weather Information", "description": "Get current weather information for any location worldwide", "inputSchema": { "type": "object", "properties": { "location": { "type": "string", "description": "City name, address, or coordinates (latitude,longitude)" }, "units": { "type": "string", "enum": ["metric", "imperial", "kelvin"], "description": "Temperature units to use in response", "default": "metric" } }, "required": ["location"] } } ], "ttlMs": 300000, "cacheScope": "public" } } ``` -------------------------------- ### Discover Response Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture JSON-RPC 2.0 response from the server to the discovery request, listing supported versions, capabilities, server info, and caching metadata. ```json { "jsonrpc": "2.0", "id": 1, "result": { "resultType": "complete", "supportedVersions": ["2026-07-28"], "capabilities": { "tools": { "listChanged": true }, "resources": {} }, "_meta": { "io.modelcontextprotocol/serverInfo": { "name": "example-server", "version": "1.0.0" } }, "ttlMs": 3600000, "cacheScope": "public" } } ``` -------------------------------- ### Pseudo-code for AI application notification handling Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Shows the core loop for listening to tool changes and updating the application's tool registry. Use this pattern when you need to keep the LLM's available tools current during an active conversation. The code checks if a conversation is active before notifying the LLM of new capabilities. ```python # Pseudo-code for AI application notification handling async def follow_tool_changes(client): async with client.listen(tools_list_changed=True) as sub: async for _event in sub: tools_response = await client.list_tools() app.update_available_tools(client, tools_response.tools) if app.conversation.is_active(): app.conversation.notify_llm_of_new_capabilities() ``` -------------------------------- ### Notification: notifications/tools/list_changed Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Server notification sent when tools change, carrying the subscription ID in _meta. No response is expected. ```json { "jsonrpc": "2.0", "method": "notifications/tools/list_changed", "params": { "_meta": { "io.modelcontextprotocol/subscriptionId": 4 } } } ``` -------------------------------- ### Tool Call Response (JSON-RPC) Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture The response to the `tools/call` request, containing a `resultType` of "complete" and a content array with a text content object. ```json { "jsonrpc": "2.0", "id": 3, "result": { "resultType": "complete", "content": [ { "type": "text", "text": "Current weather in San Francisco: 68°F, partly cloudy with light winds from the west at 8 mph. Humidity: 65%" } ] } } ``` -------------------------------- ### Acknowledgment: notifications/subscriptions/acknowledged Source: https://modelcontextprotocol.io/docs/2026-07-28/learn/architecture Server acknowledgment of the subscription, carrying the subscription ID in _meta and reflecting the agreed subset of the requested filter. ```json { "jsonrpc": "2.0", "method": "notifications/subscriptions/acknowledged", "params": { "_meta": { "io.modelcontextprotocol/subscriptionId": 4 }, "notifications": { "toolsListChanged": true } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.