import asyncio
import json
import os
import sys
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
def oracle_env() -> dict:
env = {k: v for k, v in os.environ.items() if not k.startswith("IGNITION_")}
env["IGNITION_CLI_CONFIG"] = os.environ["IGNITION_CLI_CONFIG"]
env["IGNITION_TOKEN"] = os.environ.get("IGNITION_TOKEN", "mock:name-key")
env["IGNITION_LOG"] = "trace"
return env
def server_name(initialize_result) -> str:
info = getattr(initialize_result, "server_info", None) or getattr(
initialize_result, "serverInfo", None
)
return getattr(info, "name", None)
async def main() -> int:
operands = [a for a in sys.argv[1:] if a != "--"]
if not operands or not operands[0]:
print("usage: mcp_oracle.py [--] <path-to-ign>", file=sys.stderr)
return 2
ign_path = operands[0]
if not os.environ.get("IGNITION_CLI_CONFIG"):
print(
"IGNITION_CLI_CONFIG must point at the oracle's profile config",
file=sys.stderr,
)
return 2
params = StdioServerParameters(
command=ign_path, args=["mcp", "serve"], env=oracle_env()
)
async with stdio_client(params) as (read, write):
async with ClientSession(read, write) as session:
init = await session.initialize()
name = server_name(init)
assert name == "ign", f"serverInfo.name must be ign, got {name!r}"
listed = await session.list_tools()
tools = list(listed.tools)
assert len(tools) > 0, "tools/list returned an empty catalog"
for tool in tools:
assert tool.name, "every tool has a name"
assert tool.description, "every tool has a description"
schema = getattr(tool, "input_schema", None) or getattr(
tool, "inputSchema", None
)
assert schema is not None, "every tool has inputSchema"
called = await session.call_tool("status", {})
is_error = getattr(called, "is_error", None)
if is_error is None:
is_error = getattr(called, "isError")
assert not is_error, f"tools/call status errored: {called.content}"
assert len(called.content) >= 1, "tools/call returned no content"
first = called.content[0]
text = getattr(first, "text", None)
assert text, f"the first content block is text: {first}"
envelope = json.loads(text)
assert envelope.get("ok") is True, f"envelope not ok:true: {envelope}"
print("ORACLE OK")
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main()))