fastmcp icon indicating copy to clipboard operation
fastmcp copied to clipboard

Lack of clarity in progress reporting in FastMCP Python Client

Open sandipan1 opened this issue 6 months ago • 2 comments

Description

Issue

The documentation around ctx.report_progress in FastMCP is unclear, for using it in FastMCP Python client.

  • The docs show how to use ctx.report_progress on the server, but it’s not clear how a Python client is supposed to receive those updates.
  • The standard Python client does not send a progressToken in tool/resource requests, so even if the server calls report_progress, the client never receives progress notifications.
  • There is no documented or supported way to pass a progressToken or request metadata from the Python client, and attempts to use lower-level APIs (e.g., client.session.call_tool(..., _meta={...})) result in errors.

Expected Behaviour

  • Clear guidance in the docs about when and how report_progress actually works (i.e., only if the client sends a progressToken)
  • Some way for Python devs to opt in to progress reporting—maybe an optional argument
  • And if this isn’t officially supported (yet?), it would help to explicitly say so and explain what the recommended pattern is.

To reproduce

* Build a server tool that calls ctx.report_progress.
* Trigger it from the Python client.

possible solutions

  1. exporse the progress_token argument in Client.call_tool
  2. Add a “progress_callback” argument to call_tool that handles updates, progress tokens to a user-defined function

Example Code


Version Information

fastmcp==2.2.6
mcp==1.6.0
python==3.12.8

Additional Context

No response

sandipan1 avatar May 06 '25 16:05 sandipan1

Hi @sandipan1 , Did you find a workaround for this issue?

I also tried using the low-level API as you mention

There is no documented or supported way to pass a progressToken or request metadata from the Python client, and attempts to use lower-level APIs (e.g., client.session.call_tool(..., _meta={...})) result in error

@jlowin Could you please take a look at this?

apoorv-singh-107 avatar May 17 '25 07:05 apoorv-singh-107

A workaround is use ctx.info to send your message and parse it using log_handler in client

sandipan1 avatar May 17 '25 08:05 sandipan1

How can we pass context logging back to the client? I’ve tried using both stdio and SSE, but the logs are not appearing in the client console.

For example, this tool includes context logging, but it's not visible on the client side.

# math_server.py
from fastmcp import FastMCP, Context

mcp = FastMCP("math", log_level="DEBUG")


@mcp.tool()
async def add(a: int, b: int, ctx: Context = None) -> int:
    """Add two numbers"""
    if ctx:
        await ctx.info(f"Adding {a} and {b}")
        result = a + b
        await ctx.info(f"Result: {result}")
        return result
    return a + b

@mcp.tool()
async def multiply(a: int, b: int, ctx: Context = None) -> int:
    """Multiply two numbers"""
    if ctx:
        await ctx.info(f"Multiplying {a} and {b}")
        result = a * b
        await ctx.info(f"Result: {result}")
        return result
    return a * b

if __name__ == "__main__":
    # mcp.run(transport="stdio")
    mcp.run(transport='sse', host="127.0.0.1", port=8004)

kjoth avatar May 20 '25 14:05 kjoth

@kjoth have you provided a log handler as described here? https://gofastmcp.com/clients/client#logging

If something is broken please open a separate issue, this one is closed by #513

jlowin avatar May 20 '25 14:05 jlowin

@kjoth have you provided a log handler as described here? https://gofastmcp.com/clients/client#logging

If something is broken please open a separate issue, this one is closed by #513

@jlowin I’m currently using LangChain’s MultiServerMCPClient (from langchain_mcp_adapters.client) to connect to multiple MCP servers. I haven’t tried the FastMCP client yet—does FastMCP allow connections to several MCP servers as well?

https://github.com/langchain-ai/langchain-mcp-adapters#client-1

kjoth avatar May 20 '25 15:05 kjoth