#!/usr/bin/env python3 """MCP connector: remote public MCP server (DeepWiki) via mcp_servers + mcp_toolset (beta mcp-client-2025-11-20). STATUS: LIVE_VERIFIED 2026-09-18 (same request as i1: mcp_tool_use read_wiki_structure -> mcp_tool_result, ~$0.003 on haiku 4.5). Run: .venv/bin/python examples/anthropic/mcp/mcp_connector.py [https://your-public-host/mcp] (default: https://mcp.deepwiki.com/mcp) """ import json, sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[3])) from scripts.live import anthropic_request url = sys.argv[1] if len(sys.argv) > 1 else "https://mcp.deepwiki.com/mcp" prompt = ("Call the read_wiki_structure tool for the GitHub repo anthropics/anthropic-sdk-python and reply with only the first 3 topic names." if "deepwiki" in url else "Use the echo tool to echo the word PING and reply with what it returned.") st, r, _ = anthropic_request("POST", "/v1/messages", { "model": "claude-haiku-4-5-20251001", "max_tokens": 200, "mcp_servers": [{"type": "url", "url": url, "name": "srv"}], # + "authorization_token": "" if needed "tools": [{"type": "mcp_toolset", "mcp_server_name": "srv"}], # default_config / configs for allow/deny lists "messages": [{"role": "user", "content": prompt}]}, beta="mcp-client-2025-11-20", note="mcp_connector.py") print(st, json.dumps([{k: b.get(k) for k in ("type", "name", "server_name", "input", "is_error", "text")} for b in r.get("content", [])], indent=1)[:1500] if st == 200 else r)