MCP Server Protocol Walkthrough
Inspect saved protocol exchanges, the original source and a reproducible smoke check.
Python standard library implementation of initialize, tools/list and tools/call over stdio. Task planning returns a fixed template. Exchanges below come from a custom standard-library client.
Recorded protocol exchanges
1. Initialize
Protocol 2024-11-05. Server game-agent-mcp v0.1.0 declares tools capability.
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "portfolio-smoke-client",
"version": "0.1.0"
}
}
}Response
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"tools": {}
},
"serverInfo": {
"name": "game-agent-mcp",
"version": "0.1.0"
}
}
}2. Discover two tools
Two tools expose inputSchema. plan_game_task requires game and task strings.
Request
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}Selected response fields
{
"tools": [
{
"name": "list_game_agent_scopes",
"inputSchema": {
"type": "object"
},
"propertyNames": []
},
{
"name": "plan_game_task",
"inputSchema": {
"type": "object",
"required": [
"game",
"task"
]
},
"propertyNames": [
"game",
"task"
]
}
]
}The description above translates the original tool output. The source files contain the original wording.
3. Call task planner
The tool returns a five-step fixed plan covering clarification, context, decomposition, tool use and review.
Request
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "plan_game_task",
"arguments": {
"game": "Demo Game",
"task": "Check a task plan"
}
}
}Selected response fields
{
"jsonrpc": "2.0",
"id": 3,
"isError": false,
"contentType": "text"
}The description above translates the original tool output. The source files contain the original wording.
4. Call scope list
The tool returns four categories covering game news, questions, companionship and task execution.
Request
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "list_game_agent_scopes",
"arguments": {}
}
}Selected response fields
{
"jsonrpc": "2.0",
"id": 4,
"isError": false,
"contentType": "text"
}The description above translates the original tool output. The source files contain the original wording.
5. Unknown tool error
The server returns isError = true for missing_tool.
Request
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "missing_tool",
"arguments": {}
}
}Selected response fields
{
"jsonrpc": "2.0",
"id": 5,
"isError": true,
"contentType": "text"
}The description above translates the original tool output. The source files contain the original wording.
Reproduce the check
Save these files in src/ and tests/ under the same folder, then run the command.
mcp_server.py · test_mcp_server.py
python3 tests/test_mcp_server.py
The smoke check covers initialization, tool discovery and successful calls to both tools. The error exchange was recorded separately. inputSchema declares the contract, while this implementation still needs strict argument validation, protocol edge-case tests and integration checks with named clients.
Integration and troubleshooting
Start the server with python3 src/mcp_server.py. Configure a stdio client with the Python executable and the absolute server path. Keep protocol messages on stdout and diagnostics on stderr. Verify initialization and tool discovery before testing calls.