#!/usr/bin/env python3 """Ein MCP-Server über stdin/stdout, für tests/mcp.py. Spricht genau das, was junction als stdio-Upstream erwartet: eine JSON-Zeile je Anfrage, eine JSON-Zeile je Antwort. Beendet sich bei EOF auf stdin — sonst bliebe nach einem abgebrochenen Testlauf ein Prozess zurück. """ import json import sys TOOLS = [ {"name": "echo", "description": "gibt den Text zurück", "inputSchema": {"type": "object", "properties": {"text": {"type": "string"}}}}, ] PROMPTS = [{"name": "hello", "description": "ein Gruß", "arguments": []}] RESOURCES = [{"uri": "localfile://note", "name": "Notiz", "mimeType": "text/plain"}] def handle(req): method = req.get("method") rid = req.get("id") if method == "initialize": return {"jsonrpc": "2.0", "id": rid, "result": {"protocolVersion": "2025-06-18", "capabilities": {"tools": {}, "prompts": {}, "resources": {}}, "serverInfo": {"name": "local", "version": "1"}}} if method == "tools/list": return {"jsonrpc": "2.0", "id": rid, "result": {"tools": TOOLS}} if method == "prompts/list": return {"jsonrpc": "2.0", "id": rid, "result": {"prompts": PROMPTS}} if method == "resources/list": return {"jsonrpc": "2.0", "id": rid, "result": {"resources": RESOURCES}} if method == "resources/read": uri = (req.get("params") or {}).get("uri") return {"jsonrpc": "2.0", "id": rid, "result": {"contents": [{"uri": uri, "text": "stdio:note"}]}} if method == "prompts/get": name = (req.get("params") or {}).get("name") return {"jsonrpc": "2.0", "id": rid, "result": {"description": f"stdio:{name}", "messages": [{"role": "user", "content": {"type": "text", "text": "hi"}}]}} if method == "tools/call": params = req.get("params") or {} text = (params.get("arguments") or {}).get("text", "") return {"jsonrpc": "2.0", "id": rid, "result": {"content": [{"type": "text", "text": f"stdio:{params.get('name')}:{text}"}], "isError": False}} return {"jsonrpc": "2.0", "id": rid, "error": {"code": -32601, "message": "no such method"}} for line in sys.stdin: line = line.strip() if not line: continue try: req = json.loads(line) except json.JSONDecodeError: continue sys.stdout.write(json.dumps(handle(req)) + "\n") sys.stdout.flush()