8000 How to use progress token for the tool call? · Issue #631 · modelcontextprotocol/python-sdk · GitHub
[go: up one dir, main page]

Skip to content
How to use progress token for the tool call? #631
Open
@xxzero12

Description

@xxzero12

See the document show below
https://gofastmcp.com/servers/context#progress-reporting

And on MCP Server need to use context.report_progress

Method signature:

ctx.report_progress(progress: float, total: float | None = None)
progress: Current progress value (e.g., 24)
total: Optional total value (e.g., 100). If provided, clients may interpret this as a percentage.
Progress reporting requires the client to have sent a progressToken in the initial request. If the client doesnt support progress reporting, these calls will have no effect.

But the document doesn't mention how to do it on mcp client side

See the fastmcp implement it below

    async def call_tool(
        self,
        name: str,
        arguments: dict[str, Any] | None = None,
        read_timeout_seconds: timedelta | None = None,
    ) -> types.CallToolResult:
        """Send a tools/call request."""
        return await self.send_request(
            types.ClientRequest(
                types.CallToolRequest(
                    method="tools/call",
                    params=types.CallToolRequestParams(name=name, arguments=arguments),
                )
            ),
            types.CallToolResult,
            request_read_timeout_seconds=read_timeout_seconds,
        )

And see the mcp type.py has the below implementation

class CallToolRequestParams(RequestParams):
    """Parameters for calling a tool."""

    name: str
    arguments: dict[str, Any] | None = None
    model_config = ConfigDict(extra="allow")

class RequestParams(BaseModel):
    class Meta(BaseModel):
        progressToken: ProgressToken | None = None
        """
        If specified, the caller requests out-of-band progress notifications for
        this request (as represented by notifications/progress). The value of this
        parameter is an opaque token that will be attached to any subsequent
        notifications. The receiver is not obligated to provide these notifications.
        """

        model_config = ConfigDict(extra="allow")

    meta: Meta | None = Field(alias="_meta", default=None)

So I think added in the meta field in arguments should pass the value into it but not working

        await client.call_tool("get_forecast",{ "latitude": 47.6101, "longitude": -122.2015, "meta": {"progressToken": "test"} })

Need help on what I miss or what to do to make progress feature work

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0