Home Glossary
HomeGlossaryMCP Session
MCP Glossary

MCP Session

TL;DR

An MCP session is the stateful connection between a client and a server, starting with the `initialize` handshake and ending with `shutdown`. Each session has its own capabilities, session ID (for remote transports), and lifecycle — servers typically keep per-session state like subscriptions or progress tokens.

In depth

An MCP session is the unit of connection in the protocol. Sessions begin when a client calls `initialize`, negotiate capabilities, then run indefinitely until one side disconnects (stdio: process exit; HTTP: session close or timeout). Each session is independent — multiple sessions from the same client to the same server are valid and isolated.

For stdio transport, session = subprocess lifetime. For remote transports, sessions are identified by the `Mcp-Session-Id` header and can persist across many HTTP requests. Servers use the session ID to maintain state: active subscriptions, logged-in users, cached data.

Sessions are where authentication state lives. Once the client completes OAuth during initialize, the session holds the access token. Subsequent tool calls inherit this auth context without re-authenticating.

The session lifecycle is: `initialize` → `initialized` notification → normal operation (tools/call, resources/read, etc.) → `shutdown`. Errors during any phase terminate the session cleanly.

Code example

// Session lifecycle
// 1. Client → Server: initialize
// 2. Server → Client: initialize response (with capabilities, session id)
// 3. Client → Server: notifications/initialized
// 4. ... normal operations (tools/call, etc.) ...
// 5. Client → Server: shutdown (optional — stdio just exits)

// Session ID usage in streamable HTTP:
POST /mcp HTTP/1.1
Mcp-Session-Id: 7f3a9b2c-...
Content-Type: application/json

{ "jsonrpc": "2.0", "method": "tools/call", ... }

Examples

  • 1
    A Claude Desktop session opens when you start the app, closes on quit
  • 2
    A streamable HTTP session identified by `Mcp-Session-Id: 7f3a...`
  • 3
    A short-lived session for a single `tools/list` query in a CI job
  • 4
    A long-lived session for a background agent running 24/7
  • 5
    Parallel sessions from the same client hitting different capabilities

What it's NOT

  • ✗A session is NOT the same as a conversation — one session can span many LLM conversations.
  • ✗Sessions are NOT inherently authenticated — auth is layered on top.
  • ✗A server does NOT need to persist session state across restarts — stateless servers are valid.
  • ✗Multiple sessions from one client are NOT merged — each is isolated.

Related terms

Model Context Protocol (MCP)MCP InitializeMCP CapabilityMCP ClientMCP Server

See also

  • MCP Lifecycle

Frequently asked questions

How long does an MCP session last?

Until explicit shutdown or transport disconnect. Stdio: until subprocess exits. HTTP: until idle timeout or explicit `DELETE /mcp`.

Can I reconnect to an existing session?

For streamable HTTP, yes — send the same `Mcp-Session-Id`. For stdio, no — subprocess exit ends the session.

How do sessions handle failures?

The session terminates on protocol errors. Clients typically restart the server and open a fresh session.

Build with MCP

Browse 300+ MCP servers, explore recipes, or continue learning the MCP vocabulary.

Browse MarketplaceAll terms