ExpressJS MCP

ExpressJS MCP

Exposes Express.js API endpoints as MCP tools, preserving existing schemas and authentication behavior. Supports streaming responses and can be mounted directly to existing Express apps or run as a standalone gateway.

Category
访问服务器

README

express_mcp

Expose your Express endpoints as MCP tools (mount to your app or run a standalone HTTP gateway), preserving schemas and auth behavior.

  • Inspiration: FastAPI-MCP — https://github.com/tadata-org/fastapi_mcp

Features

  • Zero Configuration: Works out-of-the-box with existing Express apps
  • Schema Preservation: Supports OpenAPI v3 and zod annotations
  • Auth Integration: Reuses existing Express middleware (no bypass)
  • Flexible Deployment: Mount to same app or run standalone
  • In-Process Efficiency: Direct middleware execution (no HTTP overhead)
  • 🚀 Streaming Support: Handle Server-Sent Events, file downloads, and real-time data
  • 📦 NPX/Bunx Commands: Easy CLI access with npx expressjs-mcp and bunx expressjs-mcp

Installation

Option 1: Install from npm (Recommended)

# Install globally or locally
npm install -g expressjs-mcp
# or with pnpm
pnpm add -g expressjs-mcp

# Use with npx (no installation required)
npx expressjs-mcp init

Option 2: Clone and build locally

git clone https://github.com/bowen31337/expressjs_mcp.git
cd expressjs_mcp
pnpm install && pnpm build

Quick Start

Option 1: CLI Commands (Recommended)

# Initialize in your project (works with npm package or locally built)
npx expressjs-mcp init
# or if installed locally: node bin/express-mcp.cjs init

# Start your server
node server.js

# Test connection
npx expressjs-mcp test --url http://localhost:3000/mcp
# or if installed locally: node bin/express-mcp.cjs test --url http://localhost:3000/mcp

Option 2: Manual Setup

npm install expressjs-mcp
# or
pnpm add expressjs-mcp

Native MCP Server (New!)

Express-MCP now includes a native MCP server using the official @modelcontextprotocol/sdk:

# Connect to your Express app
npx expressjs-mcp --url http://localhost:3000/mcp

# With debug logging
npx expressjs-mcp --debug
import express from 'express';
import { ExpressMCP } from 'expressjs-mcp';

const app = express();
app.use(express.json());

app.get('/hello', (_req, res) => res.json({ message: 'world' }));

const mcp = new ExpressMCP(app, { mountPath: '/mcp' });
await mcp.init();
mcp.mount('/mcp');

MCP Client Configuration

Once your Express server is running with MCP endpoints, you need to configure your MCP client to connect to it. Here are instructions for popular MCP clients:

For Cursor IDE

  1. Open Cursor Settings:

    • Press Cmd/Ctrl + , to open settings
    • Search for "MCP" or navigate to Extensions > MCP
  2. Add MCP Server Configuration:

    {
      "mcpServers": {
        "expressjs-mcp": {
          "command": "node",
          "args": ["/path/to/your/project/server.js"],
          "env": {
            "NODE_ENV": "production"
          }
        }
      }
    }
    
  3. Alternative: Use Native MCP Server:

    {
      "mcpServers": {
        "expressjs-mcp": {
          "command": "npx",
          "args": ["expressjs-mcp", "--url", "http://localhost:3000/mcp"]
        }
      }
    }
    

For Claude Desktop

  1. Edit Configuration File:

    • Open claude_desktop_config.json in your Claude Desktop settings
    • Location varies by OS:
      • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
      • Windows: %APPDATA%\Claude\claude_desktop_config.json
      • Linux: ~/.config/Claude/claude_desktop_config.json
  2. Add MCP Server:

    {
      "mcpServers": {
        "expressjs-mcp": {
          "command": "node",
          "args": ["/absolute/path/to/your/project/server.js"],
          "env": {
            "NODE_ENV": "production"
          }
        }
      }
    }
    
  3. Restart Claude Desktop after making changes

For Claude Web

  1. Access MCP Settings:

    • Go to claude.ai
    • Click on your profile/settings
    • Look for "MCP Configuration" or "Model Context Protocol"
  2. Add Server Configuration:

    {
      "mcpServers": {
        "expressjs-mcp": {
          "command": "node",
          "args": ["/path/to/your/project/server.js"]
        }
      }
    }
    

