A centralized manager for Model Context Protocol (MCP) servers that provides:
- Dynamic MCP server management and monitoring
- REST API for tool execution and resource access
- Real-time server status tracking
- Client connection management
- Process lifecycle handling
-
Hub Server (MCP Hub)
- Central management server that connects to and manages multiple MCP servers
- Provides unified API endpoints for clients to access MCP server capabilities
- Handles server lifecycle, health monitoring, and client connections
- Routes requests between clients and appropriate MCP servers
-
MCP Servers
- Individual servers that provide specific tools and resources
- Each server has its own capabilities (tools, resources, templates)
- Connected to and managed by the Hub server
- Process requests from clients through the Hub
npm install -g mcp-hub
Start the hub server:
mcp-hub --port 3000 --config path/to/config.json
Options:
--port Port to run the server on (default: 3000)
--config Path to config file (required)
--watch Watch config file for changes (default: false)
--shutdown-delay Delay in milliseconds before shutting down when no clients are connected (default: 0)
-h, --help Show help information
The server outputs JSON-formatted status messages on startup and state changes:
{
"status": "ready",
"server_id": "mcp-hub",
"version": "1.0.0",
"port": 3000,
"pid": 12345,
"servers": [],
"timestamp": "2024-02-20T05:55:00.000Z"
}
MCP Hub uses a JSON configuration file to define managed servers:
{
"mcpServers": {
"example-server": {
"command": "npx",
"args": ["example-server"],
"env": {
"API_KEY": "", // Will use process.env.API_KEY
"DEBUG": "true", // Will use this value
"SECRET_TOKEN": null // Will use process.env.SECRET_TOKEN
},
"disabled": false
}
}
}
- command: Command to start the MCP server
- args: Array of command line arguments
- env: Environment variables for the server. If a variable is specified with a falsy value (empty string, null, undefined), it will fall back to using the corresponding system environment variable if available.
- disabled: Whether the server is disabled (default: false)
The ravitemer/mcphub.nvim plugin provides seamless integration with Neovim, allowing direct interaction with MCP Hub from your editor:
- Execute MCP tools directly from Neovim
- Access MCP resources within your editing workflow
- Real-time status updates in Neovim
- Custom commands for common MCP operations
MCP Hub uses structured JSON logging for all events:
{
"type": "error",
"code": "TOOL_ERROR",
"message": "Failed to execute tool",
"data": {
"server": "example-server",
"tool": "example-tool",
"error": "Invalid parameters"
},
"timestamp": "2024-02-20T05:55:00.000Z"
}
Log levels include:
info
: Normal operational messageswarn
: Warning conditionsdebug
: Detailed debug informationerror
: Error conditions (includes error code and details)
GET /api/health
Response:
{
"status": "ok",
"server_id": "mcp-hub",
"version": "1.0.0",
"activeClients": 2,
"timestamp": "2024-02-20T05:55:00.000Z",
"servers": []
}
GET /api/servers
GET /api/servers/:name/info
POST /api/servers/:name/refresh
Response:
{
"status": "ok",
"server": {
"name": "example-server",
"capabilities": {
"tools": ["tool1", "tool2"],
"resources": ["resource1", "resource2"],
"resourceTemplates": []
}
},
"timestamp": "2024-02-20T05:55:00.000Z"
}
POST /api/refresh
Response:
{
"status": "ok",
"servers": [
{
"name": "example-server",
"capabilities": {
"tools": ["tool1", "tool2"],
"resources": ["resource1", "resource2"],
"resourceTemplates": []
}
}
],
"timestamp": "2024-02-20T05:55:00.000Z"
}
POST /api/servers/:name/start
Response:
{
"status": "ok",
"server": {
"name": "example-server",
"status": "connected",
"uptime": 123
},
"timestamp": "2024-02-20T05:55:00.000Z"
}
POST /api/servers/:name/stop?disable=true|false
The optional disable
query parameter can be set to true
to disable the server in the configuration.
Response:
{
"status": "ok",
"server": {
"name": "example-server",
"status": "disconnected",
"uptime": 0
},
"timestamp": "2024-02-20T05:55:00.000Z"
}
POST /api/client/register
{
"clientId": "unique_client_id"
}
POST /api/client/unregister
{
"clientId": "unique_client_id"
}
POST /api/servers/:name/tools
{
"tool": "tool_name",
"arguments": {}
}
POST /api/servers/:name/resources
{
"uri": "resource://uri"
}
The Hub Server provides real-time updates via Server-Sent Events (SSE) at /api/events
. Connect to this endpoint to receive real-time updates about server status, client connections, and capability changes.
- server_info - Initial connection information
{
"server_id": "mcp-hub",
"version": "1.0.0",
"status": "connected",
"pid": 12345,
"port": 3000,
"activeClients": 1,
"timestamp": "2024-02-20T05:55:00.000Z"
}
- server_ready - Server started and ready
{
"status": "ready",
"server_id": "mcp-hub",
"version": "1.0.0",
"port": 3000,
"pid": 12345,
"servers": [],
"timestamp": "2024-02-20T05:55:00.000Z"
}
- client_registered/unregistered - Client connection events
{
"activeClients": 2,
"clientId": "client_123",
"timestamp": "2024-02-20T05:55:00.000Z"
}
- tool_list_changed - Server's tools list has changed
{
"type": "TOOL",
"server": "example-server",
"tools": ["tool1", "tool2"],
"timestamp": "2024-02-20T05:55:00.000Z"
}
- resource_list_changed - Server's resources list has changed
{
"type": "RESOURCE",
"server": "example-server",
"resources": ["resource1", "resource2"],
"resourceTemplates": [],
"timestamp": "2024-02-20T05:55:00.000Z"
}
MCP Hub implements a comprehensive error handling system with custom error classes for different types of errors:
- ConfigError: Configuration-related errors (invalid config, missing fields)
- ConnectionError: Server connection issues (failed connections, transport errors)
- ServerError: Server startup/initialization problems
- ToolError: Tool execution failures
- ResourceError: Resource access issues
- ValidationError: Request validation errors
Each error includes:
- Error code for easy identification
- Detailed error message
- Additional context in the details object
- Stack trace for debugging
Example error structure:
{
"code": "CONNECTION_ERROR",
"message": "Failed to communicate with server",
"details": {
"server": "example-server",
"error": "connection timeout"
},
"timestamp": "2024-02-20T05:55:00.000Z"
}
-
Configuration Errors
- Invalid config format
- Missing required fields
- Environment variable issues
-
Server Management Errors
- Connection failures
- Lost connections
- Capability fetch issues
- Server startup problems
-
Request Processing Errors
- Invalid parameters
- Server availability
- Tool execution failures
- Resource access issues
-
Client Management Errors
- Registration failures
- Duplicate registrations
- Invalid client IDs
The Hub Server coordinates communication between clients and MCP servers:
- Starts and connects to configured MCP servers
- Manages client registrations
- Routes tool execution and resource requests
- Handles server monitoring and health checks
- Performs clean shutdown of all connections
The Hub Server actively manages MCP servers through:
- Configuration-based server initialization
- Connection and capability discovery
- Health monitoring and status tracking
- Automatic reconnection attempts
- Server state management
All client requests follow a standardized flow:
- Request validation
- Server status verification
- Request routing to appropriate MCP server
- Response handling and error management
- Node.js >= 18.0.0
- npm >= 9.0.0
Please read our Contributing Guidelines for details on our code of conduct and the process for submitting pull requests.
For security-related issues, please review our Security Policy and follow the vulnerability reporting process.
See CHANGELOG.md for a list of all notable changes.
Please note that this project is released with a Code of Conduct. By participating in this project you agree to abide by its terms.
This project is licensed under the MIT License - see the LICENSE.md file for details.