diff --git a/gateway/__main__.py b/gateway/__main__.py index 9bc9935..1aad784 100644 --- a/gateway/__main__.py +++ b/gateway/__main__.py @@ -10,6 +10,7 @@ import time from typing import Optional from gateway.mcp import mcp +from gateway.mcp.log import mcp_log LOCAL_COMPOSE_FILE = "gateway/docker-compose.local.yml" @@ -224,8 +225,18 @@ def main(): sys.exit(1) verb = sys.argv[1] + if verb == "help": + print_help() + return 0 + + if "INVARIANT_API_KEY" not in os.environ: + print("[ERROR] INVARIANT_API_KEY environment variable is not set.") + mcp_log("[ERROR] INVARIANT_API_KEY environment variable is not set.") + sys.exit(1) + if verb == "mcp": return asyncio.run(mcp.execute(sys.argv[2:])) + if verb == "server": if len(sys.argv) < 3: print( @@ -239,9 +250,7 @@ def main(): if not run_server_command(command, args): return 1 return 0 - if verb == "help": - print_help() - return 0 + print(f"[gateway/__main__.py] Unknown action: {verb}") return 1 diff --git a/gateway/mcp/README.md b/gateway/mcp/README.md index 598a651..1a65b90 100644 --- a/gateway/mcp/README.md +++ b/gateway/mcp/README.md @@ -67,6 +67,14 @@ Key Parameters * --push-explorer: Enables pushing annotated traces of MCP message flows to the specified project in Invariant Explorer. +### Logs + +To see logs and errors from the MCP gateway and the MCP server, you can do: + +```bash +tail -f ~/.invariant/mcp.log +``` + ### Local Development Workflow To test or develop the gateway locally: diff --git a/gateway/mcp/mcp.py b/gateway/mcp/mcp.py index 2074974..2c5890b 100644 --- a/gateway/mcp/mcp.py +++ b/gateway/mcp/mcp.py @@ -464,10 +464,6 @@ def split_args(args: list[str] = None) -> tuple[list[str], list[str]]: async def execute(args: list[str] = None): """Main function to execute the MCP gateway.""" - if "INVARIANT_API_KEY" not in os.environ: - mcp_log("[ERROR] INVARIANT_API_KEY environment variable is not set.") - sys.exit(1) - mcp_gateway_args, mcp_server_command_args = split_args(args) ctx = McpContext(mcp_gateway_args)