What is an MCP Session?

2 min read Updated

An MCP session is the logically related sequence of interactions between a client and server, beginning with the initialization handshake in which protocol version and capabilities are negotiated, and ending when either side terminates the connection.

WHY IT MATTERS

Every MCP connection follows a defined lifecycle. The client opens with an initialize request carrying its protocolVersion, capabilities and clientInfo; the server replies with its own version, capabilities and serverInfo; the client then sends a notifications/initialized notification and normal operation begins. Version negotiation is part of the handshake — if the server cannot support the requested version it responds with the latest it can, and the client should disconnect if that is unacceptable.

Capability negotiation decides which optional features apply for the session: client capabilities such as roots (see MCP roots), sampling and elicitation; server capabilities such as tools, resources, prompts and logging, with sub-capabilities like listChanged. Both sides must use only what was negotiated.

On the Streamable HTTP transport, sessions can be explicit: the server may return an MCP-Session-Id header on the initialise response, which the client must then include on every subsequent request. The session ID should be globally unique and cryptographically secure. The server may terminate the session at any time, answering subsequent requests with HTTP 404 — at which point the client must start a new session by re-initialising. Clients can terminate explicitly with an HTTP DELETE carrying the session header. On the stdio transport the session is simply bounded by the subprocess lifetime.

See mcp session working in your own stack — route your MCP servers through PolicyLayer and every tool call is checked against policy before it runs.

GOVERN YOUR MCP SERVERS →

Enforced before the call runs. Nothing to install.

HOW POLICYLAYER USES THIS

The PolicyLayer gateway sits between AI clients and upstream servers, so it observes the session lifecycle: initialisation, the negotiated capabilities, and every tools/call within the session. Policies and per-person scoped tokens apply across the session, and the audit trail records which identity performed which calls in which session.

FREQUENTLY ASKED QUESTIONS

What does the initialize handshake exchange?
The client sends its supported protocol version, capabilities, and client implementation info; the server responds with its own. The client then confirms readiness with a notifications/initialized notification.
Is the MCP-Session-Id header required?
It is optional and server-assigned. If the server returns one at initialisation, the client must include it on all subsequent HTTP requests; servers that require it should reject requests lacking it with HTTP 400.
How does an MCP session end?
No shutdown message is defined; the transport signals termination. On stdio the client closes stdin and the process exits; on HTTP the server can invalidate the session (404 on its ID) or the client can send an HTTP DELETE with the MCP-Session-Id header.

FURTHER READING

Let agents act without letting them run wild.

Route your MCP servers through PolicyLayer and every tool call is checked against your policy before it runs — allow, deny, or require approval. Per-identity grants. Full audit log. Live in minutes.

Free to start. No card required.

43,000+ MCP servers and 220,000+ tools scanned and risk-classified.

// GET IN TOUCH

Have a question or want to learn more? Send us a message.

Message sent.

We'll get back to you soon.