Skip to content

Roots/List Request Hangs in Client-Server Communication #1097

Description

@mjunaidca

Initial Checks

Description

When implementing the roots capability in a client-server setup, the communication hangs indefinitely after the server makes a list_roots() request. The client successfully initializes with roots capability, but the server's request for roots never completes.

Observed behavior:

  1. Client initializes successfully with roots capability
  2. Server receives tool call and requests roots via ctx.session.list_roots()
  3. Communication hangs at this point - no error, no timeout, just stuck
  4. Both client and server remain running but no further progress

Expected behavior:

  1. Client should receive the roots/list request
  2. Client should respond with the configured roots
  3. Server should receive the response and continue processing

Let me know if you need any additional information or would like me to try specific debugging steps.

Example Code

Example Code:

server.py

frommcp.server.fastmcpimportFastMCP, Contextfrommcp.typesimportTextContentmcp=FastMCP(
name="mcp-roots-server",
stateless_http=True
)
@mcp.tool()asyncdefanalyze_project(ctx: Context) ->TextContent:
print("-> Server: Requesting project roots from client...")
roots=awaitctx.session.list_roots() # Hangs hereifnotrootsornotroots.roots:
returnTextContent(text="No project roots found", type="text")
# Never reaches this pointreturnTextContent(text="Analysis complete", type="text")
mcp_app=mcp.streamable_http_app()

client.py

importasynciofrompathlibimportPathfromtypingimportAnyimportmcp.typesastypesfrommcp.shared.contextimportRequestContextfrommcpimportClientSessionfrommcp.client.streamable_httpimportstreamablehttp_clientasyncdefmock_roots_list(context: RequestContext["ClientSession", Any]) ->types.ListRootsResult|types.ErrorData:
print(f"<- Client: Received roots/list request")
root_uri=f"file://{Path.cwd().absolute()}"returntypes.ListRootsResult(roots=[types.Root(
uri=types.FileUrl(root_uri),
name="Current Project"
)])
asyncdefmain():
server_url="http://localhost:8000/mcp/"asyncwithstreamablehttp_client(server_url) as (read_stream, write_stream, get_session_id):
asyncwithClientSession(read_stream, write_stream, list_roots_callback=mock_roots_list) assession:
awaitsession.initialize()
result=awaitsession.call_tool("analyze_project")
if__name__=="__main__":
asyncio.run(main())

Server logs:

INFO: Started server process [36096]
INFO: Application startup complete.
INFO: 127.0.0.1:51609 - "POST /mcp/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:51611 - "POST /mcp/ HTTP/1.1" 202 Accepted
INFO: 127.0.0.1:51613 - "POST /mcp/ HTTP/1.1" 200 OK
Processing request of type CallToolRequest
-> Server: Requesting project roots from client...
# Hangs here

Client logs:

🚀 Connecting to MCP server at http://localhost:8000/mcp/
✅ Connected. Initializing session...
🛠️ Session initialized with roots capability.
-> Client: Calling analyze_project tool...
# Hangs here

Python & MCP Python SDK

Python & MCP Python SDK:
- Python version: 3.11.7
- MCP Python SDK version: 1.10.1
- OS: macOS 24.5.0
- Environment: Development setup using uvicorn for server
Additional Notes:
- The issue occurs consistently across multiple runs
- No error messages or exceptions are thrown
- Both client and server processes remain running
- Network requests complete successfully (200 OK responses)
- The hang occurs specifically during the roots/list request

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions