{"library":"mcp-http-server","title":"MCP HTTP Server","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mcp-http-server"],"cli":null},"imports":["import { startSseAndStreamableHttpMcpServer } from 'mcp-http-server';","import type { MiddlewareFunction } from 'mcp-http-server';","import type { RoutesConfig } from 'mcp-http-server';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { startSseAndStreamableHttpMcpServer } from 'mcp-http-server';\nimport { Server } from '@modelcontextprotocol/sdk/server'; // Assumed correct import path for the SDK\n\n// In a real application, createMcpServerInstance might involve more complex logic\n// like setting up tools, agents, or database connections. For this example,\n// we use a minimal MCP Server instance from the SDK.\nconst createMcpServerInstance = async (params: { headers: Record<string, string> }) => {\n  console.log('Received request headers:', params.headers);\n  // Return a new instance of an MCP Server (e.g., from @modelcontextprotocol/sdk/server)\n  return new Server(\n    { name: 'my-mcp-server', version: '1.1.0' },\n    { capabilities: { tools: {} } } // Minimal capabilities for the example\n  );\n};\n\nconst main = async () => {\n  try {\n    const server = await startSseAndStreamableHttpMcpServer({\n      port: 3000,\n      host: '::', // Listen on all available network interfaces\n      stateless: true, // Default to true, as per docs, enables streamable HTTP\n      // Optionally add custom Express middlewares or route configurations:\n      // middlewares: [ (req, res, next) => { console.log('Middleware hit:', req.method, req.url); next(); } ],\n      // routes: { prefix: '/api/v1', mcp: '/my-mcp-endpoint' },\n      createMcpServer: createMcpServerInstance,\n    });\n    console.log(`MCP HTTP Server running on http://localhost:3000. \nAccess MCP endpoint at http://localhost:3000/mcp`);\n\n    // Example: Keep the process alive. In a production app, handle graceful shutdown.\n    process.on('SIGINT', async () => {\n      console.log('Shutting down MCP HTTP server...');\n      // Add server.close() logic if available in the returned server object\n      process.exit(0);\n    });\n  } catch (error) {\n    console.error('Failed to start MCP HTTP Server:', error);\n    process.exit(1);\n  }\n};\n\nmain();","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}