@gulibs/safe-coder 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +682 -902
- package/dist/cache/cache-manager.d.ts +71 -0
- package/dist/cache/cache-manager.d.ts.map +1 -0
- package/dist/cache/cache-manager.js +244 -0
- package/dist/cache/cache-manager.js.map +1 -0
- package/dist/executor/cli-executor.d.ts +106 -0
- package/dist/executor/cli-executor.d.ts.map +1 -0
- package/dist/executor/cli-executor.js +133 -0
- package/dist/executor/cli-executor.js.map +1 -0
- package/dist/executor/dependency-checker.d.ts +23 -0
- package/dist/executor/dependency-checker.d.ts.map +1 -0
- package/dist/executor/dependency-checker.js +62 -0
- package/dist/executor/dependency-checker.js.map +1 -0
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/processor/content-processor.d.ts +76 -0
- package/dist/processor/content-processor.d.ts.map +1 -0
- package/dist/processor/content-processor.js +182 -0
- package/dist/processor/content-processor.js.map +1 -0
- package/dist/processor/guide-generator.d.ts +68 -0
- package/dist/processor/guide-generator.d.ts.map +1 -0
- package/dist/processor/guide-generator.js +189 -0
- package/dist/processor/guide-generator.js.map +1 -0
- package/dist/server/safe-coder-mcp.d.ts +18 -0
- package/dist/server/safe-coder-mcp.d.ts.map +1 -0
- package/dist/server/safe-coder-mcp.js +164 -0
- package/dist/server/safe-coder-mcp.js.map +1 -0
- package/dist/tools/cache-tools.d.ts +42 -0
- package/dist/tools/cache-tools.d.ts.map +1 -0
- package/dist/tools/cache-tools.js +70 -0
- package/dist/tools/cache-tools.js.map +1 -0
- package/dist/tools/crawl-documentation.d.ts +57 -0
- package/dist/tools/crawl-documentation.d.ts.map +1 -0
- package/dist/tools/crawl-documentation.js +96 -0
- package/dist/tools/crawl-documentation.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/save-skill.d.ts +49 -0
- package/dist/tools/save-skill.d.ts.map +1 -0
- package/dist/tools/save-skill.js +207 -0
- package/dist/tools/save-skill.js.map +1 -0
- package/package.json +18 -22
- package/dist/documentation/browser-doc-browser.d.ts +0 -41
- package/dist/documentation/browser-doc-browser.d.ts.map +0 -1
- package/dist/documentation/browser-doc-browser.js +0 -357
- package/dist/documentation/browser-doc-browser.js.map +0 -1
- package/dist/documentation/cache.d.ts +0 -13
- package/dist/documentation/cache.d.ts.map +0 -1
- package/dist/documentation/cache.js +0 -48
- package/dist/documentation/cache.js.map +0 -1
- package/dist/documentation/checkpoint-manager.d.ts +0 -38
- package/dist/documentation/checkpoint-manager.d.ts.map +0 -1
- package/dist/documentation/checkpoint-manager.js +0 -101
- package/dist/documentation/checkpoint-manager.js.map +0 -1
- package/dist/documentation/doc-crawler.d.ts +0 -185
- package/dist/documentation/doc-crawler.d.ts.map +0 -1
- package/dist/documentation/doc-crawler.js +0 -1162
- package/dist/documentation/doc-crawler.js.map +0 -1
- package/dist/documentation/github-client.d.ts +0 -13
- package/dist/documentation/github-client.d.ts.map +0 -1
- package/dist/documentation/github-client.js +0 -90
- package/dist/documentation/github-client.js.map +0 -1
- package/dist/documentation/http-fetcher.d.ts +0 -8
- package/dist/documentation/http-fetcher.d.ts.map +0 -1
- package/dist/documentation/http-fetcher.js +0 -31
- package/dist/documentation/http-fetcher.js.map +0 -1
- package/dist/documentation/index.d.ts +0 -16
- package/dist/documentation/index.d.ts.map +0 -1
- package/dist/documentation/index.js +0 -159
- package/dist/documentation/index.js.map +0 -1
- package/dist/documentation/llms-txt/detector.d.ts +0 -31
- package/dist/documentation/llms-txt/detector.d.ts.map +0 -1
- package/dist/documentation/llms-txt/detector.js +0 -77
- package/dist/documentation/llms-txt/detector.js.map +0 -1
- package/dist/documentation/llms-txt/downloader.d.ts +0 -30
- package/dist/documentation/llms-txt/downloader.d.ts.map +0 -1
- package/dist/documentation/llms-txt/downloader.js +0 -84
- package/dist/documentation/llms-txt/downloader.js.map +0 -1
- package/dist/documentation/llms-txt/index.d.ts +0 -4
- package/dist/documentation/llms-txt/index.d.ts.map +0 -1
- package/dist/documentation/llms-txt/index.js +0 -4
- package/dist/documentation/llms-txt/index.js.map +0 -1
- package/dist/documentation/llms-txt/parser.d.ts +0 -43
- package/dist/documentation/llms-txt/parser.d.ts.map +0 -1
- package/dist/documentation/llms-txt/parser.js +0 -177
- package/dist/documentation/llms-txt/parser.js.map +0 -1
- package/dist/documentation/normalizer.d.ts +0 -6
- package/dist/documentation/normalizer.d.ts.map +0 -1
- package/dist/documentation/normalizer.js +0 -38
- package/dist/documentation/normalizer.js.map +0 -1
- package/dist/documentation/npm-client.d.ts +0 -19
- package/dist/documentation/npm-client.d.ts.map +0 -1
- package/dist/documentation/npm-client.js +0 -182
- package/dist/documentation/npm-client.js.map +0 -1
- package/dist/documentation/skill-generator.d.ts +0 -108
- package/dist/documentation/skill-generator.d.ts.map +0 -1
- package/dist/documentation/skill-generator.js +0 -642
- package/dist/documentation/skill-generator.js.map +0 -1
- package/dist/documentation/web-doc-browser.d.ts +0 -67
- package/dist/documentation/web-doc-browser.d.ts.map +0 -1
- package/dist/documentation/web-doc-browser.js +0 -555
- package/dist/documentation/web-doc-browser.js.map +0 -1
- package/dist/errors/api-validator.d.ts +0 -9
- package/dist/errors/api-validator.d.ts.map +0 -1
- package/dist/errors/api-validator.js +0 -57
- package/dist/errors/api-validator.js.map +0 -1
- package/dist/errors/contextual-analysis.d.ts +0 -14
- package/dist/errors/contextual-analysis.d.ts.map +0 -1
- package/dist/errors/contextual-analysis.js +0 -173
- package/dist/errors/contextual-analysis.js.map +0 -1
- package/dist/errors/cross-file-analyzer.d.ts +0 -16
- package/dist/errors/cross-file-analyzer.d.ts.map +0 -1
- package/dist/errors/cross-file-analyzer.js +0 -172
- package/dist/errors/cross-file-analyzer.js.map +0 -1
- package/dist/errors/eslint-integration.d.ts +0 -9
- package/dist/errors/eslint-integration.d.ts.map +0 -1
- package/dist/errors/eslint-integration.js +0 -131
- package/dist/errors/eslint-integration.js.map +0 -1
- package/dist/errors/framework-detector.d.ts +0 -10
- package/dist/errors/framework-detector.d.ts.map +0 -1
- package/dist/errors/framework-detector.js +0 -126
- package/dist/errors/framework-detector.js.map +0 -1
- package/dist/errors/index.d.ts +0 -18
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -134
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/pattern-matcher.d.ts +0 -25
- package/dist/errors/pattern-matcher.d.ts.map +0 -1
- package/dist/errors/pattern-matcher.js +0 -44
- package/dist/errors/pattern-matcher.js.map +0 -1
- package/dist/errors/patterns.d.ts +0 -11
- package/dist/errors/patterns.d.ts.map +0 -1
- package/dist/errors/patterns.js +0 -351
- package/dist/errors/patterns.js.map +0 -1
- package/dist/errors/performance-detector.d.ts +0 -11
- package/dist/errors/performance-detector.d.ts.map +0 -1
- package/dist/errors/performance-detector.js +0 -119
- package/dist/errors/performance-detector.js.map +0 -1
- package/dist/errors/runtime-detector.d.ts +0 -7
- package/dist/errors/runtime-detector.d.ts.map +0 -1
- package/dist/errors/runtime-detector.js +0 -86
- package/dist/errors/runtime-detector.js.map +0 -1
- package/dist/errors/security-detector.d.ts +0 -6
- package/dist/errors/security-detector.d.ts.map +0 -1
- package/dist/errors/security-detector.js +0 -75
- package/dist/errors/security-detector.js.map +0 -1
- package/dist/errors/typescript-integration.d.ts +0 -6
- package/dist/errors/typescript-integration.d.ts.map +0 -1
- package/dist/errors/typescript-integration.js +0 -46
- package/dist/errors/typescript-integration.js.map +0 -1
- package/dist/server/mcp-server.d.ts +0 -14
- package/dist/server/mcp-server.d.ts.map +0 -1
- package/dist/server/mcp-server.js +0 -776
- package/dist/server/mcp-server.js.map +0 -1
- package/dist/types/documentation.d.ts +0 -26
- package/dist/types/documentation.d.ts.map +0 -1
- package/dist/types/documentation.js +0 -2
- package/dist/types/documentation.js.map +0 -1
- package/dist/utils/config.d.ts +0 -21
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -34
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/http-client.d.ts +0 -17
- package/dist/utils/http-client.d.ts.map +0 -1
- package/dist/utils/http-client.js +0 -62
- package/dist/utils/http-client.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -36
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -128
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/rate-limiter.d.ts +0 -9
- package/dist/utils/rate-limiter.d.ts.map +0 -1
- package/dist/utils/rate-limiter.js +0 -26
- package/dist/utils/rate-limiter.js.map +0 -1
- package/dist/validation/auto-fix.d.ts +0 -15
- package/dist/validation/auto-fix.d.ts.map +0 -1
- package/dist/validation/auto-fix.js +0 -49
- package/dist/validation/auto-fix.js.map +0 -1
- package/dist/validation/index.d.ts +0 -21
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js +0 -45
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/resolution-db.d.ts +0 -15
- package/dist/validation/resolution-db.d.ts.map +0 -1
- package/dist/validation/resolution-db.js +0 -62
- package/dist/validation/resolution-db.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,1141 +1,921 @@
|
|
|
1
|
-
# Safe Coder MCP
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
# Safe Coder MCP Server
|
|
2
|
+
|
|
3
|
+
> **Version:** 0.0.27
|
|
4
|
+
> **Status:** Development Preview
|
|
5
|
+
> **Architecture:** MCP Server (orchestration layer)
|
|
6
|
+
|
|
7
|
+
MCP Server for documentation crawling orchestration. Coordinates with `@gulibs/safe-coder-cli` to crawl documentation websites, process content, and provide structured guidance for creating Cursor AI SKILL files.
|
|
8
|
+
|
|
9
|
+
## ⚠️ Current Version Status
|
|
10
|
+
|
|
11
|
+
**Version 0.0.27 - Development Preview:**
|
|
12
|
+
- ✅ Architecture refactored: Clean separation between MCP Server and CLI
|
|
13
|
+
- ✅ Core functionality: Crawling orchestration, content processing, SKILL guidance
|
|
14
|
+
- ✅ **NEW: `save_skill` tool** - Automatic SKILL file creation with complete directory structure
|
|
15
|
+
- ⚠️ **Not published to npm** - requires manual installation from source
|
|
16
|
+
|
|
17
|
+
## What This Package Does
|
|
18
|
+
|
|
19
|
+
**Safe Coder MCP Server is an orchestration layer** that:
|
|
20
|
+
|
|
21
|
+
1. ✅ **Checks dependencies** - Verifies `safe-coder-cli` is installed
|
|
22
|
+
2. ✅ **Spawns CLI process** - Executes crawling via child process
|
|
23
|
+
3. ✅ **Parses CLI output** - Reads JSON from stdout, progress from stderr
|
|
24
|
+
4. ✅ **Processes content** - Extracts key points, code patterns, topics
|
|
25
|
+
5. ✅ **Generates guidance** - Creates structured SKILL generation recommendations
|
|
26
|
+
6. ✅ **Manages cache** - Stores results for 7 days in `~/.safe-coder/cache/`
|
|
27
|
+
7. ✅ **Saves SKILL files** - Creates complete directory structure (SKILL.md + references/)
|
|
28
|
+
8. ✅ **Exposes MCP tools** - Provides 4 tools to Cursor AI
|
|
29
|
+
|
|
30
|
+
**This package does NOT:**
|
|
31
|
+
- ❌ Perform web crawling (delegated to CLI)
|
|
32
|
+
- ❌ Run browser automation (CLI responsibility)
|
|
33
|
+
|
|
34
|
+
## Architecture
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
38
|
+
│ Cursor / Claude Desktop (MCP Client) │
|
|
39
|
+
│ • Calls MCP tools │
|
|
40
|
+
│ • Receives data + guidance │
|
|
41
|
+
│ • Creates SKILL.md based on guidance │
|
|
42
|
+
└────────────────┬────────────────────────────────────────────┘
|
|
43
|
+
│ MCP Protocol (JSON-RPC over stdio)
|
|
44
|
+
┌────────────────▼────────────────────────────────────────────┐
|
|
45
|
+
│ @gulibs/safe-coder (MCP Server) - THIS PACKAGE │
|
|
46
|
+
│ ┌──────────────────────────────────────────────────────┐ │
|
|
47
|
+
│ │ 1. Dependency Check (which safe-coder-cli) │ │
|
|
48
|
+
│ │ 2. CLI Executor (spawn child process) │ │
|
|
49
|
+
│ │ 3. Parse JSON Output (stdout → data) │ │
|
|
50
|
+
│ │ 4. Content Processor (extract key info) │ │
|
|
51
|
+
│ │ 5. Guide Generator (create SKILL guidance) │ │
|
|
52
|
+
│ │ 6. Cache Manager (store/retrieve results) │ │
|
|
53
|
+
│ └──────────────────────────────────────────────────────┘ │
|
|
54
|
+
│ │
|
|
55
|
+
│ Tools: crawl_documentation, save_skill, │
|
|
56
|
+
│ list_cached_documentation, clear_cache │
|
|
57
|
+
└────────────────┬────────────────────────────────────────────┘
|
|
58
|
+
│ spawn('safe-coder-cli', ['crawl', url, ...])
|
|
59
|
+
│ stdin: commands, stdout: JSON, stderr: progress
|
|
60
|
+
┌────────────────▼────────────────────────────────────────────┐
|
|
61
|
+
│ @gulibs/safe-coder-cli (Standalone CLI Tool) │
|
|
62
|
+
│ • HTTP + Browser-based web crawling │
|
|
63
|
+
│ • Content extraction and markup conversion │
|
|
64
|
+
│ • JSON output to stdout (results) │
|
|
65
|
+
│ • JSON output to stderr (progress messages) │
|
|
66
|
+
└────────────────┬────────────────────────────────────────────┘
|
|
67
|
+
│ HTTP requests / Puppeteer / Playwright
|
|
68
|
+
┌────────────────▼────────────────────────────────────────────┐
|
|
69
|
+
│ Documentation Website (e.g., react.dev, vuejs.org) │
|
|
70
|
+
└─────────────────────────────────────────────────────────────┘
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
### Step 1: Prerequisites
|
|
76
|
+
|
|
77
|
+
**Node.js 18+**
|
|
78
|
+
```bash
|
|
79
|
+
node --version # Must be v18.0.0 or higher
|
|
80
|
+
```
|
|
68
81
|
|
|
69
|
-
###
|
|
82
|
+
### Step 2: Install CLI Tool (Required)
|
|
70
83
|
|
|
71
|
-
|
|
84
|
+
⚠️ **The MCP server requires `@gulibs/safe-coder-cli` to be globally installed.**
|
|
72
85
|
|
|
86
|
+
**Option A: From npm (after publication)**
|
|
73
87
|
```bash
|
|
74
|
-
|
|
75
|
-
npm install -g @gulibs/safe-coder
|
|
76
|
-
|
|
77
|
-
# 或者本地安装到项目
|
|
78
|
-
npm install @gulibs/safe-coder
|
|
88
|
+
npm install -g @gulibs/safe-coder-cli
|
|
79
89
|
```
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
91
|
+
**Option B: From source (current development setup)**
|
|
83
92
|
```bash
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
cd safe-coder
|
|
87
|
-
|
|
88
|
-
# 安装依赖
|
|
93
|
+
# Clone and build CLI
|
|
94
|
+
cd /path/to/safe-coder-cli
|
|
89
95
|
npm install
|
|
90
|
-
|
|
91
|
-
# 构建项目
|
|
92
96
|
npm run build
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
## 配置
|
|
96
|
-
|
|
97
|
-
设置环境变量(可选):
|
|
98
|
-
|
|
99
|
-
- `CACHE_TTL_MINUTES` - 文档缓存 TTL(分钟),默认:60
|
|
100
|
-
- `GITHUB_TOKEN` - GitHub API token(用于访问私有仓库,可选)
|
|
101
|
-
- `ENABLE_AUTO_FIX` - 启用自动修复,默认:true
|
|
102
|
-
- `RATE_LIMIT_REQUESTS` - 每个窗口的最大请求数,默认:100
|
|
103
|
-
- `RATE_LIMIT_WINDOW_MS` - 速率限制窗口(毫秒),默认:60000
|
|
104
|
-
- `LOG_LEVEL` - 日志级别:`DEBUG`、`INFO`、`WARN`、`ERROR`,默认:`INFO`
|
|
105
|
-
- `LOG_COLORS` - 启用彩色日志输出,默认:`true`(设置为 `false` 禁用)
|
|
106
|
-
|
|
107
|
-
### 代理配置(适用于国内网络环境)
|
|
108
|
-
|
|
109
|
-
如果无法直接访问 npm registry 或 GitHub API,可以配置代理:
|
|
110
|
-
|
|
111
|
-
- `HTTP_PROXY` 或 `http_proxy` - HTTP 代理地址,例如:`http://127.0.0.1:7890`
|
|
112
|
-
- `HTTPS_PROXY` 或 `https_proxy` - HTTPS 代理地址,例如:`http://127.0.0.1:7890`
|
|
113
|
-
- `NO_PROXY` 或 `no_proxy` - 不使用代理的地址列表(逗号分隔),例如:`localhost,127.0.0.1`
|
|
114
|
-
|
|
115
|
-
**示例配置:**
|
|
97
|
+
npm link # Makes 'safe-coder-cli' available globally
|
|
116
98
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
export HTTPS_PROXY=http://127.0.0.1:7890
|
|
121
|
-
|
|
122
|
-
# 或者使用 SOCKS5 代理(如果代理支持)
|
|
123
|
-
export HTTP_PROXY=socks5://127.0.0.1:1080
|
|
124
|
-
export HTTPS_PROXY=socks5://127.0.0.1:1080
|
|
125
|
-
|
|
126
|
-
# 排除本地地址
|
|
127
|
-
export NO_PROXY=localhost,127.0.0.1,*.local
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**在 Cursor 配置文件中设置:**
|
|
131
|
-
|
|
132
|
-
```json
|
|
133
|
-
{
|
|
134
|
-
"mcpServers": {
|
|
135
|
-
"safe-coder": {
|
|
136
|
-
"command": "npx",
|
|
137
|
-
"args": ["-y", "@gulibs/safe-coder"],
|
|
138
|
-
"env": {
|
|
139
|
-
"HTTP_PROXY": "http://127.0.0.1:7890",
|
|
140
|
-
"HTTPS_PROXY": "http://127.0.0.1:7890",
|
|
141
|
-
"NO_PROXY": "localhost,127.0.0.1"
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
99
|
+
# Verify
|
|
100
|
+
safe-coder-cli --version
|
|
101
|
+
# Output: 0.0.1
|
|
146
102
|
```
|
|
147
103
|
|
|
148
|
-
|
|
104
|
+
### Step 3: Install MCP Server
|
|
149
105
|
|
|
150
|
-
|
|
106
|
+
⚠️ **Not yet published to npm - use local installation:**
|
|
151
107
|
|
|
108
|
+
**Development Installation:**
|
|
152
109
|
```bash
|
|
153
|
-
|
|
154
|
-
npm
|
|
155
|
-
|
|
156
|
-
# 生产模式(需要先构建)
|
|
110
|
+
cd /path/to/safe-coder
|
|
111
|
+
npm install
|
|
157
112
|
npm run build
|
|
158
|
-
npm start
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
服务器通过 stdio 运行,使用 MCP 协议进行通信。
|
|
162
|
-
|
|
163
|
-
### 2. 监控服务状态
|
|
164
|
-
|
|
165
|
-
#### 查看日志
|
|
166
|
-
|
|
167
|
-
所有日志输出到 `stderr`(标准错误输出),包括:
|
|
168
|
-
- 服务器启动信息
|
|
169
|
-
- 工具调用记录(请求 ID、参数、执行时间)
|
|
170
|
-
- 错误和警告信息
|
|
171
|
-
|
|
172
|
-
**日志格式示例:**
|
|
173
|
-
|
|
174
|
-
```
|
|
175
|
-
[2024-01-01T12:00:00.000Z] [INFO] Safe Coder MCP server started {"version":"1.0.0","pid":12345}
|
|
176
|
-
[2024-01-01T12:00:00.100Z] [INFO] MCP server connected to transport
|
|
177
|
-
[2024-01-01T12:00:00.200Z] [INFO] Tool invoked: get_documentation {"requestId":"req-1234567890-1","tool":"get_documentation","params":{"packageName":"react"}}
|
|
178
|
-
[2024-01-01T12:00:00.500Z] [INFO] Tool completed: get_documentation {"requestId":"req-1234567890-1","tool":"get_documentation","duration":"500ms","success":true}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
**日志级别(通过 `LOG_LEVEL` 环境变量设置):**
|
|
182
|
-
- `DEBUG` - 详细调试信息
|
|
183
|
-
- `INFO` - 一般信息(工具调用、完成)默认
|
|
184
|
-
- `WARN` - 警告信息
|
|
185
|
-
- `ERROR` - 错误信息
|
|
186
|
-
|
|
187
|
-
#### 使用 get_status 工具
|
|
188
113
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
```json
|
|
192
|
-
{
|
|
193
|
-
"status": "running",
|
|
194
|
-
"uptime": 3600,
|
|
195
|
-
"version": "1.0.0",
|
|
196
|
-
"tools": ["get_documentation", "detect_errors", "validate_code", "resolve_error", "get_status"],
|
|
197
|
-
"cacheSize": 10,
|
|
198
|
-
"pid": 12345
|
|
199
|
-
}
|
|
114
|
+
# Optional: Link for global access
|
|
115
|
+
npm link
|
|
200
116
|
```
|
|
201
117
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
1. **打开 Cursor 的开发者工具**:
|
|
205
|
-
- macOS: `Cmd + Shift + P` → "Developer: Toggle Developer Tools"
|
|
206
|
-
- Windows/Linux: `Ctrl + Shift + P` → "Developer: Toggle Developer Tools"
|
|
118
|
+
### Step 4: Configure Cursor
|
|
207
119
|
|
|
208
|
-
|
|
209
|
-
- 在开发者工具中切换到 "Console" 标签
|
|
210
|
-
- MCP 服务器的日志会显示在这里
|
|
120
|
+
**Edit Cursor MCP configuration:**
|
|
211
121
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
在 Cursor 配置中添加:
|
|
122
|
+
File location: `~/Library/Application Support/Cursor/User/globalStorage/mcp.json`
|
|
215
123
|
|
|
216
124
|
```json
|
|
217
125
|
{
|
|
218
126
|
"mcpServers": {
|
|
219
127
|
"safe-coder": {
|
|
220
|
-
"command": "
|
|
221
|
-
"args": ["
|
|
222
|
-
"env": {
|
|
223
|
-
"LOG_LEVEL": "DEBUG",
|
|
224
|
-
"LOG_COLORS": "true"
|
|
225
|
-
}
|
|
128
|
+
"command": "node",
|
|
129
|
+
"args": ["/absolute/path/to/safe-coder/dist/index.js"]
|
|
226
130
|
}
|
|
227
131
|
}
|
|
228
132
|
}
|
|
229
133
|
```
|
|
230
134
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
> **⚠️ 重要提示**:如果包还没有发布到 npm,请使用"本地开发配置"方式。
|
|
234
|
-
|
|
235
|
-
#### 步骤 1:找到 Cursor 配置文件
|
|
236
|
-
|
|
237
|
-
Cursor 的 MCP 配置文件位置:
|
|
238
|
-
- **macOS**: `~/Library/Application Support/Cursor/User/globalStorage/mcp.json`
|
|
239
|
-
- **Windows**: `%APPDATA%\Cursor\User\globalStorage\mcp.json`
|
|
240
|
-
- **Linux**: `~/.config/Cursor/User/globalStorage/mcp.json`
|
|
241
|
-
|
|
242
|
-
或者通过 Cursor 设置界面:
|
|
243
|
-
1. 打开 Cursor 设置(`Cmd/Ctrl + ,`)
|
|
244
|
-
2. 搜索 "MCP" 或 "Model Context Protocol"
|
|
245
|
-
3. 找到 MCP 服务器配置
|
|
246
|
-
|
|
247
|
-
#### 步骤 2:添加配置
|
|
248
|
-
|
|
249
|
-
根据你的安装方式选择对应的配置:
|
|
250
|
-
|
|
251
|
-
##### 方式 A:本地开发配置(推荐,如果包未发布)
|
|
252
|
-
|
|
253
|
-
使用项目的绝对路径:
|
|
254
|
-
|
|
135
|
+
**Replace `/absolute/path/to/safe-coder`** with actual path, e.g.:
|
|
255
136
|
```json
|
|
256
137
|
{
|
|
257
138
|
"mcpServers": {
|
|
258
139
|
"safe-coder": {
|
|
259
140
|
"command": "node",
|
|
260
|
-
"args": ["/Users/
|
|
261
|
-
"env": {
|
|
262
|
-
"CACHE_TTL_MINUTES": "60",
|
|
263
|
-
"GITHUB_TOKEN": "your_token_here"
|
|
264
|
-
}
|
|
141
|
+
"args": ["/Users/yourname/projects/mcp/safe-coder/dist/index.js"]
|
|
265
142
|
}
|
|
266
143
|
}
|
|
267
144
|
}
|
|
268
145
|
```
|
|
269
146
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
```bash
|
|
273
|
-
# 在项目目录下运行
|
|
274
|
-
pwd
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
##### 方式 B:通过 npm 安装(需要先发布到 npm)
|
|
278
|
-
|
|
279
|
-
如果包已发布到 npm,可以使用 npx:
|
|
280
|
-
|
|
147
|
+
**Future (after npm publication):**
|
|
281
148
|
```json
|
|
282
149
|
{
|
|
283
150
|
"mcpServers": {
|
|
284
151
|
"safe-coder": {
|
|
285
152
|
"command": "npx",
|
|
286
|
-
"args": ["-y", "@gulibs/safe-coder"]
|
|
287
|
-
"env": {
|
|
288
|
-
"CACHE_TTL_MINUTES": "60",
|
|
289
|
-
"GITHUB_TOKEN": "your_token_here"
|
|
290
|
-
}
|
|
153
|
+
"args": ["-y", "@gulibs/safe-coder@latest"]
|
|
291
154
|
}
|
|
292
155
|
}
|
|
293
156
|
}
|
|
294
157
|
```
|
|
295
158
|
|
|
296
|
-
|
|
159
|
+
### Step 5: Restart Cursor
|
|
297
160
|
|
|
298
|
-
|
|
299
|
-
# 全局安装
|
|
300
|
-
npm install -g @gulibs/safe-coder
|
|
161
|
+
Restart Cursor to load the MCP server.
|
|
301
162
|
|
|
302
|
-
|
|
303
|
-
npm root -g
|
|
304
|
-
```
|
|
163
|
+
## Usage: SKILL File Generation Workflow
|
|
305
164
|
|
|
306
|
-
|
|
165
|
+
### ⚠️ Important: How SKILL Files Are Created
|
|
307
166
|
|
|
308
|
-
|
|
309
|
-
{
|
|
310
|
-
"mcpServers": {
|
|
311
|
-
"safe-coder": {
|
|
312
|
-
"command": "node",
|
|
313
|
-
"args": ["<global-node-modules-path>/@gulibs/safe-coder/dist/index.js"],
|
|
314
|
-
"env": {
|
|
315
|
-
"CACHE_TTL_MINUTES": "60",
|
|
316
|
-
"GITHUB_TOKEN": "your_token_here"
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
```
|
|
167
|
+
**The MCP server does NOT create `SKILL.md` files directly.** Here's the actual workflow:
|
|
322
168
|
|
|
323
|
-
|
|
169
|
+
#### What the MCP Server Returns
|
|
324
170
|
|
|
325
|
-
|
|
171
|
+
1. **Crawled content** - Full text from all pages
|
|
172
|
+
2. **Processed data** - Key points, code patterns, categories, topics
|
|
173
|
+
3. **SKILL generation guide** - Structured recommendations for SKILL.md
|
|
174
|
+
4. **Quality assessment** - Scores for content quality, completeness
|
|
326
175
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
176
|
+
#### Where SKILL Files Are Saved
|
|
177
|
+
|
|
178
|
+
**You must explicitly tell Cursor AI where to save the file:**
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
User: "Crawl React docs and create a SKILL file"
|
|
182
|
+
↓
|
|
183
|
+
Cursor AI: [Calls crawl_documentation, receives data + guidance]
|
|
184
|
+
↓
|
|
185
|
+
User: "Save it to ~/.claude/skills/react-docs/SKILL.md"
|
|
186
|
+
↓
|
|
187
|
+
Cursor AI: [Creates file at specified location]
|
|
340
188
|
```
|
|
341
189
|
|
|
342
|
-
|
|
190
|
+
**Recommended location pattern:**
|
|
191
|
+
```
|
|
192
|
+
~/.claude/skills/
|
|
193
|
+
├── react-docs/SKILL.md # React documentation
|
|
194
|
+
├── vue-guide/SKILL.md # Vue.js guide
|
|
195
|
+
├── typescript-handbook/SKILL.md # TypeScript handbook
|
|
196
|
+
└── [tech-name]/SKILL.md # Generic pattern
|
|
197
|
+
```
|
|
343
198
|
|
|
344
|
-
|
|
199
|
+
**Naming conventions:**
|
|
200
|
+
- Directory: `[technology-name]` (lowercase, hyphens)
|
|
201
|
+
- File: Always `SKILL.md` (Cursor convention)
|
|
202
|
+
- Examples: `react-docs`, `vue-guide`, `next-js-docs`
|
|
345
203
|
|
|
346
|
-
|
|
347
|
-
# macOS/Linux
|
|
348
|
-
pwd
|
|
204
|
+
### Complete Example Workflow
|
|
349
205
|
|
|
350
|
-
|
|
351
|
-
|
|
206
|
+
**1. Request crawl:**
|
|
207
|
+
```
|
|
208
|
+
User: "Crawl the React documentation at https://react.dev and create a SKILL file"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**2. Cursor AI calls MCP tool:**
|
|
212
|
+
```typescript
|
|
213
|
+
crawl_documentation({
|
|
214
|
+
url: "https://react.dev",
|
|
215
|
+
maxPages: 200, // Default
|
|
216
|
+
depth: 3 // Default
|
|
217
|
+
})
|
|
352
218
|
```
|
|
353
219
|
|
|
354
|
-
|
|
220
|
+
**3. MCP Server process:**
|
|
221
|
+
```
|
|
222
|
+
[Dependency Check] ✓ safe-coder-cli found at /usr/local/bin/safe-coder-cli
|
|
223
|
+
[Spawning CLI] safe-coder-cli crawl https://react.dev --output-format json ...
|
|
224
|
+
[Progress] Crawling... 10/50 pages
|
|
225
|
+
[Progress] Crawling... 25/50 pages
|
|
226
|
+
[Progress] Crawling... 50/50 pages complete
|
|
227
|
+
[Processing] Analyzing content...
|
|
228
|
+
[Processing] Generating SKILL guidance...
|
|
229
|
+
[Cache] Saving to ~/.safe-coder/cache/aHR0cHM6Ly9yZWFjdC5kZXY=.json
|
|
230
|
+
[Complete] Ready to return
|
|
231
|
+
```
|
|
355
232
|
|
|
233
|
+
**4. MCP returns to Cursor:**
|
|
356
234
|
```json
|
|
357
235
|
{
|
|
358
|
-
"
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
"
|
|
362
|
-
"
|
|
363
|
-
|
|
364
|
-
|
|
236
|
+
"success": true,
|
|
237
|
+
"data": {
|
|
238
|
+
"source": {
|
|
239
|
+
"url": "https://react.dev",
|
|
240
|
+
"crawledAt": "2026-01-15T14:30:00Z",
|
|
241
|
+
"pageCount": 50,
|
|
242
|
+
"depth": 3
|
|
243
|
+
},
|
|
244
|
+
"pages": [
|
|
245
|
+
{
|
|
246
|
+
"url": "https://react.dev/learn",
|
|
247
|
+
"title": "Quick Start",
|
|
248
|
+
"content": "Welcome to React...",
|
|
249
|
+
"keyPoints": [
|
|
250
|
+
"React is a JavaScript library",
|
|
251
|
+
"Components are building blocks",
|
|
252
|
+
"...more..."
|
|
253
|
+
],
|
|
254
|
+
"codePatterns": [
|
|
255
|
+
{
|
|
256
|
+
"language": "jsx",
|
|
257
|
+
"pattern": "function Component() { return <div>...</div> }",
|
|
258
|
+
"description": "Functional component syntax"
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
"wordCount": 1500,
|
|
262
|
+
"codeBlocks": 12
|
|
365
263
|
}
|
|
264
|
+
// ... 49 more pages
|
|
265
|
+
],
|
|
266
|
+
"analysis": {
|
|
267
|
+
"mainTopics": ["Components", "Hooks", "State", "Props", "Effects"],
|
|
268
|
+
"difficulty": "intermediate",
|
|
269
|
+
"technicalDensity": 0.65
|
|
366
270
|
}
|
|
367
|
-
}
|
|
271
|
+
},
|
|
272
|
+
"skillGenerationGuide": {
|
|
273
|
+
"suggestedStructure": [
|
|
274
|
+
"Overview",
|
|
275
|
+
"Quick Start",
|
|
276
|
+
"Core Concepts",
|
|
277
|
+
"Hooks Reference",
|
|
278
|
+
"Best Practices",
|
|
279
|
+
"Common Patterns",
|
|
280
|
+
"Troubleshooting"
|
|
281
|
+
],
|
|
282
|
+
"keyTopics": [
|
|
283
|
+
"JSX Syntax",
|
|
284
|
+
"Components (Functional & Class)",
|
|
285
|
+
"Props and State",
|
|
286
|
+
"Hooks (useState, useEffect, useContext, etc.)",
|
|
287
|
+
"Event Handling",
|
|
288
|
+
"Conditional Rendering",
|
|
289
|
+
"Lists and Keys"
|
|
290
|
+
],
|
|
291
|
+
"recommendedSections": {
|
|
292
|
+
"overview": "React is a JavaScript library for building user interfaces...",
|
|
293
|
+
"quickStart": [
|
|
294
|
+
"Install: npx create-react-app my-app",
|
|
295
|
+
"Create first component",
|
|
296
|
+
"Understand JSX"
|
|
297
|
+
],
|
|
298
|
+
"coreFeatures": [
|
|
299
|
+
"Component-based architecture",
|
|
300
|
+
"Virtual DOM",
|
|
301
|
+
"One-way data flow",
|
|
302
|
+
"Declarative UI"
|
|
303
|
+
],
|
|
304
|
+
"bestPractices": [
|
|
305
|
+
"Use functional components with Hooks",
|
|
306
|
+
"Keep components small and focused",
|
|
307
|
+
"Lift state up when needed"
|
|
308
|
+
]
|
|
309
|
+
},
|
|
310
|
+
"tips": [
|
|
311
|
+
"Focus on the Hooks API (modern approach)",
|
|
312
|
+
"Include examples for common Hooks",
|
|
313
|
+
"Explain component lifecycle clearly",
|
|
314
|
+
"Cover both client and server rendering"
|
|
315
|
+
],
|
|
316
|
+
"quality": {
|
|
317
|
+
"contentQuality": 90,
|
|
318
|
+
"codeExamples": 85,
|
|
319
|
+
"completeness": 88,
|
|
320
|
+
"overall": 87
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
"fromCache": false,
|
|
324
|
+
"message": "Successfully crawled 50 pages. Quality score: 87/100"
|
|
368
325
|
}
|
|
369
326
|
```
|
|
370
327
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
1. **检查配置文件格式**:确保 JSON 格式正确,可以使用在线 JSON 验证器
|
|
374
|
-
2. **重启 Cursor**:保存配置后,完全重启 Cursor
|
|
375
|
-
3. **检查连接状态**:
|
|
376
|
-
- 在 Cursor 设置中查看 MCP 服务器列表
|
|
377
|
-
- 应该能看到 "safe-coder" 服务器
|
|
378
|
-
- 状态应该显示为已连接(绿色)
|
|
379
|
-
|
|
380
|
-
#### 步骤 4:测试工具
|
|
381
|
-
|
|
382
|
-
在 Cursor 的 AI 对话中测试:
|
|
383
|
-
|
|
328
|
+
**5. Tell Cursor where to save:**
|
|
384
329
|
```
|
|
385
|
-
|
|
330
|
+
User: "Save this as a SKILL file at ~/.claude/skills/react-docs/SKILL.md"
|
|
386
331
|
```
|
|
387
332
|
|
|
388
|
-
|
|
333
|
+
**6. Cursor AI generates and saves:**
|
|
334
|
+
- Uses `data.pages` for content
|
|
335
|
+
- Uses `skillGenerationGuide` for structure
|
|
336
|
+
- Creates formatted `SKILL.md`
|
|
337
|
+
- Saves to specified location
|
|
389
338
|
|
|
390
|
-
|
|
339
|
+
## MCP Tools Reference
|
|
391
340
|
|
|
392
|
-
|
|
341
|
+
### Tool 1: `crawl_documentation`
|
|
393
342
|
|
|
394
|
-
|
|
395
|
-
1. `get_documentation` - 获取文档
|
|
396
|
-
2. `browse_documentation` - 浏览网页文档
|
|
397
|
-
3. `crawl_documentation` - 爬取文档并生成技能
|
|
398
|
-
4. `detect_spa` - 检测单页应用
|
|
399
|
-
5. `detect_errors` - 检测代码错误
|
|
400
|
-
6. `validate_code` - 验证代码
|
|
401
|
-
7. `resolve_error` - 解决错误
|
|
402
|
-
8. `get_status` - 获取服务器状态
|
|
403
|
-
9. `get_version` - 获取版本号
|
|
343
|
+
(**Recommended Workflow**: Use with `save_skill` for complete automation)
|
|
404
344
|
|
|
405
|
-
|
|
345
|
+
Crawl documentation website and return processed data with SKILL generation guidance.
|
|
406
346
|
|
|
407
|
-
|
|
347
|
+
**Parameters:**
|
|
408
348
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
349
|
+
| Parameter | Type | Required | Default | Description |
|
|
350
|
+
|-----------|------|----------|---------|-------------|
|
|
351
|
+
| `url` | `string` | ✅ Yes | - | Documentation URL to crawl |
|
|
352
|
+
| `maxPages` | `number` | No | `200` | Maximum pages to crawl |
|
|
353
|
+
| `depth` | `number` | No | `3` | Maximum crawl depth |
|
|
354
|
+
| `workers` | `number` | No | `1` | Number of parallel workers |
|
|
355
|
+
| `useBrowser` | `boolean` | No | `false` | Force browser automation |
|
|
356
|
+
| `browser` | `'puppeteer'` \| `'playwright'` | No | `'puppeteer'` | Browser type |
|
|
357
|
+
| `spaStrategy` | `'smart'` \| `'auto'` \| `'manual'` | No | `'smart'` | SPA detection |
|
|
358
|
+
| `useCache` | `boolean` | No | `true` | Use cached results |
|
|
359
|
+
| `forceRefresh` | `boolean` | No | `false` | Bypass cache |
|
|
413
360
|
|
|
414
|
-
|
|
361
|
+
**⚠️ Parameters NOT Currently Exposed (CLI supports, MCP doesn't):**
|
|
362
|
+
- `strategy` (bfs/dfs) - Crawl strategy
|
|
363
|
+
- `checkpoint`, `resume` - Checkpoint/resume functionality
|
|
364
|
+
- `rateLimit`, `maxRetries`, `retryDelay` - Rate limiting and retry control
|
|
365
|
+
- `includePaths`, `excludePaths` - URL path filtering
|
|
366
|
+
- `skipLlmsTxt` - llms.txt detection control
|
|
415
367
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
或者直接调用:
|
|
421
|
-
|
|
422
|
-
```json
|
|
368
|
+
**Returns:**
|
|
369
|
+
```typescript
|
|
423
370
|
{
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
371
|
+
success: boolean;
|
|
372
|
+
data: {
|
|
373
|
+
source: { url, crawledAt, pageCount, depth };
|
|
374
|
+
pages: Array<{
|
|
375
|
+
url, title, content, keyPoints, codePatterns,
|
|
376
|
+
category, wordCount, codeBlocks, headings
|
|
377
|
+
}>;
|
|
378
|
+
metadata: { technology, version, documentType, categories };
|
|
379
|
+
statistics: { totalPages, maxDepthReached, errors, linkDiscovery };
|
|
380
|
+
analysis: {
|
|
381
|
+
totalWords, totalCodeBlocks, categories,
|
|
382
|
+
mainTopics, technicalDensity, difficulty
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
skillGenerationGuide: {
|
|
386
|
+
suggestedStructure: string[];
|
|
387
|
+
keyTopics: string[];
|
|
388
|
+
recommendedSections: {
|
|
389
|
+
overview, quickStart, coreFeatures, bestPractices, troubleshooting
|
|
390
|
+
};
|
|
391
|
+
tips: string[];
|
|
392
|
+
quality: { contentQuality, codeExamples, completeness, overall };
|
|
393
|
+
};
|
|
394
|
+
fromCache: boolean;
|
|
395
|
+
cacheAge?: string; // If from cache
|
|
396
|
+
message: string;
|
|
427
397
|
}
|
|
428
398
|
```
|
|
429
399
|
|
|
430
|
-
|
|
400
|
+
**Example Cursor prompts:**
|
|
431
401
|
|
|
432
|
-
|
|
402
|
+
```bash
|
|
403
|
+
# Basic usage
|
|
404
|
+
"Crawl https://react.dev and create a SKILL"
|
|
433
405
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
- `query`(可选):搜索查询词,用于过滤内容
|
|
437
|
-
- `navigateTo`(可选):导航到文档内的其他页面
|
|
406
|
+
# Limit pages
|
|
407
|
+
"Crawl Vue.js docs but only 50 pages"
|
|
438
408
|
|
|
439
|
-
|
|
409
|
+
# Force refresh
|
|
410
|
+
"Re-crawl React docs, ignore cache"
|
|
440
411
|
|
|
441
|
-
|
|
442
|
-
|
|
412
|
+
# Use browser for SPA
|
|
413
|
+
"Crawl https://app.example.com with Playwright"
|
|
443
414
|
```
|
|
444
415
|
|
|
445
|
-
|
|
446
|
-
在 https://expressjs.com/en/guide 中查找关于路由的内容
|
|
447
|
-
```
|
|
416
|
+
### Tool 2: `list_cached_documentation`
|
|
448
417
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
递归爬取文档网站,提取内容并生成结构化的 Agent Skill。
|
|
452
|
-
|
|
453
|
-
**基础参数:**
|
|
454
|
-
- `url`(必需):文档根 URL
|
|
455
|
-
- `maxDepth`(可选):最大爬取深度(默认:3)
|
|
456
|
-
- `maxPages`(可选):最大页面数(默认:50)
|
|
457
|
-
- `includePaths`(可选):额外包含的路径模式
|
|
458
|
-
- `excludePaths`(可选):排除的路径模式
|
|
459
|
-
- `rateLimit`(可选):请求间隔(毫秒,默认:500)
|
|
460
|
-
- `maxRetries`(可选):失败请求的最大重试次数(默认:2)
|
|
461
|
-
- `retryDelay`(可选):重试前的延迟(毫秒,默认:1000)
|
|
462
|
-
- `outputDir`(可选):保存技能文件的目录(如果不提供,只返回内容)
|
|
463
|
-
- `filename`(可选):自定义文件名(不含扩展名)
|
|
464
|
-
|
|
465
|
-
**🌟 增强参数(新增):**
|
|
466
|
-
- `crawlStrategy`(可选):爬取策略 `'bfs'` | `'dfs'`(默认:bfs)
|
|
467
|
-
- **BFS**(广度优先):逐层爬取,适合全面覆盖
|
|
468
|
-
- **DFS**(深度优先):深入一条路径,适合深度理解
|
|
469
|
-
- `workers`(可选):并发worker数量 1-10(默认:1)
|
|
470
|
-
- 建议:小型站点2-3个,大型站点5-8个
|
|
471
|
-
- 性能提升:3 workers ≈ 3倍,5 workers ≈ 4-5倍
|
|
472
|
-
- `skipLlmsTxt`(可选):是否跳过llms.txt检测(默认:false)
|
|
473
|
-
- 启用时自动检测和使用llms.txt,效率提升2-3倍
|
|
474
|
-
- `checkpoint`(可选):断点续传配置
|
|
475
|
-
- `enabled`:是否启用断点功能
|
|
476
|
-
- `interval`:每N页保存一次(默认:10)
|
|
477
|
-
- `file`:checkpoint文件路径(可选)
|
|
478
|
-
- `resume`(可选):是否从上次断点恢复(默认:false)
|
|
479
|
-
|
|
480
|
-
**基础功能:**
|
|
481
|
-
- ✅ **SPA 检测**:自动检测单页应用(SPA)并提供建议
|
|
482
|
-
- ✅ **智能重试**:对临时错误(超时、网络错误等)自动重试
|
|
483
|
-
- ✅ **错误分类**:详细的错误类型分类和统计
|
|
484
|
-
- ✅ **进度日志**:实时显示爬取进度和统计信息
|
|
485
|
-
|
|
486
|
-
**🎯 使用示例:**
|
|
487
|
-
|
|
488
|
-
##### 1. 快速基础爬取
|
|
489
|
-
```
|
|
490
|
-
爬取 https://react.dev/docs 的文档并生成技能
|
|
491
|
-
```
|
|
418
|
+
List all cached documentation crawl results with metadata.
|
|
492
419
|
|
|
493
|
-
|
|
494
|
-
```
|
|
495
|
-
从 https://react.dev 生成 agent skill,使用 5 个并发worker,最多爬取 200 页
|
|
496
|
-
```
|
|
420
|
+
**Parameters:** None
|
|
497
421
|
|
|
498
|
-
|
|
499
|
-
```
|
|
422
|
+
**Returns:**
|
|
423
|
+
```typescript
|
|
500
424
|
{
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
425
|
+
success: boolean;
|
|
426
|
+
entries: Array<{
|
|
427
|
+
url: string;
|
|
428
|
+
technology?: string;
|
|
429
|
+
pageCount: number;
|
|
430
|
+
cachedAt: string; // ISO timestamp
|
|
431
|
+
age: string; // Human-readable, e.g., "2 hours ago"
|
|
432
|
+
size: string; // Human-readable, e.g., "2.5 MB"
|
|
433
|
+
}>;
|
|
434
|
+
statistics: {
|
|
435
|
+
totalEntries: number;
|
|
436
|
+
totalSize: number; // Bytes
|
|
437
|
+
oldestEntry?: Date;
|
|
438
|
+
newestEntry?: Date;
|
|
439
|
+
};
|
|
440
|
+
message: string;
|
|
505
441
|
}
|
|
506
442
|
```
|
|
507
443
|
|
|
508
|
-
|
|
509
|
-
```
|
|
510
|
-
|
|
444
|
+
**Example Cursor prompts:**
|
|
445
|
+
```bash
|
|
446
|
+
"Show me all cached documentation"
|
|
447
|
+
"List cached docs"
|
|
448
|
+
"What's in the cache?"
|
|
511
449
|
```
|
|
512
450
|
|
|
513
|
-
|
|
514
|
-
```json
|
|
515
|
-
{
|
|
516
|
-
"url": "https://docs.example.com",
|
|
517
|
-
"crawlStrategy": "dfs",
|
|
518
|
-
"maxDepth": 6,
|
|
519
|
-
"workers": 3
|
|
520
|
-
}
|
|
521
|
-
```
|
|
451
|
+
### Tool 3: `save_skill` ⭐ NEW
|
|
522
452
|
|
|
523
|
-
|
|
524
|
-
```
|
|
525
|
-
爬取 https://large-docs.com,最多 1000 页,启用断点每 50 页保存一次
|
|
526
|
-
```
|
|
453
|
+
**Save complete SKILL directory structure to filesystem.**
|
|
527
454
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
"maxPages": 1000,
|
|
533
|
-
"workers": 8,
|
|
534
|
-
"checkpoint": {
|
|
535
|
-
"enabled": true,
|
|
536
|
-
"interval": 50
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
```
|
|
455
|
+
Creates a properly formatted Cursor Agent Skill with:
|
|
456
|
+
- `SKILL.md` - Main skill file with metadata
|
|
457
|
+
- `references/` - Reference documentation organized by category
|
|
458
|
+
- Standard directory structure compatible with Cursor
|
|
540
459
|
|
|
541
|
-
|
|
542
|
-
```
|
|
543
|
-
从断点恢复 https://large-docs.com 的爬取
|
|
544
|
-
```
|
|
460
|
+
**Parameters:**
|
|
545
461
|
|
|
546
|
-
|
|
547
|
-
|
|
462
|
+
| Parameter | Type | Required | Default | Description |
|
|
463
|
+
|-----------|------|----------|---------|-------------|
|
|
464
|
+
| `skillName` | `string` | ✅ Yes | - | Name for skill directory (e.g., "react-docs") |
|
|
465
|
+
| `skillContent` | `string` | ✅ Yes | - | Content for SKILL.md file |
|
|
466
|
+
| `referenceFiles` | `Record<string, string>` | No | `{}` | Map of category → markdown content |
|
|
467
|
+
| `baseDirectory` | `string` | No | `~/.claude/skills` | Base directory for skills |
|
|
468
|
+
| `overwrite` | `boolean` | No | `false` | Overwrite existing skill |
|
|
469
|
+
|
|
470
|
+
**Returns:**
|
|
471
|
+
```typescript
|
|
548
472
|
{
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
473
|
+
success: boolean;
|
|
474
|
+
skillDirectory: string; // Absolute path to skill directory
|
|
475
|
+
filesCreated: {
|
|
476
|
+
skillMd: string; // Path to SKILL.md
|
|
477
|
+
references: string[]; // Paths to reference files
|
|
478
|
+
};
|
|
479
|
+
message: string;
|
|
552
480
|
}
|
|
553
481
|
```
|
|
554
482
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
| 爬取规模 | 串行模式 | 并行模式(workers=5) | 提升 |
|
|
558
|
-
|---------|---------|-------------------|------|
|
|
559
|
-
| 50页 | ~90秒 | ~22秒 | **4倍** ⚡ |
|
|
560
|
-
| 100页 | ~180秒 | ~45秒 | **4倍** ⚡ |
|
|
561
|
-
| 200页 | ~360秒 | ~80秒 | **4.5倍** ⚡ |
|
|
562
|
-
|
|
563
|
-
**输出内容:**
|
|
564
|
-
- `skillContent`: Markdown 格式的技能内容
|
|
565
|
-
- `metadata`: 技能元数据(标题、描述、源 URL 等)
|
|
566
|
-
- `crawlStats`: 爬取统计(总页数、最大深度、错误列表、质量指标)
|
|
567
|
-
- `files`(可选):保存的文件路径
|
|
568
|
-
- `skillFile`: SKILL.md 文件路径
|
|
569
|
-
- `manifestFile`: metadata.json 文件路径
|
|
570
|
-
|
|
571
|
-
**💡 最佳实践:**
|
|
572
|
-
1. **先小规模测试**:maxPages设为10-20验证效果
|
|
573
|
-
2. **逐步增加并发**:从workers=2开始,观察效果
|
|
574
|
-
3. **大规模使用断点**:超过200页建议启用checkpoint
|
|
575
|
-
4. **关注质量指标**:diversity和coverage应 > 0.5
|
|
576
|
-
|
|
577
|
-
**📚 详细文档:**
|
|
578
|
-
- 完整使用指南:`docs/ENHANCED_CRAWLING.md`
|
|
579
|
-
- 快速上手:查看项目中的 `QUICKSTART_*.md` 文档
|
|
580
|
-
- 实施细节:`IMPLEMENTATION_SUMMARY.md`
|
|
581
|
-
|
|
582
|
-
#### `detect_errors` - 检测错误
|
|
583
|
-
|
|
584
|
-
检测代码中的错误和警告。
|
|
585
|
-
|
|
586
|
-
**参数:**
|
|
587
|
-
- `code`(必需):要分析的代码
|
|
588
|
-
- `filename`(可选):用于上下文的文件名(默认:'code.ts')
|
|
589
|
-
|
|
590
|
-
**使用示例:**
|
|
591
|
-
|
|
483
|
+
**Directory Structure Created:**
|
|
592
484
|
```
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
485
|
+
~/.claude/skills/
|
|
486
|
+
└── [skillName]/
|
|
487
|
+
├── SKILL.md # Main skill file
|
|
488
|
+
└── references/ # Reference documentation
|
|
489
|
+
├── api.md # API category
|
|
490
|
+
├── guides.md # Guides category
|
|
491
|
+
├── getting_started.md # Getting started
|
|
492
|
+
└── ... # Other categories
|
|
596
493
|
```
|
|
597
494
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
验证代码并可选择自动修复常见错误。
|
|
495
|
+
**Example Cursor Prompts:**
|
|
601
496
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
-
|
|
497
|
+
```bash
|
|
498
|
+
# After crawling, extract and save skill data
|
|
499
|
+
"Use the crawled React data to create a complete SKILL:
|
|
500
|
+
- skillName: 'react-docs'
|
|
501
|
+
- skillContent: [generated from guidance]
|
|
502
|
+
- referenceFiles: [organized by category]"
|
|
606
503
|
|
|
607
|
-
|
|
504
|
+
# Save with custom location
|
|
505
|
+
"Save the Vue skill to ~/my-skills/"
|
|
608
506
|
|
|
507
|
+
# Overwrite existing
|
|
508
|
+
"Update the react-docs skill with new content"
|
|
609
509
|
```
|
|
610
|
-
请验证并修复这段代码:
|
|
611
|
-
function test() {
|
|
612
|
-
return x
|
|
613
|
-
}
|
|
614
|
-
```
|
|
615
|
-
|
|
616
|
-
#### `resolve_error` - 解决错误
|
|
617
|
-
|
|
618
|
-
获取特定错误的解决方案建议。
|
|
619
|
-
|
|
620
|
-
**参数:**
|
|
621
|
-
- `errorType`(必需):错误类型
|
|
622
|
-
- `message`(必需):错误消息
|
|
623
|
-
- `line`(可选):错误发生的行号
|
|
624
510
|
|
|
625
|
-
|
|
511
|
+
**Automated Workflow Example:**
|
|
626
512
|
|
|
627
513
|
```
|
|
628
|
-
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
#### `detect_spa` - 检测单页应用
|
|
632
|
-
|
|
633
|
-
检测网站是否为需要 JavaScript 渲染的单页应用(SPA)。
|
|
634
|
-
|
|
635
|
-
**参数:**
|
|
636
|
-
- `url`(必需):要检测的 URL
|
|
637
|
-
|
|
638
|
-
**使用示例:**
|
|
514
|
+
User: "Crawl React docs and save as a complete SKILL"
|
|
639
515
|
|
|
516
|
+
Step 1: Cursor calls crawl_documentation
|
|
517
|
+
Step 2: Receives data with pages organized by category
|
|
518
|
+
Step 3: Cursor calls save_skill with:
|
|
519
|
+
{
|
|
520
|
+
skillName: "react-docs",
|
|
521
|
+
skillContent: "[Generated SKILL.md from guidance]",
|
|
522
|
+
referenceFiles: {
|
|
523
|
+
"api": "[API pages content]",
|
|
524
|
+
"guides": "[Guide pages content]",
|
|
525
|
+
"getting_started": "[Getting started content]"
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
Step 4: Tool creates complete directory structure
|
|
529
|
+
Step 5: Returns paths to all created files
|
|
640
530
|
```
|
|
641
|
-
检测 https://react-dnd.github.io/react-dnd/docs 是否是 SPA
|
|
642
|
-
```
|
|
643
|
-
|
|
644
|
-
**返回:**
|
|
645
|
-
- `isSPA`:是否为 SPA
|
|
646
|
-
- `confidence`:检测置信度(high/medium/low)
|
|
647
|
-
- `indicators`:检测到的 SPA 指标
|
|
648
|
-
- `suggestion`:建议(如果检测到 SPA)
|
|
649
|
-
|
|
650
|
-
### 4. 使用 MCP 资源
|
|
651
531
|
|
|
652
|
-
|
|
532
|
+
### Tool 4: `clear_cache`
|
|
653
533
|
|
|
654
|
-
|
|
534
|
+
Clear cached documentation results by pattern, all entries, or expired only.
|
|
655
535
|
|
|
656
|
-
|
|
536
|
+
**Parameters:**
|
|
657
537
|
|
|
658
|
-
|
|
538
|
+
| Parameter | Type | Required | Default | Description |
|
|
539
|
+
|-----------|------|----------|---------|-------------|
|
|
540
|
+
| `urlPattern` | `string` | No | - | URL pattern to match (substring) |
|
|
541
|
+
| `clearAll` | `boolean` | No | `false` | Clear all cached entries |
|
|
659
542
|
|
|
660
|
-
|
|
543
|
+
**Behavior:**
|
|
544
|
+
- If `clearAll: true` → Delete all cached entries
|
|
545
|
+
- If `urlPattern` provided → Delete entries matching pattern
|
|
546
|
+
- If neither → Delete only expired entries (>7 days old)
|
|
661
547
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
│ │ ├── web-doc-browser.ts # 网页文档浏览
|
|
670
|
-
│ │ ├── doc-crawler.ts # 文档爬取
|
|
671
|
-
│ │ └── skill-generator.ts # 技能生成
|
|
672
|
-
│ ├── errors/ # 错误检测(ESLint、TypeScript、模式、上下文)
|
|
673
|
-
│ ├── validation/ # 代码验证和自动修复
|
|
674
|
-
│ ├── server/ # MCP 服务器实现
|
|
675
|
-
│ ├── types/ # TypeScript 类型定义
|
|
676
|
-
│ ├── utils/ # 配置和工具函数
|
|
677
|
-
│ └── index.ts # 入口文件
|
|
678
|
-
├── tests/ # 测试文件
|
|
679
|
-
├── dist/ # 编译输出
|
|
680
|
-
└── package.json
|
|
548
|
+
**Returns:**
|
|
549
|
+
```typescript
|
|
550
|
+
{
|
|
551
|
+
success: boolean;
|
|
552
|
+
deletedCount: number;
|
|
553
|
+
message: string;
|
|
554
|
+
}
|
|
681
555
|
```
|
|
682
556
|
|
|
683
|
-
|
|
684
|
-
|
|
557
|
+
**Example Cursor prompts:**
|
|
685
558
|
```bash
|
|
686
|
-
#
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
# 构建项目
|
|
690
|
-
npm run build
|
|
691
|
-
|
|
692
|
-
# 开发模式运行(自动重新编译)
|
|
693
|
-
npm run dev
|
|
694
|
-
|
|
695
|
-
# 运行测试
|
|
696
|
-
npm test
|
|
697
|
-
|
|
698
|
-
# 监听模式运行测试
|
|
699
|
-
npm run test:watch
|
|
559
|
+
# Clear all
|
|
560
|
+
"Clear all cached documentation"
|
|
700
561
|
|
|
701
|
-
#
|
|
702
|
-
|
|
562
|
+
# Clear by pattern
|
|
563
|
+
"Clear cache for react.dev"
|
|
564
|
+
"Delete cached Vue docs"
|
|
703
565
|
|
|
704
|
-
#
|
|
705
|
-
|
|
566
|
+
# Clear expired only
|
|
567
|
+
"Clear old cached docs"
|
|
706
568
|
```
|
|
707
569
|
|
|
708
|
-
|
|
570
|
+
## Internal Workflow
|
|
709
571
|
|
|
710
|
-
|
|
572
|
+
### 1. Dependency Check
|
|
711
573
|
|
|
712
|
-
|
|
574
|
+
```typescript
|
|
575
|
+
const checker = new DependencyChecker();
|
|
576
|
+
const check = await checker.checkCLIInstalled();
|
|
713
577
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
应该看到:`Safe Coder MCP server running on stdio`
|
|
578
|
+
if (!check.installed) {
|
|
579
|
+
throw new Error(`
|
|
580
|
+
⚠️ safe-coder-cli is not installed.
|
|
719
581
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
- 查看控制台中的 MCP 相关错误
|
|
582
|
+
Please install globally:
|
|
583
|
+
npm install -g @gulibs/safe-coder-cli
|
|
723
584
|
|
|
724
|
-
|
|
725
|
-
|
|
585
|
+
Or from source:
|
|
586
|
+
cd /path/to/safe-coder-cli
|
|
587
|
+
npm install && npm run build && npm link
|
|
726
588
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
### Q: 服务器无法启动?
|
|
589
|
+
Then verify:
|
|
590
|
+
safe-coder-cli --version
|
|
591
|
+
`);
|
|
592
|
+
}
|
|
593
|
+
```
|
|
734
594
|
|
|
735
|
-
|
|
736
|
-
- 确保已运行 `npm install` 和 `npm run build`
|
|
737
|
-
- 检查 Node.js 版本(建议 18+)
|
|
738
|
-
- 查看错误日志
|
|
595
|
+
### 2. CLI Execution
|
|
739
596
|
|
|
740
|
-
|
|
597
|
+
```typescript
|
|
598
|
+
const executor = new CLIExecutor(checker);
|
|
599
|
+
const result = await executor.executeCrawl({
|
|
600
|
+
url: 'https://react.dev',
|
|
601
|
+
maxPages: 200,
|
|
602
|
+
maxDepth: 3,
|
|
603
|
+
// ... other params
|
|
604
|
+
}, (progress) => {
|
|
605
|
+
console.error(`[Progress] ${progress.message}`);
|
|
606
|
+
});
|
|
607
|
+
```
|
|
741
608
|
|
|
742
|
-
**
|
|
743
|
-
|
|
744
|
-
-
|
|
609
|
+
**Under the hood:**
|
|
610
|
+
```bash
|
|
611
|
+
spawn('safe-coder-cli', [
|
|
612
|
+
'crawl',
|
|
613
|
+
'https://react.dev',
|
|
614
|
+
'--output-format', 'json',
|
|
615
|
+
'--max-pages', '200',
|
|
616
|
+
'--depth', '3'
|
|
617
|
+
])
|
|
745
618
|
|
|
746
|
-
|
|
619
|
+
# stdout → JSON result
|
|
620
|
+
# stderr → Progress messages
|
|
621
|
+
```
|
|
747
622
|
|
|
748
|
-
|
|
749
|
-
- 确保代码文件扩展名正确(`.ts` 用于 TypeScript,`.js` 用于 JavaScript)
|
|
750
|
-
- 某些复杂的错误可能需要更多上下文
|
|
751
|
-
- 可以尝试使用 `validate_code` 工具获得更全面的分析
|
|
623
|
+
### 3. Content Processing
|
|
752
624
|
|
|
753
|
-
|
|
625
|
+
```typescript
|
|
626
|
+
const processor = new ContentProcessor();
|
|
627
|
+
const processed = await processor.process(rawResult);
|
|
754
628
|
|
|
755
|
-
|
|
756
|
-
-
|
|
757
|
-
-
|
|
758
|
-
-
|
|
629
|
+
// Extracts:
|
|
630
|
+
// - Key points from each page
|
|
631
|
+
// - Code patterns and examples
|
|
632
|
+
// - Content categories
|
|
633
|
+
// - Technical density
|
|
634
|
+
// - Difficulty level
|
|
635
|
+
```
|
|
759
636
|
|
|
760
|
-
###
|
|
637
|
+
### 4. SKILL Guidance Generation
|
|
761
638
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
- 支持配置深度和页面限制
|
|
766
|
-
- 详见 `DOC_CRAWLER_USAGE.md`
|
|
639
|
+
```typescript
|
|
640
|
+
const guideGenerator = new GuideGenerator();
|
|
641
|
+
const guide = guideGenerator.generate(processed);
|
|
767
642
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
643
|
+
// Creates:
|
|
644
|
+
// - Suggested SKILL structure
|
|
645
|
+
// - Key topics to cover
|
|
646
|
+
// - Recommended sections
|
|
647
|
+
// - Writing tips
|
|
648
|
+
// - Quality assessment
|
|
771
649
|
```
|
|
772
650
|
|
|
773
|
-
###
|
|
651
|
+
### 5. Caching
|
|
774
652
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
- 使用 `maxDepth` 参数限制爬取深度(默认 3)
|
|
778
|
-
- 调整 `rateLimit` 避免对服务器造成压力(默认 500ms)
|
|
779
|
-
- 大型站点建议分多次爬取不同部分
|
|
653
|
+
```typescript
|
|
654
|
+
const cache = new CacheManager();
|
|
780
655
|
|
|
781
|
-
|
|
656
|
+
// Save (7-day TTL)
|
|
657
|
+
await cache.set(url, processed, guide);
|
|
782
658
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
如果你想将这个包发布到 npm:
|
|
659
|
+
// Retrieve
|
|
660
|
+
const cached = await cache.get(url);
|
|
661
|
+
if (cached && !forceRefresh) {
|
|
662
|
+
return cached;
|
|
663
|
+
}
|
|
664
|
+
```
|
|
791
665
|
|
|
792
|
-
|
|
666
|
+
**Cache location:** `~/.safe-coder/cache/`
|
|
667
|
+
**Cache format:** JSON files with base64-encoded URL as filename
|
|
668
|
+
**TTL:** 7 days (default)
|
|
793
669
|
|
|
794
|
-
|
|
795
|
-
# 确保已登录 npm
|
|
796
|
-
npm login
|
|
670
|
+
## Error Handling
|
|
797
671
|
|
|
798
|
-
|
|
799
|
-
npm view @gulibs/safe-coder
|
|
672
|
+
### CLI Not Installed
|
|
800
673
|
|
|
801
|
-
# 更新版本号
|
|
802
|
-
npm version patch # 或 minor, major
|
|
803
674
|
```
|
|
675
|
+
Error: safe-coder-cli is not installed
|
|
804
676
|
|
|
805
|
-
|
|
677
|
+
Please install:
|
|
678
|
+
npm install -g @gulibs/safe-coder-cli
|
|
806
679
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
npm publish --access public
|
|
680
|
+
Current PATH checked:
|
|
681
|
+
/usr/local/bin
|
|
682
|
+
/usr/bin
|
|
683
|
+
/bin
|
|
684
|
+
...
|
|
813
685
|
```
|
|
814
686
|
|
|
815
|
-
###
|
|
687
|
+
### CLI Execution Failed
|
|
816
688
|
|
|
817
|
-
```bash
|
|
818
|
-
# 检查包是否已发布
|
|
819
|
-
npm view @gulibs/safe-coder
|
|
820
|
-
|
|
821
|
-
# 测试安装
|
|
822
|
-
npm install -g @gulibs/safe-coder
|
|
823
689
|
```
|
|
690
|
+
Error: CLI process exited with code 1
|
|
824
691
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
692
|
+
stderr output:
|
|
693
|
+
[Error] Failed to crawl: Network timeout
|
|
694
|
+
[Error] URL: https://example.com
|
|
828
695
|
|
|
829
|
-
|
|
696
|
+
Possible solutions:
|
|
697
|
+
- Check network connectivity
|
|
698
|
+
- Try with --use-browser flag
|
|
699
|
+
- Increase timeout with --rate-limit
|
|
700
|
+
```
|
|
830
701
|
|
|
831
|
-
|
|
702
|
+
### Cache Errors
|
|
832
703
|
|
|
833
|
-
```json
|
|
834
|
-
{
|
|
835
|
-
"mcpServers": {
|
|
836
|
-
"safe-coder": {
|
|
837
|
-
"command": "node",
|
|
838
|
-
"args": ["./dist/index.js"],
|
|
839
|
-
"env": {
|
|
840
|
-
"CACHE_TTL_MINUTES": "60",
|
|
841
|
-
"GITHUB_TOKEN": ""
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
704
|
```
|
|
705
|
+
Warning: Failed to cache results
|
|
706
|
+
Error: EACCES: permission denied, mkdir '~/.safe-coder/cache'
|
|
847
707
|
|
|
848
|
-
|
|
708
|
+
Continuing without cache...
|
|
709
|
+
```
|
|
849
710
|
|
|
850
|
-
|
|
711
|
+
Cache errors are non-fatal - the operation continues without caching.
|
|
851
712
|
|
|
852
|
-
|
|
713
|
+
## Configuration
|
|
853
714
|
|
|
854
|
-
|
|
855
|
-
#!/bin/bash
|
|
856
|
-
# test-mcp.sh
|
|
715
|
+
### Cache Settings
|
|
857
716
|
|
|
858
|
-
|
|
859
|
-
npm run build
|
|
717
|
+
Modify cache behavior by editing `src/cache/cache-manager.ts`:
|
|
860
718
|
|
|
861
|
-
|
|
862
|
-
|
|
719
|
+
```typescript
|
|
720
|
+
const cache = new CacheManager(
|
|
721
|
+
'/custom/cache/path', // Default: ~/.safe-coder/cache
|
|
722
|
+
14 // TTL in days (default: 7)
|
|
723
|
+
);
|
|
863
724
|
```
|
|
864
725
|
|
|
865
|
-
|
|
726
|
+
### CLI Arguments Mapping
|
|
866
727
|
|
|
867
|
-
|
|
728
|
+
| MCP Parameter | CLI Argument |
|
|
729
|
+
|---------------|--------------|
|
|
730
|
+
| `url` | `<url>` (positional) |
|
|
731
|
+
| `maxPages` | `--max-pages <number>` |
|
|
732
|
+
| `depth` | `--max-depth <number>` |
|
|
733
|
+
| `workers` | `--workers <number>` |
|
|
734
|
+
| `useBrowser` | (implicitly sets `--spa-strategy auto`) |
|
|
735
|
+
| `browser` | `--browser <type>` |
|
|
736
|
+
| `spaStrategy` | `--spa-strategy <type>` |
|
|
737
|
+
| - | `--output-format json` (forced) |
|
|
868
738
|
|
|
869
|
-
|
|
870
|
-
1. 检查路径是否正确(使用绝对路径)
|
|
871
|
-
2. 确保 `dist/index.js` 文件存在
|
|
872
|
-
3. 检查 Node.js 是否在 PATH 中:`which node` 或 `where node`
|
|
739
|
+
## Troubleshooting
|
|
873
740
|
|
|
874
|
-
###
|
|
741
|
+
### MCP Server Not Appearing in Cursor
|
|
875
742
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
743
|
+
1. **Check configuration file exists:**
|
|
744
|
+
```bash
|
|
745
|
+
cat ~/Library/Application\ Support/Cursor/User/globalStorage/mcp.json
|
|
746
|
+
```
|
|
880
747
|
|
|
881
|
-
|
|
748
|
+
2. **Verify JSON syntax is valid**
|
|
882
749
|
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
750
|
+
3. **Check absolute path is correct:**
|
|
751
|
+
```bash
|
|
752
|
+
node /absolute/path/to/safe-coder/dist/index.js
|
|
753
|
+
# Should not error
|
|
754
|
+
```
|
|
887
755
|
|
|
888
|
-
|
|
756
|
+
4. **Restart Cursor completely**
|
|
889
757
|
|
|
890
|
-
|
|
758
|
+
### "CLI Not Found" Error
|
|
891
759
|
|
|
892
760
|
```bash
|
|
893
|
-
#
|
|
894
|
-
|
|
895
|
-
```
|
|
896
|
-
|
|
897
|
-
## 许可证
|
|
898
|
-
|
|
899
|
-
MIT
|
|
900
|
-
|
|
901
|
-
## 🎓 在大模型中使用MCP Server生成Agent Skill
|
|
902
|
-
|
|
903
|
-
### 快速上手
|
|
904
|
-
|
|
905
|
-
#### 步骤1:在Claude/Cursor中触发爬取
|
|
906
|
-
|
|
907
|
-
**中文触发词:**
|
|
908
|
-
```
|
|
909
|
-
帮我爬取 https://react.dev 的文档并生成Agent Skill
|
|
910
|
-
```
|
|
761
|
+
# Check if CLI is in PATH
|
|
762
|
+
which safe-coder-cli
|
|
911
763
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
```
|
|
917
|
-
递归抓取 https://nextjs.org/docs 的文档,深度优先策略
|
|
918
|
-
```
|
|
764
|
+
# If not found, reinstall
|
|
765
|
+
cd /path/to/safe-coder-cli
|
|
766
|
+
npm link
|
|
919
767
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
Crawl https://react.dev and generate an agent skill
|
|
768
|
+
# Verify
|
|
769
|
+
safe-coder-cli --version
|
|
923
770
|
```
|
|
924
771
|
|
|
925
|
-
|
|
926
|
-
Use parallel crawling to create a skill from https://docs.example.com
|
|
927
|
-
```
|
|
772
|
+
### Slow Crawling
|
|
928
773
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
774
|
+
- Reduce `maxPages` (e.g., 50 instead of 200)
|
|
775
|
+
- Decrease `depth` (e.g., 2 instead of 3)
|
|
776
|
+
- Increase `workers` (e.g., 3 for parallel crawling) - *requires CLI support*
|
|
932
777
|
|
|
933
|
-
|
|
778
|
+
### Cache Not Working
|
|
934
779
|
|
|
935
|
-
|
|
780
|
+
```bash
|
|
781
|
+
# Check cache directory
|
|
782
|
+
ls -la ~/.safe-coder/cache/
|
|
936
783
|
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
爬取 https://react.dev/docs,最多50页
|
|
940
|
-
```
|
|
784
|
+
# Permissions issue?
|
|
785
|
+
chmod 755 ~/.safe-coder/cache/
|
|
941
786
|
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
787
|
+
# Clear and rebuild
|
|
788
|
+
rm -rf ~/.safe-coder/cache/
|
|
789
|
+
# Cache will recreate on next crawl
|
|
945
790
|
```
|
|
946
791
|
|
|
947
|
-
|
|
948
|
-
```
|
|
949
|
-
使用DFS策略深入爬取 https://docs.example.com,深度限制为6层
|
|
950
|
-
```
|
|
951
|
-
|
|
952
|
-
**大规模爬取:**
|
|
953
|
-
```
|
|
954
|
-
爬取 https://large-docs.com,最多1000页,启用断点续传每50页保存
|
|
955
|
-
```
|
|
792
|
+
## Development
|
|
956
793
|
|
|
957
|
-
###
|
|
794
|
+
### Project Structure
|
|
958
795
|
|
|
959
|
-
#### 场景1:快速探索新技术栈
|
|
960
|
-
```
|
|
961
|
-
帮我爬取 Svelte 的官方文档,快速生成一个技能
|
|
962
796
|
```
|
|
797
|
+
safe-coder/
|
|
798
|
+
├── src/
|
|
799
|
+
│ ├── index.ts # Entry point
|
|
800
|
+
│ ├── server/
|
|
801
|
+
│ │ └── safe-coder-mcp.ts # MCP server class
|
|
802
|
+
│ ├── executor/
|
|
803
|
+
│ │ ├── dependency-checker.ts # Check CLI installation
|
|
804
|
+
│ │ └── cli-executor.ts # Spawn CLI process
|
|
805
|
+
│ ├── processor/
|
|
806
|
+
│ │ ├── content-processor.ts # Analyze content
|
|
807
|
+
│ │ └── guide-generator.ts # Generate SKILL guidance
|
|
808
|
+
│ ├── cache/
|
|
809
|
+
│ │ └── cache-manager.ts # Cache management
|
|
810
|
+
│ └── tools/
|
|
811
|
+
│ ├── crawl-documentation.ts # Main MCP tool
|
|
812
|
+
│ ├── cache-tools.ts # Cache MCP tools
|
|
813
|
+
│ └── index.ts # Tool exports
|
|
814
|
+
├── dist/ # Compiled output
|
|
815
|
+
├── tsconfig.json
|
|
816
|
+
├── package.json
|
|
817
|
+
└── README.md
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
### Build and Test
|
|
963
821
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
- crawlStrategy: bfs(全面覆盖)
|
|
822
|
+
```bash
|
|
823
|
+
# Install dependencies
|
|
824
|
+
npm install
|
|
968
825
|
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
深入爬取 Vue 3 的文档,我要完整理解它的 API
|
|
972
|
-
```
|
|
826
|
+
# Build
|
|
827
|
+
npm run build
|
|
973
828
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
- maxDepth: 5(深入层级)
|
|
977
|
-
- workers: 5(加速)
|
|
978
|
-
- maxPages: 200(完整覆盖)
|
|
829
|
+
# Watch mode
|
|
830
|
+
npm run build -- --watch
|
|
979
831
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
爬取 MDN Web Docs 的 JavaScript 部分,分多次进行,支持断点恢复
|
|
983
|
-
```
|
|
984
|
-
|
|
985
|
-
**自动参数:**
|
|
986
|
-
- workers: 8(大规模)
|
|
987
|
-
- maxPages: 1000
|
|
988
|
-
- checkpoint: { enabled: true, interval: 50 }
|
|
832
|
+
# Test locally
|
|
833
|
+
node dist/index.js
|
|
989
834
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
上次爬取中断了,从断点继续爬取 https://large-docs.com
|
|
835
|
+
# Test with MCP Inspector (if available)
|
|
836
|
+
npx @modelcontextprotocol/inspector node dist/index.js
|
|
993
837
|
```
|
|
994
838
|
|
|
995
|
-
|
|
996
|
-
- resume: true
|
|
997
|
-
- checkpoint: { enabled: true }
|
|
998
|
-
|
|
999
|
-
### 生成的Agent Skill格式
|
|
1000
|
-
|
|
1001
|
-
爬取完成后,会生成标准的Claude Agent Skill格式:
|
|
839
|
+
### Running with Debug Output
|
|
1002
840
|
|
|
1003
|
-
```
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
├── Core Concepts # 核心概念
|
|
1008
|
-
├── API Reference # API参考
|
|
1009
|
-
├── Examples # 示例代码
|
|
1010
|
-
└── Reference Files # 引用文件列表
|
|
1011
|
-
|
|
1012
|
-
references/ # 引用文件目录
|
|
1013
|
-
├── page-1.md
|
|
1014
|
-
├── page-2.md
|
|
1015
|
-
└── ...
|
|
841
|
+
```typescript
|
|
842
|
+
// In src/index.ts
|
|
843
|
+
console.error('[Debug] MCP Server starting...');
|
|
844
|
+
console.error('[Debug] Available tools:', server.listTools());
|
|
1016
845
|
```
|
|
1017
846
|
|
|
1018
|
-
|
|
847
|
+
MCP uses stdio, so:
|
|
848
|
+
- `stdout` → MCP protocol messages (JSON-RPC)
|
|
849
|
+
- `stderr` → Debug/log output (visible in Cursor logs)
|
|
1019
850
|
|
|
1020
|
-
|
|
851
|
+
## Roadmap / Future Enhancements
|
|
1021
852
|
|
|
1022
|
-
|
|
1023
|
-
|-----|-----|---------|
|
|
1024
|
-
| **内容充足性** | 每页内容长度 | > 100字符/页 |
|
|
1025
|
-
| **结构完整性** | 标题、章节组织 | 至少1个标题/页 |
|
|
1026
|
-
| **内容多样性** | URL路径和主题分布 | diversity > 0.7 |
|
|
1027
|
-
| **API覆盖度** | 代码示例比例 | coverage > 0.5 |
|
|
853
|
+
### Planned Features
|
|
1028
854
|
|
|
1029
|
-
|
|
855
|
+
1. **Expose More CLI Parameters**
|
|
856
|
+
- [ ] `strategy` (bfs/dfs)
|
|
857
|
+
- [ ] `checkpoint`, `resume`
|
|
858
|
+
- [ ] `rateLimit`, `maxRetries`
|
|
859
|
+
- [ ] `includePaths`, `excludePaths`
|
|
1030
860
|
|
|
1031
|
-
|
|
861
|
+
2. **Direct File Creation Tool**
|
|
862
|
+
- [ ] `save_skill` tool to create SKILL.md directly
|
|
863
|
+
- [ ] Automatic filename generation
|
|
864
|
+
- [ ] Default location management
|
|
1032
865
|
|
|
1033
|
-
|
|
866
|
+
3. **Enhanced Processing**
|
|
867
|
+
- [ ] Semantic analysis of content
|
|
868
|
+
- [ ] Automatic category detection
|
|
869
|
+
- [ ] Code example quality scoring
|
|
870
|
+
- [ ] Cross-reference detection
|
|
1034
871
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
872
|
+
4. **Better Caching**
|
|
873
|
+
- [ ] Configurable TTL per URL
|
|
874
|
+
- [ ] Cache compression
|
|
875
|
+
- [ ] Partial cache updates
|
|
876
|
+
- [ ] Cache analytics
|
|
1038
877
|
|
|
1039
|
-
|
|
878
|
+
## Contributing
|
|
1040
879
|
|
|
1041
|
-
|
|
880
|
+
This package is part of the Safe Coder project. Contributions welcome!
|
|
1042
881
|
|
|
1043
|
-
|
|
1044
|
-
爬取并保存到 ./skills 目录,文件名为 react-docs
|
|
1045
|
-
```
|
|
1046
|
-
|
|
1047
|
-
生成文件:
|
|
1048
|
-
- `./skills/react-docs.md` - Skill内容
|
|
1049
|
-
- `./skills/react-docs.metadata.json` - 元数据
|
|
882
|
+
### Development Workflow
|
|
1050
883
|
|
|
1051
|
-
|
|
884
|
+
1. Fork and clone both `safe-coder` and `safe-coder-cli`
|
|
885
|
+
2. Make changes
|
|
886
|
+
3. Build and test locally
|
|
887
|
+
4. Submit pull request
|
|
1052
888
|
|
|
1053
|
-
|
|
889
|
+
### Testing
|
|
1054
890
|
|
|
1055
891
|
```bash
|
|
1056
|
-
#
|
|
1057
|
-
|
|
892
|
+
# Unit tests (when implemented)
|
|
893
|
+
npm test
|
|
1058
894
|
|
|
1059
|
-
#
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
895
|
+
# Integration test
|
|
896
|
+
# 1. Build both packages
|
|
897
|
+
cd safe-coder-cli && npm run build && npm link
|
|
898
|
+
cd ../safe-coder && npm run build && npm link
|
|
1063
899
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
#### Q: 如何选择爬取策略?
|
|
1067
|
-
**A:**
|
|
1068
|
-
- **BFS(广度优先)**:适合扁平结构、需要全面覆盖的文档
|
|
1069
|
-
- **DFS(深度优先)**:适合层级结构、需要深入理解的文档
|
|
1070
|
-
|
|
1071
|
-
#### Q: workers设置多少合适?
|
|
1072
|
-
**A:**
|
|
1073
|
-
- 小型站点(<50页):workers: 2-3
|
|
1074
|
-
- 中型站点(50-200页):workers: 3-5
|
|
1075
|
-
- 大型站点(>200页):workers: 5-8
|
|
1076
|
-
|
|
1077
|
-
#### Q: 什么时候需要启用断点?
|
|
1078
|
-
**A:**
|
|
1079
|
-
- 爬取页面超过200页
|
|
1080
|
-
- 网络不稳定
|
|
1081
|
-
- 需要分批次爬取
|
|
1082
|
-
|
|
1083
|
-
#### Q: 如何提高爬取速度?
|
|
1084
|
-
**A:**
|
|
1085
|
-
1. 增加workers数量(推荐5-8个)
|
|
1086
|
-
2. 降低rateLimit(200-300ms)
|
|
1087
|
-
3. 确保站点有llms.txt(自动检测)
|
|
1088
|
-
|
|
1089
|
-
#### Q: 生成的Skill质量不够怎么办?
|
|
1090
|
-
**A:**
|
|
1091
|
-
1. 增加maxPages(建议200+)
|
|
1092
|
-
2. 调整maxDepth(建议3-5)
|
|
1093
|
-
3. 使用includePaths精确指定路径
|
|
1094
|
-
4. 查看日志中的质量指标建议
|
|
1095
|
-
|
|
1096
|
-
### 性能提示
|
|
1097
|
-
|
|
1098
|
-
**🚀 极速模式(适合快速探索):**
|
|
1099
|
-
```json
|
|
1100
|
-
{
|
|
1101
|
-
"workers": 5,
|
|
1102
|
-
"maxPages": 50,
|
|
1103
|
-
"rateLimit": 200,
|
|
1104
|
-
"crawlStrategy": "bfs"
|
|
1105
|
-
}
|
|
900
|
+
# 2. Configure in Cursor
|
|
901
|
+
# 3. Test end-to-end
|
|
1106
902
|
```
|
|
1107
903
|
|
|
1108
|
-
|
|
1109
|
-
```json
|
|
1110
|
-
{
|
|
1111
|
-
"workers": 5,
|
|
1112
|
-
"maxPages": 300,
|
|
1113
|
-
"maxDepth": 5,
|
|
1114
|
-
"crawlStrategy": "dfs",
|
|
1115
|
-
"checkpoint": { "enabled": true }
|
|
1116
|
-
}
|
|
1117
|
-
```
|
|
904
|
+
## License
|
|
1118
905
|
|
|
1119
|
-
|
|
1120
|
-
```json
|
|
1121
|
-
{
|
|
1122
|
-
"workers": 8,
|
|
1123
|
-
"skipLlmsTxt": false,
|
|
1124
|
-
"rateLimit": 200
|
|
1125
|
-
}
|
|
1126
|
-
```
|
|
906
|
+
MIT
|
|
1127
907
|
|
|
1128
|
-
|
|
908
|
+
## Related Projects
|
|
1129
909
|
|
|
1130
|
-
-
|
|
1131
|
-
-
|
|
1132
|
-
-
|
|
1133
|
-
- **原始文档爬取指南**:`docs/DOC_CRAWLER_USAGE.md`
|
|
910
|
+
- **@gulibs/safe-coder-cli** - Standalone documentation crawler
|
|
911
|
+
- **Cursor** - AI-powered code editor
|
|
912
|
+
- **Model Context Protocol (MCP)** - Protocol for AI tool integration
|
|
1134
913
|
|
|
1135
|
-
|
|
914
|
+
## Support
|
|
1136
915
|
|
|
1137
|
-
|
|
916
|
+
Issues: https://github.com/gulibs/safe-coder/issues
|
|
917
|
+
Discord: [Link TBD]
|
|
1138
918
|
|
|
1139
|
-
|
|
919
|
+
---
|
|
1140
920
|
|
|
1141
|
-
|
|
921
|
+
**Safe Coder** - Bringing documentation intelligence to your AI coding assistant.
|