feat: add support for partial results and streaming responses by matoushavlena · Pull Request #776 · modelcontextprotocol/modelcontextprotocol · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/specification/draft/basic/index.mdx
8 changes: 4 additions & 4 deletions docs/specification/draft/basic/transports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ MCP endpoint.
`Content-Type: application/json`, to return one JSON object. The client **MUST**
support both these cases.
6. If the server initiates an SSE stream:
- The SSE stream **SHOULD** eventually include JSON-RPC _response_ for the
- The SSE stream **SHOULD** eventually include JSON-RPC _response(s)_ for the
JSON-RPC _request_ sent in the POST body.
- The server **MAY** send JSON-RPC _requests_ and _notifications_ before sending the
JSON-RPC _response_. These messages **SHOULD** relate to the originating client
final JSON-RPC _response_. These messages **SHOULD** relate to the originating client
_request_.
- The server **SHOULD NOT** close the SSE stream before sending the JSON-RPC _response_
- The server **SHOULD NOT** close the SSE stream before sending the JSON-RPC _response(s)_
for the received JSON-RPC _request_, unless the [session](#session-management)
expires.
- After the JSON-RPC _response_ has been sent, the server **SHOULD** close the SSE
- After the final JSON-RPC _response_ has been sent, the server **SHOULD** close the SSE
stream.
- Disconnection **MAY** occur at any time (e.g., due to network conditions).
Therefore:
Expand Down
23 changes: 23 additions & 0 deletions docs/specification/draft/server/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,29 @@ Providing an output schema helps clients and LLMs understand and properly handle
- Guiding clients and LLMs to properly parse and utilize the returned data
- Supporting better documentation and developer experience

## Content streaming

Tools might provide result as a stream of partial results:

```mermaid
sequenceDiagram
participant User
participant Client
participant Server

Note over Client,Server: Streaming
Client->>Server: tools/call
Server-->>Client: Tool partial result
Client-->>User: Content
Server-->>Client: Tool partial result
Client-->>User: Content
Server-->>Client: Tool partial result
Client-->>User: Content
```

_Unstructured_ content is incremental and the complete result can be acquired by concatenation.
_Structured_ content is not incremental unless the tool's output schema states otherwise.

## Error Handling

Tools use two error reporting mechanisms:
Expand Down
100 changes: 100 additions & 0 deletions schema/draft/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion schema/draft/schema.ts