Chuna AI
将任何REST API公开为MCP服务器,而无需编写一行代码。
Chuna AI是LLM访问任何组织API的网关。它可以将所有API作为MCP(模型上下文协议)服务器公开,这样LLM就可以理解它们并与之交互,而无需编写一行代码。
🚀 特性
- 零代码配置:使用简单的JSON配置定义API
- MCP协议支持:适用于Claude Desktop、Cursor和其他MCP客户端
- 中间件系统:添加身份验证、日志记录、验证和自定义逻辑
- 环境变量:使用安全令牌管理
${ENV:VAR}替换 - 多种HTTP方法:支持GET、POST、PUT、PATCH、DELETE
- TypeScript:使用TypeScript构建,以提高可靠性和类型安全性
🏗️ 建筑
graph TB
subgraph "LLM Client"
A[Claude Desktop]
B[Cursor IDE]
C[Other MCP Clients]
end
subgraph "Chuna AI"
D[MCP StdIO Server]
E[Config Loader]
F[Middleware Engine]
G[HTTP Executor]
end
subgraph "Configuration"
H[tools.json]
I[middleware/index.ts]
end
subgraph "External APIs"
J[REST API 1]
K[REST API 2]
L[REST API N]
end
A --> D
B --> D
C --> D
D --> E
E --> H
E --> I
D --> F
F --> G
G --> J
G --> K
G --> L
style D fill:#e1f5fe
style F fill:#f3e5f5
style G fill:#e8f5e8📋 运作原理
- 配置:在中定义您的API
tools.json带可选中间件 - 启动服务器:运行
chuna-ai serve -c ./config - MCP集成:在LLM客户端中配置(Claude Desktop、Cursor等)
- LLM互动:要求LLM将您的API用作工具
🛠️ 安装
# Clone the repository
git clone https://github.com/Krishank/chuna-ai.git
cd chuna-ai
# Install dependencies
npm install
# Build the project
npm run build⚙️ 配置
基本设置
创建一个 config/tools.json 文件:
[
{
"name": "products_list",
"description": "List all products from the API",
"method": "GET",
"url": "https://api.example.com/products"
},
{
"name": "create_product",
"description": "Create a new product",
"method": "POST",
"url": "https://api.example.com/products",
"headers": {
"Content-Type": "application/json"
}
}
]使用中间件
[
{
"name": "secure_products",
"description": "List products with authentication and logging",
"method": "GET",
"url": "https://api.example.com/products",
"preMiddleware": ["addAuthHeader", "logRequest"],
"postMiddleware": ["validateResponse", "logResponse"]
}
]环境变量
对敏感数据使用环境变量:
[
{
"name": "authenticated_call",
"method": "GET",
"url": "https://api.example.com/data",
"headers": {
"Authorization": "Bearer ${ENV:API_TOKEN}"
}
}
]🔧 中间件系统
可用中间件
addAuthHeader-添加授权标头logRequest-记录HTTP请求logResponse-记录HTTP响应addTimestamp-添加X时间戳标头validateResponse-4xx/5xx响应抛出错误
自定义中间件
在中添加自定义中间件 src/middleware/index.ts:
export const customAuth: PreMiddleware = (spec, context) => {
return {
...spec,
headers: {
...spec.headers,
'X-API-Key': process.env.CUSTOM_API_KEY,
},
};
};
export const transformResponse: PostMiddleware = async (result, context) => {
return {
...result,
body: {
data: result.body,
timestamp: new Date().toISOString(),
},
};
};然后在你的配置中使用:
{
"name": "my_tool",
"method": "GET",
"url": "https://api.example.com/data",
"preMiddleware": ["customAuth"],
"postMiddleware": ["transformResponse"]
}🚀 用法
命令行接口命令模式
# Start the MCP server
node dist/cli.cjs serve -c ./config
# Or with npm
npm run build
npx chuna-ai serve -c ./config库模式
import { startMcpServer, loadConfigFromPath } from 'chuna-ai';
const config = await loadConfigFromPath('./config');
await startMcpServer({ config });🔌 MCP客户端集成
Chuna AI可与任何兼容MCP的客户端配合使用。以下是最受欢迎的选项:
🤖 克劳德桌面(拟人)
最适合:API集成的通用人工智能协助
设置:
- 从下载克劳德桌面 Anthropic网站
- 查找您的配置文件:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 视窗: %APPDATA%\Claude\claude_desktop_config.json
- 添加Chuna AI服务器:
{
"mcpServers": {
"chuna-ai": {
"command": "node",
"args": [
"/path/to/chuna-ai/dist/cli.cjs",
"serve",
"-c",
"/path/to/chuna-ai/config"
]
}
}
}- 重新启动克劳德桌面
- 在新的对话中,提问:“有哪些工具可用?”或“列出我的API工具”
💻 光标IDE
最适合:代码开发与API集成
设置:
- 打开光标IDE
- 转到“设置”→ 特性→ 模型上下文协议
- 点击“编辑JSON”并添加:
{
"mcpServers": {
"chuna-ai": {
"command": "node",
"args": [
"/path/to/chuna-ai/dist/cli.cjs",
"serve",
"-c",
"/path/to/chuna-ai/config"
]
}
}
}- 在MCP设置中单击“重新加载”
- 打开新聊天并使用API工具
🧠 Continue.dev
最适合:VS Code,AI编码辅助
设置:
- 在VS代码中安装Continue扩展
- 打开继续设置(
Cmd/Ctrl + Shift + P→ “继续:打开配置”) - 增添
config.json:
{
"mcpServers": {
"chuna-ai": {
"command": "node",
"args": [
"/path/to/chuna-ai/dist/cli.cjs",
"serve",
"-c",
"/path/to/chuna-ai/config"
]
}
}
}- 重新启动VS代码
- 使用
@在继续聊天以访问您的工具
🔧 MCP检查员(开发)
最适合:测试和调试MCP服务器
设置:
# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector
# Start your Chuna AI server
node dist/cli.cjs serve -c ./config
# In another terminal, start inspector
mcp-inspector特性:
- 可视化工具测试界面
- 请求/响应检查
- 中间件调试
- 实时工具执行
🐍 Python MCP客户端
最适合:自定义Python应用程序
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
server_params = StdioServerParameters(
command="node",
args=["/path/to/chuna-ai/dist/cli.cjs", "serve", "-c", "/path/to/chuna-ai/config"]
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# List available tools
tools = await session.list_tools()
print(f"Available tools: {[tool.name for tool in tools.tools]}")
# Call a tool
result = await session.call_tool("products_list", {})
print(f"Result: {result.content}")
asyncio.run(main())🌐 基于Web的MCP客户端
最适合:基于浏览器的人工智能应用程序
热门选项:
- MCP Web客户端:基于浏览器的MCP客户端
- 自定义Web应用程序:使用MCP WebSocket传输构建自己的
📱 移动MCP客户端
最适合:移动AI应用程序
- 克劳德·莫比尔:支持MCP的iOS/Android应用程序
- 自定义移动应用程序:将MCP集成到React Native/Flutter应用程序中
🎯 客户比较
| 客户端 | 最适合 | 易于安装 | 功能 |
|---|---|---|---|
| 克劳德桌面 | 一般人工智能协助 | ⭐⭐⭐⭐⭐ | 全面对话,工具调用 |
| 光标IDE | 代码开发 | ⭐⭐⭐⭐ | 代码上下文,API集成 |
| Continue.dev | VS代码开发 | ⭐⭐⭐⭐ | 内联代码辅助 |
| MCP检查员 | 测试/调试 | ⭐⭐⭐ | 可视化界面,调试 |
| Python客户端 | 自定义应用程序 | ⭐⭐ | 完全程序化控制 |
| Web客户端 | 浏览器应用程序 | ⭐⭐ | 基于Web的AI应用程序 |
🚀 快速入门示例
示例1:使用Claude Desktop进行电子商务
// config/tools.json
[
{
"name": "get_products",
"description": "Get all products from our store",
"method": "GET",
"url": "https://api.mystore.com/products",
"preMiddleware": ["addAuthHeader", "logRequest"]
}
]克劳德对话:
You: "Show me all products in our store"
Claude: I'll get the products for you using the get_products tool.
[Claude calls get_products tool]
Claude: Here are all the products in your store: [product list]示例2:CRM与Cursor的集成
// config/tools.json
[
{
"name": "create_lead",
"description": "Create a new sales lead",
"method": "POST",
"url": "https://crm.company.com/leads",
"headers": {
"Authorization": "Bearer ${ENV:CRM_TOKEN}",
"Content-Type": "application/json"
},
"preMiddleware": ["logRequest"],
"postMiddleware": ["validateResponse"]
}
]光标聊天:
You: "Create a lead for John Doe, email john@example.com, interested in our premium plan"
Cursor: I'll create that lead for you using the CRM API.
[Cursor calls create_lead tool with the provided information]🔍 故障排除
常见问题
- 工具未出现:检查MCP服务器是否正在运行以及配置是否有效
- 身份验证错误:验证是否设置了环境变量
- 连接问题:确保MCP配置中的路径是绝对的
- 中间件错误:检查中间件函数名称是否与导出匹配
调试模式
# Run with debug logging
DEBUG=* node dist/cli.cjs serve -c ./config健康检查
# Test MCP server manually
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | node dist/cli.cjs serve -c ./config💡 示例工作流
电子商务API
[
{
"name": "list_products",
"description": "Get all products",
"method": "GET",
"url": "https://api.shop.com/products"
},
{
"name": "create_order",
"description": "Create a new order",
"method": "POST",
"url": "https://api.shop.com/orders",
"preMiddleware": ["addAuthHeader", "logRequest"]
},
{
"name": "update_inventory",
"description": "Update product inventory",
"method": "PUT",
"url": "https://api.shop.com/inventory",
"preMiddleware": ["addAuthHeader"]
}
]CRM集成
[
{
"name": "get_contacts",
"description": "Retrieve all contacts",
"method": "GET",
"url": "https://crm.example.com/contacts",
"headers": {
"Authorization": "Bearer ${ENV:CRM_TOKEN}"
},
"preMiddleware": ["logRequest"],
"postMiddleware": ["validateResponse"]
},
{
"name": "create_lead",
"description": "Create a new sales lead",
"method": "POST",
"url": "https://crm.example.com/leads",
"headers": {
"Authorization": "Bearer ${ENV:CRM_TOKEN}",
"Content-Type": "application/json"
}
}
]🧪 测试
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Type checking
npm run typecheck
# Linting
npm run lint📦 发展
# Watch mode for development
npm run dev
# Build for production
npm run build
# Format code
npm run format🤝 贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature/amazing-feature - 提交更改:
git commit -m 'Add amazing feature' - 推送到分支:
git push origin feature/amazing-feature - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 为MCP(模型上下文协议)生态系统构建
- 灵感来自对无缝LLM-API集成的需求
- 感谢开源社区提供的工具和库
______________________________________________________________________
由以下材料制成❤️ 对于AI社区
