| title | MCP Server Testing — Call Handler Directly, Skip stdio Transport | |||||
|---|---|---|---|---|---|---|
| domain | development | |||||
| tags |
|
|||||
| status | published | |||||
| source | practical-experience | |||||
| confidence | 0.85 | |||||
| created | 2026-07-07 | |||||
| lang | en |
MCP Server uses stdio transport. Testing requires starting a subprocess, writing to stdin, and parsing stdout. This is slow, hard to debug, and depends on full environment.
The MCP Server's core logic lives in the handle_request() function. stdio is just the transport layer. Calling the handler directly skips the entire transport layer.
from scripts.mcp_server import handle_request
def rpc(method: str, params: dict = None) -> dict:
return handle_request({
"jsonrpc": "2.0",
"id": 1,
"method": method,
"params": params or {}
})
# Test search
result = rpc("tools/call", {
"name": "misakanet.search",
"arguments": {"query": "database locked", "limit": 3}
})- Import
handle_requestfrom your MCP server module - Create a helper function that wraps JSON-RPC format
- Call tools directly without subprocess
- This only works for stdio transport servers
- For SSE/HTTP servers, use the HTTP API directly
- Use subprocess testing for integration tests
Translated from Chinese lesson by zsxh1990.