#326·fastmcp

client.set_roots and send_roots_list_changed not update the roots

Author: xxzero12Created May 5, 2025Updated Sep 16, 2026
Labelsbug

Description

Hi, is trying to test the root capability, somewhat the client set the root but the server still return old one

Example Code

python
Ex:

Client.py

client = Client(
    "http://localhost:9000/sse", 
    sampling_handler=sampling_handler, 
    log_handler=log_handler,
    roots=[
        "file://home/projects/roots-example/frontend"
    ],
    message_handler=message_handler)

async def main():
    # Connection is established here
    async with client:
        await client.call_tool("get_forecast",{ "latitude": 47.6101, "longitude": -122.2015 })
        client.set_roots([
            "file://home/projects/roots-example/backend"
        ])
        await client.send_roots_list_changed()
        await client.call_tool("get_forecast",{ "latitude": 47.6101, "longitude": -122.2015 })

if __name__ == "__main__":
        asyncio.run(main())


Server.py

logging.basicConfig(level=logging.DEBUG)
mcp = FastMCP(name="Tutorial Server")


@mcp.tool()
async def get_forecast(latitude: float, longitude: float, ctx: Context) -> str:
    """Get weather forecast for a location.

    Args:
        latitude: Latitude of the location
        longitude: Longitude of the location
    """
    roots = await ctx.list_roots()
    await ctx.info(f"{roots}")
    await ctx.info(f"Info Message: Processing coordinates: {latitude}, {longitude}")

if __name__ == "__main__":
    mcp.run(transport="sse", host="127.0.0.1", port=9000)


Somewhat the result is like below

First call
DEBUG:mcp.server.sse:Sending message via SSE: root=JSONRPCRequest(method='roots/list', params=None, jsonrpc='2.0', id=1)
DEBUG:mcp.server.sse:Received JSON: b'{"jsonrpc":"2.0","id":0,"result":{"roots":[{"uri":"file://home/projects/roots-example/frontend"}]}}'
Second call(should return backend since set the root)
DEBUG:mcp.server.sse:Received JSON: b'{"method":"notifications/roots/list_changed","jsonrpc":"2.0"}'
DEBUG:mcp.server.sse:Sending message via SSE: root=JSONRPCRequest(method='roots/list', params=None, jsonrpc='2.0', id=1)
DEBUG:mcp.server.sse:Received JSON: b'{"jsonrpc":"2.0","id":1,"result":{"roots":[{"uri":"file://home/projects/roots-example/frontend"}]}}'

Version Information

FastMCP version:                                                                     2.2.7
MCP version:                                                                         1.7.1
Python version:                                                                     3.13.3
Platform:                                                        Windows-11-10.0.26100-SP0

Additional Context

No response