ClawSkills logoClawSkills

Claude Code Agent

集成 MCP 工具服务器以进行编排,使用 IndexedDB/localStorage 持久化状态,并在 OpenClaw/Clawdbot 中跨设备同步会话。

介绍

# OpenClaw Claude Code Skill

## 描述

OpenClaw/Clawdbot 的 MCP(模型上下文协议)集成。在您需要以下情况时使用: - 连接并编排 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. 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" } } }); ```

### 状态持久化

```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 // or omit for localStorage );

// Check hydration status if (useStore.getState()._hasHydrated) { console.log("State restored!"); } ```

### 会话同步

```typescript 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 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 规范](https://spec.modelcontextprotocol.io/)

更多产品