Skip to main content
Glama
test_mcp_handshake.py1.62 kB
import subprocess import json import sys import os def test_handshake(): # Path to your main.py server_script = os.path.join("src", "main.py") # Start the MCP server process print(f"Starting server: uv run {server_script} ...") process = subprocess.Popen( ["uv", "run", server_script], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=0 # Unbuffered ) # JSON-RPC 2.0 Initialize Request init_request = { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": { "name": "test-client", "version": "1.0" } } } print("Sending 'initialize' request...") # Write to the server's stdin json_str = json.dumps(init_request) process.stdin.write(json_str + "\n") process.stdin.flush() # Read from the server's stdout print("Waiting for response...") response_line = process.stdout.readline() if response_line: print("\nServer Responded:") try: resp = json.loads(response_line) print(json.dumps(resp, indent=2)) except json.JSONDecodeError: print(f"Received non-JSON: {response_line}") else: print("\nNo response received.") print("Stderr content:") print(process.stderr.read()) # Clean up process.terminate() if __name__ == "__main__": test_handshake()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nice-bills/dune-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server