fastmcp icon indicating copy to clipboard operation
fastmcp copied to clipboard

client send msg to server

Open merlinarer opened this issue 7 months ago • 3 comments

Enhancement Description

Hello, server could use logging/sampling to send msg to client. How do client send general msg back to server?

Use Case

No response

Proposed Implementation


merlinarer avatar May 15 '25 12:05 merlinarer

hi @merlinarer - can you elaborate on what exactly you're looking for functionality / DX wise?

zzstoatzz avatar May 15 '25 17:05 zzstoatzz

Yes. I want to find a way to exchange general msg between client and server. The logging only supports to send msg to client like this:

Server.py
# Add an addition tool
@mcp.tool(
    "add",
    "adds two numbers"
)
async def add(a: int, b: int, ctx: Context) -> int:
    """Add two numbers"""
    response = await ctx.info("Starting")
    return a + b

Is there a way to support client send general msg back to server like ctx.msg? The server acts differently according to the response from client. A demo case could be like this:

@mcp.tool(
    "add",
    "adds two numbers or delta of two numbers"
)
async def add_or_delta(a: int, b: int, ctx: Context) -> int:
    """Add two numbers"""
    await ctx.info("Starting")
    response = await ctx.msg("Copy that?")
    if response is "ok":
        return a + b
    else:
        return a - b

merlinarer avatar May 16 '25 01:05 merlinarer

Just wanted to chime in! For now, the MCP spec only defines a small number of notifications that the client can send:

export type ClientNotification =
  | CancelledNotification
  | ProgressNotification
  | InitializedNotification
  | RootsListChangedNotification;

Right now in FastMCP, you can send a progress notification and a roots list changed notification (the low-level server handles initialized notifications). Unfortunately, the spec doesn’t provide a way for clients to send a “general message notification” to the server.

It’s a good idea though! If you think this would be useful, consider opening an issue or discussion on the Model Context Protocol repo to propose expanding the spec.

davenpi avatar May 22 '25 21:05 davenpi

This will be addressed by elicitation #889

jlowin avatar Jun 25 '25 02:06 jlowin

Closed in #889

jlowin avatar Jun 30 '25 23:06 jlowin