Change only starter/mcp_server.py.
- Implement
MCPServerclass:register_tool(name: str, description: str, schema: dict, handler: Callable) -> Nonehandle_request(request: dict) -> dict: Processes a JSON-RPC 2.0 request dict and returns a response dict.
- JSON-RPC 2.0 compliance:
- Must check
"jsonrpc": "2.0"and preserve request"id". - Return error
-32600(Invalid Request) if request is not a valid dict or lacksmethodorjsonrpc != "2.0". - Return error
-32601(Method not found) if method is unknown.
- Must check
- 2026-07-28 stateless behavior:
initializemust return-32601with a message noting it was removed by the stateless 2026-07-28 specification; there is no handshake before tool calls.- If a request carries
_meta.protocolVersionand it is not"2026-07-28", return-32600(Invalid Request); requests self-describe their version.
- Supported methods:
"tools/list": returns{"result": {"tools": [{"name": ..., "description": ..., "inputSchema": ...}, ...]}}."tools/call": acceptsparams: {"name": ..., "arguments": ..., "inputResponses": {...}?}and calls the handler ashandler(arguments, inputResponses).- If tool not registered: returns
{"result": {"isError": True, "content": [{"type": "text", "text": "Tool not found"}]}}. - If required argument missing: returns
{"result": {"isError": True, "content": [{"type": "text", "text": "Missing required argument: <arg>"}]}}. - If the handler raises
InputRequired(requests): returns{"result": {"resultType": "input_required", "requests": <requests>, "content": [{"type": "text", "text": "Additional client input is required before this tool can finish."}]}}. The client retries the same call with answers inparams.inputResponses. - On handler success: returns
{"result": {"content": [{"type": "text", "text": str(output)}]}}. - On any other handler exception: catch and return
{"result": {"isError": True, "content": [{"type": "text", "text": f"Error: {e}"}]}}.
- If tool not registered: returns
- Provide
InputRequired(Exception)with arequestsattribute so tools can request client input.
Done means python examples/mcp-server/verify.py starter exits successfully.