Skip to main content
Glama
stdio_server.py•1.05 kB
import json import sys from time import sleep def run_stdio_server(handler): """ Reads JSON-RPC requests from stdin, calls the handler, and writes responses to stdout. The handler should be a function that takes a dict and returns a dict (the response). """ while True: line = sys.stdin.readline() if not line: print("No line read", file=sys.stderr) sleep(1) continue line = line.strip() if not line: continue try: data = json.loads(line) response = handler(data) sys.stdout.write(json.dumps(response) + "\n") sys.stdout.flush() except Exception as e: sys.stdout.write( json.dumps( { "jsonrpc": "2.0", "error": {"code": -32000, "message": str(e)}, "id": None, } ) + "\n" ) sys.stdout.flush()

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/DrDroidLab/grafana-mcp-server'

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