39 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 极速部署
openmcp-sdk 的核心特性之一就是极速部署,利用和 openmcp-client 的联动性您可以在短短10秒内闪电般完成 MCP Agent 的部署。
## 1. 从 openmcp 中导出 mcpconfig.json
首先,先在 openmcp 中打开你调试好的 mcp 项目。假设在交互测试中,你已经完成了让您满意的调试结果。
此时,点击对话框工具栏的最右侧一个小火箭一样的图标,你会看到这样的窗口:
![](./images/export-config.png)
点击复制或者导出都可以获得一份 mcpconfig.json 文件。
## 2. 部署到 openmcp-sdk 中
然后我们创建文件 main.ts直接简单几行代码就能把上面的配置部署成一个 agent
```typescript
import { OmAgent } from 'openmcp-sdk/service/sdk';
const agent = new OmAgent();
agent.loadMcpConfig('./mcpconfig.json');
const res = await agent.ainvoke({ messages: '今天杭州的天气是什么样子的?' });
console.log('⚙️ Agent Response', res);
```
使用 `npx tsx main.ts` 运行一下,得到如下结果:
```
[2025/6/22 19:05:08] 🚀 [SimpleMcpServer] 1.9.2 connected
[2025/6/22 19:05:11] 🤖 Agent wants to use these tools weather
[2025/6/22 19:05:11] 🔧 using tool weather
[2025/6/22 19:05:11] ✓ use tools success
⚙️ Agent Response 今天杭州的天气是小雨气温为24.7°C湿度为95%空气质量指数AQI为26空气质量良好。
```