mcp-server-remote-architecture

gregra81/mcp-server-remote-architecture

3.1

If you are the rightful owner of mcp-server-remote-architecture and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Model Context Protocol (MCP) server provides a modular and dynamic architecture for integrating local and remote tools, offering a seamless experience for developers and users.

Tools
8
Resources
0
Prompts
0

MCP Tools Demo

A Model Context Protocol (MCP) implementation showcasing clean, modular tool architecture with local and remote tools support and an interactive browser client.

๐ŸŒŸ Features

  • ๐Ÿ—๏ธ Clean Architecture: Modular tool design with MCPToolsManager
  • ๐Ÿ”ง 8 Demo Tools: 4 local + 4 remote tools working seamlessly together
  • ๐ŸŒ Remote Tools Support: Load tools dynamically from external APIs
  • ๐ŸŒ Browser Client: Interactive web interface for testing all tools
  • ๐Ÿ”ง Admin Panel: Powerful web-based tool management with on/off toggles
  • โšก Tool Configuration: JSON-based tool state management with persistence
  • ๐Ÿ“ก Multiple Server Options: Stdio, Simple HTTP, and Remote Tools servers
  • ๐Ÿ”’ Type Safety: Full TypeScript implementation with Zod validation

๐Ÿš€ Quick Start

1. Installation

git clone <your-repo-url>
cd mcp-hello-world
npm install

2. Full Demo (Local + Remote Tools)

Start both servers for the complete experience:

# Terminal 1: Start remote tools server (4 remote tools)
npm run start:remote

# Terminal 2: Start HTTP server (4 local + 4 remote = 8 total tools)
npm run start:http

Then open:

3. Local Tools Only

# Just local tools (4 tools)
REMOTE_TOOLS_ENABLED=false npm run start:http

4. Command Line Usage (Cursor/Claude)

npm run build
node dist/index.js  # Stdio MCP server

๐Ÿ—๏ธ Architecture

Modular Structure

mcp-hello-world/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts                 # Main MCP stdio server
โ”‚   โ”œโ”€โ”€ mcp-tools-manager.ts     # Generic tools manager (local + remote)
โ”‚   โ”œโ”€โ”€ simple-http-server.ts    # HTTP wrapper with remote tools support
โ”‚   โ”œโ”€โ”€ tool-config.ts          # ๐Ÿ”ง Tool configuration manager
โ”‚   โ”œโ”€โ”€ tools/                   # ๐Ÿ  Local tools directory
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts            # Tools exports and registry
โ”‚   โ”‚   โ”œโ”€โ”€ greg-test-tool.ts   # Mood testing tool
โ”‚   โ”‚   โ”œโ”€โ”€ http-post-tool.ts   # Generic HTTP POST
โ”‚   โ”‚   โ”œโ”€โ”€ weather-tool.ts     # Weather API integration
โ”‚   โ”‚   โ””โ”€โ”€ create-post-tool.ts # JSONPlaceholder posts
โ”‚   โ””โ”€โ”€ types/mcp.ts            # TypeScript definitions
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ client.html             # ๐ŸŒ Interactive browser client
โ”‚   โ”œโ”€โ”€ admin.html              # ๐Ÿ”ง Admin panel for tool management
โ”‚   โ”œโ”€โ”€ remote-tools-api-example.json      # Remote tools definition
โ”‚   โ””โ”€โ”€ remote-tool-server-example.js     # ๐ŸŒ Remote tools server
โ”œโ”€โ”€ tool-config.json            # โšก Tool configuration state
โ””โ”€โ”€ dist/                       # Compiled JavaScript

Key Design Principles

  • Single Source of Truth: Local tools in src/tools/, remote tools via API
  • Generic Manager: MCPToolsManager automatically loads all tools
  • Tool Configuration: JSON-based persistent tool state management
  • Hot-loadable: Remote tools can be added/updated without restart
  • Multiple Interfaces: Same tools work with stdio, HTTP, and browser
  • Admin Control: Web-based tool management with real-time toggles

๐Ÿ”ง Available Tools

๐Ÿ  Local Tools (4)

  1. ๐ŸŽญ Greg Test (greg-test) - Mood testing tool
  2. ๐ŸŒ HTTP POST (http_post) - Generic HTTP requests
  3. ๐ŸŒค๏ธ Weather (get_weather) - Weather API with OpenWeatherMap
  4. ๐Ÿ“„ Create Post (create_post) - JSONPlaceholder integration

๐ŸŒ Remote Tools (4)

  1. ๐Ÿงฎ Calculate Tax (calculate_tax) - Tax calculations
  2. ๐Ÿ“ง Send Email (send_email) - Mock email sending
  3. ๐Ÿ–ผ๏ธ Image OCR (image_ocr) - Mock text extraction
  4. ๐Ÿ—„๏ธ Database Query (database_query) - Mock SQL queries

๐ŸŒ Remote Tools Support

Load tools dynamically from external APIs alongside local tools.

Quick Configuration

const toolsManager = new MCPToolsManager({
  enabled: true,
  toolsUrl: 'http://localhost:3001/mcp/tools',
  timeout: 5000,
  retryAttempts: 2,
});

await toolsManager.initialize();

Remote Tools API Format

Your remote API should return:

{
  "tools": [
    {
      "name": "calculate_tax",
      "description": "Calculate tax for given amount",
      "executeUrl": "https://api.example.com/tools/calculate-tax",
      "method": "POST",
      "inputSchema": {
        "type": "object",
        "properties": {
          "amount": { "type": "number" },
          "rate": { "type": "number" }
        },
        "required": ["amount", "rate"]
      }
    }
  ]
}

Environment Configuration

export REMOTE_TOOLS_ENABLED=true              # Enable/disable remote tools
export REMOTE_TOOLS_URL=http://localhost:3001/mcp/tools
export REMOTE_TOOLS_TIMEOUT=5000
export REMOTE_TOOLS_RETRY_ATTEMPTS=2

๐Ÿ”ง Admin Panel

Powerful web-based tool management interface for controlling tool availability:

Features

  • ๐ŸŽ›๏ธ Tool Toggles: Enable/disable individual tools with visual switches
  • ๐Ÿ“Š Real-time Statistics: Live dashboard showing enabled/disabled counts
  • โšก Bulk Operations: Enable All / Disable All tools at once
  • ๐Ÿ”„ Auto-refresh: Automatically syncs with server every 30 seconds
  • ๐ŸŽจ Modern UI: Beautiful, responsive interface with visual feedback
  • ๐Ÿ’พ Persistent State: Tool configurations saved to tool-config.json

Default Behavior

All tools are disabled by default - you must enable them via the admin panel.

Usage

  1. Start server: npm run start:http
  2. Open admin panel: http://localhost:3000/examples/admin.html
  3. Toggle tools on/off as needed
  4. Use client interface to test: http://localhost:3000/examples/client.html

Tool Configuration File

The admin panel manages tool-config.json with this structure:

[
  {
    "toolName": "greg-test",
    "enabled": true
  },
  {
    "toolName": "http_post",
    "enabled": false
  }
]

๐ŸŒ Browser Client

The interactive web client dynamically loads and displays ONLY enabled tools:

Features

  • ๐Ÿ” Auto-Discovery: Loads enabled tools from server (local + remote)
  • ๐ŸŽฏ Quick Tests: One-click testing for enabled tools
  • ๐Ÿ“Š Tool Statistics: Shows local vs remote breakdown
  • โœ… Health Monitoring: Real-time server status
  • ๐Ÿ”„ Dynamic Updates: Reflects tool availability in real-time

Usage

  1. Start servers: npm run start:remote && npm run start:http
  2. Enable tools in admin panel: http://localhost:3000/examples/admin.html
  3. Use client interface: http://localhost:3000/examples/client.html
  4. Click "Load Available Tools" to see enabled tools
  5. Use quick test buttons or detailed tool information

