mirror of
https://github.com/open-webui/mcpo.git
synced 2026-11-05 01:27:39 +00:00
[GH-ISSUE #152] issue: When I use the .NET SSE service of MCPO, I frequently encounter ClosedResourceError issues. #67
Labels
No labels
bug
can't reproduce
documentation
enhancement
good first issue
help wanted
invalid
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/mcpo#67
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tamakiramimy on GitHub (May 22, 2025).
Original GitHub issue: https://github.com/open-webui/mcpo/issues/152
Check Existing Issues
mcpo Version
v0.0.12
Open WebUI Version (if applicable)
v0.6.5
Operating System
docker or ocp(red hat) for dotnet mcpo
Browser (if applicable)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Confirmation
README.md.Expected Behavior
To ensure stable communication between MCPO and the **.NET SSE service**, even after long idle periods, you should create a new session per request instead of reusing the same session.
Actual Behavior
When I use the .NET SSE service of MCPO, I frequently encounter ClosedResourceError issues.
Local Debug Mode:
When testing locally in debug mode, both the **.NET SSE service and MCPO** work flawlessly. Even after prolonged inactivity, reconnecting succeeds without issues.
Deployment Issues (Docker/Red Hat OCP):
After deploying to Docker or Red Hat OpenShift (OCP):
Services initially function correctly.
Within 2-3 minutes, consistent ClosedResourceError occurs.
Error source: mcp/session.py.
Attempted fix: Upgraded MCPO to v1.9.0 – issue persists.
Observation:
MCPO’s main.py initializes a session, but subsequent tool invocations reuse the same session instead of creating a new request.
Suspected root cause: Session reuse leads to stale/closed connections.
Steps to Reproduce
1.pubulish mcpo to docker
2.pubulish dotnet sse service to docker
3.request once at both services start
4.wait for 3-5 min,request again
Error Details;
Unexpected error calling GetCurrentDateTime:
Error traceback: Traceback (most recent call last):
File "/opt/app-root/src/mcpo/utils/main.py", line 268, in tool
result = await session.call_tool(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/app-root/lib64/python3.12/site-packages/mcp/client/session.py", line 277, in call_tool
return await self.send_request(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/app-root/lib64/python3.12/site-packages/mcp/shared/session.py", line 265, in send_request
await self._write_stream.send(
File "/opt/app-root/lib64/python3.12/site-packages/anyio/streams/memory.py", line 242, in send
self.send_nowait(item)
File "/opt/app-root/lib64/python3.12/site-packages/anyio/streams/memory.py", line 211, in send_nowait
raise ClosedResourceError
anyio.ClosedResourceError
INFO: 127.0.0.6:40397 - "POST /net_sse/GetCurrentDateTime HTTP/1.1" 500 Internal Server Error
Logs & Screenshots
Additional Information
No response
@tamakiramimy commented on GitHub (May 26, 2025):
@tjbck
I've already resolved this issue. I suggest merging my changes into your branch. The main fix handles automatic reconnection when the MCP server restarts or encounters a timeout. Here’s the code:
async def McpReCallTools(
server_type: str,
args: Union[str, List[str]],
command: Optional[str],
env: Dict[str, str],
endpoint_name: str,
arguments: Dict[str, Any]
) -> Any:
"""
重新初始化MCP会话并调用工具
@Anduin2017 commented on GitHub (Jun 26, 2025):
I'm having similar issue. I believe since MCP is a stateful protocol, the session may expired on remote sse server. Try rebooting mcpo may solve.
I believe the mcpo side should have some fallback machenisem that automatically request a new session if the current one was expired.
@gyk6985432 commented on GitHub (Jun 28, 2025):
java也是同样的问题,但是我把mcpo的端口和java mcp的端口设置成不一样的就没问题了。但是有的是可以正常返回的,有的会报错:
@ocelotpa commented on GitHub (Jul 5, 2025):
I experience the same issue. The system can be briefly restored after restarting the mcpo container, but it fails again within half an hour. I'm using ModelScope's MCP service.
mcpo Version:v0.0.16
Open WebUI Version:v0.6.15
@StevenAlexanderJohnson commented on GitHub (Aug 12, 2025):
I believe that I've experienced the same error using
builder.Services.AddMcpServer().WithHttpTransport().WithToolsFromAssembly(). After some time of inactivity the MCP server would terminate the connection. MCPO would continue to try and use the old connection and would result with a "Session Terminated" error.My solution was to disable the IdleTimeout of the HttpTransport.
But it would be nice to have a way for MCPO to reconnect with a new connection after the session has expired to save resources. Especially if you have multiple tools using that MCPO server.
@Guigxs commented on GitHub (Aug 23, 2025):
Seems to have the same issue proxying codemcp (sse server). If I don't keep alive manually I have a anyio.ClosedResourceError after a few sec.
@schaveyt commented on GitHub (Sep 5, 2025):
@StevenAlexanderJohnson thanks for sharing that workaround. I have been banging my head on this.
Unfortunately, that workaround does not seem to be working for me 🙃
Make me want to start a Blazor alternative based on the new ASP.NET Blazor AI Chat Template in order to support native MCP over SSE and Streaming HTTP 🤷