mcp-http-server is a high-performance HTTP server designed specifically for the Model Context Protocol (MCP) ecosystem, providing robust transport for both standard HTTP POST and Server-Sent Events (SSE). It offers flexible routing configurations, allows access to HTTP headers within the MCP server context, and supports custom Express-style middleware for extending server logic. The package currently maintains a stable version 1.2.4, suggesting a mature and consistent API for its core functionality. While originating from the broader UI-TARS-desktop project on GitHub, its specific release cadence appears independent of the more rapid beta iterations seen in related `@agent-tars` components. Key differentiators include its dual support for stateful and stateless modes for streamable HTTP, making it suitable for diverse real-time communication needs where MCP interactions are central.
npm install mcp-http-serverVerified import paths — ran on the pinned version, not inferred.
Initializes and starts a high-performance HTTP+SSE server for the Model Context Protocol (MCP) on port 3000, demonstrating basic setup with a minimal MCP server instance, access to request headers, and graceful shutdown.
Always explicitly set the `port` in the `startSseAndStreamableHttpMcpServer` configuration object, for example: `{ port: 3000 }`.Ensure all custom middleware functions explicitly call `next()` at the end of their logic, or terminate the request using methods like `res.end()` or `res.send()` if they are designed to send a response.
Test your custom routes thoroughly. Remember that `prefix` is prepended to other paths. The server automatically handles leading/trailing slashes, so `/api/v1/` and `/api/v1` for a prefix are typically equivalent.
Install `@modelcontextprotocol/sdk/server` if you intend to use the official MCP server implementation: `npm install @modelcontextprotocol/sdk/server`. Ensure `createMcpServer` returns a valid MCP server instance.
Choose a different port for the `mcp-http-server` (e.g., `port: 4000`) or identify and terminate the process currently occupying the port.
Ensure `createMcpServer` is a valid asynchronous function that returns an MCP server instance, as demonstrated in the quickstart example.
Install the necessary dependency: `npm install @modelcontextprotocol/sdk/server`.
Ensure your client is making POST requests to the `/mcp` or `/message` endpoints as intended for data submission. For SSE connections, clients should initiate a GET request to the `/sse` endpoint.