diff --git a/apps/cli/package.json b/apps/cli/package.json index e672d99c..0e6e2da3 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -18,7 +18,7 @@ "publishConfig": { "access": "public" }, - "license": "MIT", + "license": "AGPL-3.0", "repository": { "type": "git", "url": "git+https://github.com/ChatLab/ChatLab.git", diff --git a/apps/cli/src/cli.ts b/apps/cli/src/cli.ts index e8b7154d..ccc50a8c 100644 --- a/apps/cli/src/cli.ts +++ b/apps/cli/src/cli.ts @@ -267,7 +267,7 @@ program program .command('mcp') - .description('Start MCP Server (stdio transport, for Claude Desktop / Cursor / AI agents)') + .description('Start MCP Server (stdio transport, for ClaudeCode / Cursor / AI agents)') .action(async () => { const { startCliMcpServer } = await import('./mcp') await startCliMcpServer() diff --git a/docs/cn/standard/chatlab-api.md b/docs/cn/standard/chatlab-api.md index 9ecb37ff..c1066c0d 100644 --- a/docs/cn/standard/chatlab-api.md +++ b/docs/cn/standard/chatlab-api.md @@ -422,7 +422,7 @@ curl "http://127.0.0.1:5200/api/v1/sessions/abc123/messages?page=1&limit=50&keyw ### 1. MCP 集成 -将 ChatLab API 接入 Claude Desktop 等 AI 工具,实现 AI 对聊天记录的直接查询和分析。 +将 ChatLab API 接入 ClaudeCode 等 AI 工具,实现 AI 对聊天记录的直接查询和分析。 ### 2. 自动化导入 diff --git a/docs/en/chatlab-api.md b/docs/en/chatlab-api.md index 66a4643c..af6315e3 100644 --- a/docs/en/chatlab-api.md +++ b/docs/en/chatlab-api.md @@ -472,7 +472,7 @@ Content-Type and request body format are the same as `POST /api/v1/import`. ### 1. MCP Integration -Connect the ChatLab API to AI tools like Claude Desktop, enabling AI to directly query and analyze chat records. +Connect the ChatLab API to AI tools like ClaudeCode, enabling AI to directly query and analyze chat records. ### 2. Automation Scripts diff --git a/docs/tw/chatlab-api.md b/docs/tw/chatlab-api.md index 86860373..e2f9e4aa 100644 --- a/docs/tw/chatlab-api.md +++ b/docs/tw/chatlab-api.md @@ -472,7 +472,7 @@ Content-Type 和请求体格式与 `POST /api/v1/import` 相同。 ### 1. MCP 集成 -将 ChatLab API 接入 Claude Desktop 等 AI 工具,实现 AI 对聊天记录的直接查询和分析。 +将 ChatLab API 接入 ClaudeCode 等 AI 工具,实现 AI 对聊天记录的直接查询和分析。 ### 2. 自动化脚本 diff --git a/packages/mcp-server/README.md b/packages/mcp-server/README.md new file mode 100644 index 00000000..ad0307ce --- /dev/null +++ b/packages/mcp-server/README.md @@ -0,0 +1,91 @@ +# chatlab-mcp + +ChatLab MCP Server exposes local ChatLab conversation data to MCP clients such as ClaudeCode, Cursor, Codex, and OpenClaw. + +It runs over stdio and provides read-only access to imported ChatLab sessions, including session discovery, keyword search, member statistics, time analysis, SQL queries, and conversation context tools. + +## Quick Start + +Use it directly with `npx`: + +```bash +npx -y chatlab-mcp +``` + +The command starts an MCP stdio server and waits for an MCP client. It does not print a help screen because stdout is reserved for MCP protocol messages. + +## MCP Client Configuration + +Add this server to your MCP client configuration: + +```json +{ + "mcpServers": { + "chatlab": { + "command": "npx", + "args": ["-y", "chatlab-mcp"] + } + } +} +``` + +If you install the package globally, you can also use: + +```json +{ + "mcpServers": { + "chatlab": { + "command": "chatlab-mcp" + } + } +} +``` + +## Data Directory + +`chatlab-mcp` reads the same local data directory as ChatLab: + +```text +~/.chatlab/ +``` + +If you configured a custom ChatLab data directory in `~/.chatlab/config.toml`, the MCP server will use that configuration automatically. + +The server is read-only. It opens existing ChatLab session databases and does not modify chat data. + +## Available Capabilities + +The server registers ChatLab tools for: + +- Listing imported chat sessions +- Reading session metadata and database schema +- Searching messages and keywords +- Loading recent messages and message context +- Listing members and member activity +- Analyzing active hours, response time, interaction pairs, and daily active users +- Running read-only SQL queries +- Producing text or JSON output for tool results + +## Requirements + +- Node.js 20 or later +- Existing ChatLab data under `~/.chatlab/` + +`better-sqlite3` is installed as a runtime dependency. On platforms without a matching prebuilt binary, npm may need local build tools for native modules. + +`@node-rs/jieba` is optional and improves Chinese word segmentation for keyword-frequency tools. If it is unavailable, core MCP functionality still works. + +## Package API + +Advanced callers can import the shared server core: + +```js +import { startMcpServer } from 'chatlab-mcp' +``` + +Most users should prefer the `npx -y chatlab-mcp` command. + +## Links + +- ChatLab: https://github.com/ChatLab/ChatLab +- Model Context Protocol: https://modelcontextprotocol.io/ diff --git a/packages/mcp-server/bin/chatlab-mcp.js b/packages/mcp-server/bin/chatlab-mcp.js new file mode 100755 index 00000000..40579bc4 --- /dev/null +++ b/packages/mcp-server/bin/chatlab-mcp.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +import('../dist/bin.mjs') diff --git a/packages/mcp-server/package.json b/packages/mcp-server/package.json index 88a43a6c..164529bf 100644 --- a/packages/mcp-server/package.json +++ b/packages/mcp-server/package.json @@ -4,9 +4,10 @@ "description": "ChatLab MCP Server — shared core for CLI and Desktop, also usable standalone via npx", "main": "./dist/index.mjs", "bin": { - "chatlab-mcp": "./dist/bin.mjs" + "chatlab-mcp": "bin/chatlab-mcp.js" }, "files": [ + "bin/", "dist/" ], "engines": { @@ -15,7 +16,7 @@ "publishConfig": { "access": "public" }, - "license": "MIT", + "license": "AGPL-3.0", "repository": { "type": "git", "url": "git+https://github.com/ChatLab/ChatLab.git", @@ -39,6 +40,9 @@ "smol-toml": "^1.3.1", "zod": "^3.24.4" }, + "optionalDependencies": { + "@node-rs/jieba": "^2.0.1" + }, "devDependencies": { "@openchatlab/config": "workspace:*", "@openchatlab/core": "workspace:*", diff --git a/packages/mcp-server/src/server.ts b/packages/mcp-server/src/server.ts index d731d0c6..6fd35968 100644 --- a/packages/mcp-server/src/server.ts +++ b/packages/mcp-server/src/server.ts @@ -2,7 +2,7 @@ * ChatLab MCP Server core * * Registers @openchatlab/tools as MCP tools and exposes session data as MCP resources. - * Communicates with AI agents (Claude Desktop, Cursor, etc.) via stdio transport. + * Communicates with AI agents (ClaudeCode, Cursor, etc.) via stdio transport. */ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d5f3588a..9b17f3a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -236,6 +236,10 @@ importers: zod: specifier: ^3.24.4 version: 3.25.76 + optionalDependencies: + '@node-rs/jieba': + specifier: ^2.0.1 + version: 2.0.1 devDependencies: '@openchatlab/config': specifier: workspace:* diff --git a/src/components/common/Settings/McpSettingsTab.vue b/src/components/common/Settings/McpSettingsTab.vue index a70d4798..350a0b19 100644 --- a/src/components/common/Settings/McpSettingsTab.vue +++ b/src/components/common/Settings/McpSettingsTab.vue @@ -11,7 +11,7 @@ type McpClient = 'claude' | 'codex' | 'openclaw' | 'other' const selectedClient = ref('claude') const clientOptions = computed(() => [ - { label: 'Claude', value: 'claude' }, + { label: 'ClaudeCode', value: 'claude' }, { label: 'Codex', value: 'codex' }, { label: 'OpenClaw', value: 'openclaw' }, { label: t('settings.mcp.clients.other'), value: 'other' }, diff --git a/src/i18n/locales/en-US/settings.json b/src/i18n/locales/en-US/settings.json index 8bbf62d3..720d6c00 100644 --- a/src/i18n/locales/en-US/settings.json +++ b/src/i18n/locales/en-US/settings.json @@ -568,7 +568,7 @@ "clientLabel": "MCP Client", "copy": "Copy", "copied": "Copied", - "claudeHint": "Add this to the claude_desktop_config.json file in Claude Desktop.", + "claudeHint": "Add this config to ClaudeCode's MCP configuration.", "codexHint": "Add this TOML config to your ~/.codex/config.toml file.", "openclawHint": "Add this config to your project's openclaw.json file.", "otherHint": "Add this JSON config to your MCP client configuration file." diff --git a/src/i18n/locales/ja-JP/settings.json b/src/i18n/locales/ja-JP/settings.json index d47ee1aa..219f48c5 100644 --- a/src/i18n/locales/ja-JP/settings.json +++ b/src/i18n/locales/ja-JP/settings.json @@ -568,7 +568,7 @@ "clientLabel": "MCP クライアント", "copy": "コピー", "copied": "コピー済み", - "claudeHint": "Claude Desktop の claude_desktop_config.json ファイルにこの設定を追加してください。", + "claudeHint": "この設定を ClaudeCode の MCP 設定に追加してください。", "codexHint": "この TOML 設定を ~/.codex/config.toml ファイルに追加してください。", "openclawHint": "この設定をプロジェクトの openclaw.json ファイルに追加してください。", "otherHint": "この JSON 設定を MCP クライアントの設定ファイルに追加してください。" diff --git a/src/i18n/locales/zh-CN/settings.json b/src/i18n/locales/zh-CN/settings.json index 004ac202..ed66c896 100644 --- a/src/i18n/locales/zh-CN/settings.json +++ b/src/i18n/locales/zh-CN/settings.json @@ -568,7 +568,7 @@ "clientLabel": "MCP 客户端", "copy": "复制", "copied": "已复制", - "claudeHint": "将此配置添加到 Claude Desktop 的 claude_desktop_config.json 文件中。", + "claudeHint": "将此配置添加到 ClaudeCode 的 MCP 配置中。", "codexHint": "将此 TOML 配置添加到 ~/.codex/config.toml 文件中。", "openclawHint": "将此配置添加到项目的 openclaw.json 文件中。", "otherHint": "将此 JSON 配置添加到你的 MCP 客户端配置文件中。" diff --git a/src/i18n/locales/zh-TW/settings.json b/src/i18n/locales/zh-TW/settings.json index c236043c..3238161d 100644 --- a/src/i18n/locales/zh-TW/settings.json +++ b/src/i18n/locales/zh-TW/settings.json @@ -568,7 +568,7 @@ "clientLabel": "MCP 用戶端", "copy": "複製", "copied": "已複製", - "claudeHint": "將此設定新增至 Claude Desktop 的 claude_desktop_config.json 檔案中。", + "claudeHint": "將此設定新增至 ClaudeCode 的 MCP 設定中。", "codexHint": "將此 TOML 設定新增至 ~/.codex/config.toml 檔案中。", "openclawHint": "將此設定新增至專案的 openclaw.json 檔案中。", "otherHint": "將此 JSON 設定新增到你的 MCP 用戶端設定檔中。" diff --git a/tsconfig.web.json b/tsconfig.web.json index dabdecc9..51dc0bc0 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -1,6 +1,7 @@ { "extends": "@electron-toolkit/tsconfig/tsconfig.web.json", "include": ["src/env.d.ts", "src/**/*", "apps/desktop/preload/**/*.d.ts", "packages/**/*"], + "exclude": ["**/dist/**", "packages/*/bin/**"], "compilerOptions": { "baseUrl": ".", "target": "ESNext",