For VS Code with MCP Extension

  1. Install MCP Extension:

    • Search for "MCP" in VS Code extensions
    • Install the official MCP extension
  2. Configure in settings.json:

    {
      "mcp.servers": {
        "expressjs-mcp": {
          "command": "node",
          "args": ["/path/to/your/project/server.js"]
        }
      }
    }
    

For Other MCP Clients

Most MCP clients follow a similar configuration pattern:

{
  "mcpServers": {
    "expressjs-mcp": {
      "command": "node",
      "args": ["/path/to/your/project/server.js"],
      "env": {
        "NODE_ENV": "production"
      }
    }
  }
}

Configuration Options

  • command: The command to run (usually node for JavaScript/TypeScript)
  • args: Array of arguments (path to your server file)
  • env: Environment variables (optional)
  • cwd: Working directory (optional)

Testing Your Configuration

  1. Start your Express server:

    node server.js
    
  2. Test MCP endpoints:

    # Check available tools
    curl http://localhost:3000/mcp/tools
    
    # Test a tool invocation
    curl -X POST http://localhost:3000/mcp/invoke \
      -H "Content-Type: application/json" \
      -d '{"toolName": "GET_/hello", "args": {}}'
    
  3. Verify in your MCP client:

    • The MCP client should show available tools
    • You should be able to invoke tools through the client interface

Troubleshooting

Common Issues:

  1. Path Issues: Use absolute paths in your configuration
  2. Permission Issues: Ensure the server file is executable
  3. Port Conflicts: Make sure your Express server is running on the expected port
  4. Environment Variables: Set NODE_ENV=production for better performance

Debug Mode:

# Run with debug logging
NODE_ENV=development node server.js

# Or use the native MCP server with debug
npx expressjs-mcp --url http://localhost:3000/mcp --debug

Check MCP Server Status:

# Test if MCP endpoints are working
curl http://localhost:3000/mcp/tools | jq .

# Check server health
curl http://localhost:3000/health

Streaming Support

Express MCP supports three types of streaming for real-time data:

🌊 1. HTTP Chunked Streaming

app.get('/api/chunked', (req, res) => {
  res.setHeader('Transfer-Encoding', 'chunked');
  res.write('Processing...\n');
  // Stream data in chunks
});

📡 2. Server-Sent Events (SSE)

app.get('/api/sse', (req, res) => {
  res.setHeader('Content-Type', 'text/event-stream');
  res.setHeader('Cache-Control', 'no-cache');
  
  let count = 0;
  const interval = setInterval(() => {
    res.write(`data: ${JSON.stringify({ count: ++count })}\n\n`);
    if (count >= 10) {
      clearInterval(interval);
      res.end();
    }
  }, 1000);
});

📄 3. NDJSON/JSON Lines

app.get('/api/ndjson', (req, res) => {
  res.setHeader('Content-Type', 'application/x-ndjson');
  
  const data = [{ id: 1 }, { id: 2 }];
  data.forEach(item => {
    res.write(JSON.stringify(item) + '\n');
  });
  res.end();
});

Testing All Streaming Types

# HTTP Streaming via MCP
curl -X POST http://localhost:3000/mcp/invoke \
  -H "Content-Type: application/json" \
  -d '{"toolName": "GET /api/stream", "args": {}, "streaming": true}'

# stdio Streaming via MCP Bridge (npm package)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"GET /api/ndjson","arguments":{"_streaming":true}}}' | \
  npx expressjs-mcp bridge
  
# Test with native MCP server:
npx expressjs-mcp --url http://localhost:3000/mcp --debug

# Direct endpoint testing
curl http://localhost:3000/api/sse        # SSE
curl http://localhost:3000/api/ndjson     # NDJSON
curl http://localhost:3000/api/chunked    # Chunked

Documentation

Development

pnpm install
pnpm test      # Run tests
pnpm build     # Build for production
pnpm lint      # Check code quality

Configuration Options

  • OpenAPI: Provide your OpenAPI v3 spec for rich schemas
  • Schema Annotations: Use zod for per-route type validation
  • Route Filtering: Include/exclude specific endpoints
  • Auth Preservation: Existing middleware runs unchanged
  • Streaming: Automatic detection and handling of streaming responses
  • Timeouts: Configurable request timeouts for long-running operations

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选