Google Flights MCP, CLI and Python Library
Add HTTP transport tests and update MCP server configuration (#114)
Punit Arani56766d91dbd2
diff --git a/Makefile b/Makefileindex 2c2ec50..05c99da 100644--- a/Makefile+++ b/Makefile@@ -17,6 +17,10 @@ install-all:mcp:uv run fli-mcp+# Run the MCP server over HTTP+mcp-http:+ uv run fli-mcp-http+# Build the docsdocs:uv run --extra dev mkdocs build@@ -83,4 +87,4 @@ help:@echo " make devcontainer - Build dev container image"@echo " make requirements - Generate the requirements.txt file"# Declare the targets as phony-.PHONY: help install install-dev install-all mcp docs format lint lint-fix test test-mcp test-fuzz test-all ci ci-docker devcontainer requirements+.PHONY: help install install-dev install-all mcp mcp-http docs format lint lint-fix test test-mcp test-fuzz test-all ci ci-docker devcontainer requirementsdiff --git a/fli/mcp/server.py b/fli/mcp/server.pyindex 317c8c4..13522cf 100755--- a/fli/mcp/server.py+++ b/fli/mcp/server.py@@ -716,8 +716,14 @@ def run():mcp.run(transport="stdio")-def run_http(host: str = "127.0.0.1", port: int = 8000) -> None:- """Run the MCP server over HTTP (streamable)."""+def run_http(host: str = "0.0.0.0", port: int = 8000) -> None:+ """Run the MCP server over HTTP (streamable).++ The default host is ``0.0.0.0`` so the server is reachable from outside the+ container when deployed (e.g. Railway, Docker). When running locally this+ exposes the server on every network interface — set ``HOST=127.0.0.1`` to+ restrict it to loopback.+ """env_host = os.getenv("HOST")env_port = os.getenv("PORT")diff --git a/tests/mcp/test_mcp_http.py b/tests/mcp/test_mcp_http.pynew file mode 100644index 0000000..7d79e1f--- /dev/null+++ b/tests/mcp/test_mcp_http.py@@ -0,0 +1,108 @@+"""Tests that the MCP HTTP server boots and exposes the expected tools.++Covers:+ 1. In-process client test — verifies tool listing without networking.+ 2. HTTP transport test — starts the server on a free port and connects over HTTP.+"""++import threading+import time++import pytest+import uvicorn+from fastmcp import Client++from fli.mcp.server import mcp++EXPECTED_TOOLS = {"search_flights", "search_dates", "find_airports"}+++# ---------------------------------------------------------------------------+# Fixtures+# ---------------------------------------------------------------------------+++def http_mcp_url():+ """Boot the MCP server in a background thread and yield its base URL.++ Uses uvicorn port=0 so the OS assigns a free port at bind time, then reads+ the actual port back from the bound socket. This avoids the TOCTOU race of+ pre-allocating a port and hoping nothing else claims it before uvicorn binds.+ """+ app = mcp.http_app()+ config = uvicorn.Config(app, host="127.0.0.1", port=0, log_level="warning")+ server = uvicorn.Server(config)+ thread = threading.Thread(target=server.run, daemon=True)+ thread.start()++ deadline = time.monotonic() + 10+ while not server.started:+ if time.monotonic() > deadline:+ server.should_exit = True+ thread.join(timeout=5)+ pytest.fail("MCP HTTP server did not start in time")+ time.sleep(0.05)++ port = server.servers[0].sockets[0].getsockname()[1]+ try:+ yield f"http://127.0.0.1:{port}/mcp/"+ finally:+ server.should_exit = True+ thread.join(timeout=5)+++# ---------------------------------------------------------------------------+# Test A: In-process (no network)+# ---------------------------------------------------------------------------+++class TestMCPInProcess:+ """Verify MCP tool listing via the in-process FastMCP client."""++ @pytest.mark.asyncio+ async def test_list_tools_returns_expected_names(self):+ """list_tools() must return the expected MCP tools."""+ client = Client(mcp)+ async with client:+ tools = await client.list_tools()+ names = {t.name for t in tools}+ assert names == EXPECTED_TOOLS++ @pytest.mark.asyncio+ async def test_tools_have_description_and_schema(self):+ """Each tool must have a non-empty description and an inputSchema."""+ client = Client(mcp)+ async with client:+ tools = await client.list_tools()+ for tool in tools:+ assert tool.description, f"{tool.name} is missing a description"+ assert tool.inputSchema, f"{tool.name} is missing inputSchema"+++# ---------------------------------------------------------------------------+# Test B: HTTP transport (full integration)+# ---------------------------------------------------------------------------+++class TestMCPHTTP:+ """Start the MCP server over HTTP and verify tools via a real connection."""++ @pytest.mark.asyncio+ async def test_http_list_tools(self, http_mcp_url):+ """Boot the HTTP server, connect, and verify tool names."""+ client = Client(http_mcp_url)+ async with client:+ tools = await client.list_tools()+ names = {t.name for t in tools}+ assert names == EXPECTED_TOOLS++ @pytest.mark.asyncio+ async def test_http_tools_have_description_and_schema(self, http_mcp_url):+ """Boot the HTTP server and verify each tool has description + schema."""+ client = Client(http_mcp_url)+ async with client:+ tools = await client.list_tools()+ for tool in tools:+ assert tool.description, f"{tool.name} is missing a description"+ assert tool.inputSchema, f"{tool.name} is missing inputSchema"