MCP服务器生成器

一个基于Docker的MCP(Model Context Protocol)服务器工厂,可自动从工具和连接器构建、配置和部署MCP服务器。

  • by klogdog
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 klogdog/EasyMCP

使用说明

EasyMCP-MCP服务器生成器

Docker原生MCP(模型上下文协议)服务器工厂,可从您的工具和连接器自动构建、配置和部署MCP服务器。


🚀 快速开始

在5分钟内获得一个可用的MCP服务器!

先决条件

步骤1:克隆并安装

# Clone the repository
git clone https://github.com/klogdog/EasyMCP.git
cd EasyMCP

# Install dependencies
npm install

# Build the TypeScript code
npm run build

步骤2:构建生成器映像

# Build the MCP generator Docker image
docker build -t mcp-generator .

步骤3:生成MCP服务器

# Run the generator (interactive mode)
docker run -it \
  --privileged \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v $(pwd)/tools:/app/tools \
  -v $(pwd)/connectors:/app/connectors \
  -v $(pwd)/config:/app/config \
  mcp-generator build

# Expected output:
# ✔ Scanning /app/tools... Found 4 tools
# ✔ Scanning /app/connectors... Found 2 connectors
# ✔ Generating MCP manifest...
# ✔ Building Docker image: mcp-server:latest
# ✔ Done! Your MCP server is ready.

步骤4:运行MCP服务器

# Run the generated MCP server
docker run -d \
  -p 8080:8080 \
  -e DATABASE_URL="sqlite:./data/mcp.db" \
  -e OPENAI_API_KEY="sk-your-key" \
  mcp-server:latest

# Test the server
curl http://localhost:8080/health
# {"status":"ok","version":"1.0.0"}

步骤5:使用MCP客户端进行测试

# List available tools
curl http://localhost:8080/tools
# {"tools":["summarize","classify","translate","calculator"]}

# Call a tool
curl -X POST http://localhost:8080/tools/summarize \
  -H "Content-Type: application/json" \
  -d '{"text":"Your long text here...","maxLength":100}'

📖 接下来是什么?

现在您已经运行了第一台MCP服务器,请浏览以下指南:

指南 说明
工具开发 创建具有验证和最佳实践的自定义工具
连接器开发 为外部服务构建连接器
配置 配置数据库、日志记录和功能
部署 部署到Docker、Kubernetes或云

🏗️ 建筑

┌─────────────────────────────────────────────────────────────────┐
│                    MCP Generator (Docker)                        │
│                                                                  │
│  ┌──────────┐   ┌──────────┐   ┌──────────┐   ┌──────────────┐ │
│  │  Loader  │ → │ Manifest │ → │ Config   │ → │  Dockerizer  │ │
│  │          │   │ Generator│   │ Generator│   │              │ │
│  └──────────┘   └──────────┘   └──────────┘   └──────────────┘ │
│       ↑              ↑                              ↓           │
│  ┌─────────┐    ┌──────────┐                 ┌──────────────┐  │
│  │ /tools  │    │/connectors│                │ MCP Server   │  │
│  │         │    │          │                 │ Docker Image │  │
│  └─────────┘    └──────────┘                 └──────────────┘  │
└─────────────────────────────────────────────────────────────────┘
                              ↓
              ┌───────────────────────────────┐
              │     Generated MCP Server      │
              │  ┌─────────────────────────┐ │
              │  │ Tools: summarize,       │ │
              │  │   classify, translate   │ │
              │  ├─────────────────────────┤ │
              │  │ Connectors: gmail,      │ │
              │  │   notion, database      │ │
              │  ├─────────────────────────┤ │
              │  │ Config: config.yaml     │ │
              │  └─────────────────────────┘ │
              └───────────────────────────────┘

🔧 常见用法示例

使用自定义工具构建

# Add your custom tool
cat > tools/my-tool.ts << 'EOF'
export const metadata = {
    name: 'my-tool',
    description: 'My custom tool',
    schemaVersion: '1.0',
    version: '1.0.0'
};

export async function handler(input: { text: string }) {
    return { result: input.text.toUpperCase() };
}
EOF

# Rebuild the server
docker run -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v $(pwd)/tools:/app/tools \
  mcp-generator build

在本地运行服务器(开发)

# Start in development mode
npm run dev

# Or with specific config
NODE_ENV=development npm start

卷曲测试

