HttpMcpServer
MCP server over Streamable HTTP using Express. Each HTTP client gets its own
session. Extends BaseMcpServer. See
src/mcp/mcp-server.ts for the full signature.
constructor(serverInfo)
| Parameter | Type | Description |
|---|---|---|
serverInfo |
HttpServerInfo |
{ name: string; version: string; port: number } |
start()
Binds Express to the configured port. Idempotent: subsequent calls are no-ops while the server is already listening.
stop()
Closes all active HTTP sessions (each transport is closed), clears the session map, then stops the Express listener and destroys all remaining connections, including idle keep-alive and open SSE sockets, so the process can shut down and the port is fully released. Idempotent; safe to call when not running.
Request routing (/mcp)
| Method | Session ID header | Action |
|---|---|---|
| DELETE | present | Disconnect that session |
| DELETE | missing | 404 |
| POST | present | Route to existing session |
| POST | missing | Create a new session |
| GET | present | Route to existing session |
| GET | missing | 400 |
| Other | missing | 400 |
| Other | present | Route to existing session; the SDK rejects unsupported methods |
Lifecycle
constructor(info): initialises Express app and wires routesregisterTool(item): tools must be registered beforestart()(they are copied into each per-sessionMcpServerat creation time)start(): begins listening on the configured port- Client sends
POST /mcp(initialize) →handleCreateSessioncreates a transport, connects a freshMcpServer(viacreateFreshMcpServer()), stores the session, forwards the response - Subsequent requests include
Mcp-Session-Id→ routed viahandleExistingSession DELETE /mcp→handleDeleteremoves and closes the sessionstop()→onStop()snapshots and clears all sessions, closes each transport, then stops Express and destroys any lingering keep-alive/SSE connections
Types
HttpServerInfo
Extends ServerInfo with the TCP port for Express to
bind to.
| Field | Type | Description |
|---|---|---|
name |
string |
Server name |
version |
string |
Server version |
port |
number |
TCP port for Express to bind to |
See also: BaseMcpServer, StdioMcpServer,
Architecture, Quick Start