{"slug": "talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-a", "title": "Talk to a remote MCP server with only the Python standard library (and call two tools without a key)", "summary": "A developer demonstrated a roughly 60-line Python standard-library client that talks directly to a remote MCP server over JSON-RPC and HTTPS POST, skipping any SDK. The script implements the initialize, tools/list and tools/call methods against Siftwright's MCP endpoint and invokes its domain_whois and pqc_scan tools without an API key, subject to a free daily limit per network.", "body_md": "Most \"connect your agent to MCP\" guides start with installing an SDK and a client. But the protocol underneath a remote MCP server is just JSON-RPC over HTTPS POST. If you want to know what a server actually does before you wire it into Claude, Cursor or VS Code, you can talk to it with the Python standard library in about 60 lines.\n\nThis post does exactly that against a real server, `https://siftwright.com/mcp`. Two of its nine tools, `domain_whois` and `pqc_scan`, answer **without an API key** (one domain per call, with a free daily limit per network). That means every command below works as you read it. I ran all of them on 26 November 2026, and the outputs shown are from those runs.\n\nA client needs three JSON-RPC methods:\n\n`initialize`: agree on a protocol version and learn the server's name.` tools/list`: get each tool's name, description and JSON Schema for its input.`tools/call`: run a tool with arguments.\nEach one is a POST with `Content-Type: application/json` and an `Accept` header that allows both JSON and `text/event-stream` (the Streamable HTTP transport lets a server reply either way; this one replies with plain JSON).\n\nYou can check it with curl first:\n\n```\ncurl -s https://siftwright.com/mcp \\\n  -H 'Content-Type: application/json' \\\n  -H 'Accept: application/json, text/event-stream' \\\n  -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\"}' | jq -r '.result.tools[].name'\nyoutube_transcript\nwebsite_screenshot\ngoogle_news\npqc_scan\ncontact_details\ntech_stack\napp_store_reviews\nats_jobs\ndomain_whois\n\"\"\"Call a remote MCP server's tools with nothing but the Python standard library.\"\"\"\nimport json\nimport os\nimport sys\nimport urllib.request\n\nMCP_URL = \"https://siftwright.com/mcp\"\nAPI_KEY = os.environ.get(\"SIFTWRIGHT_API_KEY\")  # optional: keyless calls use the free trial\n\ndef rpc(method, params=None, _id=[0]):\n    _id[0] += 1\n    body = {\"jsonrpc\": \"2.0\", \"id\": _id[0], \"method\": method}\n    if params is not None:\n        body[\"params\"] = params\n    headers = {\n        \"Content-Type\": \"application/json\",\n        \"Accept\": \"application/json, text/event-stream\",\n        \"MCP-Protocol-Version\": \"2025-06-18\",\n        # Cloudflare-fronted sites often refuse the default \"Python-urllib\" agent.\n        \"User-Agent\": \"stdlib-mcp-demo/1.0\",\n    }\n    if API_KEY:\n        headers[\"Authorization\"] = f\"Bearer {API_KEY}\"\n    req = urllib.request.Request(MCP_URL, json.dumps(body).encode(), headers)\n    with urllib.request.urlopen(req, timeout=120) as resp:\n        msg = json.load(resp)\n    if \"error\" in msg:\n        raise RuntimeError(msg[\"error\"])\n    return msg[\"result\"]\n\ndef call_tool(name, arguments):\n    result = rpc(\"tools/call\", {\"name\": name, \"arguments\": arguments})\n    # Tool results come back as content blocks; these tools put JSON in a text block.\n    text = \"\".join(b.get(\"text\", \"\") for b in result[\"content\"] if b[\"type\"] == \"text\")\n    if result.get(\"isError\"):\n        raise RuntimeError(text)\n    try:\n        return json.loads(text)\n    except json.JSONDecodeError:\n        return text\n\nif __name__ == \"__main__\":\n    info = rpc(\"initialize\", {\n        \"protocolVersion\": \"2025-06-18\",\n        \"capabilities\": {},\n        \"clientInfo\": {\"name\": \"stdlib-demo\", \"version\": \"1.0\"},\n    })\n    print(\"server:\", info[\"serverInfo\"][\"title\"], info[\"protocolVersion\"])\n\n    tools = rpc(\"tools/list\")[\"tools\"]\n    print(\"tools:\", \", \".join(t[\"name\"] for t in tools))\n\n    domain = sys.argv[1] if len(sys.argv) > 1 else \"wikipedia.org\"\n    print(json.dumps(call_tool(\"domain_whois\", {\"domains\": [domain]}), indent=2)[:1500])\n    print(json.dumps(call_tool(\"pqc_scan\", {\"hosts\": [domain]}), indent=2)[:1500])\n```\n\nRun it:\n\n```\npython3 mcp_try.py wikipedia.org\n```\n\nTrimmed output from my run:\n\n```\nserver: Siftwright web data 2025-06-18\ntools: youtube_transcript, website_screenshot, google_news, pqc_scan, contact_details, tech_stack, app_store_reviews, ats_jobs, domain_whois\n{\n  \"mode\": \"free_trial\",\n  \"results\": [\n    {\n      \"domain\": \"wikipedia.org\",\n      \"source\": \"rdap\",\n      \"registrar\": \"MarkMonitor Inc.\",\n      \"createdAt\": \"2001-01-13T00:12:14.754Z\",\n      \"expiresAt\": \"2027-01-13T00:12:14Z\",\n      \"ageDays\": 9448,\n      \"daysUntilExpiry\": 47,\n      \"nameservers\": [\"ns0.wikimedia.org\", \"ns1.wikimedia.org\", \"ns2.wikimedia.org\"],\n      \"dnssec\": false,\n      \"dns\": {\n        \"mx\": [{\"priority\": 10, \"host\": \"mx-in1001.wikimedia.org\"}, ...],\n        \"spf\": \"v=spf1 include:_cidrs.wikimedia.org ~all\",\n        \"dmarc\": \"v=DMARC1; p=reject; rua=mailto:dmarc-rua@wikimedia.org;\",\n        ...\n{\n  \"mode\": \"free_trial\",\n  \"results\": [\n    {\n      \"host\": \"wikipedia.org\",\n      \"tls13\": true,\n      \"pqKeyExchange\": false,\n      \"groups\": {\"X25519MLKEM768\": false, ..., \"classical\": \"x25519\"},\n      \"grade\": {\"letter\": \"D\", \"label\": \"Not quantum-safe yet\", ...},\n      ...\n```\n\nFor comparison, `pqc_scan` on `cloudflare.com` in the same session returned `pqKeyExchange: true`, `X25519MLKEM768: true`, `prefersPostQuantum: true` and grade `A+`.\n\n**1. The default Python user agent got a 403.** My first run failed with `HTTP Error 403: Forbidden` before reaching the MCP server at all. Many Cloudflare-fronted sites refuse requests whose `User-Agent` is `Python-urllib/3.x`. Setting any honest agent string (` stdlib-mcp-demo/1.0`) fixed it. If a remote MCP server works with curl but not from your script, check this first.\n\n**2. Tool results are content blocks, not raw JSON.** `tools/call` returns `{\"content\": [{\"type\": \"text\", \"text\": \"...\"}], \"isError\": ...}`. These tools put a JSON document inside the text block, so the client joins the text blocks and tries `json.loads`. A model sees the same text, which is why small, structured output matters for context size.\n\n**3. Errors a model should read come back as `isError: true`, not as HTTP errors.** Calling a key-only tool without a key returns HTTP 200 with:\n\n```\nThis tool needs a Siftwright API key. Add the header \"Authorization: Bearer sw_live_...\" to your MCP client config. ...\n```\n\nThat is the right design for agents: the model gets a readable reason instead of a transport failure. Your own client should check `isError` rather than rely on status codes.\n\n**4. Read the extra fields, not just `results`.** When I passed two domains without a key, the server checked only the first and said so in a `note` field:\n\n```\nFree keyless trial: one host per call with a daily limit per network. Only the first of your 2 entries was checked. ...\n```\n\nA script that only reads `results` would silently miss the second domain.\n\nOnce the raw calls behave, adding the server to a client is one line or one small JSON block. I tested the protocol above directly. The client configs below follow each client's documented format for remote HTTP servers.\n\nClaude Code:\n\n```\nclaude mcp add --transport http siftwright https://siftwright.com/mcp\n```\n\nCursor (`~/.cursor/mcp.json`):\n\n```\n{\n  \"mcpServers\": {\n    \"siftwright\": { \"url\": \"https://siftwright.com/mcp\" }\n  }\n}\n```\n\nVS Code (`.vscode/mcp.json`):\n\n```\n{\n  \"servers\": {\n    \"siftwright\": { \"type\": \"http\", \"url\": \"https://siftwright.com/mcp\" }\n  }\n}\n```\n\nWithout a key, the agent can run `domain_whois` and `pqc_scan` on one domain at a time. The other seven tools (YouTube transcripts, screenshots/PDFs, Google News, contact details, tech stack, App Store reviews, ATS jobs) and list inputs need an API key, sent as an `Authorization: Bearer ...` header. Plans start at $29/month, and failed results are not counted. Details are at [siftwright.com/web-data-for-ai-agents](https://siftwright.com/web-data-for-ai-agents/).\n\nNothing in `rpc()` or `call_tool()` is specific to this server. Change `MCP_URL`, and the script will list and call tools on any remote MCP server that speaks Streamable HTTP and answers with plain JSON. Servers that stream `text/event-stream` responses or require an `Mcp-Session-Id` header from `initialize` need a few more lines, so check the response's `Content-Type` before calling `json.load`.\n\n*Disclosure: I work on Siftwright, the service used in the examples.*", "url": "https://wpnews.pro/news/talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-a", "canonical_source": "https://dev.to/siftwright/talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-tools-without-a-key-380h", "published_at": "2026-11-26 20:09:52+00:00", "updated_at": "2026-11-26 20:14:53.487777+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "developer-tools", "ai-tools"], "entities": ["Siftwright", "Claude", "Cursor", "Visual Studio Code", "Python"], "also_reported_by": [], "takeaway": "A remote MCP server can be driven with plain urllib JSON-RPC POSTs to initialize, tools/list and tools/call, provided the request sends an Accept header allowing application/json and text/event-stream and a non-default User-Agent to get past Cloudflare.", "recommendation": {"advice": "Before wiring an MCP server into your agent, probe it with a stdlib JSON-RPC client that calls initialize, tools/list and tools/call, setting the Accept and User-Agent headers.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-a", "markdown": "https://wpnews.pro/news/talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-a.md", "text": "https://wpnews.pro/news/talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-a.txt", "jsonld": "https://wpnews.pro/news/talk-to-a-remote-mcp-server-with-only-the-python-standard-library-and-call-two-a.jsonld"}}