INNER CODE UNIT · Python

mcp_call

Arthur-Ficial/apfel · mcp/calculator/test_round_trip.py:37

def mcp_call(tool_name, arguments):
    """Call the MCP calculator server via stdio."""
    init_msg = json.dumps({
        "jsonrpc": "2.0", "id": 1, "method": "initialize",
        "params": {"protocolVersion": "2025-06-18", "capabilities": {},
                    "clientInfo": {"name": "apfel-test", "version": "1.0"}}
    })
    call_msg = json.dumps({
        "jsonrpc": "2.0", "id": 2, "method": "tools/call",
        "params": {"name": tool_name, "arguments": arguments}
    })
    proc = subprocess.run(
        [sys.executable, CALC],
        input=f"{init_msg}\n{call_msg}\n",
        capture_output=True, text=True, timeout=5
    )
    for line in proc.stdout.strip().split("\n"):
        msg = json.loads(line)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…