enderfga-claude-code-skill
OpenClaw/Clawdbot 的 MCP(模型上下文协议)集成技能,支持连接编排 MCP 工具服务器、IndexedDB/localStorage 状态持久化及多设备会话同步。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw skills install shop:totalclaw:totalclaw~enderfga-claude-code-skillcURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~enderfga-claude-code-skill/file -o enderfga-claude-code-skill.md## 概述(中文)
OpenClaw/Clawdbot 的 MCP(模型上下文协议)集成技能,支持连接编排 MCP 工具服务器、IndexedDB/localStorage 状态持久化及多设备会话同步。
## 技能正文
# OpenClaw Claude Code 技能
## 描述
OpenClaw/Clawdbot 的 MCP(Model Context Protocol)集成。适用于:
- 连接与编排 MCP 工具服务器(文件系统、GitHub 等)
- 通过 IndexedDB/localStorage 跨会话持久化状态
- 多设备间同步会话
触发词:「MCP」、「tool server」、「sub-agent orchestration」、「session sync」、「state persistence」、「Claude Code integration」
## 安装
```bash
npm install openclaw-claude-code-skill
```
## 核心 API
### MCP 服务器管理
```typescript
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" } }
});
```
### 状态持久化
```typescript
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("State restored!");
}
```
### 会话同步
```typescript
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 store |
| `mergeSessions()` | 合并会话数组 |
| `mergeWithUpdate()` | 基于时间戳合并 |
| `mergeKeyValueStore()` | 合并键值存储 |
## 配置
创建 `mcp_config.json`:
```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"
}
}
}
```
设置自定义配置路径:
```typescript
import { setConfigPath } from "openclaw-claude-code-skill";
setConfigPath("/path/to/mcp_config.json");
```
## 要求
- Node.js 18+
- TypeScript(可选但推荐)
## 链接
- [GitHub](https://github.com/Enderfga/openclaw-claude-code-skill)
- [npm](https://www.npmjs.com/package/openclaw-claude-code-skill)
- [MCP Specification](https://spec.modelcontextprotocol.io/)