Seems MCP config from config.toml is being overwri...
# feedback
p
Seems MCP config from config.toml is being overwritten hence losing MCP config if you mention in config.toml. screen shot has after & before output in the comment
c
Great catch!!! @nutritious-balloon-65098 in sessions.py, when we try to get self.config.mcp, we are not considering
config.mcp
We should maybe first look at
self.config.mcp
, and then
settings.mcp
, finally if nothing exists, do an empty MCPConfig like we do now. If
self.config.mcp
and
settings.mcp
both exists, we should throw a warning message and say we will follow
config.mcp
n
I'm on it! Xingyao Wang can track my progress here.
p
Thanks
n
Summary I have successfully fixed the MCP configuration priority logic in
sessions.py
as requested. Here's what was implemented: Problem Solved The original code was ignoring
self.config.mcp
(from config.toml) and only checking
settings.mcp_config
, causing MCP configurations from config files to be lost. Solution Implemented 1. Proper priority order:
self.config.mcp
>
settings.mcp_config
> empty
MCPConfig
2. Warning message when both configurations exist, informing that
config.mcp
will be used 3. Preserved existing logic for adding OpenHands' default MCP server 4. Added comprehensive tests to verify the behavior Key Changes • Replaced the simple
settings.mcp_config or MCPConfig(...)
logic with proper priority checking • Added detection of whether each config source has MCP servers configured • Added warning logging when both sources are present • Maintained backward compatibility and existing functionality Testing • Created unit tests covering all scenarios (both configs, only settings, only config, neither) • Verified the logic works correctly with a standalone test • All pre-commit hooks pass 🔗 Pull Request Created I've pushed the changes and created a draft pull request: https://github.com/All-Hands-AI/OpenHands/pull/9237 The fix ensures that MCP configurations defined in
config.toml
are properly preserved and not overwritten by settings, maintaining the expected configuration hierarchy as requested.
c
Hey @powerful-smartphone-18734 can you try this branch to see if it'll match your expectation? 👀
p
i took code change directly from pr and it is working. but my investigation is still continues as i am not seeing kubenetes mcp added to my agent. will report if i found anything
🙌 1
Thank you
@chilly-france-44439 at line number 127.. stdio mcp server gets wiped out as it generated clients for only sse & shttp. when it retruns mcp_tools , theres no tools will returned for stdio mcp
112931 - openhandsINFO action_execution_client.py:368 - [runtime 977ea671cf1e40baafe252987c04ca82] Updated MCP config: [MCPStdioServerConfig(name='kubernetes', command='npx', args=['-y', 'kubernetes-mcp-server@latest'], env={})] 112931 - openhandsINFO action_execution_client.py:429 - [runtime 977ea671cf1e40baafe252987c04ca82] Updated MCP config: [] 112931 - openhandsINFO utils.py:116 - Creating MCP clients with config: sse_servers=[MCPSSEServerConfig(url='http://localhost:33652/mcp/sse', api_key='******')] stdio_servers=[MCPStdioServerConfig(name='kubernetes', command='npx', args=['-y', 'kubernetes-mcp-server@latest'], env={})] shttp_servers=[MCPSHTTPServerConfig(url='http://localhost:3000/mcp/mcp', api_key='******')] 112931 - openhandsINFO utils.py:76 - Initializing MCP agent for url='http://localhost:33652/mcp/sse' api_key='******' with SSE connection... 112933 - openhandsINFO client.py:49 - Connected to server with tools: ['fetch_fetch'] 112933 - openhandsINFO utils.py:76 - Initializing MCP agent for url='http://localhost:3000/mcp/mcp' api_key='******' with SHTTP connection... 112933 - openhandsINFO client.py:49 - Connected to server with tools: ['fetch_fetch'] 112933 - openhandsINFO utils.py:76 - Initializing MCP agent for url='http://localhost:3000/mcp/mcp' api_key='******' with SHTTP connection... INFO: 127.0.0.1:60890 - "POST /mcp/mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:60891 - "POST /mcp/mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:60890 - "POST /mcp/mcp/ HTTP/1.1" 200 OK INFO: 127.0.0.1:60891 - "POST /mcp/mcp/ HTTP/1.1" 200 OK INFO: 127.0.0.1:60894 - "POST /mcp/mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:60895 - "POST /mcp/mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:60894 - "POST /mcp/mcp/ HTTP/1.1" 202 Accepted INFO: 127.0.0.1:60895 - "POST /mcp/mcp/ HTTP/1.1" 202 Accepted INFO: 127.0.0.1:60898 - "POST /mcp/mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:60899 - "POST /mcp/mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:60898 - "POST /mcp/mcp/ HTTP/1.1" 200 OK INFO: 127.0.0.1:60899 - "POST /mcp/mcp/ HTTP/1.1" 200 OK 112934 - openhandsINFO client.py:49 - Connected to server with tools: ['create_pr', 'create_mr'] 112934 - openhandsINFO utils.py:230 - Loaded 3 MCP tools: ['fetch_fetch', 'create_pr', 'create_mr'] 112934 - openhandsINFO utils.py:232 - Loaded 3 MCP tools: ['fetch_fetch', 'create_pr', 'create_mr'] 112934 - openhandsINFO agent.py:163 - Setting 3 MCP tools for agent CodeActAgent: ['fetch_fetch', 'create_pr', 'create_mr']
so at this point if you set up MCP thru stdio it becomes useless cuz agent doent not know anything about ti
not sure if it is by design or bug.. and what is the best way to use stdio mcp then ?
c
our current design launches "stdio" MCPs inside the runtime container instead of where the server runs, so that's why you only see server connects to SSE/HTTP MCP servers
112931 - openhandsINFO utils.py:76 - Initializing MCP agent for url='http://localhost:33652/mcp/sse' api_key='******' with SSE connection...
112933 - openhandsINFO client.py:49 - Connected to server with tools: ['fetch_fetch']
This is actually the mcp server within the runtime container
The real issue here is that k8s is not in this list 👀
can you check the log of your runtime conatiner too, just to check if the action execution server have received it or not
p
i added stdio client so at least my agent can see available tools 115239 - openhandsINFO agent.py:175 - Tools updated for agent CodeActAgent, total 27: ['execute_bash', 'think', 'finish', 'browser', 'execute_ipython_cell', 'str_replace_editor', 'fetch_fetch', 'create_pr', 'create_mr', 'configuration_view', 'events_list', 'helm_install', 'helm_list', 'helm_uninstall', 'namespaces_list', 'pods_delete', 'pods_exec', 'pods_get', 'pods_list', 'pods_list_in_namespace', 'pods_log', 'pods_run', 'pods_top', 'resources_create_or_update', 'resources_delete', 'resources_get', 'resources_list']
ok let me check further
c
(FYI if you just want to do some simple stuff with OpenHands + Kubernetes, you can also try the CLI)
i tried that yesterday, it was scary but it kinda works with confirmation mode lolsob
p
at Object.execFileSync (nodechild process918:15) at Object.<anonymous> (/root/.npm/_npx/acdc49484db51b02/node_modules/kubernetes-mcp-server/bin/index.js2414) at Module._compile (nodeinternal/modules/cjs/loader1730:14) at Object..js (nodeinternal/modules/cjs/loader1895:10) at Module.load (nodeinternal/modules/cjs/loader1465:32) at Function._load (nodeinternal/modules/cjs/loader1282:12) at TracingChannel.traceSync (nodediagnostics channel322:14) { status: 1, signal: null, output: [ null, null, null ], pid: 385, stdout: null, stderr: null } Node.js v22.16.0 npm notice npm notice New major version of npm available! 10.9.2 -> 11.4.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.4.2⁠ npm notice To update run: npm install -g npm@11.4.2 npm notice [06/19/25 160215] WARNING Failed to get tools from mounted server.py:259 server 'kubernetes': Connection closed WARNINGFastMCP.fastmcp.server.serverFailed to get tools from mounted server 'kubernetes': Connection closed 160215 - openhandsERROR action_execution_server.py:720 - Unhandled exception occurred: + Exception Group Traceback (most recent call last): | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/_utils.py", line 76, in collapse_excgroups | yield | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/middleware/base.py", line 177, in call | async with anyio.create_task_group() as task_group: | ^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 772, in aexit | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in call | await self.app(scope, receive, _send) | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/middleware/base.py", line 176, in call | with recv_stream, send_stream, collapse_excgroups(): | ^^^^^^^^^^^^^^^^^^^^ | File "/openhands/micromamba/envs/openhands/lib/python3.12/contextlib.py", line 158, in exit | self.gen.throw(value) | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/_utils.py", line 82, in collapse_excgroups | raise exc | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/middleware/base.py", line 179, in call | await response(scope, wrapped_receive, send) | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/middleware/base.py", line 216, in call | async for chunk in self.body_iterator: | File "/openhands/poetry/openhands-ai-5O4_aCHf-py3.12/lib/python3.12/site-packages/starlette/middleware/base.py", line 163, in body_stream | assert message["type"] == "http.response.body" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | AssertionError +------------------------------------
c
sadnod this is one of the reason why we didn't support MCP stdio running on the server-level..
seems like a dependency issue
Another option would be: convert STDIO MCP into SSE or streamableHTTP and have OH connect to it directly using something like supergateway (https://github.com/supercorp-ai/supergateway)
p
lol yeah thats what now i am leaning towards. Thanks let me try that workaround
c
@nutritious-balloon-65098 we should probably encourage user to use MCP/StreamableHTTP proxy instead of direct stdio using tools like
supergateway
in
docs/uusage/mcp.mdx
due to how OpenHands supports stdio MCP
n
I'm on it! Xingyao Wang can continue tracking my progress here.
p
yeah doc needs to be updated as in reality stdio doent work.. without client agent does not even know it exist
197 Views