openmcp-sdk 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  <div align="center">
2
2
 
3
- <img src="./icons/openmcp.png" height="200px"/>
3
+ <img src="./icons/openmcp-sdk.svg" height="200px"/>
4
4
 
5
- <h3>OpenMCP: 一体化 MCP Server 调试器</h3>
5
+ <h3>openmcp-sdk : 适用于 openmcp 的部署框架</h3>
6
+ <h4>闪电般将您的 agent 从实验室部署到生产环境</h4>
6
7
 
7
- <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>
8
+ <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>
8
9
 
9
10
 
10
- <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>
11
+ <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>
11
12
 
12
13
  </div>
13
14
 
@@ -18,6 +19,8 @@
18
19
  npm install openmcp-sdk
19
20
  ```
20
21
 
22
+ > 目前 openmcp-sdk 只支持 esm 模式的导入
23
+
21
24
  ## 使用
22
25
 
23
26
  文件名:main.ts
@@ -25,25 +28,22 @@ npm install openmcp-sdk
25
28
  ```typescript
26
29
  import { TaskLoop } from 'openmcp-sdk/task-loop';
27
30
  import { TaskLoopAdapter } from 'openmcp-sdk/service';
28
-
29
31
  async function main() {
30
32
  // 创建适配器,负责通信和 mcp 连接
31
33
  const adapter = new TaskLoopAdapter();
32
34
 
33
- // 连接 mcp 服务器
34
- await adapter.connectMcpServer({
35
+ // 添加 mcp 服务器
36
+ adapter.addMcp({
35
37
  connectionType: 'STDIO',
36
- command: 'node',
37
- args: [
38
- '~/projects/mcp/servers/src/puppeteer/dist/index.js'
39
- ]
38
+ commandString: 'node index.js',
39
+ cwd: '~/projects/openmcp-tutorial/my-browser/dist'
40
40
  });
41
41
 
42
- // 获取工具列表
43
- const tools = await adapter.listTools();
42
+ // 创建事件循环驱动器, verbose 数值越高,输出的日志越详细
43
+ const taskLoop = new TaskLoop({ adapter, verbose: 1 });
44
44
 
45
- // 创建事件循环驱动器
46
- const taskLoop = new TaskLoop({ adapter });
45
+ // 获取所有工具
46
+ const tools = await taskLoop.getTools();
47
47
 
48
48
  // 配置改次事件循环使用的大模型
49
49
  taskLoop.setLlmConfig({
@@ -58,8 +58,11 @@ async function main() {
58
58
  messages: [],
59
59
  settings: {
60
60
  temperature: 0.7,
61
+ // 在本次对话使用所有工具
61
62
  enableTools: tools,
63
+ // 系统提示词
62
64
  systemPrompt: 'you are a clever bot',
65
+ // 对话上下文的轮数
63
66
  contextLength: 20
64
67
  }
65
68
  };
@@ -67,29 +70,55 @@ async function main() {
67
70
  // 本次发出的问题
68
71
  const message = 'hello world';
69
72
 
70
- // 事件循环结束的句柄
71
- taskLoop.registerOnDone(() => {
72
- console.log('taskLoop done');
73
- });
74
-
75
- // 事件循环每一次 epoch 开始的句柄
76
- taskLoop.registerOnError((error) => {
77
- console.log('taskLoop error', error);
78
- });
79
-
80
- // 事件循环出现 error 时的句柄(出现 error 不一定会停止事件循环)
81
- taskLoop.registerOnEpoch(() => {
82
- console.log('taskLoop epoch');
83
- });
84
-
85
73
  // 开启事件循环
86
74
  await taskLoop.start(storage, message);
87
75
 
88
76
  // 打印上下文,最终的回答在 messages.at(-1) 中
89
- console.log(storage.messages);
90
- }
77
+ const content = storage.messages.at(-1).content;
78
+ console.log('最终回答:', content);
79
+ }
91
80
 
92
81
  main();
93
82
  ```
94
83
 
84
+ 下面是可能的输出:
85
+
86
+ ```
87
+ [6/5/2025, 8:16:15 PM] 🚀 [my-browser] 0.1.0 connected
88
+ [6/5/2025, 8:16:15 PM] task loop enters a new epoch
89
+ [6/5/2025, 8:16:23 PM] task loop finish a epoch
90
+ [6/5/2025, 8:16:23 PM] 🤖 llm wants to call these tools k_navigate
91
+ [6/5/2025, 8:16:23 PM] 🔧 calling tool k_navigate
92
+ [6/5/2025, 8:16:34 PM] × fail to call tools McpError: MCP error -32603: net::ERR_CONNECTION_RESET at https://towardsdatascience.com/tag/editors-pick/
93
+ [6/5/2025, 8:16:34 PM] task loop enters a new epoch
94
+ [6/5/2025, 8:16:40 PM] task loop finish a epoch
95
+ [6/5/2025, 8:16:40 PM] 🤖 llm wants to call these tools k_navigate
96
+ [6/5/2025, 8:16:40 PM] 🔧 calling tool k_navigate
97
+ [6/5/2025, 8:16:44 PM] ✓ call tools okey dockey success
98
+ [6/5/2025, 8:16:44 PM] task loop enters a new epoch
99
+ [6/5/2025, 8:16:57 PM] task loop finish a epoch
100
+ [6/5/2025, 8:16:57 PM] 🤖 llm wants to call these tools k_evaluate
101
+ [6/5/2025, 8:16:57 PM] 🔧 calling tool k_evaluate
102
+ [6/5/2025, 8:16:57 PM] ✓ call tools okey dockey success
103
+ [6/5/2025, 8:16:57 PM] task loop enters a new epoch
104
+ [6/5/2025, 8:17:06 PM] task loop finish a epoch
105
+ [6/5/2025, 8:17:06 PM] 🤖 llm wants to call these tools k_navigate, k_navigate
106
+ [6/5/2025, 8:17:06 PM] 🔧 calling tool k_navigate
107
+ [6/5/2025, 8:17:09 PM] ✓ call tools okey dockey success
108
+ [6/5/2025, 8:17:09 PM] 🔧 calling tool k_navigate
109
+ [6/5/2025, 8:17:12 PM] ✓ call tools okey dockey success
110
+ [6/5/2025, 8:17:12 PM] task loop enters a new epoch
111
+ [6/5/2025, 8:17:19 PM] task loop finish a epoch
112
+ [6/5/2025, 8:17:19 PM] 🤖 llm wants to call these tools k_evaluate, k_evaluate
113
+ [6/5/2025, 8:17:19 PM] 🔧 calling tool k_evaluate
114
+ [6/5/2025, 8:17:19 PM] ✓ call tools okey dockey success
115
+ [6/5/2025, 8:17:19 PM] 🔧 calling tool k_evaluate
116
+ [6/5/2025, 8:17:19 PM] ✓ call tools okey dockey success
117
+ [6/5/2025, 8:17:19 PM] task loop enters a new epoch
118
+ [6/5/2025, 8:17:45 PM] task loop finish a epoch
119
+ "以下是整理好的热门文章信息,并已翻译为简体中文:\n\n---\n\n### K1 标题 \n**《数据漂移并非真正问题:你的监控策略才是》** \n\n**简介** \n在机器学习领域,数据漂移常被视为模型性能下降的罪魁祸首,但本文作者提出了一种颠覆性的观点:数据漂移只是一个信号,真正的核心问题在于监控策略的不足。文章通过实际案例(如电商推荐系统和金融风控模型)揭示了传统统计监控的局限性,并提出了一个三层监控框架: \n1. **统计监控**:快速检测数据分布变化,但仅作为初步信号。 \n2. **上下文监控**:结合业务逻辑,判断漂移是否对关键指标产生影响。 \n3. **行为监控**:追踪模型预测的实际效果,避免“无声漂移”。 \n\n亮点在于作者强调了监控系统需要与业务目标紧密结合,而非单纯依赖技术指标。 \n\n**原文链接** \n[点击阅读原文](https://towardsdatascience.com/data-drift-is-not-the-actual-problem-your-monitoring-strategy-is/) \n\n---\n\n### K2 标题 \n**《从 Jupyter 到程序员的快速入门指南》** \n\n**简介** \n本文为数据科学家和初学者提供了一条从 Jupyter Notebook 过渡到专业编程的清晰路径。作者通过实际代码示例和工具推荐(如 VS Code、Git 和 Docker),帮助读者摆脱 Notebook 的局限性,提升代码的可维护性和可扩展性。 \n\n亮点包括: \n- 如何将 Notebook 代码模块化为可复用的 Python 脚本。 \n- 使用版本控制和容器化技术优化开发流程。 \n- 实战案例展示如何将实验性代码转化为生产级应用。 \n\n**原文链接** \n[点击阅读原文](https://towardsdatascience.com/the-journey-from-jupyter-to-programmer-a-quick-start-guide/) \n\n---\n\n如果需要进一步优化或补充其他内容,请随时告诉我!"
120
+ ```
121
+
122
+ 更多使用请看官方文档:https://kirigaya.cn/openmcp/sdk-tutorial/
123
+
95
124
  star 我们的项目:https://github.com/LSTM-Kirigaya/openmcp-client
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg width="600" height="674" viewBox="0 0 600 674" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <defs>
4
+ <linearGradient id="gradient_1" gradientUnits="userSpaceOnUse" x1="300" y1="0" x2="300" y2="600">
5
+ <stop offset="0" stop-color="#A1A7F6" />
6
+ <stop offset="1" stop-color="#FFFFFF" stop-opacity="0.2" />
7
+ </linearGradient>
8
+ <linearGradient id="gradient_2" gradientUnits="userSpaceOnUse" x1="110.5" y1="0" x2="110.5" y2="221">
9
+ <stop offset="0.441" stop-color="#A8A3FF" />
10
+ <stop offset="1" stop-color="#FFFFFF" />
11
+ </linearGradient>
12
+ <linearGradient id="gradient_3" gradientUnits="userSpaceOnUse" x1="55.5" y1="0" x2="55.5" y2="111">
13
+ <stop offset="0" stop-color="#FFFFFF" />
14
+ <stop offset="1" stop-color="#A489FB" />
15
+ </linearGradient>
16
+ <linearGradient id="gradient_5" gradientUnits="userSpaceOnUse" x1="126" y1="0" x2="126" y2="647">
17
+ <stop offset="0" stop-color="#FFF2B0" />
18
+ <stop offset="0.461" stop-color="#F2B63A" />
19
+ </linearGradient>
20
+ </defs>
21
+ <g>
22
+ <g>
23
+ <g transform="translate(0 74)">
24
+ <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" />
25
+ <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" />
26
+ </g>
27
+ <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)" />
28
+ <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)" />
29
+ <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)" />
30
+ <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)" />
31
+ </g>
32
+ <rect width="432" height="432" transform="translate(84 107)" />
33
+ </g>
34
+ </svg>
package/main.js CHANGED
@@ -5,9 +5,25 @@ async function main() {
5
5
  // 创建适配器,负责通信和 mcp 连接
6
6
  const adapter = new TaskLoopAdapter();
7
7
 
8
+ // 添加 mcp 服务器
9
+ adapter.addMcp({
10
+ connectionType: 'STDIO',
11
+ commandString: 'uv run mcp run main.py',
12
+ cwd: '~/projects/openmcp-tutorial/crawl4ai-mcp'
13
+ });
14
+
15
+ adapter.addMcp({
16
+ connectionType: 'STDIO',
17
+ commandString: 'node index.js',
18
+ cwd: '~/projects/openmcp-tutorial/my-browser/dist'
19
+ });
20
+
8
21
  // 创建事件循环驱动器
9
22
  const taskLoop = new TaskLoop({ adapter });
10
23
 
24
+ // 获取所有工具
25
+ const tools = await taskLoop.getTools();
26
+
11
27
  // 配置改次事件循环使用的大模型
12
28
  taskLoop.setLlmConfig({
13
29
  id: 'deepseek',
@@ -21,8 +37,11 @@ async function main() {
21
37
  messages: [],
22
38
  settings: {
23
39
  temperature: 0.7,
24
- enableTools: [],
40
+ // 在本次对话使用所有工具
41
+ enableTools: tools,
42
+ // 系统提示词
25
43
  systemPrompt: 'you are a clever bot',
44
+ // 对话上下文的轮数
26
45
  contextLength: 20
27
46
  }
28
47
  };
@@ -45,15 +64,22 @@ async function main() {
45
64
  console.log('taskLoop epoch');
46
65
  });
47
66
 
67
+ // 每一次工具调用前
68
+ taskLoop.registerOnToolCall((toolCall) => {
69
+ return toolCall;
70
+ });
71
+
72
+ // 每一次工具调用完后的结果
73
+ taskLoop.registerOnToolCalled((result) => {
74
+ return result;
75
+ });
76
+
48
77
  // 开启事件循环
49
78
  await taskLoop.start(storage, message);
50
79
 
51
80
  // 打印上下文,最终的回答在 messages.at(-1) 中
52
- console.log(storage.messages);
53
-
54
81
  const content = storage.messages.at(-1).content;
55
- console.log(content);
56
-
82
+ console.log('最终回答:', content);
57
83
  }
58
84
 
59
85
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmcp-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "openmcp-sdk",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -24,12 +24,13 @@
24
24
  },
25
25
  "homepage": "https://document.kirigaya.cn/blogs/openmcp/main.html",
26
26
  "dependencies": {
27
- "@modelcontextprotocol/sdk": "^1.10.2",
27
+ "@modelcontextprotocol/sdk": "^1.12.1",
28
28
  "@seald-io/nedb": "^4.1.1",
29
29
  "@vue/server-renderer": "^3.5.13",
30
30
  "axios": "^1.7.7",
31
+ "chalk": "^5.4.1",
31
32
  "bson": "^6.8.0",
32
- "openai": "^4.93.0",
33
+ "openai": "^5.0.1",
33
34
  "pako": "^2.1.0",
34
35
  "tesseract.js": "^6.0.1",
35
36
  "uuid": "^11.1.0",