client send msg to server
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
hi @merlinarer - can you elaborate on what exactly you're looking for functionality / DX wise?
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
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.
This will be addressed by elicitation #889
Closed in #889