@cobola/dsh-geo 0.7.0 → 0.8.0
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/CHANGELOG.md +21 -0
- package/README.md +7 -3
- package/bin/dsh-geo-mcp.js +31 -0
- package/bin/dsh-geo.js +19 -0
- package/docs/CI.md +1 -1
- package/docs/MCP.md +67 -0
- package/docs/index.json +1 -1
- package/examples/geo-audit.yml +1 -1
- package/examples/geo-baseline.yml +1 -1
- package/lib/mcp-summary.js +71 -0
- package/lib/mcp.js +294 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0 - 2026-11-29
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Add a zero-dependency MCP server (`dsh-geo mcp`, plus the `dsh-geo-mcp`
|
|
8
|
+
binary) exposing `geo_scan`, `geo_fix_plan` and `geo_history` over stdio
|
|
9
|
+
JSON-RPC, so MCP clients such as Cursor and Claude Code can audit a workspace
|
|
10
|
+
directly.
|
|
11
|
+
- `geo_scan` over MCP persists reports by default, since the usual next call is
|
|
12
|
+
`geo_fix_plan`, which reads the saved audit.
|
|
13
|
+
|
|
14
|
+
### Design notes
|
|
15
|
+
|
|
16
|
+
- The stdio transport is implemented directly rather than through the official
|
|
17
|
+
SDK: the protocol surface used here is small, and the SDK brings ~6 MB plus
|
|
18
|
+
express, hono and ajv, which conflicts with the project's auditable,
|
|
19
|
+
minimal-dependency stance.
|
|
20
|
+
- Tool failures return `isError: true` results rather than protocol errors, so a
|
|
21
|
+
model can read the reason and decide what to do next.
|
|
22
|
+
|
|
23
|
+
|
|
3
24
|
## 0.7.0 - 2026-11-29
|
|
4
25
|
|
|
5
26
|
### Features
|
package/README.md
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
| 会话内结果卡 | 模型调用 `geo_scan` / `geo_fix_plan` 后,对话中直接显示分数、五维、平台参考分与优先修复,不用另开页面 |
|
|
24
24
|
| `geo_fix_plan`(DSH 工具) | 把最近一次(或指定的)报告变成按影响力排序的修复清单 |
|
|
25
25
|
| **设置 → GEO 体检**(面板) | 修改抓取页数、robots 策略、限速、超时、体积上限、报告目录、私有目标开关 |
|
|
26
|
-
| CLI(`dsh-geo`) | `scan` / `fix-plan` / `history` / `diff`,支持 `--json` 与 `--fail-under
|
|
26
|
+
| CLI(`dsh-geo`) | `scan` / `ci` / `mcp` / `fix-plan` / `history` / `diff`,支持 `--json` 与 `--fail-under` |
|
|
27
|
+
| MCP server | `npx -y @cobola/dsh-geo mcp`,给 Cursor / Claude Code 等客户端直接调用 |
|
|
27
28
|
|
|
28
29
|
报告固定在会话工作区的 `.dsh-geo/` 下;报告可能包含页面正文摘录,上传 CI artifact 前请先审阅内容:
|
|
29
30
|
|
|
@@ -166,7 +167,7 @@ dsh-geo ci https://journal123.com \
|
|
|
166
167
|
|
|
167
168
|
```yaml
|
|
168
169
|
- uses: actions/checkout@v4
|
|
169
|
-
- uses: cobola/dsh-geo@v0.
|
|
170
|
+
- uses: cobola/dsh-geo@v0.8.0
|
|
170
171
|
with:
|
|
171
172
|
url: https://journal123.com
|
|
172
173
|
baseline: geo-baseline.json
|
|
@@ -241,7 +242,7 @@ fixture 基线(参考时间 `2026-06-15T00:00:00Z`,由测试锁定):
|
|
|
241
242
|
## 开发与发布
|
|
242
243
|
|
|
243
244
|
```sh
|
|
244
|
-
npm test # 运行完整测试套件,验证规则、平台、CI、工具、存储、面板、CLI 与安全边界
|
|
245
|
+
npm test # 运行完整测试套件,验证规则、平台、CI、MCP、工具、存储、面板、CLI 与安全边界
|
|
245
246
|
npm run docs # 规则改动后重新生成 docs/RULES.md
|
|
246
247
|
```
|
|
247
248
|
|
|
@@ -259,6 +260,9 @@ lib/scan.js 抓取流程
|
|
|
259
260
|
lib/rules.js 45 条 Core 规则(唯一事实源)
|
|
260
261
|
lib/platforms/ 平台 profile(Bing、百度、OpenAI、Perplexity 已实现)
|
|
261
262
|
lib/ci.js CI 审计、基线与质量门禁
|
|
263
|
+
lib/mcp.js stdio MCP server(零依赖手写 JSON-RPC)
|
|
264
|
+
bin/dsh-geo-mcp.js MCP 二进制入口
|
|
265
|
+
docs/MCP.md MCP 用法与协议行为
|
|
262
266
|
action.yml GitHub composite action
|
|
263
267
|
lib/score.js 评分聚合(纯函数)
|
|
264
268
|
lib/report.js 报告/修复清单/diff 生成
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MCP server entry point.
|
|
4
|
+
*
|
|
5
|
+
* Register it with any MCP client (Cursor, Claude Code, …):
|
|
6
|
+
*
|
|
7
|
+
* { "command": "npx", "args": ["-y", "@cobola/dsh-geo", "mcp"] }
|
|
8
|
+
*
|
|
9
|
+
* Reports are written to `<cwd>/.dsh-geo/`, so run the client in the workspace
|
|
10
|
+
* you want audited.
|
|
11
|
+
*/
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
|
|
14
|
+
import { serve } from '../lib/mcp.js';
|
|
15
|
+
|
|
16
|
+
const log = (text) => process.stderr.write(`${text}\n`);
|
|
17
|
+
|
|
18
|
+
serve({
|
|
19
|
+
input: process.stdin,
|
|
20
|
+
output: process.stdout,
|
|
21
|
+
cwd: process.cwd(),
|
|
22
|
+
log,
|
|
23
|
+
}).then(
|
|
24
|
+
() => { process.exitCode = 0; },
|
|
25
|
+
(error) => {
|
|
26
|
+
log(`dsh-geo mcp: ${error && error.message ? error.message : String(error)}`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
log(`dsh-geo mcp: serving stdio in ${path.resolve(process.cwd())}`);
|
package/bin/dsh-geo.js
CHANGED
|
@@ -26,11 +26,17 @@ const HELP = `dsh-geo ${version} — deterministic GEO/SEO audit
|
|
|
26
26
|
Usage:
|
|
27
27
|
dsh-geo scan <url> [options]
|
|
28
28
|
dsh-geo ci <url> [options]
|
|
29
|
+
dsh-geo mcp Serve the Model Context Protocol over stdio.
|
|
29
30
|
dsh-geo fix-plan [options]
|
|
30
31
|
dsh-geo history [options]
|
|
31
32
|
dsh-geo diff <before.json> <after.json> [--json]
|
|
32
33
|
dsh-geo --help | --version
|
|
33
34
|
|
|
35
|
+
mcp:
|
|
36
|
+
Runs an MCP stdio server exposing geo_scan, geo_fix_plan and geo_history.
|
|
37
|
+
Register it in an MCP client as: npx -y @cobola/dsh-geo mcp
|
|
38
|
+
Reports are written to <cwd>/.dsh-geo/ for the directory you start it in.
|
|
39
|
+
|
|
34
40
|
ci options (for CI jobs):
|
|
35
41
|
--baseline <path> Compare against a committed baseline report.
|
|
36
42
|
--fail-under <score> Exit 3 when the total is below this score.
|
|
@@ -390,9 +396,22 @@ async function commandCi(positionals, options) {
|
|
|
390
396
|
return result.exitCode;
|
|
391
397
|
}
|
|
392
398
|
|
|
399
|
+
async function commandMcp(positionals, options) {
|
|
400
|
+
if (positionals.length > 0) throw new Error(`Unexpected argument: ${positionals[0]}`);
|
|
401
|
+
const { serve } = await import('../lib/mcp.js');
|
|
402
|
+
await serve({
|
|
403
|
+
input: process.stdin,
|
|
404
|
+
output: process.stdout,
|
|
405
|
+
cwd: process.cwd(),
|
|
406
|
+
log: (text) => process.stderr.write(`${text}\n`),
|
|
407
|
+
});
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
393
411
|
const COMMANDS = {
|
|
394
412
|
scan: commandScan,
|
|
395
413
|
ci: commandCi,
|
|
414
|
+
mcp: commandMcp,
|
|
396
415
|
'fix-plan': commandFixPlan,
|
|
397
416
|
history: commandHistory,
|
|
398
417
|
diff: commandDiff,
|
package/docs/CI.md
CHANGED
package/docs/MCP.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# 用 MCP 客户端调用 dsh-geo
|
|
2
|
+
|
|
3
|
+
`dsh-geo` 自带一个 stdio MCP server,Cursor、Claude Code 等支持 MCP 的客户端可以直接调用它的工具。
|
|
4
|
+
|
|
5
|
+
## 为什么不用官方 SDK
|
|
6
|
+
|
|
7
|
+
MCP 的 stdio 传输就是 stdin/stdout 上的换行分隔 JSON-RPC 2.0。官方 `@modelcontextprotocol/sdk` 约 6 MB,还带 express、hono、ajv 等依赖。这个项目的原则是最小依赖、每一行可审计,所以 server 是手写的([lib/mcp.js](../lib/mcp.js)),零新增依赖。
|
|
8
|
+
|
|
9
|
+
## 注册
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"mcpServers": {
|
|
14
|
+
"dsh-geo": {
|
|
15
|
+
"command": "npx",
|
|
16
|
+
"args": ["-y", "@cobola/dsh-geo", "mcp"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
或全局安装后用二进制:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm install -g @cobola/dsh-geo
|
|
26
|
+
dsh-geo-mcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
报告写入**启动目录**下的 `.dsh-geo/`,所以请在你要体检的工作区里启动客户端。
|
|
30
|
+
|
|
31
|
+
## 提供的工具
|
|
32
|
+
|
|
33
|
+
| 工具 | 作用 |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `geo_scan` | 审计一个站点,返回分数、五维、平台参考分与优先修复 |
|
|
36
|
+
| `geo_fix_plan` | 把最近一次审计变成有序修复清单,写入 `.dsh-geo/` |
|
|
37
|
+
| `geo_history` | 列出本工作区最近的审计记录 |
|
|
38
|
+
|
|
39
|
+
`geo_scan` 默认落盘(`save: false` 可关),因为客户端下一步通常就是 `geo_fix_plan`,它需要读持久化的报告。
|
|
40
|
+
|
|
41
|
+
## 协议行为
|
|
42
|
+
|
|
43
|
+
- init、`tools/list`、`tools/call`、`ping` 全部实现;
|
|
44
|
+
- 通知(无 `id`)永不回应;
|
|
45
|
+
- 未知方法返回 `-32601`,参数错误返回 `-32602`;
|
|
46
|
+
- **工具执行失败是一个 `isError: true` 的结果,不是协议错误**——模型需要读到失败原因再决定下一步;
|
|
47
|
+
- stdout 只走协议消息,日志全部走 stderr。
|
|
48
|
+
|
|
49
|
+
## 安全边界
|
|
50
|
+
|
|
51
|
+
MCP server 沿用引擎的默认策略:
|
|
52
|
+
|
|
53
|
+
- 只允许公网 http(s);
|
|
54
|
+
- 拒绝回环、私网、CGNAT、NAT64/6to4/Teredo 与云元数据地址;
|
|
55
|
+
- 默认遵守 robots.txt;
|
|
56
|
+
- 限额 6 页 / 1.5 MB / 10 秒 / 同主机 250 ms。
|
|
57
|
+
|
|
58
|
+
`allowPrivate` 与 `insecureTls` 只存在于测试上下文,stdio server 不会开启它们——外部 MCP 客户端无法借此访问你的内网。
|
|
59
|
+
|
|
60
|
+
## 它不做什么
|
|
61
|
+
|
|
62
|
+
- 不测排名、流量或 AI 引用;
|
|
63
|
+
- 不修改被审计的站点;
|
|
64
|
+
- 不执行 JavaScript;
|
|
65
|
+
- 不保证任何平台会引用你的页面。
|
|
66
|
+
|
|
67
|
+
平台分(Bing、百度、OpenAI、Perplexity)单独展示,且每个 profile 都写明该平台哪些规则没有公开。
|
package/docs/index.json
CHANGED
package/examples/geo-audit.yml
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing text for one audit.
|
|
3
|
+
*
|
|
4
|
+
* An MCP client shows this text to a model, so it has to be compact, factual
|
|
5
|
+
* and explicit about what the numbers mean. The same facts also exist as JSON
|
|
6
|
+
* in `.dsh-geo/latest.json` for anything that wants to parse them.
|
|
7
|
+
*/
|
|
8
|
+
const STATUS_LABEL = {
|
|
9
|
+
pass: 'pass',
|
|
10
|
+
warn: 'partial',
|
|
11
|
+
fail: 'fail',
|
|
12
|
+
skip: 'n/a',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {object} scan - Scan artifact.
|
|
17
|
+
* @param {object} report - Score report.
|
|
18
|
+
* @returns {string} Markdown-ish plain text for a model.
|
|
19
|
+
*/
|
|
20
|
+
export function summariseScanForModel(scan, report) {
|
|
21
|
+
const lines = [];
|
|
22
|
+
lines.push(`Website visibility audit — ${scan.startUrl}`);
|
|
23
|
+
lines.push(`Score: ${report.total}/100 (${report.grade} ${report.gradeLabel}) across ${scan.stats.pages} page(s)`);
|
|
24
|
+
lines.push(`Checks: ${report.counts.pass} pass / ${report.counts.warn} partial / ${report.counts.fail} fail / ${report.counts.skip} n/a`);
|
|
25
|
+
lines.push('');
|
|
26
|
+
|
|
27
|
+
lines.push('Dimensions:');
|
|
28
|
+
for (const dimension of report.dimensions) {
|
|
29
|
+
lines.push(`- ${dimension.title}: ${dimension.score} (weight ${dimension.weight})`);
|
|
30
|
+
}
|
|
31
|
+
lines.push('');
|
|
32
|
+
|
|
33
|
+
const platforms = report.platforms ?? [];
|
|
34
|
+
if (platforms.length > 0) {
|
|
35
|
+
lines.push('Platform reference scores (these do NOT contribute to the score above):');
|
|
36
|
+
for (const platform of platforms) {
|
|
37
|
+
lines.push(`- ${platform.title}: ${platform.total}`);
|
|
38
|
+
}
|
|
39
|
+
for (const platform of platforms) {
|
|
40
|
+
if (platform.limitation) lines.push(` note (${platform.title}): ${platform.limitation}`);
|
|
41
|
+
}
|
|
42
|
+
lines.push('');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (report.blockedByRobots) {
|
|
46
|
+
lines.push('robots.txt refused this audit, so no pages were fetched. Fix robots or get owner approval before re-running.');
|
|
47
|
+
lines.push('');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (report.actions.length > 0) {
|
|
51
|
+
lines.push('Failures and partial results, highest impact first:');
|
|
52
|
+
report.actions.forEach((action, index) => {
|
|
53
|
+
lines.push(`${index + 1}. [${action.dimensionTitle} ${action.weight}] ${action.title} — ${action.evidence}`);
|
|
54
|
+
lines.push(` fix: ${action.fix}`);
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
lines.push('Every check passed.');
|
|
58
|
+
}
|
|
59
|
+
lines.push('');
|
|
60
|
+
|
|
61
|
+
const failing = report.findings.filter((finding) => finding.status === 'fail' || finding.status === 'warn');
|
|
62
|
+
if (failing.length > report.actions.length) {
|
|
63
|
+
lines.push(`(${failing.length - report.actions.length} more checks need attention; see .dsh-geo/latest.json)`);
|
|
64
|
+
lines.push('');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
lines.push('This is a readiness report on crawlable structure. It does not measure rankings, traffic, or whether any AI product cites the page.');
|
|
68
|
+
return lines.join('\n');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { STATUS_LABEL };
|
package/lib/mcp.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MCP server over stdio.
|
|
3
|
+
*
|
|
4
|
+
* The Model Context Protocol's stdio transport is newline-delimited JSON-RPC
|
|
5
|
+
* 2.0 on stdin/stdout, so a server needs no SDK: the handshake, tool listing and
|
|
6
|
+
* tool calls are a handful of methods. Implementing them here keeps the package
|
|
7
|
+
* dependency-free and every line auditable, which matches the rest of the
|
|
8
|
+
* project — a 6 MB SDK with express and hono would not.
|
|
9
|
+
*
|
|
10
|
+
* Protocol notes that matter for correctness:
|
|
11
|
+
* - stdout carries protocol messages only; logs and errors go to stderr, or
|
|
12
|
+
* they corrupt the stream.
|
|
13
|
+
* - an initialize request must be answered before any other request.
|
|
14
|
+
* - a notification has no `id` and must never be answered.
|
|
15
|
+
* - unknown tools and bad arguments are reported as tool results with
|
|
16
|
+
* `isError: true`, not as protocol errors; protocol errors are for malformed
|
|
17
|
+
* JSON-RPC envelopes.
|
|
18
|
+
*/
|
|
19
|
+
import { auditSite, persistAudit, planFromReport } from './audit.js';
|
|
20
|
+
import { summariseScanForModel } from './mcp-summary.js';
|
|
21
|
+
|
|
22
|
+
export const PROTOCOL_VERSION = '2024-11-05';
|
|
23
|
+
export const SERVER_INFO = { name: 'dsh-geo', version: '1.0.0' };
|
|
24
|
+
|
|
25
|
+
const PARSE_ERROR = -32700;
|
|
26
|
+
const INVALID_REQUEST = -32600;
|
|
27
|
+
const METHOD_NOT_FOUND = -32601;
|
|
28
|
+
const INVALID_PARAMS = -32602;
|
|
29
|
+
const INTERNAL_ERROR = -32603;
|
|
30
|
+
|
|
31
|
+
/** Tool definitions advertised to the client. */
|
|
32
|
+
export const MCP_TOOLS = [
|
|
33
|
+
{
|
|
34
|
+
name: 'geo_scan',
|
|
35
|
+
description:
|
|
36
|
+
'Audit a public website for GEO/SEO readiness. Fetches raw HTML only, honors robots.txt by default, refuses private and cloud-metadata destinations, and rate-limits requests. Returns a reproducible score with evidence across five dimensions plus platform reference scores and prioritized fixes. It never edits the site or measures rankings, traffic or AI citations.',
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
url: { type: 'string', description: 'Absolute http(s) URL of the site entry page.' },
|
|
41
|
+
max_pages: { type: 'integer', minimum: 1, maximum: 50, description: 'Pages to crawl (default 6).' },
|
|
42
|
+
now: { type: 'string', description: 'ISO-8601 reference time for freshness checks. Reuse one value across runs so results stay comparable.' },
|
|
43
|
+
save: { type: 'boolean', description: 'Write reports into the workspace .dsh-geo/ directory (default true).' },
|
|
44
|
+
},
|
|
45
|
+
required: ['url'],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'geo_fix_plan',
|
|
50
|
+
description:
|
|
51
|
+
'Turn the latest saved audit into an ordered repair plan. Writes fix-plan.md and fix-plan.json into the workspace .dsh-geo/ directory. It does not change the site; apply the fixes in your own workflow and re-run geo_scan to verify.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
report_path: { type: 'string', description: 'Path to a saved report inside the workspace. Defaults to the newest audit.' },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'geo_history',
|
|
61
|
+
description: 'List recent saved audits for this workspace, newest first, with totals and grades.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
limit: { type: 'integer', minimum: 1, maximum: 50, description: 'Entries to return (default 10).' },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
function errorMessage(error) {
|
|
72
|
+
return error && error.message ? error.message : String(error);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function assertString(value, name) {
|
|
76
|
+
if (typeof value !== 'string' || value.trim() === '') throw new Error(`${name} must be a non-empty string`);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Run one tool call.
|
|
82
|
+
* @param {string} name - Tool name from the client.
|
|
83
|
+
* @param {object} args - Parsed arguments.
|
|
84
|
+
* @param {{cwd: string, allowPrivate?: boolean, insecureTls?: boolean}} context - Workspace root for
|
|
85
|
+
* reports. `allowPrivate` exists for local fixtures only; the stdio server
|
|
86
|
+
* never sets it, so a public MCP client cannot reach loopback addresses.
|
|
87
|
+
* @returns {Promise<{content: Array<{type: string, text: string}>, isError?: boolean}>}
|
|
88
|
+
*/
|
|
89
|
+
export async function callTool(name, args, context) {
|
|
90
|
+
const input = args !== null && typeof args === 'object' ? args : {};
|
|
91
|
+
const { cwd } = context;
|
|
92
|
+
|
|
93
|
+
if (name === 'geo_scan') {
|
|
94
|
+
const url = assertString(input.url, 'url');
|
|
95
|
+
if (input.max_pages !== undefined && (!Number.isInteger(input.max_pages) || input.max_pages < 1 || input.max_pages > 50)) {
|
|
96
|
+
throw new Error('max_pages must be an integer between 1 and 50');
|
|
97
|
+
}
|
|
98
|
+
if (input.now !== undefined && !Number.isFinite(Date.parse(input.now))) {
|
|
99
|
+
throw new Error('now must be an ISO-8601 timestamp');
|
|
100
|
+
}
|
|
101
|
+
const { scan, report } = await auditSite(url, {
|
|
102
|
+
maxPages: input.max_pages,
|
|
103
|
+
now: input.now ?? undefined,
|
|
104
|
+
allowPrivate: context.allowPrivate === true,
|
|
105
|
+
insecureTls: context.insecureTls === true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Save by default: an MCP client's next call is usually geo_fix_plan, which
|
|
109
|
+
// reads the persisted report. `save: false` keeps a pure snapshot.
|
|
110
|
+
let persisted = null;
|
|
111
|
+
if (input.save !== false) {
|
|
112
|
+
persisted = await persistAudit(cwd, { scan, report });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const text = summariseScanForModel(scan, report);
|
|
116
|
+
return {
|
|
117
|
+
content: [{
|
|
118
|
+
type: 'text',
|
|
119
|
+
text: persisted
|
|
120
|
+
? `${text}\n\nSaved to .dsh-geo/latest.json (report: .dsh-geo/report.md)`
|
|
121
|
+
: `${text}\n\nNot saved (save: false).`,
|
|
122
|
+
}],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (name === 'geo_fix_plan') {
|
|
127
|
+
const { payload, plan } = await planFromReport(cwd, {
|
|
128
|
+
reportPath: input.report_path ? assertString(input.report_path, 'report_path') : undefined,
|
|
129
|
+
});
|
|
130
|
+
const lines = [
|
|
131
|
+
`Fix plan for ${payload.url ?? payload.score.startUrl} — ${payload.score.total}/100 (${payload.score.grade})`,
|
|
132
|
+
`${plan.actions.length} action(s). Wrote .dsh-geo/fix-plan.md and .dsh-geo/fix-plan.json.`,
|
|
133
|
+
'',
|
|
134
|
+
];
|
|
135
|
+
plan.actions.slice(0, 10).forEach((action, index) => {
|
|
136
|
+
lines.push(`${index + 1}. [${action.dimensionTitle} ${action.weight}] ${action.title}`);
|
|
137
|
+
lines.push(` evidence: ${action.evidence}`);
|
|
138
|
+
lines.push(` fix: ${action.fix}`);
|
|
139
|
+
});
|
|
140
|
+
if (plan.actions.length > 10) lines.push(`… ${plan.actions.length - 10} more in fix-plan.md`);
|
|
141
|
+
lines.push('');
|
|
142
|
+
lines.push('This tool did not change the site. Apply the fixes in your own workflow, then run geo_scan again.');
|
|
143
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (name === 'geo_history') {
|
|
147
|
+
const limit = input.limit === undefined ? 10 : input.limit;
|
|
148
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 50) throw new Error('limit must be an integer between 1 and 50');
|
|
149
|
+
const { listAudits, resolveStoreDir } = await import('./store.js');
|
|
150
|
+
const entries = await listAudits(resolveStoreDir(cwd), limit);
|
|
151
|
+
if (entries.length === 0) {
|
|
152
|
+
return { content: [{ type: 'text', text: 'No saved audits in this workspace yet. Run geo_scan first.' }] };
|
|
153
|
+
}
|
|
154
|
+
const lines = [`Recent audits (${entries.length}):`, ''];
|
|
155
|
+
for (const entry of entries) {
|
|
156
|
+
lines.push(`${entry.savedAt ?? 'unknown time'} ${entry.total} ${entry.grade} ${entry.url ?? ''}`);
|
|
157
|
+
}
|
|
158
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Handle one JSON-RPC message.
|
|
166
|
+
*
|
|
167
|
+
* @param {object} message - Parsed request or notification.
|
|
168
|
+
* @param {{cwd: string, initialized: {value: boolean}}} state - Server state.
|
|
169
|
+
* @returns {Promise<object|null>} Response, or null for a notification.
|
|
170
|
+
*/
|
|
171
|
+
export async function handleMessage(message, state) {
|
|
172
|
+
const isNotification = message.id === undefined || message.id === null;
|
|
173
|
+
|
|
174
|
+
if (message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
|
|
175
|
+
if (isNotification) return null;
|
|
176
|
+
return {
|
|
177
|
+
jsonrpc: '2.0',
|
|
178
|
+
id: message.id ?? null,
|
|
179
|
+
error: { code: INVALID_REQUEST, message: 'Expected a JSON-RPC 2.0 request' },
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const reply = (result) => (isNotification ? null : { jsonrpc: '2.0', id: message.id, result });
|
|
184
|
+
const fail = (code, text) => (isNotification ? null : { jsonrpc: '2.0', id: message.id, error: { code, message: text } });
|
|
185
|
+
|
|
186
|
+
switch (message.method) {
|
|
187
|
+
case 'initialize': {
|
|
188
|
+
state.initialized.value = true;
|
|
189
|
+
return reply({
|
|
190
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
191
|
+
capabilities: { tools: { listChanged: false } },
|
|
192
|
+
serverInfo: SERVER_INFO,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
case 'notifications/initialized':
|
|
197
|
+
case 'notifications/cancelled':
|
|
198
|
+
return null;
|
|
199
|
+
|
|
200
|
+
case 'ping':
|
|
201
|
+
return reply({});
|
|
202
|
+
|
|
203
|
+
case 'tools/list':
|
|
204
|
+
return reply({ tools: MCP_TOOLS });
|
|
205
|
+
|
|
206
|
+
case 'tools/call': {
|
|
207
|
+
const params = message.params ?? {};
|
|
208
|
+
const name = params.name;
|
|
209
|
+
if (typeof name !== 'string') return fail(INVALID_PARAMS, 'tools/call requires a tool name');
|
|
210
|
+
try {
|
|
211
|
+
const result = await callTool(name, params.arguments ?? {}, {
|
|
212
|
+
cwd: state.cwd,
|
|
213
|
+
allowPrivate: state.allowPrivate === true,
|
|
214
|
+
insecureTls: state.insecureTls === true,
|
|
215
|
+
});
|
|
216
|
+
return reply(result);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
// A tool failure is a result, not a protocol error: the model needs to
|
|
219
|
+
// read it and decide what to do next.
|
|
220
|
+
return reply({ content: [{ type: 'text', text: `Error: ${errorMessage(error)}` }], isError: true });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
default:
|
|
225
|
+
return fail(METHOD_NOT_FOUND, `Unsupported method: ${message.method}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Serve MCP over a pair of streams.
|
|
231
|
+
*
|
|
232
|
+
* @param {object} options
|
|
233
|
+
* @param {NodeJS.ReadableStream} options.input - Usually process.stdin.
|
|
234
|
+
* @param {NodeJS.WritableStream} options.output - Usually process.stdout.
|
|
235
|
+
* @param {string} options.cwd - Workspace root for reports.
|
|
236
|
+
* @param {(text: string) => void} [options.log] - Diagnostics sink (stderr).
|
|
237
|
+
* @returns {Promise<void>} Resolves when the input stream ends.
|
|
238
|
+
*/
|
|
239
|
+
export function serve({ input, output, cwd, log = () => {}, allowPrivate = false, insecureTls = false }) {
|
|
240
|
+
const state = { cwd, allowPrivate, insecureTls, initialized: { value: false } };
|
|
241
|
+
let buffer = '';
|
|
242
|
+
|
|
243
|
+
const write = (message) => {
|
|
244
|
+
output.write(`${JSON.stringify(message)}\n`);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const handleLine = async (line) => {
|
|
248
|
+
const trimmed = line.trim();
|
|
249
|
+
if (trimmed === '') return;
|
|
250
|
+
let message;
|
|
251
|
+
try {
|
|
252
|
+
message = JSON.parse(trimmed);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
write({ jsonrpc: '2.0', id: null, error: { code: PARSE_ERROR, message: `Invalid JSON: ${errorMessage(error)}` } });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (Array.isArray(message)) {
|
|
258
|
+
write({ jsonrpc: '2.0', id: null, error: { code: INVALID_REQUEST, message: 'Batch requests are not supported' } });
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
const response = await handleMessage(message, state);
|
|
263
|
+
if (response) write(response);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
log(`dsh-geo mcp: ${errorMessage(error)}`);
|
|
266
|
+
write({
|
|
267
|
+
jsonrpc: '2.0',
|
|
268
|
+
id: message && message.id !== undefined ? message.id : null,
|
|
269
|
+
error: { code: INTERNAL_ERROR, message: errorMessage(error) },
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
return new Promise((resolve) => {
|
|
275
|
+
let chain = Promise.resolve();
|
|
276
|
+
input.setEncoding?.('utf8');
|
|
277
|
+
input.on('data', (chunk) => {
|
|
278
|
+
buffer += chunk;
|
|
279
|
+
let index = buffer.indexOf('\n');
|
|
280
|
+
while (index !== -1) {
|
|
281
|
+
const line = buffer.slice(0, index);
|
|
282
|
+
buffer = buffer.slice(index + 1);
|
|
283
|
+
// Serialize handling so responses stay ordered.
|
|
284
|
+
chain = chain.then(() => handleLine(line));
|
|
285
|
+
index = buffer.indexOf('\n');
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
input.on('end', () => {
|
|
289
|
+
if (buffer.trim() !== '') chain = chain.then(() => handleLine(buffer));
|
|
290
|
+
chain.then(resolve, resolve);
|
|
291
|
+
});
|
|
292
|
+
input.on('error', () => chain.then(resolve, resolve));
|
|
293
|
+
});
|
|
294
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobola/dsh-geo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Read-only, reproducible GEO/SEO website audits for DeepSeek Harness: inspect crawlability and citation-ready structure, return evidence and prioritized fixes, and never edit the site or promise rankings.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"./icon": "./icon.svg"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
25
|
-
"dsh-geo": "bin/dsh-geo.js"
|
|
25
|
+
"dsh-geo": "bin/dsh-geo.js",
|
|
26
|
+
"dsh-geo-mcp": "bin/dsh-geo-mcp.js"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"index.js",
|