Skip to content

Commit 3493bd1

Browse files
authored
docs(protocol): define the v2 session lifecycle (#2579)
* docs(protocol): define the v2 session lifecycle * docs(protocol): leave session retention to the Agent
1 parent eebf18f commit 3493bd1

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎docs/protocol/v2/draft/error.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Malformed parameters and unsupported values get `-32602`. For example, an invali
4949

5050
### Unknown Sessions
5151

52-
If a session-scoped request names a session that does not exist or is not active on the connection, the Agent **MUST** respond with `-32002` and set `data.sessionId` to the requested ID. A session is active once it is created or resumed on the connection, until it is closed.
52+
If a session-scoped request names a session that does not exist or is not active on the connection, the Agent **MUST** respond with `-32002` and set `data.sessionId` to the requested ID. A session is active once it is created or resumed on the connection, until it is closed or the connection ends. See [Session Lifecycle](/protocol/v2/draft/session-setup#session-lifecycle).
5353

5454
This applies to `session/prompt` and `session/set_config_option`, and to `session/resume` of a session that does not exist or was deleted. Closing or deleting a session that does not exist still succeeds; see [Closing Active Sessions](/protocol/v2/draft/session-setup#closing-active-sessions) and [Deleting Sessions](/protocol/v2/draft/session-delete).
5555

‎docs/protocol/v2/draft/session-setup.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ sequenceDiagram
4242

4343
<br />
4444

45+
## Session Lifecycle
46+
47+
A session exists from `session/new` until the Agent discards it. Agents choose how long to keep sessions: for example, they may not store a session that was never prompted, may expire old sessions, or may remove one through [`session/delete`](/protocol/v2/draft/session-delete). `session/list` and `session/resume` only see sessions the Agent still has, and resuming one it no longer has fails with `-32002`.
48+
49+
On a connection, a session is **active** from a successful `session/new` or `session/resume` until `session/close` or the end of the connection. Agents **SHOULD NOT** discard a session while it is active.
50+
51+
- Session-scoped requests such as `session/prompt` and `session/set_config_option` require an active session. Otherwise the Agent responds with `-32002`; see [Unknown Sessions](/protocol/v2/draft/error#unknown-sessions). Agents ignore `session/cancel` for a session that isn't active.
52+
- Closing a session ends it on the connection but doesn't discard it. Whether a closed session stays listed and resumable depends on how long the Agent keeps it.
53+
- Resuming a session that is already active on the connection synchronizes it again, like any resume. Ongoing work continues, and the request's MCP servers and workspace roots replace the previous ones.
54+
- When the connection ends, its sessions stop being active. The Agent **MAY** continue or cancel their foreground work. A later `session/resume` reports the outcome in its [current-state snapshot](#current-state-synchronization).
55+
4556
## Creating a Session
4657

4758
Clients create a new session by calling the `session/new` method with:

‎docs/protocol/v2/error.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Malformed parameters and unsupported values get `-32602`. For example, an invali
4949

5050
### Unknown Sessions
5151

52-
If a session-scoped request names a session that does not exist or is not active on the connection, the Agent **MUST** respond with `-32002` and set `data.sessionId` to the requested ID. A session is active once it is created or resumed on the connection, until it is closed.
52+
If a session-scoped request names a session that does not exist or is not active on the connection, the Agent **MUST** respond with `-32002` and set `data.sessionId` to the requested ID. A session is active once it is created or resumed on the connection, until it is closed or the connection ends. See [Session Lifecycle](/protocol/v2/session-setup#session-lifecycle).
5353

5454
This applies to `session/prompt` and `session/set_config_option`, and to `session/resume` of a session that does not exist or was deleted. Closing or deleting a session that does not exist still succeeds; see [Closing Active Sessions](/protocol/v2/session-setup#closing-active-sessions) and [Deleting Sessions](/protocol/v2/session-delete).
5555

‎docs/protocol/v2/session-setup.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ sequenceDiagram
4242

4343
<br />
4444

45+
## Session Lifecycle
46+
47+
A session exists from `session/new` until the Agent discards it. Agents choose how long to keep sessions: for example, they may not store a session that was never prompted, may expire old sessions, or may remove one through [`session/delete`](/protocol/v2/session-delete). `session/list` and `session/resume` only see sessions the Agent still has, and resuming one it no longer has fails with `-32002`.
48+
49+
On a connection, a session is **active** from a successful `session/new` or `session/resume` until `session/close` or the end of the connection. Agents **SHOULD NOT** discard a session while it is active.
50+
51+
- Session-scoped requests such as `session/prompt` and `session/set_config_option` require an active session. Otherwise the Agent responds with `-32002`; see [Unknown Sessions](/protocol/v2/error#unknown-sessions). Agents ignore `session/cancel` for a session that isn't active.
52+
- Closing a session ends it on the connection but doesn't discard it. Whether a closed session stays listed and resumable depends on how long the Agent keeps it.
53+
- Resuming a session that is already active on the connection synchronizes it again, like any resume. Ongoing work continues, and the request's MCP servers and workspace roots replace the previous ones.
54+
- When the connection ends, its sessions stop being active. The Agent **MAY** continue or cancel their foreground work. A later `session/resume` reports the outcome in its [current-state snapshot](#current-state-synchronization).
55+
4556
## Creating a Session
4657

4758
Clients create a new session by calling the `session/new` method with:

0 commit comments

Comments
 (0)