You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to stream reponse back from MCP server to Client? (MCP Tool Streaming) #1124
I have an MCP server with streamable http transport. It exposes some tools and the tools call external APIs. Lets say one of the external APIs steams back the response in chunks. How can my MCP tool relay this reponse in chunks back to the client (as in stream it back as it recieves it from the external API)
Is it possible?
changed the title [-]How to stream reponse back from MCP server to Client?[/-][+]How to stream reponse back from MCP server to Client? (MCP Tool Streaming)[/+]on Jul 11, 2025
Hi friend, I recently implemented this feature using a somewhat hacky approach while making as few changes as possible to the original SDK. Later, I tried integrating the feature as an extension of client.call_tool directly into the client class. I’ll now present both approaches.
Let's take a look at the results now. I test the function with postman.
This is the result response in chunks.
And here is the mcp server tool code.
Of cource you can only yield one chunk , which is the tool finally return.
What I did was provide a custom implementation of the ProgressHandler used inside client.call_tool. I had first tried to yield chunks directly from the handler, but that’s impossible when call_tool itself is awaited. So I extended call_tool so that the custom progress states can also be yielded out.
I didn’t change the original @server.tool at all, so you can still use it exactly as before. Whenever you want to return additional states, just send your custom protocol—say, a JSON chunk—via ctx.report_progress().
Now let’s look at the code, starting with the interface layer.
Activity
[-]How to stream reponse back from MCP server to Client?[/-][+]How to stream reponse back from MCP server to Client? (MCP Tool Streaming)[/+]1810912213qqcom commentedon Jul 25, 2025
Hi friend, I recently implemented this feature using a somewhat hacky approach while making as few changes as possible to the original SDK. Later, I tried integrating the feature as an extension of
client.call_tooldirectly into theclientclass. I’ll now present both approaches.Let's take a look at the results now. I test the function with postman.
This is the result response in chunks.

And here is the mcp server tool code.
Of cource you can only yield one chunk , which is the tool finally return.
What I did was provide a custom implementation of the
ProgressHandlerused insideclient.call_tool. I had first tried toyieldchunks directly from the handler, but that’s impossible whencall_toolitself is awaited. So I extendedcall_toolso that the custom progress states can also be yielded out.I didn’t change the original
@server.toolat all, so you can still use it exactly as before. Whenever you want to return additional states, just send your custom protocol—say, a JSON chunk—viactx.report_progress().Now let’s look at the code, starting with the interface layer.
Next, we created an enhanced version of
call_toolas a custom method inside theClientclass.If you prefer not to touch the
Clientclass, you can also wrapclient.call_toolexternally, like this:There are some miscellaneous bits in here—like database reads and logging—just ignore those; the overall idea is the same.Hope it helps!