publish openmcp-sdk 0.0.6

This commit is contained in:
锦恢 2025-06-05 17:21:37 +08:00
parent e65ebe3b81
commit 0c50ebcc2c
4 changed files with 103 additions and 21 deletions

View File

@ -1,13 +1,14 @@
<div align="center">
<img src="./icons/openmcp.png" height="200px"/>
<img src="./icons/openmcp-sdk.svg" height="200px"/>
<h3>OpenMCP: 一体化 MCP Server 调试器</h3>
<h3>openmcp-sdk : 适用于 openmcp 的部署框架</h3>
<h4>闪电般将您的 agent 从实验室部署到生产环境</h4>
<a href="https://qm.qq.com/cgi-bin/qm/qr?k=C6ZUTZvfqWoI12lWe7L93cWa1hUsuVT0&jump_from=webapi&authKey=McW6B1ogTPjPDrCyGttS890tMZGQ1KB3QLuG4aqVNRaYp4vlTSgf2c6dMcNjMuBD" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: #CB81DA; color: white; border-radius: .5em; text-decoration: none;">👉 加入 OpenMCP正式级技术组</a>
<a href="https://kirigaya.cn/openmcp" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: #7D3FF8; color: white; border-radius: .5em; text-decoration: none;">📄 OpenMCP 官方文档</a>
<a href="https://discord.gg/af5cfB9a" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: rgb(84, 176, 84); color: white; border-radius: .5em; text-decoration: none;"> 加入 OpenMCP Discord频道</a>
<a href="https://qm.qq.com/cgi-bin/qm/qr?k=C6ZUTZvfqWoI12lWe7L93cWa1hUsuVT0&jump_from=webapi&authKey=McW6B1ogTPjPDrCyGttS890tMZGQ1KB3QLuG4aqVNRaYp4vlTSgf2c6dMcNjMuBD" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: #CB81DA; color: white; border-radius: .5em; text-decoration: none;">QQ 讨论群</a><a href="https://discord.gg/af5cfB9a" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: rgb(84, 176, 84); color: white; border-radius: .5em; text-decoration: none; margin-left: 5px;">Discord频道</a>
</div>
@ -18,6 +19,8 @@
npm install openmcp-sdk
```
> 目前 openmcp-sdk 只支持 esm 模式的导入
## 使用
文件名main.ts
@ -25,26 +28,29 @@ npm install openmcp-sdk
```typescript
import { TaskLoop } from 'openmcp-sdk/task-loop';
import { TaskLoopAdapter } from 'openmcp-sdk/service';
async function main() {
// 创建适配器,负责通信和 mcp 连接
const adapter = new TaskLoopAdapter();
// 连接 mcp 服务器
await adapter.connectMcpServer({
// 添加 mcp 服务器
adapter.addMcp({
connectionType: 'STDIO',
command: 'node',
args: [
'~/projects/mcp/servers/src/puppeteer/dist/index.js'
]
commandString: 'uv run mcp run main.py',
cwd: '~/projects/openmcp-tutorial/crawl4ai-mcp'
});
// 获取工具列表
const tools = await adapter.listTools();
adapter.addMcp({
connectionType: 'STDIO',
commandString: 'node index.js',
cwd: '~/projects/openmcp-tutorial/my-browser/dist'
});
// 创建事件循环驱动器
const taskLoop = new TaskLoop({ adapter });
// 获取所有工具
const tools = await taskLoop.getTools();
// 配置改次事件循环使用的大模型
taskLoop.setLlmConfig({
id: 'deepseek',
@ -58,8 +64,11 @@ async function main() {
messages: [],
settings: {
temperature: 0.7,
// 在本次对话使用所有工具
enableTools: tools,
// 系统提示词
systemPrompt: 'you are a clever bot',
// 对话上下文的轮数
contextLength: 20
}
};
@ -82,14 +91,27 @@ async function main() {
console.log('taskLoop epoch');
});
// 每一次工具调用前
taskLoop.registerOnToolCall((toolCall) => {
return toolCall;
});
// 每一次工具调用完后的结果
taskLoop.registerOnToolCalled((result) => {
return result;
});
// 开启事件循环
await taskLoop.start(storage, message);
// 打印上下文,最终的回答在 messages.at(-1) 中
console.log(storage.messages);
}
const content = storage.messages.at(-1).content;
console.log('最终回答:', content);
}
main();
```
更多使用请看官方文档https://kirigaya.cn/openmcp/sdk-tutorial/
star 我们的项目https://github.com/LSTM-Kirigaya/openmcp-client

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="600" height="674" viewBox="0 0 600 674" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient_1" gradientUnits="userSpaceOnUse" x1="300" y1="0" x2="300" y2="600">
<stop offset="0" stop-color="#A1A7F6" />
<stop offset="1" stop-color="#FFFFFF" stop-opacity="0.2" />
</linearGradient>
<linearGradient id="gradient_2" gradientUnits="userSpaceOnUse" x1="110.5" y1="0" x2="110.5" y2="221">
<stop offset="0.441" stop-color="#A8A3FF" />
<stop offset="1" stop-color="#FFFFFF" />
</linearGradient>
<linearGradient id="gradient_3" gradientUnits="userSpaceOnUse" x1="55.5" y1="0" x2="55.5" y2="111">
<stop offset="0" stop-color="#FFFFFF" />
<stop offset="1" stop-color="#A489FB" />
</linearGradient>
<linearGradient id="gradient_5" gradientUnits="userSpaceOnUse" x1="126" y1="0" x2="126" y2="647">
<stop offset="0" stop-color="#FFF2B0" />
<stop offset="0.461" stop-color="#F2B63A" />
</linearGradient>
</defs>
<g>
<g>
<g transform="translate(0 74)">
<path d="M300 0C465.708 0 600 134.292 600 300C600 300 600 300 600 300C600 465.708 465.708 600 300 600C300 600 300 600 300 600C134.292 600 0 465.708 0 300C0 300 0 300 0 300C0 134.292 134.292 0 300 0Z" fill="#5A00FF" fill-rule="evenodd" />
<path d="M300 0C465.708 0 600 134.292 600 300C600 300 600 300 600 300C600 465.708 465.708 600 300 600C300 600 300 600 300 600C134.292 600 0 465.708 0 300C0 300 0 300 0 300C0 134.292 134.292 0 300 0Z" fill="url(#gradient_1)" fill-rule="evenodd" />
</g>
<path d="M0 110.5C0 49.4725 49.4725 0 110.5 0C171.527 0 221 49.4725 221 110.5C221 171.527 171.527 221 110.5 221C49.4725 221 0 171.527 0 110.5Z" fill="url(#gradient_2)" fill-rule="evenodd" transform="translate(284 417)" />
<path d="M0 55.5C0 24.8482 24.8482 0 55.5 0C86.1518 0 111 24.8482 111 55.5C111 86.1518 86.1518 111 55.5 111C24.8482 111 0 86.1518 0 55.5Z" fill="url(#gradient_3)" fill-rule="evenodd" transform="translate(49 374)" />
<path d="M0 182.5C0 81.708 81.708 0 182.5 0C283.292 0 365 81.708 365 182.5C365 283.292 283.292 365 182.5 365C81.708 365 0 283.292 0 182.5Z" fill="url(#gradient_4)" fill-rule="evenodd" transform="translate(179 108)" />
<path d="M215.354 294.309L24.8044 647C24.8044 647 80.3091 362.484 80.3091 362.484C80.9377 359.199 79.5325 355.85 77.4987 355.85C77.4987 355.85 23.6951 355.85 23.6951 355.85C6.50011 355.85 -4.96321 325.459 2.13664 298.669C2.13664 298.669 75.28 23.6938 75.28 23.6938C79.1258 9.28799 87.5569 0 96.8384 0C96.8384 0 252 0 252 0C252 0 178.82 218.868 178.82 218.868C177.71 222.217 179.115 226.45 181.371 226.45C181.371 226.45 197.938 226.45 197.938 226.45C218.571 226.45 229.332 268.404 215.354 294.309C215.354 294.309 215.354 294.309 215.354 294.309Z" fill="url(#gradient_5)" transform="translate(193 0)" />
</g>
<rect width="432" height="432" transform="translate(84 107)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -5,9 +5,25 @@ async function main() {
// 创建适配器,负责通信和 mcp 连接
const adapter = new TaskLoopAdapter();
// 添加 mcp 服务器
adapter.addMcp({
connectionType: 'STDIO',
commandString: 'uv run mcp run main.py',
cwd: '~/projects/openmcp-tutorial/crawl4ai-mcp'
});
adapter.addMcp({
connectionType: 'STDIO',
commandString: 'node index.js',
cwd: '~/projects/openmcp-tutorial/my-browser/dist'
});
// 创建事件循环驱动器
const taskLoop = new TaskLoop({ adapter });
// 获取所有工具
const tools = await taskLoop.getTools();
// 配置改次事件循环使用的大模型
taskLoop.setLlmConfig({
id: 'deepseek',
@ -21,8 +37,11 @@ async function main() {
messages: [],
settings: {
temperature: 0.7,
enableTools: [],
// 在本次对话使用所有工具
enableTools: tools,
// 系统提示词
systemPrompt: 'you are a clever bot',
// 对话上下文的轮数
contextLength: 20
}
};
@ -45,15 +64,22 @@ async function main() {
console.log('taskLoop epoch');
});
// 每一次工具调用前
taskLoop.registerOnToolCall((toolCall) => {
return toolCall;
});
// 每一次工具调用完后的结果
taskLoop.registerOnToolCalled((result) => {
return result;
});
// 开启事件循环
await taskLoop.start(storage, message);
// 打印上下文,最终的回答在 messages.at(-1) 中
console.log(storage.messages);
const content = storage.messages.at(-1).content;
console.log(content);
console.log('最终回答:', content);
}
main();

View File

@ -1,6 +1,6 @@
{
"name": "openmcp-sdk",
"version": "0.0.5",
"version": "0.0.6",
"description": "openmcp-sdk",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"