-
Notifications
You must be signed in to change notification settings - Fork 784
Open
Labels
bugSomething isn't workingSomething isn't workingp2-mediumMedium priority - normal timelineMedium priority - normal timeline
Description
Describe the bug
STDIO server is not restarting after it is disconnected from the sidebar, could be related to #380
To Reproduce
Steps to reproduce the behavior:
- Using the python-sdk to build the server
- Currently seems specific to the
lifespan
attribute when its included in the server, here is an example lifespan sample
@contextlib.asynccontextmanager
async def stdio_lifespan(app) -> t.AsyncIterator[None]:
"""Dummy lifespan context for stdio server."""
logger.info("Starting application with dummy stdio lifespan...")
# Simulate a long-running process
_loop_task = asyncio.create_task(custom_loop())
try:
yield
finally:
logger.info("Application shutting down...")
if _loop_task:
_loop_task.cancel()
try:
await _loop_task
except asyncio.CancelledError:
pass
except Exception as e:
logger.error(f"Error during shutdown: {e}")
logger.info("Application shutdown complete.")
async def main():
mcp = Server(name="stdio-server", lifespan=stdio_lifespan)
async with stdio_server() as (read_stream, write_stream):
await mcp.run(read_stream, write_stream, mcp.create_initialization_options())
asyncio.run(main())
brave_xkjOXXNdyw.mp4
A similar above example seems to work when there is no lifespan
set and works as expected
REPO URL: https://github.com/FallenDeity/discord-mcp
Expected behavior
Should be able to re-connect after disconnecting from the inspector, the whole process and proxy server shouldnt crash
Logs
If applicable, add logs to help explain your problem.
server side output of the npx @modelcontextprotocol/inspector
command
STDIO transport: command=C:\Users\Triyan Mukherjee\AppData\Local\Programs\Python\Python310\Scripts\poetry.exe, args=--directory,C:\Users\Triyan Mukherjee\VsCodeProjects\discord-mcp,run,python,-m,discord_mcp,--file-logging,--server-type,STDIO
Created server transport
Created client transport
Received POST message for sessionId c815eda5-05ff-41aa-9b92-1f2dcb159e53
Received POST message for sessionId c815eda5-05ff-41aa-9b92-1f2dcb159e53
file:///C:/Users/Triyan%20Mukherjee/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:146
throw new Error("Not connected");
^
Error: Not connected
at SSEServerTransport.send (file:///C:/Users/Triyan%20Mukherjee/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:146:19)
at PassThrough.<anonymous> (file:///C:/Users/Triyan%20Mukherjee/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:311:33)
at PassThrough.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at node:internal/streams/transform:178:12
at PassThrough._transform (node:internal/streams/passthrough:46:3)
at Transform._write (node:internal/streams/transform:171:8)
at writeOrBuffer (node:internal/streams/writable:570:12)
Node.js v20.17.0
It gives this error once I click the disconnect button
subsequent errors in console.log in browser on clicking connect
index-BNqYF5Na.js:24658 GET http://localhost:6277/health net::ERR_CONNECTION_REFUSED
checkProxyHealth @ index-BNqYF5Na.js:24658
connect @ index-BNqYF5Na.js:24699
Nb @ index-BNqYF5Na.js:1322
Tb @ index-BNqYF5Na.js:1334
Ub @ index-BNqYF5Na.js:1337
nf @ index-BNqYF5Na.js:2274
se @ index-BNqYF5Na.js:2297
(anonymous) @ index-BNqYF5Na.js:2569
Qk @ index-BNqYF5Na.js:5873
Jb @ index-BNqYF5Na.js:1275
hd @ index-BNqYF5Na.js:2370
fd @ index-BNqYF5Na.js:1768
ed @ index-BNqYF5Na.js:1751
index-BNqYF5Na.js:24664 Couldn't connect to MCP Proxy Server TypeError: Failed to fetch
at checkProxyHealth (index-BNqYF5Na.js:24658:41)
at connect (index-BNqYF5Na.js:24699:13)
at Object.Nb (index-BNqYF5Na.js:1322:9)
at Tb (index-BNqYF5Na.js:1334:8)
at Ub (index-BNqYF5Na.js:1337:8)
at nf (index-BNqYF5Na.js:2274:5)
at se (index-BNqYF5Na.js:2297:11)
at index-BNqYF5Na.js:2569:7
at Qk (index-BNqYF5Na.js:5873:14)
at Jb (index-BNqYF5Na.js:1275:14)
Additional context
Add any other context about the problem here.
PaulRBerg and demid-ns
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingp2-mediumMedium priority - normal timelineMedium priority - normal timeline