Claude Code Agent
2026-03-30
新闻来源:网淘吧
围观:11
电脑广告
手机广告
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. Initialize all configured servers
await initializeMcpSystem();
// 2. Add a new MCP server
await addMcpServer("fs", {
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
});
// 3. Get available tools
const tools = await getAllTools();
// 4. Call a tool
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 // or omit for localStorage
);
// Check hydration status
if (useStore.getState()._hasHydrated) {
console.log("State restored!");
}
会话同步
import { mergeSessions, mergeWithUpdate, mergeKeyValueStore } from "openclaw-claude-code-skill";
// Merge chat sessions from multiple sources
const mergedSessions = mergeSessions(localSessions, remoteSessions);
// Merge configs with timestamp-based resolution
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(可选但推荐)
链接
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~