Setup
Install and define the direct MCP client
Use the canonical raw JSON-RPC transport and local signer setup from the executed notebook.
pip install httpx pynacl base58 solders import json, hashlib, os, time, base64, pathlibimport httpxfrom nacl.signing import SigningKeyimport base58 BASE = "https://nukez-mcp-538908875166.us-central1.run.app/mcp"HEADERS = {"Content-Type": "application/json", "Accept": "application/json, text/event-stream"}KEYPAIR_PATH = pathlib.Path("/path/to/svm_key.json")RPC_URL = "https://mainnet.helius-rpc.com/?api-key=<API_KEY>" _kp_bytes = json.loads(KEYPAIR_PATH.read_text())_sk = SigningKey(bytes(_kp_bytes[:32]))PUBKEY = base58.b58encode(_sk.verify_key.encode()).decode()_req_id = 0 def rpc(method: str, params: dict = None): global _req_id _req_id += 1 payload = {"jsonrpc": "2.0", "id": _req_id, "method": method} if params: payload["params"] = params resp = httpx.post(BASE, json=payload, headers=HEADERS, timeout=120) ct = resp.headers.get("content-type", "") if "text/event-stream" in ct: for line in resp.text.splitlines(): if line.startswith("data: "): data = json.loads(line[6:]) return data.get("result") or data.get("error") body = resp.json() return body.get("result") or body.get("error") def call(tool: str, args: dict = None): params = {"name": tool} if args: params["arguments"] = args result = rpc("tools/call", params) if result and "content" in result: texts = [c["text"] for c in result["content"] if c.get("type") == "text"] if texts: try: return json.loads(texts[0]) except json.JSONDecodeError: return texts[0] return result
Code notes
This is the canonical setup from the usage guide and executed notebook: install direct-client dependencies, configure the hosted endpoint, load a local keypair, create JSON-RPC helpers, build signed envelopes, and provide an explicit solders-based Solana transfer helper.
The full guide also defines compute_locker_id(), build_envelope(), and solana_transfer(); those helpers are used by the following examples.
