#!/usr/bin/env python3 """A local, side-effect-free MCP server for the Kastra documentation walkthrough.""" import json import sys for line in sys.stdin: try: request = json.loads(line) except json.JSONDecodeError: print(json.dumps({"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": "Invalid JSON"}}), flush=True) continue if not isinstance(request, dict) or "id" not in request: continue # Notifications have no response. method = request.get("method") params = request.get("params", {}) response = {"jsonrpc": "2.0", "id": request["id"]} if method == "initialize": response["result"] = {"protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": {"name": "kastra-docs-echo", "version": "1.0.0"}} elif method == "ping": response["result"] = {} elif method == "tools/list": response["result"] = {"tools": [{"name": "docs_echo", "description": "Echo a documentation test message without modifying files or making network requests.", "inputSchema": {"type": "object", "properties": {"message": {"type": "string"}}, "required": ["message"], "additionalProperties": False}}]} elif method == "tools/call" and isinstance(params, dict): arguments = params.get("arguments", {}) if params.get("name") == "docs_echo" and isinstance(arguments, dict) and isinstance(arguments.get("message"), str) and set(arguments) == {"message"}: response["result"] = {"content": [{"type": "text", "text": "echo completed: " + arguments["message"]}]} else: response["error"] = {"code": -32602, "message": "Use docs_echo with one string argument: message"} else: response["error"] = {"code": -32601, "message": "Method not found"} print(json.dumps(response), flush=True)