# Health check
curl http://localhost:8080/health

# List tools
curl http://localhost:8080/tools

# Call summarize tool
curl -X POST http://localhost:8080/tools/summarize \
  -H "Content-Type: application/json" \
  -d '{
    "text": "This is a very long text that needs to be summarized...",
    "maxLength": 50,
    "style": "paragraph"
  }'

# Call classify tool
curl -X POST http://localhost:8080/tools/classify \
  -H "Content-Type: application/json" \
  -d '{
    "text": "I love this product! Amazing quality!",
    "categories": ["positive", "negative", "neutral"]
  }'

❓ 故障排除常见问题

Docker未运行

# Check Docker status
docker info

# Start Docker (Linux)
sudo systemctl start docker

# Start Docker (Mac)
open -a Docker

Docker套接字上的权限被拒绝

# Add user to docker group
sudo usermod -aG docker $USER

# Or run with sudo
sudo docker run ...

端口已在使用中

# Find process using port
lsof -i :8080

# Use different port
docker run -p 3000:8080 mcp-server:latest

模块未找到

# Rebuild TypeScript
npm run build

# Clear node_modules
rm -rf node_modules && npm install

未设置环境变量

# Check if set
echo $DATABASE_URL

# Set for current session
export DATABASE_URL="postgres://..."

# Or use .env file
echo 'DATABASE_URL=postgres://...' >> .env

📁 项目结构

EasyMCP/
├── base/                    # Core generator code
│   ├── loader.ts           # Tool/connector discovery
│   ├── generator.ts        # Manifest generation
│   ├── dockerizer.ts       # Docker image builder
│   ├── config-generator.ts # Config file generator
│   ├── prompt.ts           # Interactive prompts
│   └── templates/          # Server templates
│
├── tools/                   # Drop-in tool modules
│   ├── summarize.ts        # Text summarization
│   ├── classify.ts         # Text classification
│   ├── translate.ts        # Translation
│   └── calculator.py       # Math operations
│
├── connectors/              # Drop-in connectors
│   ├── gmail.ts            # Gmail API
│   ├── notion.ts           # Notion API
│   └── database-connector.py
│
├── config/                  # Configuration files
│   ├── config.yaml         # Main config
│   ├── config.dev.yaml     # Development overrides
│   └── config.prod.yaml    # Production overrides
│
├── docs/                    # Documentation
│   ├── tool-development.md
│   ├── connector-development.md
│   ├── configuration.md
│   └── deployment.md
│
├── .devcontainer/           # VS Code dev container
├── Dockerfile               # Generator image
└── package.json

🔄 运作原理

1.工具和连接器发现

发电机扫描 /tools 和 /connectors 对于TypeScript(.ts)Python(.py)文件:

✔ Scanning /app/tools... Found 4 tools
  - summarize.ts
  - classify.ts
  - translate.ts
  - calculator.py
✔ Scanning /app/connectors... Found 2 connectors
  - gmail.ts
  - notion.ts

2.凭证提示

交互式凭证收集(或从环境中):

? Enter database URL: postgresql://user:password@db:5432/appdb
? Enter OpenAI API key: sk-...
? Enter Notion token: secret_...

3.配置生成

创建 config.yaml 使用收集的设置:

server:
  name: mcp-server
  version: 1.0.0
  port: 8080

database:
  url: ${DATABASE_URL}

services:
  openai:
    apiKey: ${OPENAI_API_KEY}

connectors:
  gmail:
    enabled: true
  notion:
    enabled: true

4.Docker镜像构建

构建一个自包含的MCP服务器映像:

Step 1/8 : FROM node:20-alpine
Step 2/8 : WORKDIR /app
Step 3/8 : COPY package*.json ./
...
Successfully built abc123def
Successfully tagged mcp-server:latest

🛠️ 开发设置

使用开发容器(推荐)

  1. 安装 VS Code
  2. 安装 开发容器扩展
  3. 在VS Code中打开项目
  4. 出现提示时,单击“在容器中重新打开”

手动设置

# Clone repository
git clone https://github.com/klogdog/EasyMCP.git
cd EasyMCP

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run tests
npm test

# Start development server
npm run dev

🤝 贡献

我们欢迎捐款!看 贡献.md 作为指导方针。

  1. 复刻仓库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

📄 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。


🙏 致谢


Built with ❤️ for the MCP community