Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161"""Minimal line-delimited JSON-RPC MCP server used by mcp_test.py."""
import jsonimport osimport signalimport sysimport timefrom pathlib import Path
TOOLS = [ { "name": "echo", "description": "Echo one message back", "inputSchema": { "type": "object", "required": ["message"], "properties": {"message": {"type": "string"}}, }, }]
# Optional test controls: `delay` holds the handshake for that many seconds,# `hold` holds it while that file exists, and `tools` replaces the catalogue,# without changing the server's config.# `mode` is "modern" for a 2026-07-28 server (server/discover, `_meta` on# every request, no initialize), "silent" for an older server that ignores# methods it does not know, or "deaf" for one that ignores stdin EOF and# SIGTERM. Every method received is appended to `seen`.CONTROL = Path(os.environ.get("FAKE_MCP_CONTROL") or "/nonexistent")MODERN = "2026-07-28"
REVISIONS = {"2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25"}STRICT = os.environ.get("FAKE_MCP_STRICT") == "1"REFUSE = os.environ.get("FAKE_MCP_REFUSE_INITIALIZE") == "1"RECORD = os.environ.get("FAKE_MCP_RECORD")if os.environ.get("FAKE_MCP_PIDFILE"): Path(os.environ["FAKE_MCP_PIDFILE"]).write_text(str(os.getpid()))
def control(name): path = CONTROL / name return path.read_text() if path.exists() else None
MODE = control("mode")if MODE == "deaf": signal.signal(signal.SIGTERM, signal.SIG_IGN) (CONTROL / "pid").write_text(str(os.getpid()))
def record(method): if CONTROL.exists(): with (CONTROL / "seen").open("a") as seen: seen.write(f"{method}\n")
def initialized(params): """The answer to an initialize, under the opt-in modes above.""" if REFUSE: return None, {"code": -32603, "message": "initialize refused"} if not STRICT: return { "protocolVersion": "2025-06-18", "capabilities": {"tools": {}}, "serverInfo": {"name": "fake", "version": "1"}, }, None version = params.get("protocolVersion") if version not in REVISIONS: return None, { "code": -32602, "message": f"unsupported protocolVersion: {version!r}", } return { "protocolVersion": version, "capabilities": {"tools": {}}, "serverInfo": {"name": "fake", "version": "1"}, }, None
def reply(id, result=None, error=None): body = {"jsonrpc": "2.0", "id": id} body["error" if error else "result"] = error or result sys.stdout.write(json.dumps(body) + chr(10)) sys.stdout.flush()
for line in sys.stdin: message = json.loads(line) if line.strip() else {} method, id = message.get("method"), message.get("id") record(method) if id is None: continue meta = (message.get("params") or {}).get("_meta") or {} if MODE == "modern" and method == "server/discover": reply( id, { "resultType": "complete", "supportedVersions": [MODERN], "capabilities": {"tools": {}}, }, ) elif MODE == "modern" and ( meta.get("io.modelcontextprotocol/protocolVersion") != MODERN or "io.modelcontextprotocol/clientCapabilities" not in meta ): reply(id, error={"code": -32602, "message": f"this server speaks {MODERN}"}) elif MODE == "silent" and method not in ("initialize", "tools/list", "tools/call"): continue elif method == "initialize": time.sleep(float(control("delay") or 0)) while control("hold") is not None: time.sleep(0.05) params = message.get("params") or {} if RECORD: with open(RECORD, "a") as record_file: record_file.write(json.dumps(params) + chr(10)) result, error = initialized(params) reply(id, result, error=error) elif method == "tools/list": tools = control("tools") reply(id, {"tools": json.loads(tools) if tools else TOOLS}) elif method == "tools/call": arguments = message["params"].get("arguments", {}) if arguments.get("message") == "fail": reply(id, error={"code": -32000, "message": "the tool exploded"}) continue reply( id, { "content": [ { "type": "text", "text": json.dumps( { "echoed": arguments.get("message"), "secret": os.environ.get("FAKE_SECRET"), **( {"cwd": os.getcwd()} if os.environ.get("FAKE_REPORT_CWD") else {} ), "ambient": os.environ.get("ALBEDO_MCP_AMBIENT"), } ), } ] }, ) elif method == "ping": reply(id, {}) else: reply(id, error={"code": -32601, "message": "method not found"})
if os.environ.get("FAKE_MCP_CLOSED"): Path(os.environ["FAKE_MCP_CLOSED"]).write_text("closed")if MODE == "deaf": time.sleep(120)