OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  claude-code-skill:针对 MCP(模型上下文协议)的深度集成工具

claude-code-skill:针对 MCP(模型上下文协议)的深度集成工具

 
  microservice ·  2026-02-18 19:55:24 · 3 次点击  · 0 条评论  

OpenClaw Claude 代码技能

描述

为 OpenClaw/Clawdbot 提供的 MCP(模型上下文协议)集成。在以下场景中使用:
- 连接并编排 MCP 工具服务器(文件系统、GitHub 等)
- 通过 IndexedDB/localStorage 实现跨会话状态持久化
- 跨多设备同步会话

触发词:"MCP"、"工具服务器"、"子代理编排"、"会话同步"、"状态持久化"、"Claude 代码集成"

安装

npm install openclaw-claude-code-skill

核心 API

MCP 服务器管理

import { 
  initializeMcpSystem, 
  addMcpServer, 
  executeMcpAction, 
  getAllTools 
} from "openclaw-claude-code-skill";

// 1. 初始化所有已配置的服务器
await initializeMcpSystem();

// 2. 添加新的 MCP 服务器
await addMcpServer("fs", {
  command: "npx",
  args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
});

// 3. 获取可用工具
const tools = await getAllTools();

// 4. 调用工具
const result = await executeMcpAction("fs", {
  method: "tools/call",
  params: { name: "read_file", arguments: { path: "/tmp/test.txt" } }
});

状态持久化

import { createPersistStore, indexedDBStorage } from "openclaw-claude-code-skill";

const useStore = createPersistStore(
  { count: 0, items: [] },
  (set, get) => ({
    increment: () => set({ count: get().count + 1 }),
    addItem: (item: string) => set({ items: [...get().items, item] })
  }),
  { name: "my-store" },
  indexedDBStorage  // 省略则使用 localStorage
);

// 检查水合状态
if (useStore.getState()._hasHydrated) {
  console.log("状态已恢复!");
}

会话同步

import { mergeSessions, mergeWithUpdate, mergeKeyValueStore } from "openclaw-claude-code-skill";

// 合并来自多个源的聊天会话
const mergedSessions = mergeSessions(localSessions, remoteSessions);

// 基于时间戳的配置合并
const mergedConfig = mergeWithUpdate(localConfig, remoteConfig);

关键功能

函数 用途
initializeMcpSystem() 从配置启动所有 MCP 服务器
addMcpServer(id, config) 动态添加新服务器
removeMcpServer(id) 移除服务器
pauseMcpServer(id) 暂停服务器
resumeMcpServer(id) 恢复已暂停的服务器
executeMcpAction(id, req) 在指定服务器上调用工具
getAllTools() 列出所有可用工具
getClientsStatus() 获取所有 MCP 客户端状态
setConfigPath(path) 设置自定义配置文件路径
createPersistStore() 创建带持久化的 Zustand 存储
mergeSessions() 合并会话数组
mergeWithUpdate() 基于时间戳合并
mergeKeyValueStore() 合并键值存储

配置

创建 mcp_config.json

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
      "status": "active"
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "your-token" },
      "status": "active"
    }
  }
}

设置自定义配置路径:

import { setConfigPath } from "openclaw-claude-code-skill";
setConfigPath("/path/to/mcp_config.json");

要求

  • Node.js 18+
  • TypeScript(可选但推荐)

链接

3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor