内容
# mcpify
一款将REST API转换为MCP(模型上下文协议)服务器的代理服务器。
## 功能特点
- **REST API 转 MCP**: 自动将 REST API 端点转换为 MCP 工具
- **多重传输支持**: 支持stdio和HTTP通信
- **符合 JSON-RPC 2.0**: 完全符合 MCP 协议
- **可配置**: 通过配置文件进行灵活的自定义
- **模拟 API 服务器**: 内置简单的 REST API 服务器用于测试
## 安装
### 选项 1:下载预编译二进制文件(推荐)
从 [Releases 页面](https://github.com/f-asai-monox/mcpify/releases) 下载适用于您平台的最新版本。
#### Linux/macOS
使用 curl:
```bash
# 安装最新版本
curl -sSL https://raw.githubusercontent.com/f-asai-monox/mcpify/main/install.sh | bash
# 安装特定版本
VERSION=v0.1.2 curl -sSL https://raw.githubusercontent.com/f-asai-monox/mcpify/main/install.sh | bash
```
使用 wget:
```bash
wget -qO- https://raw.githubusercontent.com/f-asai-monox/mcpify/main/install.sh | bash
```
#### Windows
使用 PowerShell(推荐):
```powershell
iwr -useb https://raw.githubusercontent.com/f-asai-monox/mcpify/main/install.ps1 | iex
```
使用命令提示符:
```cmd
curl -sSL https://raw.githubusercontent.com/f-asai-monox/mcpify/main/install.bat -o install.bat && install.bat
```
#### 手动下载
1. 访问 [Releases](https://github.com/f-asai-monox/mcpify/releases)
2. 下载适用于您的操作系统和架构的存档
3. 解压并将二进制文件移动到您的 PATH
### 选项 2:使用 go install 安装
```bash
go install github.com/f-asai-monox/mcpify/cmd/mcp-server-stdio@latest
```
### 选项 3:从源代码构建
```bash
# 克隆仓库
git clone https://github.com/f-asai-monox/mcpify.git
cd mcpify
# 构建 MCP 服务器
go build -o bin/mcp-server-stdio ./cmd/mcp-server-stdio
# 为测试构建模拟 API
go build -o bin/mock-api ./cmd/mock-api
```
## 快速入门
### 1. 启动模拟 API(用于测试)
```bash
# 如果从源代码构建
./bin/mock-api
```
### 2. 启动 MCP 服务器
#### 使用stdio传输(适用于Claude Code):
```bash
# 如果通过二进制文件安装
mcp-server-stdio
# 使用配置文件
mcp-server-stdio -config ./example-config.json
# 使用 API URL
mcp-server-stdio -api-url http://localhost:8080
# 如果从源代码构建
./bin/mcp-server-stdio -config ./example-config.json
```
#### 使用HTTP传输:
```bash
# 如果通过二进制文件安装
mcp-server-http -port 8080
# 使用配置文件
mcp-server-http -config ./example-config.json -port 8080
# 如果从源代码构建
./bin/mcp-server-http -port 8080
```
## 基本用法
### 配置示例
创建 `config.json` 文件:
```json
{
"apis": [
{
"name": "users-api",
"baseUrl": "http://localhost:8081",
"endpoints": [
{
"name": "get_users",
"description": "获取所有用户",
"method": "GET",
"path": "/users",
"parameters": []
},
{
"name": "create_user",
"description": "创建新用户",
"method": "POST",
"path": "/users",
"parameters": [
{
"name": "name",
"type": "string",
"required": true,
"description": "用户名",
"in": "body"
},
{
"name": "email",
"type": "string",
"required": true,
"description": "用户邮箱",
"in": "body"
}
]
}
]
}
]
}
```
### 与Claude Code一起使用
```json
{
"mcpServers": {
"mcp-bridge": {
"command": "mcp-server-stdio",
"args": ["-config", "./config.json"]
}
}
}
```
## 可用工具
使用示例配置,您可以获得以下工具:
- `get_users` - 获取所有用户
- `create_user` - 创建新用户
- `get_user` - 获取特定用户ID的用户
- `update_user` - 更新用户信息
- `delete_user` - 删除用户
## HTTP传输
代替stdio的HTTP传输:
```bash
# 启动HTTP服务器
go build -o bin/mcp-server-http ./cmd/mcp-server-http
./bin/mcp-server-http -port 8080
# 配置Claude Code
{
"mcpServers": {
"mcp-bridge-http": {
"transport": {
"type": "http",
"url": "http://localhost:8080/mcp"
}
}
}
}
```
## 文档
- **[架构](docs/ARCHITECTURE.md)** - 项目结构和技术细节
- **[配置](docs/CONFIGURATION.md)** - 完整的配置指南
- **[开发](docs/DEVELOPMENT.md)** - 开发和测试指南
- **[API 参考](docs/API-REFERENCE.md)** - 可用工具和用法示例
## 许可证
MIT 许可证
## 贡献
欢迎提交拉取请求和问题报告。