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.
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 | — | 400 |
Lifecycle
constructor(info)— initialises Express app and wires routesregister(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
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