A stateful streamable HTTP MCP (Model Context Protocol) server with session management.
This project was created with @agentailor/create-mcp-server.
# Install dependencies
npm install
# Build and run in development
npm run dev
# Or build and start separately
npm run build
npm startThe server will start on port 3000 by default. You can change this by setting the PORT environment variable.
- POST /mcp - Main MCP endpoint for JSON-RPC messages
- First request must be an initialization request (no session ID required)
- Subsequent requests must include
mcp-session-idheader
- GET /mcp - Server-Sent Events (SSE) stream for server-initiated messages
- Requires
mcp-session-idheader
- Requires
- DELETE /mcp - Terminate a session
- Requires
mcp-session-idheader
- Requires
This server maintains stateful sessions:
- Initialize: Send a POST request without a session ID to start a new session
- Session ID: The server returns an
mcp-session-idheader in the response - Subsequent requests: Include the session ID in the
mcp-session-idheader - SSE Stream: Use GET /mcp with your session ID to receive server-initiated messages
- Terminate: Send DELETE /mcp with your session ID to end the session
This server comes with example implementations to help you get started:
- greeting-template - A simple greeting prompt that takes a name parameter
- start-notification-stream - Sends periodic notifications for testing. Parameters:
interval: Milliseconds between notifications (default: 100)count: Number of notifications to send (default: 10, use 0 for unlimited)
- greeting-resource - A simple text resource at
https://example.com/greetings/default
fetch-mcp-server/
├── src/
│ ├── server.ts # MCP server definition (tools, prompts, resources)
│ └── index.ts # Express app and stateful HTTP transport setup
├── package.json
├── tsconfig.json
└── README.md
- Add new tools, prompts, and resources in
src/server.ts - Modify the HTTP transport configuration in
src/index.ts