Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCP Inspector Fails to Connect with stdio Transport and --connect Flag (macOS) #106

Open
dazzaji opened this issue Dec 7, 2024 · 1 comment
Labels
question Further information is requested

Comments

@dazzaji
Copy link

dazzaji commented Dec 7, 2024

Description:

When attempting to connect the MCP Inspector to the "everything" server using stdio transport and the --connect flag (with the server running in a separate terminal), the connection fails. The Inspector frontend consistently shows "Connection Error," and the browser console logs repeated ERR_CONNECTION_REFUSED. No MCP messages are exchanged.

Steps to Reproduce:

  1. Environment:

    • Node.js v, npm v, mcp-inspector v
    • Python 3.11.1 (via pyenv), macOS Ventura 13.5, VS Code 1.95.3
  2. Create and activate a Python virtual environment:

    python3.11 -m venv .venv
    source .venv/bin/activate
  3. Install mcp and trio packages:

    pip install mcp trio
  4. Terminal 1 (external terminal):

    • Navigate to your project directory:
      cd /path/to/your/directory
      source .venv/bin/activate
      python -m mcp.server
    • Leave this terminal running.
  5. Terminal 2 (VS Code integrated terminal):

    • Open VS Code, set Python interpreter to .venv/bin/python.
    • Run the following:
      cd /path/to/your/directory
      source .venv/bin/activate
      mcp-inspector --transport stdio --connect
  6. Open Inspector in a browser at http://localhost:5173 (or the URL displayed in Terminal 2). Observe the "Connection Error."

  7. External Terminal Test (Optional):
    Repeat the steps above using only external terminals (instead of the VS Code integrated terminal) to rule out VS Code as a factor.

Expected Behavior:

The MCP Inspector connects to the externally running server, and the frontend UI (including the "Tools" tab) is fully functional.

Actual Behavior:

The Inspector frontend displays "Connection Error," the browser console logs repeated ERR_CONNECTION_REFUSED, and no MCP messages are exchanged. The server appears to restart repeatedly.

Additional Information:

  • VS Code's terminal.integrated.closeWhenInactive setting is disabled.
  • No launch.json (debugger configuration) is present.
  • No firewall or port conflicts on localhost (verified using lsof -i :3000 and lsof -i :5173).

ATTACHMENTS

Terminal 1 (server)

Last login: Sat Dec 7 00:10:52 on ttys009
-bash: chruby: command not found
-bash: chruby: command not found

The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh.
For more details, please visit https://support.apple.com/kb/HT208050.
Users-iMac:~ User$ cd /Users/User/test-mcp
Users-iMac:test-mcp User$ rm -rf .venv
Users-iMac:test-mcp User$ python3.11 -m venv .venv
Users-iMac:test-mcp User$ source .venv/bin/activate
(.venv) Users-iMac:test-mcp User$ pip install --upgrade mcp trio
Collecting mcp
Using cached mcp-1.1.0-py3-none-any.whl (36 kB)
Collecting trio
Using cached trio-0.27.0-py3-none-any.whl (481 kB)
Collecting anyio>=4.6
Using cached anyio-4.7.0-py3-none-any.whl (93 kB)
Collecting httpx-sse>=0.4
Using cached httpx_sse-0.4.0-py3-none-any.whl (7.8 kB)
Collecting httpx>=0.27
Using cached httpx-0.28.1-py3-none-any.whl (73 kB)
Collecting pydantic>=2.8.0
Using cached pydantic-2.10.3-py3-none-any.whl (456 kB)
Collecting sse-starlette>=2.0
Using cached sse_starlette-2.1.3-py3-none-any.whl (9.4 kB)
Collecting starlette>=0.39
Using cached starlette-0.41.3-py3-none-any.whl (73 kB)
Collecting attrs>=23.2.0
Using cached attrs-24.2.0-py3-none-any.whl (63 kB)
Collecting sortedcontainers
Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting idna
Using cached idna-3.10-py3-none-any.whl (70 kB)
Collecting outcome
Using cached outcome-1.3.0.post0-py2.py3-none-any.whl (10 kB)
Collecting sniffio>=1.3.0
Using cached sniffio-1.3.1-py3-none-any.whl (10 kB)
Collecting typing_extensions>=4.5
Using cached typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting certifi
Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
Collecting httpcore==1.*
Using cached httpcore-1.0.7-py3-none-any.whl (78 kB)
Collecting h11<0.15,>=0.13
Using cached h11-0.14.0-py3-none-any.whl (58 kB)
Collecting annotated-types>=0.6.0
Using cached annotated_types-0.7.0-py3-none-any.whl (13 kB)
Collecting pydantic-core==2.27.1
Using cached pydantic_core-2.27.1-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB)
Collecting uvicorn
Using cached uvicorn-0.32.1-py3-none-any.whl (63 kB)
Collecting click>=7.0
Using cached click-8.1.7-py3-none-any.whl (97 kB)
Installing collected packages: sortedcontainers, typing_extensions, sniffio, idna, httpx-sse, h11, click, certifi, attrs, annotated-types, uvicorn, pydantic-core, outcome, httpcore, anyio, trio, starlette, pydantic, httpx, sse-starlette, mcp
Successfully installed annotated-types-0.7.0 anyio-4.7.0 attrs-24.2.0 certifi-2024.8.30 click-8.1.7 h11-0.14.0 httpcore-1.0.7 httpx-0.28.1 httpx-sse-0.4.0 idna-3.10 mcp-1.1.0 outcome-1.3.0.post0 pydantic-2.10.3 pydantic-core-2.27.1 sniffio-1.3.1 sortedcontainers-2.4.0 sse-starlette-2.1.3 starlette-0.41.3 trio-0.27.0 typing_extensions-4.12.2 uvicorn-0.32.1

