Skip to main content

Overview

MCP Hub is the central server component of the MCP system, responsible for managing AI model contexts, tools, and resources. It provides RESTful APIs for integration and handles the orchestration of tools and contexts.

Installation

# Clone the repository
git clone <mcp-hub-repo>
cd mcp-hub

# Install dependencies
npm install

# Build the project
npm run build

# Start the server
npm start
The server will start on http://localhost:3000 by default.

Configuration

Basic Configuration

Create a configuration file or use environment variables:
{
  "server": {
    "port": 3000,
    "host": "localhost"
  },
  "security": {
    "apiKey": "your-api-key",
    "enableRBAC": true
  }
}

Server Configuration

MCP Hub supports various server types that can be configured:
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/allowed/path1",
        "/allowed/path2"
      ]
    },
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "<YOUR_BRAVE_API_KEY>"
      }
    }
  }
}

API Endpoints

Session Management

// Initialize a user session
POST /sessions/:userId
{
  "serverConfigs": {
    "filesystem": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem", "./allowed_directory"]
    }
  }
}

// Delete a session
DELETE /sessions/:userId

Tool Operations

// Execute a tool
POST /users/:userId/tools
{
  "name": "write_file",
  "arguments": {
    "path": "allowed_directory/example.txt",
    "content": "Hello World!"
  }
}

// Get available tools
GET /users/:userId/tools

Integration Example

Here’s a basic example of using MCP Hub:
import axios from 'axios'

const mcpHub = {
  baseUrl: 'http://localhost:3000',
  userId: 'user123',

  async initialize() {
    await axios.post(`${this.baseUrl}/sessions/${this.userId}`, {
      serverConfigs: {
        filesystem: {
          command: 'npx',
          args: ['-y', '@modelcontextprotocol/server-filesystem', './data']
        }
      }
    })
  },

  async writeFile(path: string, content: string) {
    return axios.post(`${this.baseUrl}/users/${this.userId}/tools`, {
      name: 'write_file',
      arguments: { path, content }
    })
  },

  async readFile(path: string) {
    return axios.post(`${this.baseUrl}/users/${this.userId}/tools`, {
      name: 'read_file',
      arguments: { path }
    })
  }
}

Available Tools

MCP Hub comes with several built-in tools:
  1. Filesystem Operations
    • read_file
    • write_file
    • list_directory
    • delete_file
  2. Search Operations
    • brave_search
    • web_search
  3. GitHub Integration
    • github_search
    • github_content

Security Considerations

  1. API Key Authentication
    • Always use API keys for authentication
    • Rotate keys regularly
    • Store keys securely
  2. Path Security
    • Only allow access to specified directories
    • Validate all file paths
    • Prevent directory traversal attacks
  3. RBAC Integration
    • Enable RBAC when using with MCP Enterprise
    • Configure appropriate permissions
    • Regular audit of access patterns

Monitoring

MCP Hub provides several endpoints for monitoring:
// Health check
GET /health

// Server status
GET /status

// Tool status
GET /tools/status

Common Issues and Solutions

  1. Connection Issues
    • Verify the server is running
    • Check port availability
    • Confirm network settings
  2. Tool Execution Errors
    • Verify tool configuration
    • Check permissions
    • Review tool logs
  3. Performance Issues
    • Monitor resource usage
    • Implement rate limiting
    • Configure caching

Best Practices

  1. Tool Management
    • Register tools with specific versions
    • Implement proper error handling
    • Monitor tool performance
  2. Security
    • Use HTTPS in production
    • Implement rate limiting
    • Regular security audits
  3. Integration
    • Use connection pooling
    • Implement retry logic
    • Handle errors gracefully