mcp连接
简单的MCP(模型上下文协议)服务器,用于将应用程序功能暴露给AI代理
](https://www.npmjs.com/package/mcp-connect) 
🚀 克劳德桌面设置(5分钟)
步骤1:安装mcp连接
npm install -g @myatkyawthu/mcp-connect第二步:创建mcp.config.js
步骤2:创建MCP服务器
# Navigate to your project directory
cd your-project
# Generate sample config
mcp-connect init这创造了 mcp.config.js 使用示例工具:
import { defineMCP } from "@myatkyawthu/mcp-connect";
export default defineMCP({
name: "My MCP App",
version: "1.0.0",
tools: [
["hello", async ({ name = "World" }) => `Hello ${name}!`],
["echo", async ({ message }) => `Echo: ${message}`]
]
});步骤3:本地测试
步骤3:配置Claude桌面
打开Claude Desktop配置文件:
- 视窗:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
添加您的MCP服务器:
{
"mcpServers": {
"my-app": {
"command": "mcp-connect",
"args": ["C:/full/path/to/your/mcp.config.js"]
}
}
}重要:使用完整的绝对路径 mcp.config.js 文件。
步骤4:启动和测试
- 重新启动克劳德桌面 完全
- 测试连接问克劳德 *“你们有什么工具?”*
- 使用你的工具:试试 *“你好!”* 或 *“回显此消息”*
✅ 完成! 您的功能现在可用于Claude Desktop。
______________________________________________________________________
📖 工具定义指南
简单格式(推荐)
// Just name and function
["toolName", async (args) => "result"]🔧 CLI使用情况
高级格式(带验证)
{
name: "toolName",
description: "What this tool does",
schema: {
type: "object",
properties: {
param: { type: "string", description: "Parameter description" }
},
required: ["param"]
},
handler: async ({ param }) => `Result: ${param}`
}🛠 开发命令
# Start with auto-reload during development
npm run dev
# Start server with specific config file
mcp-connect /path/to/your/mcp.config.js
# Format code
npm run format
# Lint code
npm run lint🔧 故障排除
未找到配置文件
# Create sample config
mcp-connect init克劳德桌面未连接
- 检查配置文件路径是否为绝对路径
- 完全重新启动克劳德桌面
- 检查Claude Desktop日志是否有错误
工具不工作
- 验证中的工具语法
mcp.config.js - 检查服务器日志是否有错误
- 先用简单的工具进行测试
📋 例子
文件操作
["readFile", async ({ path }) => {
const fs = await import('fs/promises');
return await fs.readFile(path, 'utf8');
}]API调用
["getWeather", async ({ city }) => {
const response = await fetch(`https://api.weather.com/${city}`);
return await response.json();
}]数据库查询
["getUser", async ({ id }) => {
// Your database logic here
return { id, name: "John Doe", email: "john@example.com" };
}]🌐 其他MCP客户端
Claude桌面设置如上所述。其他MCP客户教程即将推出:
- VS代码扩展
- 定制应用
- 其他AI平台
📄 许可证
MIT© myat kyaw thu