[notice] A new release of pip available: 22.3.1 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
(.venv) Users-iMac:test-mcp User$ python -m mcp.server
INFO:server:Starting receive loop


Terminal 2 (inspector)

bash: chruby: command not found
bash: chruby: command not found

The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh.
For more details, please visit https://support.apple.com/kb/HT208050.
(.venv) Users-iMac:test-mcp User$ cd /Users/User/test-mcp
(.venv) Users-iMac:test-mcp User$ rm -rf .venv
(.venv) Users-iMac:test-mcp User$ python3.11 -m venv .venv
(.venv) Users-iMac:test-mcp User$ source .venv/bin/activate
(.venv) (.venv) Users-iMac:test-mcp User$ mcp-inspector --transport stdio --connect
Starting MCP inspector...
node:internal/util/parse_args/parse_args:87
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(errorMessage);
^

TypeError [ERR_PARSE_ARGS_INVALID_OPTION_VALUE]: Option '--env' argument is ambiguous.
Did you forget to specify the option argument for '--env'?
To specify an option argument starting with a dash use '--env=-XYZ'.
at checkOptionLikeValue (node:internal/util/parse_args/parse_args:87:11)
at node:internal/util/parse_args/parse_args:382:9
at Array.forEach ()
at parseArgs (node:internal/util/parse_args/parse_args:378:3)
at file:///usr/local/lib/node_modules/@modelcontextprotocol/inspector/server/build/index.js:14:20
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5) {
code: 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE'
}

Node.js v20.16.0

🔍 MCP Inspector is up and running at http://localhost:5173 🚀


Console output from browser on Inspector page

Failed to load resource: net::ERR_CONNECTION_REFUSEDUnderstand this errorAI
index-BKN3G2r3.js:22136 Error fetching default environment: TypeError: Failed to fetch
at index-BKN3G2r3.js:22127:5
at Qj (index-BKN3G2r3.js:5012:22)
at Hk (index-BKN3G2r3.js:6247:19)
at Ek (index-BKN3G2r3.js:5811:3)
at jg (index-BKN3G2r3.js:2725:16)
at Wk (index-BKN3G2r3.js:6151:3)
at Pk (index-BKN3G2r3.js:6094:36)
at Gk (index-BKN3G2r3.js:5750:11)
at J2 (index-BKN3G2r3.js:442:19)
at MessagePort.R2 (index-BKN3G2r3.js:470:14)
(anonymous) @ index-BKN3G2r3.js:22136Understand this errorAI
index-BKN3G2r3.js:22353 Error: SSE error: {"isTrusted":true}
at _eventSource.onerror (index-BKN3G2r3.js:12410:23)
connectMcpServer @ index-BKN3G2r3.js:22353Understand this errorAI
:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   Failed to load resource: net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   Failed to load resource: net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   Failed to load resource: net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSEDUnderstand this errorAI

:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D:1

   GET http://localhost:3000/sse?transportType=stdio&command=python&args=-m+mcp.server&env=%7B%7D net::ERR_CONNECTION_REFUSED

Screenshot of Inspector

Screenshot 2024-12-07 at 1 20 19 AM
@dazzaji dazzaji added the bug Something isn't working label Dec 7, 2024
@jspahrsummers
Copy link
Member

It's not possible to connect to a separate, already-running process using the stdio transport, as stdio involves launching MCP servers as a subprocess.

The connection error is likely due to the Python virtual environment not being applied properly when launching from the inspector. Can you try explicitly giving a full path to the python binary you wish to use, and setting a PYTHONPATH environment variable?

You may find it easier to use uv, like we do in our examples.

@jspahrsummers jspahrsummers added question Further information is requested and removed bug Something isn't working labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants