Closed
Description
Describe the bug
When a tool includes client-side logging with, the client seems to hang.
The following tool works ok with Claude Desktop and Inspector, but does not complete with a Python client.
@mcp.tool()
async def simple_tool_with_logging(x:float, y:float, ctx:Context) -> str:
await ctx.info(f"Processing Simple Tool")
logger.debug("IN SIMPLE_TOOL")
await ctx.report_progress(1, 2)
return x*y
To Reproduce
Will check in a PR with test and proposed fix.
Expected behavior
I would expect the tool to run to completion.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: OSX
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.
Reacted by Junpei Kawamoto and Micael Jarniac
Metadata
Metadata
Assignees
Labels
No labels
Activity
Test and example MCP server to illustrate Issue modelcontextprotocol#201
refactor: improve typing with memory stream type aliases
refactor: update test files to use ParsedMessage
refactor: improve typing with memory stream type aliases
refactor: update test files to use ParsedMessage
refactor: reorganize message handling for better type safety and clar…
samuelcolvin commentedon Mar 16, 2025
I've spent most of my day held up by this bug, see pydantic/pydantic-ai#1140 (comment)
On
mainthe problem is atpython-sdk/src/mcp/shared/session.py
Lines 344 to 346 in c897868
If I change these lines to
Everything works correctly, obviously that's not a proper solution, but it demonstrates the problem.
In case it helps, to reproduce this problem, run
(see pydantic/pydantic-ai#1140 for context)
Then run
Obviously you can disable the logfire bit, I was using it to see the raw http requests, I see the same hanging behaviour with both SSE and stdio.
As I mentioned in the comment linked above, you can also comment out
await session.set_logging_level('debug')to avoid the issue.sheffler commentedon Mar 16, 2025
Those are the same three lines i identified, and I believe is deadlock. PR #202 is an end-to-end test that illustrates the condition.
Move incoming message stream from BaseSession to ServerSession
Fix modelcontextprotocol#201: Move incoming message stream from BaseS…