๐Ÿš€ Running the Servers

HTTP Server (Browser Demo)

npm run start:http      # Local tools only
# OR with remote tools:
npm run start:remote    # Terminal 1: Remote tools server
npm run start:http      # Terminal 2: HTTP server (8 tools total)

Stdio Server (Cursor/Claude Integration)

npm run build
node dist/index.js

Then add to your MCP configuration:

{
  "mcpServers": {
    "demo-tools": {
      "command": "node",
      "args": ["path/to/mcp-server-remote-architecture/dist/index.js"]
    }
  }
}

Important for Cursor/Claude:

  • All tools are disabled by default - you'll see 0 tools initially
  • Enable tools first: Use the admin panel to enable desired tools
    1. Run: npm run start:http
    2. Open: http://localhost:3000/examples/admin.html
    3. Enable tools you want to use
    4. Restart Cursor's MCP connection to see tools
  • Tool state persists across server restarts

๐Ÿ”ง Admin API Endpoints

The server provides dedicated admin endpoints for tool management:

GET /admin/tools

Get all tool configurations (enabled and disabled):

{
  "success": true,
  "tools": [
    {
      "toolName": "greg-test",
      "enabled": true,
      "type": "local",
      "description": "amazing tool"
    }
  ],
  "count": 4
}

POST /admin/tools/:toolName/toggle

Toggle a tool's enabled/disabled state:

curl -X POST http://localhost:3000/admin/tools/greg-test/toggle \
  -H "Content-Type: application/json" \
  -d '{"enabled": true}'

Response:

{
  "success": true,
  "message": "Tool 'greg-test' enabled",
  "toolName": "greg-test",
  "enabled": true,
  "timestamp": "2025-06-21T18:29:38.323Z"
}

๐Ÿ”ง Troubleshooting

Cursor/Claude Shows 0 Tools

Problem: MCP server shows red dot and 0 tools in Cursor Solution:

  1. Tools are disabled by default - enable them via admin panel
  2. Ensure tool configuration file exists in project directory
  3. Restart Cursor's MCP connection after enabling tools

Tool Configuration Not Found

Problem: Server creates new config with all tools disabled Solution: Tool config uses absolute paths - works regardless of working directory

๐Ÿงช Testing

Quick API Tests

# Test tool endpoints
curl http://localhost:3000/mcp/tools          # Enabled tools only
curl http://localhost:3000/mcp/tools/local    # Enabled local tools only
curl http://localhost:3000/mcp/tools/remote   # Enabled remote tools only

# Test admin endpoints
curl http://localhost:3000/admin/tools         # All tool configurations
curl -X POST http://localhost:3000/admin/tools/greg-test/toggle \
  -H "Content-Type: application/json" \
  -d '{"enabled": true}'                       # Enable a tool

# Test specific tools (only if enabled)
curl http://localhost:3000/mcp/test/greg-test
curl http://localhost:3000/mcp/test/calculate_tax  # Remote tool

Tool Calls

# Note: Tools must be enabled first via admin panel
curl -X POST http://localhost:3000/mcp/call-tool \
  -H "Content-Type: application/json" \
  -d '{"tool": "calculate_tax", "parameters": {"amount": 100, "rate": 0.08}}'

๐Ÿ”ง Adding New Tools

Local Tools

  1. Create src/tools/my-tool.ts
  2. Export from src/tools/index.ts
  3. Restart server to load new tool
  4. Enable the tool via admin panel (disabled by default)

Remote Tools

  1. Add tool definition to your remote API
  2. Implement the execution endpoint
  3. Refresh remote tools or restart server
  4. Enable the tool via admin panel (disabled by default)

Tool State Management

  • All new tools are disabled by default
  • Use the admin panel to enable/disable tools
  • Tool states persist in tool-config.json
  • Only enabled tools appear in /mcp/tools endpoints

๐Ÿ“„ License

MIT License - see LICENSE file for details.