π The fast, Pythonic way to build MCP servers and clients.
Run dev inspector servers over stdio and stop mapping the deployment port to the proxy (#6029)
Asem ahmed616860c846e4
diff --git a/fastmcp_slim/fastmcp/cli/cli.py b/fastmcp_slim/fastmcp/cli/cli.pyindex 4a19158d1..7cd8e6633 100644--- a/fastmcp_slim/fastmcp/cli/cli.py+++ b/fastmcp_slim/fastmcp/cli/cli.py@@ -239,13 +239,7 @@ async def inspector(with_requirements=with_requirements,project=project,editable=[str(p) for p in with_editable] if with_editable else None,- port=server_port, # Use deployment config for server port)-- # Get server port from config if not specified via CLI- if not server_port:- server_port = config.deployment.port-except FileNotFoundError:sys.exit(1)@@ -293,9 +287,12 @@ async def inspector(# Build the fastmcp run commandfastmcp_cmd = ["fastmcp", "run", server_spec, "--no-banner"]- # Forward module mode flag+ # The Inspector connects over stdio, so a fastmcp.json deployment+ # must not make the child serve HTTP. Module mode ignores --transport.if module:fastmcp_cmd.append("--module")+ else:+ fastmcp_cmd.extend(["--transport", "stdio"])# Add reload flags if enabled - the server will handle reloadingif reload:diff --git a/tests/cli/test_run.py b/tests/cli/test_run.pyindex 350c8feff..487f2e750 100644--- a/tests/cli/test_run.py+++ b/tests/cli/test_run.py@@ -1069,6 +1069,68 @@ class TestInspectorModuleMode:# --module should be in the subprocess commandcmd = mock_subprocess.call_args[0][0]assert "--module" in cmd+ # `fastmcp run --module` ignores --transport and warns about it+ assert "--transport" not in cmd+++class TestInspectorHttpDeployment:+ """Test the inspector command with an HTTP deployment in fastmcp.json."""++ @pytest.fixture+ def http_config(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:+ monkeypatch.delenv("SERVER_PORT", raising=False)+ server_file = tmp_path / "server.py"+ server_file.write_text("from fastmcp import FastMCP\n\nmcp = FastMCP('test')\n")+ config_file = tmp_path / "fastmcp.json"+ config_file.write_text(+ json.dumps(+ {+ "source": {"path": str(server_file), "entrypoint": "mcp"},+ "deployment": {"transport": "http", "port": 8000},+ }+ )+ )+ return config_file++ async def _run_inspector(self, config_file: Path, **kwargs) -> MagicMock:+ mock_process = MagicMock()+ mock_process.returncode = 0+ with (+ patch("fastmcp.cli.cli._get_npx_command", return_value="npx"),+ patch(+ "fastmcp.cli.cli.subprocess.run", return_value=mock_process+ ) as mock_subprocess,+ pytest.raises(SystemExit),+ ):+ await inspector(str(config_file), **kwargs)+ return mock_subprocess++ async def test_server_runs_over_stdio(self, http_config: Path):+ """The Inspector connects over stdio, so the child must not serve HTTP."""+ mock_subprocess = await self._run_inspector(http_config)++ assert mock_subprocess.call_args.args[0] == [+ "npx",+ "@modelcontextprotocol/inspector",+ "fastmcp",+ "run",+ str(http_config),+ "--no-banner",+ "--transport",+ "stdio",+ "--reload",+ ]++ async def test_deployment_port_is_not_the_proxy_port(self, http_config: Path):+ """The MCP server's HTTP port is unrelated to the Inspector proxy port."""+ mock_subprocess = await self._run_inspector(http_config)++ assert "SERVER_PORT" not in mock_subprocess.call_args.kwargs["env"]++ async def test_server_port_option_sets_the_proxy_port(self, http_config: Path):+ mock_subprocess = await self._run_inspector(http_config, server_port=6277)++ assert mock_subprocess.call_args.kwargs["env"]["SERVER_PORT"] == "6277"class TestRunDevApps: