You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I want to make mcp python-sdk jupyter notebook compatible. When running in a notebook environment, MCP work but do not output stderr as it does normally.
meta=None nextCursor=None tools=[Tool(name='echo_tool', description='Echo the input text\n\n Args:\n text (str): The text to echo\n\n Returns:\n str: The echoed text\n ', inputSchema={'properties': {'text': {'title': 'Text', 'type': 'string'}}, 'required': ['text'], 'title': 'echo_toolArguments', 'type': 'object'})]
while running the server without jupyter notebook:
❯ uv run --quiet src/echo.py
starting echo server
stderr is correctly displayed.
This is a big problem mostly because if the server is crashing or the command is wrong you have no way to know what's wrong: nothing is logged and the jupyter notebook cell just hangs.
Describe the solution you'd like
I found the culprit being the use of:
In particular sys.stderr here is not working in the jupyter / ipython context. Instead I would suggest a working change as follow:
remove the stderr params from the process and handle process.stderr in an async function as stdout / stdin is handled.
to that effect, use a stderr_reader async function like the following:
asyncdefstderr_reader():
assertprocess.stderr, "Opened process is missing stderr"try:
asyncforlineinprocess.stderr:
ifis_jupyter_notebook():
print(f"\033[91m {line.decode().strip()}")
else:
# redirect to stderr as beforeprint(line.decode().strip(), file=sys.stderr)
exceptanyio.ClosedResourceError:
awaitanyio.lowlevel.checkpoint()
This would result in the same behavior as before while allowing the stderr to be logged in the jupyter notebook context.
Additional context
Jupyter notebook support support is also requested for mcpadapt which bring MCP server tools in any agentic framework, as many agentic framework demonstrate usage in jupyter notebooks. https://github.com/grll/mcpadapt
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I want to make mcp python-sdk jupyter notebook compatible. When running in a notebook environment, MCP work but do not output stderr as it does normally.
For instance in jupyter notebook:
Outputs:
while running the server without jupyter notebook:
❯ uv run --quiet src/echo.py starting echo server
stderr is correctly displayed.
This is a big problem mostly because if the server is crashing or the command is wrong you have no way to know what's wrong: nothing is logged and the jupyter notebook cell just hangs.
Describe the solution you'd like
I found the culprit being the use of:
In particular sys.stderr here is not working in the jupyter / ipython context. Instead I would suggest a working change as follow:
stderr_reader
async function like the following:This would result in the same behavior as before while allowing the stderr to be logged in the jupyter notebook context.
Additional context
Jupyter notebook support support is also requested for mcpadapt which bring MCP server tools in any agentic framework, as many agentic framework demonstrate usage in jupyter notebooks.
https://github.com/grll/mcpadapt
The text was updated successfully, but these errors were encountered: