Skip to content

Cancelling a Call Tool Request from Client #1410

@asheshvidyut

Description

@asheshvidyut

Question

Hey Team,
I have a question regarding cancelling the tool call from client when the MCP server is created from FastMCP class.

I see the test - test_cancel_handling but this one uses low level server.

My question is specifically on how we can get the request_id which the client needs for cancelling the call tool request on server.

await client.send_notification(
        ClientNotification(
            CancelledNotification(
                params=CancelledNotificationParams(
                    requestId={request_id},
                    reason="Reson",
              ),
          )
     )
)

Do we have to get the request id from call_tool request? like below?

  request_id = None
  mcp = FastMCP(
      name="Simple gRPC Server",
  )
  @mcp.tool()
  def get_temperature(city: str, ctx: Context[ServerSession, None]) -> float:
      # fetching request id from context 
      request_id = ctx.request_context.request_id
      return 22.5
  

Or is there another way?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featuredocumentationImprovements or additions to documentationquestionFurther information is requestedready 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