@@ -148,25 +148,26 @@ act as a cursor within that particular stream.
148
148
149
149
### Session Management
150
150
151
- Where a client desires to share a single logical session across multiple requests, it
152
- ** MAY** attach an ` Mcp-Session-Id ` HTTP header to its requests. This permits maintenance
153
- of session state across separate POSTs.
154
-
155
- 1 . It is the client's responsibility to generate or select the session ID.
156
- 2 . This session ID ** SHOULD** be globally unique and cryptographically secure (e.g., a
157
- UUID or a JWT), unless it is specifically desired to share a session ID across users
158
- or clients.
159
- 3 . The server ** MAY** use this header to associate state with the logical session.
160
- - If the server agrees to re-establish an existing session, it ** MUST** include a
161
- ` Mcp-Session-Status: resumed ` HTTP header in its response.
162
- - If the server begins a new session associated with the session ID, it ** MUST**
163
- include a ` Mcp-Session-Status: created ` HTTP header in its response.
164
- - The server ** MAY** delete session state at any time; however, it ** MUST NOT**
165
- prevent the same session ID from creating a new session again in future.
166
- 4 . If [ authorization] ({{< ref "authorization" >}}) is used _ and_ the server makes use of
167
- the ` Mcp-Session-Id ` header:
168
- - The server ** SHOULD** bind the session ID to the authorization context, and return
169
- an error if the session ID is reused in a different authorization context.
151
+ An MCP "session" consists of logically related interactions between a client and a
152
+ server, beginning with the [ initialization phase] ({{< ref "lifecycle" >}}). To support
153
+ servers which want to establish stateful sessions:
154
+
155
+ 1 . A server using the Streamable HTTP transport ** MAY** assign a session ID at
156
+ initialization time, by including it in the ` sessionId ` field of the
157
+ ` InitializeResult ` .
158
+ - The session ID ** SHOULD** be globally unique and cryptographically secure (e.g., a
159
+ securely generated UUID, a JWT, or a cryptographic hash).
160
+ - The session ID ** MUST** only contain visible ASCII characters.
161
+ 2 . If a ` sessionId ` is returned in the ` InitializeResult ` , clients using the Streamable
162
+ HTTP transport ** MUST** include it in the ` Mcp-Session-Id ` header on all of their
163
+ subsequent HTTP requests.
164
+ - Servers that require a session ID ** SHOULD** respond to requests without an
165
+ ` Mcp-Session-Id ` header (other than initialization) with HTTP 400 Bad Request.
166
+ 3 . The server ** MAY** terminate the session at any time, after which it ** MUST** respond
167
+ to requests containing that session ID with HTTP 404 Not Found.
168
+ 4 . When a client receives HTTP 404 in response to a request containing an
169
+ ` Mcp-Session-Id ` , it ** MUST** start a new session by sending a new ` InitializeRequest `
170
+ without a session ID attached.
170
171
171
172
### Sequence Diagram
172
173
@@ -177,25 +178,15 @@ sequenceDiagram
177
178
178
179
note over Client, Server: initialization
179
180
180
- Client->>+Server: POST InitializeRequest<br>Mcp-Session-Id: foo
181
- Server->>Client: InitializeResponse
182
- deactivate Server
183
-
184
- Client->>+Server: POST InitializedNotification<br>Mcp-Session-Id: foo
181
+ Client->>+Server: POST InitializeRequest
182
+ Server->>-Client: InitializeResponse<br>Mcp-Session-Id: 1868a90c...
185
183
186
- alt single HTTP response
187
- Server->>Client: 202 Accepted
188
- else server opens SSE stream
189
- loop while connection remains open
190
- Server-)Client: ... SSE messages from server ...
191
- end
192
- Client-->Server: (client or server MAY disconnect)
193
- end
194
- deactivate Server
184
+ Client->>+Server: POST InitializedNotification<br>Mcp-Session-Id: 1868a90c...
185
+ Server->>-Client: 202 Accepted
195
186
196
187
note over Client, Server: normal operation (sequentially or concurrently)
197
188
198
- Client->>+Server: POST ... other messages ...<br>Mcp-Session-Id: foo
189
+ Client->>+Server: POST ... other messages ...<br>Mcp-Session-Id: 1868a90c...
199
190
200
191
alt single HTTP response
201
192
Server->>Client: ... response ...
0 commit comments