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
Copy file name to clipboardExpand all lines: docs/specification/draft/basic/transports.md
+93-41Lines changed: 93 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,73 +50,112 @@ sequenceDiagram
50
50
51
51
## Streamable HTTP
52
52
53
-
{{< callout type="info" >}} This replaces the [HTTP+SSE transport]({{< ref "/specification/2024-11-05/basic/transports#http-with-sse" >}}) from protocol version 2024-11-05. See the [backwards compatibility](#backwards-compatibility) guide below. {{< /callout >}}
53
+
{{< callout type="info" >}} This replaces the [HTTP+SSE
54
+
transport]({{< ref "/specification/2024-11-05/basic/transports#http-with-sse" >}}) from
55
+
protocol version 2024-11-05. See the [backwards compatibility](#backwards-compatibility)
56
+
guide below. {{< /callout >}}
54
57
55
-
In the **Streamable HTTP** transport, the server operates as an independent process that can handle multiple client connections. This transport uses standard HTTP with optional [Server-Sent Events](https://en.wikipedia.org/wiki/Server-sent_events) (SSE) for streaming multiple server messages. This permits "plain HTTP" MCP servers, as well as more feature-rich servers supporting streaming and bidirectional communication.
58
+
In the **Streamable HTTP** transport, the server operates as an independent process that
59
+
can handle multiple client connections. This transport uses standard HTTP with optional
60
+
[Server-Sent Events](https://en.wikipedia.org/wiki/Server-sent_events) (SSE) for
61
+
streaming multiple server messages. This permits "plain HTTP" MCP servers, as well as
62
+
more feature-rich servers supporting streaming and bidirectional communication.
56
63
57
-
The server **MUST** provide a single HTTP endpoint (hereafter referred to as the **MCP endpoint**) that supports both POST and GET methods. For example, this could be a URL like `https://example.com/mcp`.
64
+
The server **MUST** provide a single HTTP endpoint (hereafter referred to as the **MCP
65
+
endpoint**) that supports both POST and GET methods. For example, this could be a URL
66
+
like `https://example.com/mcp`.
58
67
59
68
### Message Exchange
60
69
61
-
1. Every JSON-RPC message sent from the client **MUST** be a new HTTP POST request to the MCP endpoint.
70
+
1. Every JSON-RPC message sent from the client **MUST** be a new HTTP POST request to the
71
+
MCP endpoint.
62
72
63
73
2. When the client sends a JSON-RPC _request_ message to the MCP endpoint via POST:
64
-
- The client **MUST** include an `Accept` header, listing both `application/json` and `text/event-stream` as supported content types.
65
-
- The server **MUST** either return `Content-Type: text/event-stream`, to initiate an SSE stream, or `Content-Type: application/json`, to return a single JSON-RPC _response_. The client **MUST** support both these cases.
74
+
75
+
- The client **MUST** include an `Accept` header, listing both `application/json` and
76
+
`text/event-stream` as supported content types.
77
+
- The server **MUST** either return `Content-Type: text/event-stream`, to initiate an
78
+
SSE stream, or `Content-Type: application/json`, to return a single JSON-RPC
79
+
_response_. The client **MUST** support both these cases.
66
80
- If the server initiates an SSE stream:
67
81
- The SSE stream **SHOULD** eventually include a JSON-RPC _response_ message.
68
-
- The server **MAY** send JSON-RPC _requests_ and JSON-RPC _notifications_ before sending a JSON-RPC _response_.
69
-
- The server **SHOULD NOT** close the SSE stream before sending the JSON-RPC _response_.
70
-
- After the JSON-RPC _response_ has been sent, the server **MAY** close the SSE stream at any time.
71
-
- The client **MAY** close the SSE stream at any time. The server **SHOULD** interpret this as the client cancelling the request, if it is still in-flight.
72
-
73
-
3. When the client sends a JSON-RPC _notification_ or _response_ to the MCP endpoint via POST:
74
-
- The client **MUST** include an `Accept` header, listing `text/event-stream` as a supported content type.
75
-
- The server **MUST** either return `Content-Type: text/event-stream`, to initiate an SSE stream, or else HTTP status code 202 Accepted with no body. The client **MUST** support both these cases.
82
+
- The server **MAY** send JSON-RPC _requests_ and JSON-RPC _notifications_ before
83
+
sending a JSON-RPC _response_.
84
+
- The server **SHOULD NOT** close the SSE stream before sending the JSON-RPC
85
+
_response_.
86
+
- After the JSON-RPC _response_ has been sent, the server **MAY** close the SSE
87
+
stream at any time.
88
+
- The client **MAY** close the SSE stream at any time. The server **SHOULD**
89
+
interpret this as the client cancelling the request, if it is still in-flight.
90
+
91
+
3. When the client sends a JSON-RPC _notification_ or _response_ to the MCP endpoint via
92
+
POST:
93
+
94
+
- The client **MUST** include an `Accept` header, listing `text/event-stream` as a
95
+
supported content type.
96
+
- The server **MUST** either return `Content-Type: text/event-stream`, to initiate an
97
+
SSE stream, or else HTTP status code 202 Accepted with no body. The client **MUST**
98
+
support both these cases.
76
99
- If the server initiates an SSE stream:
77
-
- The receipt of the message is acknowledged as soon as the HTTP status code is received (before the SSE stream begins).
100
+
- The receipt of the message is acknowledged as soon as the HTTP status code is
101
+
received (before the SSE stream begins).
78
102
- The server **MAY** close the SSE stream at any time.
79
103
- The client **MAY** close the SSE stream at any time.
80
104
81
-
4. The client **MAY** also issue an HTTP GET to the MCP endpoint. This can be used to open an SSE stream (allowing the server to communicate to the client) without having first sent a _request_, _notification_, or _response_.
82
-
- The client **MUST** include an `Accept` header, listing `text/event-stream` as a supported content type.
83
-
- The server **MUST** either return `Content-Type: text/event-stream` in response to this HTTP GET, or else HTTP status code 204 No Content with no body. The client **MUST** support both these cases.
105
+
4. The client **MAY** also issue an HTTP GET to the MCP endpoint. This can be used to
106
+
open an SSE stream (allowing the server to communicate to the client) without having
107
+
first sent a _request_, _notification_, or _response_.
108
+
- The client **MUST** include an `Accept` header, listing `text/event-stream` as a
109
+
supported content type.
110
+
- The server **MUST** either return `Content-Type: text/event-stream` in response to
111
+
this HTTP GET, or else HTTP status code 204 No Content with no body. The client
112
+
**MUST** support both these cases.
84
113
- If the server initiates an SSE stream:
85
114
- The server **MAY** close the SSE stream at any time.
86
115
- The client **MAY** close the SSE stream at any time.
87
116
88
117
### Session Management
89
118
90
-
Where a client desires to share a single logical session across multiple requests, it **MAY** attach an `Mcp-Session-Id` HTTP header to its requests. This permits resumability and maintenance of session state across separate POSTs.
119
+
Where a client desires to share a single logical session across multiple requests, it
120
+
**MAY** attach an `Mcp-Session-Id` HTTP header to its requests. This permits resumability
121
+
and maintenance of session state across separate POSTs.
91
122
92
123
1. It is the client's responsibility to generate or select the session ID.
93
-
2. This session ID **SHOULD** be globally unique and cryptographically secure (e.g., a UUID or a JWT), unless it is specifically desired to share a session ID across users or clients.
124
+
2. This session ID **SHOULD** be globally unique and cryptographically secure (e.g., a
125
+
UUID or a JWT), unless it is specifically desired to share a session ID across users
126
+
or clients.
94
127
3. The server **MAY** use this header to associate state with the logical session.
95
-
4. If [authorization]({{< ref "authorization" >}}) is used _and_ the server makes use of the `Mcp-Session-Id` header:
96
-
- The server **SHOULD** bind the session ID to the authorization context, and return an error if the session ID is reused in a different authorization context.
128
+
4. If [authorization]({{< ref "authorization" >}}) is used _and_ the server makes use of
129
+
the `Mcp-Session-Id` header:
130
+
- The server **SHOULD** bind the session ID to the authorization context, and return
131
+
an error if the session ID is reused in a different authorization context.
97
132
98
133
### Multiple Connections
99
134
100
135
1. The client **MAY** remain connected to multiple SSE streams simultaneously.
101
-
2. The server **MAY** broadcast its JSON-RPC messages on all connected SSE streams, or it **MAY** limit its communication on any particular stream only to messages related to the client's original request on that stream.
102
-
- The client **MUST** ignore duplicate _requests_ and _responses_ received in this way, by ignoring any duplicate JSON-RPC request IDs in either.
103
-
- The client **MUST** be resilient to duplicate _notifications_, handling them with idempotency.
136
+
2. The server **MAY** broadcast its JSON-RPC messages on all connected SSE streams, or it
137
+
**MAY** limit its communication on any particular stream only to messages related to
138
+
the client's original request on that stream.
139
+
- The client **MUST** ignore duplicate _requests_ and _responses_ received in this
140
+
way, by ignoring any duplicate JSON-RPC request IDs in either.
141
+
- The client **MUST** be resilient to duplicate _notifications_, handling them with
142
+
idempotency.
104
143
105
144
### Sequence Diagram
106
145
107
146
```mermaid
108
147
sequenceDiagram
109
148
participant Client
110
149
participant Server
111
-
150
+
112
151
note over Client, Server: initialization
113
152
114
153
Client->>+Server: POST InitializeRequest<br>Mcp-Session-Id: foo
115
154
Server->>Client: InitializeResponse
116
155
deactivate Server
117
-
156
+
118
157
Client->>+Server: POST InitializedNotification<br>Mcp-Session-Id: foo
119
-
158
+
120
159
alt single HTTP response
121
160
Server->>Client: 202 Accepted
122
161
else server opens SSE stream
@@ -126,11 +165,11 @@ sequenceDiagram
126
165
Client-->Server: (client or server MAY disconnect)
127
166
end
128
167
deactivate Server
129
-
168
+
130
169
note over Client, Server: normal operation (sequentially or concurrently)
131
-
170
+
132
171
Client->>+Server: POST ... other messages ...<br>Mcp-Session-Id: foo
133
-
172
+
134
173
alt single HTTP response
135
174
Server->>Client: ... response ...
136
175
else server opens SSE stream
@@ -141,25 +180,38 @@ sequenceDiagram
141
180
Server-)Client: SSE event: (response)
142
181
end
143
182
end
144
-
183
+
145
184
deactivate Server
146
185
```
147
186
148
187
### Backwards Compatibility
149
188
150
-
Clients and servers can maintain backwards compatibility with the deprecated [HTTP+SSE transport]({{< ref "/specification/2024-11-05/basic/transports#http-with-sse" >}}) (from protocol version 2024-11-05) as follows:
189
+
Clients and servers can maintain backwards compatibility with the deprecated [HTTP+SSE
**Servers** wanting to support older clients should:
153
-
- Continue to host both the SSE and POST endpoints of the old transport, alongside the new "MCP endpoint" defined for the Streamable HTTP transport.
154
-
- It is also possible to combine the old POST endpoint and the new MCP endpoint, but this may introduce unneeded complexity.
194
+
195
+
- Continue to host both the SSE and POST endpoints of the old transport, alongside the
196
+
new "MCP endpoint" defined for the Streamable HTTP transport.
197
+
- It is also possible to combine the old POST endpoint and the new MCP endpoint, but
198
+
this may introduce unneeded complexity.
155
199
156
200
**Clients** wanting to support older servers should:
157
-
1. Accept an MCP server URL from the user, which may point to either a server using the old transport or the new transport.
158
-
2. Attempt to POST an `InitializeRequest` to the server URL, with an `Accept` header as defined above:
159
-
- If it succeeds or opens an SSE stream in response, the client can assume this is a server supporting the new Streamable HTTP transport.
160
-
- If it fails with an HTTP 4xx status code (e.g., 405 Method Not Allowed or 404 Not Found):
161
-
- Issue a GET request to the server URL, expecting that this will open an SSE stream and return an `endpoint` event as the first event.
162
-
- When the `endpoint` event arrives, the client can assume this is a server running the old HTTP+SSE transport, and should use that transport for all subsequent communication.
201
+
202
+
1. Accept an MCP server URL from the user, which may point to either a server using the
203
+
old transport or the new transport.
204
+
2. Attempt to POST an `InitializeRequest` to the server URL, with an `Accept` header as
205
+
defined above:
206
+
- If it succeeds or opens an SSE stream in response, the client can assume this is a
207
+
server supporting the new Streamable HTTP transport.
208
+
- If it fails with an HTTP 4xx status code (e.g., 405 Method Not Allowed or 404 Not
209
+
Found):
210
+
- Issue a GET request to the server URL, expecting that this will open an SSE stream
211
+
and return an `endpoint` event as the first event.
212
+
- When the `endpoint` event arrives, the client can assume this is a server running
213
+
the old HTTP+SSE transport, and should use that transport for all subsequent
0 commit comments