# Model Context Protocol Testcases Testcases collected from https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/ and https://spec.modelcontextprotocol.io/specification/2024-11-05/server/. ## Basic Protocol Testcases ### Message Format #### Request Message ```json { "jsonrpc": "2.0", "id": "string | number", "method": "string", "params": { "key": "value" } } ``` #### Response Message ```json { "jsonrpc": "2.0", "id": "string | number", "result": { "key": "value" } } ``` #### Notification Message ```json { "jsonrpc": "2.0", "method": "string", "params": { "key": "value" } } ``` ### Lifecycle Testcases #### Initialization Request ```json { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": { "roots": { "listChanged": true }, "sampling": {} }, "clientInfo": { "name": "ExampleClient", "version": "1.0.0" } } } ``` #### Initialization Response ```json { "jsonrpc": "2.0", "id": 1, "result": { "protocolVersion": "2024-11-05", "capabilities": { "logging": {}, "prompts": { "listChanged": true }, "resources": { "subscribe": true, "listChanged": true }, "tools": { "listChanged": true } }, "serverInfo": { "name": "ExampleServer", "version": "1.0.0" } } } ``` #### Initialization Notification ```json { "jsonrpc": "2.0", "method": "notifications/initialized" } ``` #### Initialization Error (Unsupported Version) ```json { "jsonrpc": "2.0", "id": 1, "error": { "code": -32602, "message": "Unsupported protocol version", "data": { "supported": ["2024-11-05"], "requested": "1.0.0" } } } ``` ### Tool Testcases #### Ping Request ```json { "jsonrpc": "2.0", "id": "123", "method": "ping" } ``` #### Ping Response ```json { "jsonrpc": "2.0", "id": "123", "result": {} } ``` #### Cancellation Notification ```json { "jsonrpc": "2.0", "method": "notifications/cancelled", "params": { "requestId": "123", "reason": "User requested cancellation" } } ``` #### Progress Request ```json { "jsonrpc": "2.0", "id": 1, "method": "some_method", "params": { "_meta": { "progressToken": "abc123" } } } ``` #### Progress Notification ```json { "jsonrpc": "2.0", "method": "notifications/progress", "params": { "progressToken": "abc123", "progress": 50, "total": 100 } } ``` ## Server Testcases ### Tool Testcases #### Tool List Request ```json { "jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": { "cursor": "optional-cursor-value" } } ``` #### Tool List Response ```json { "jsonrpc": "2.0", "id": 1, "result": { "tools": [ { "name": "get_weather", "description": "Get current weather information for a location", "inputSchema": { "type": "object", "properties": { "location": { "type": "string", "description": "City name or zip code" } }, "required": ["location"] } } ], "nextCursor": "next-page-cursor" } } ``` #### Tool Call Request ```json { "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "get_weather", "arguments": { "location": "New York" } } } ``` #### Tool Call Response ```json { "jsonrpc": "2.0", "id": 2, "result": { "content": [ { "type": "text", "text": "Current weather in New York:\nTemperature: 72°F\nConditions: Partly cloudy" } ], "isError": false } } ``` #### Tool List Changed Notification ```json { "jsonrpc": "2.0", "method": "notifications/tools/list_changed" } ``` ### Resource Testcases #### Resource List Request ```json { "jsonrpc": "2.0", "id": 1, "method": "resources/list", "params": { "cursor": "optional-cursor-value" } } ``` #### Resource List Response ```json { "jsonrpc": "2.0", "id": 1, "result": { "resources": [ { "uri": "file:///project/src/main.rs", "name": "main.rs", "description": "Primary application entry point", "mimeType": "text/x-rust" } ], "nextCursor": "next-page-cursor" } } ``` #### Resource Read Request ```json { "jsonrpc": "2.0", "id": 2, "method": "resources/read", "params": { "uri": "file:///project/src/main.rs" } } ``` #### Resource Read Response ```json { "jsonrpc": "2.0", "id": 2, "result": { "contents": [ { "uri": "file:///project/src/main.rs", "mimeType": "text/x-rust", "text": "fn main() {\n println!(\"Hello world!\");\n}" } ] } } ``` #### Resource Template List Request ```json { "jsonrpc": "2.0", "id": 3, "method": "resources/templates/list" } ``` #### Resource Template List Response ```json { "jsonrpc": "2.0", "id": 3, "result": { "resourceTemplates": [ { "uriTemplate": "file:///{path}", "name": "Project Files", "description": "Access files in the project directory", "mimeType": "application/octet-stream" } ] } } ``` #### Resource List Changes Notification ```json { "jsonrpc": "2.0", "method": "notifications/resources/list_changed" } ``` #### Resource Description Request ```json { "jsonrpc": "2.0", "id": 4, "method": "resources/subscribe", "params": { "uri": "file:///project/src/main.rs" } } ``` #### Resource Updated Notification ```json { "jsonrpc": "2.0", "method": "notifications/resources/updated", "params": { "uri": "file:///project/src/main.rs" } } ``` #### Resource Error (Not Found) ```json { "jsonrpc": "2.0", "id": 5, "error": { "code": -32002, "message": "Resource not found", "data": { "uri": "file:///nonexistent.txt" } } } ``` ### Tool Result #### Text Content ```json { "type": "text", "text": "Tool result text" } ``` #### Image Content ```json { "type": "image", "data": "base64-encoded-data", "mimeType": "image/png" } ``` #### Resource Content ```json { "type": "resource", "resource": { "uri": "resource://example", "mimeType": "text/plain", "text": "Resource content" } } ```