@nitpicker/mcp-server 0.12.0 → 0.13.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/README.md CHANGED
@@ -1,35 +1,12 @@
1
1
  # @nitpicker/mcp-server
2
2
 
3
- `.nitpicker` アーカイブファイルを AI アシスタントから操作するための MCP サーバー。
3
+ `.nitpicker` アーカイブを Model Context Protocol (MCP) 経由で問い合わせるためのサーバーです。
4
4
 
5
- ## 概要
6
-
7
- [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) を介して、`.nitpicker` アーカイブの内容を AI アシスタント(Claude Desktop 等)から直接クエリできるサーバーです。stdio トランスポートで動作し、14 のツールを提供します。
8
-
9
- 内部では `@nitpicker/query` パッケージのクエリ関数を呼び出しています。
10
-
11
- ### 提供ツール
12
-
13
- | ツール | 説明 |
14
- | ------------------------ | ---------------------------------------------------- |
15
- | `open_archive` | `.nitpicker` ファイルを読み込み、archiveId を返す |
16
- | `close_archive` | アーカイブを閉じてリソースを解放 |
17
- | `get_summary` | サイト全体の概要統計 |
18
- | `list_pages` | ページ一覧(フィルタ・ソート・ページネーション対応) |
19
- | `get_page_detail` | 特定ページの詳細情報 |
20
- | `get_page_html` | HTML スナップショットの取得 |
21
- | `list_links` | リンク分析(壊れたリンク、外部リンク、孤立ページ) |
22
- | `list_resources` | サブリソース一覧(CSS、JS、画像、フォント) |
23
- | `list_images` | 画像品質チェック(alt 欠落、サイズ欠落、過大画像) |
24
- | `get_violations` | 分析プラグインの違反結果 |
25
- | `find_duplicates` | メタデータ重複検出 |
26
- | `find_mismatches` | メタデータ不一致検出 |
27
- | `get_resource_referrers` | リソース参照元ページの検出 |
28
- | `check_headers` | セキュリティヘッダー確認 |
5
+ 内部では [@nitpicker/query](../query/README.md) を使い、AIアシスタントなどからアーカイブ内容を参照できるようにします。
29
6
 
30
7
  ## セットアップ
31
8
 
32
- Claude Desktop の設定ファイルに以下を追加してください。
9
+ Claude Desktop の設定ファイルに以下を追加します。
33
10
 
34
11
  ```json
35
12
  {
@@ -42,7 +19,28 @@ Claude Desktop の設定ファイルに以下を追加してください。
42
19
  }
43
20
  ```
44
21
 
45
- このパッケージは [Nitpicker](../../README.md) モノレポの内部パッケージです。
22
+ stdio トランスポートで起動し、`.nitpicker` アーカイブを開いてページ、リンク、リソース、分析結果などを問い合わせます。
23
+
24
+ ## 主なツール
25
+
26
+ | ツール | 説明 |
27
+ | ----------------- | -------------------------------------------- |
28
+ | `open_archive` | `.nitpicker` ファイルを開き、archiveIdを返す |
29
+ | `close_archive` | アーカイブを閉じる |
30
+ | `get_summary` | サイト全体の概要統計 |
31
+ | `list_pages` | ページ一覧 |
32
+ | `get_page_detail` | 指定ページの詳細 |
33
+ | `get_page_html` | HTMLスナップショット |
34
+ | `list_links` | リンク一覧 |
35
+ | `list_resources` | リソース一覧 |
36
+ | `list_images` | 画像一覧 |
37
+ | `get_violations` | 分析プラグインの違反結果 |
38
+
39
+ ## 関連リンク
40
+
41
+ - [Nitpicker README](../../../README.md)
42
+ - [CLI query docs](../cli/docs/query.md)
43
+ - [ARCHITECTURE.md](../../../ARCHITECTURE.md)
46
44
 
47
45
  ## ライセンス
48
46
 
@@ -3,7 +3,15 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  * Creates and configures the Nitpicker MCP server with all tools registered.
4
4
  * Uses the low-level Server API to avoid deep type instantiation issues
5
5
  * with McpServer + Zod schemas.
6
- * @returns The configured Server instance.
6
+ * @returns The configured Server instance. Connect it to a transport to start serving.
7
+ * @example
8
+ * ```ts
9
+ * import { createServer } from '@nitpicker/mcp-server';
10
+ * import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
11
+ *
12
+ * const server = createServer();
13
+ * await server.connect(new StdioServerTransport());
14
+ * ```
7
15
  */
8
16
  export declare function createServer(): Server<{
9
17
  method: string;
@@ -42,5 +50,13 @@ export declare function createServer(): Server<{
42
50
  /**
43
51
  * Starts the MCP server using stdio transport.
44
52
  * This is the entry point for the `nitpicker-mcp` binary.
53
+ * @returns Resolves once the stdio transport is connected; the server then
54
+ * keeps serving requests until the process exits.
55
+ * @example
56
+ * ```ts
57
+ * import { startServer } from '@nitpicker/mcp-server';
58
+ *
59
+ * await startServer();
60
+ * ```
45
61
  */
46
62
  export declare function startServer(): Promise<void>;
package/lib/mcp-server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
4
- import { ArchiveManager, checkHeaders, countPagesByJsonLdType, countPagesByTag, findDuplicates, findMismatches, getIsolatedCluster, getPageDetail, getPageHtml, getPageJsonLd, getPageJsonLdOverview, getPageTags, getResourceReferrers, getSummary, getTagInventory, getViolations, listImages, listIsolatedClusters, listIsolatedPages, listLinks, listPages, listPagesByJsonLdType, listPagesByTag, listResources, listUnusedResources, } from '@nitpicker/query';
4
+ import { ArchiveManager, countPagesByJsonLdType, countPagesByTag, getDuplicatesFastPath, getHeaderChecksFastPath, getImagesFastPath, getIsolatedClusterFastPath, getMismatchesFastPath, getPageDetail, getPageHtml, getPageJsonLd, getPageJsonLdOverview, getPageTags, getResourceReferrers, getSummaryFastPath, getTagInventory, getViolations, listIsolatedClustersFastPath, listIsolatedPagesFastPath, listLinks, listPages, listPagesByJsonLdType, listPagesByTag, listResources, listUnusedResources, } from '@nitpicker/query';
5
5
  import { toolDefinitions } from './tool-definitions.js';
6
6
  /**
7
7
  * Validates that a required string argument is present and returns it.
@@ -61,6 +61,23 @@ function optionalBoolean(args, key) {
61
61
  }
62
62
  throw new TypeError(`Invalid boolean for argument: ${key}`);
63
63
  }
64
+ /**
65
+ * Extracts an optional string argument with validation.
66
+ * @param args - The arguments object.
67
+ * @param key - The argument key.
68
+ * @returns The string value, or `undefined` if not present.
69
+ * @throws {TypeError} If the value is present but not a string.
70
+ */
71
+ function optionalString(args, key) {
72
+ const value = args[key];
73
+ if (value == null) {
74
+ return undefined;
75
+ }
76
+ if (typeof value !== 'string') {
77
+ throw new TypeError(`Invalid string for argument: ${key}`);
78
+ }
79
+ return value;
80
+ }
64
81
  /** Valid link analysis types. */
65
82
  const VALID_LINK_TYPES = ['broken', 'external'];
66
83
  /** Valid mismatch types. */
@@ -100,7 +117,15 @@ function omit(args, ...keys) {
100
117
  * Creates and configures the Nitpicker MCP server with all tools registered.
101
118
  * Uses the low-level Server API to avoid deep type instantiation issues
102
119
  * with McpServer + Zod schemas.
103
- * @returns The configured Server instance.
120
+ * @returns The configured Server instance. Connect it to a transport to start serving.
121
+ * @example
122
+ * ```ts
123
+ * import { createServer } from '@nitpicker/mcp-server';
124
+ * import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
125
+ *
126
+ * const server = createServer();
127
+ * await server.connect(new StdioServerTransport());
128
+ * ```
104
129
  */
105
130
  export function createServer() {
106
131
  // Route ArchiveManager warnings to stderr explicitly via process.stderr.write
@@ -114,7 +139,7 @@ export function createServer() {
114
139
  process.stderr.write(`${message}\n`);
115
140
  },
116
141
  });
117
- const server = new Server({ name: 'nitpicker', version: '0.10.0' }, { capabilities: { tools: {} } });
142
+ const server = new Server({ name: 'nitpicker', version: '0.13.0' }, { capabilities: { tools: {} } });
118
143
  server.setRequestHandler(ListToolsRequestSchema, () => Promise.resolve({ tools: toolDefinitions }));
119
144
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
120
145
  const { name } = request.params;
@@ -124,7 +149,7 @@ export function createServer() {
124
149
  case 'open_archive': {
125
150
  const filePath = requireString(args, 'filePath');
126
151
  const { archiveId, accessor, mode, crawlerLockHolder } = await manager.open(filePath);
127
- const summary = await getSummary(accessor);
152
+ const summary = await getSummaryFastPath(accessor);
128
153
  return jsonResult({
129
154
  archiveId,
130
155
  baseUrl: summary.baseUrl,
@@ -146,7 +171,7 @@ export function createServer() {
146
171
  }
147
172
  case 'get_summary': {
148
173
  const accessor = manager.get(requireString(args, 'archiveId'));
149
- return jsonResult(await getSummary(accessor));
174
+ return jsonResult(await getSummaryFastPath(accessor));
150
175
  }
151
176
  case 'list_pages': {
152
177
  const accessor = manager.get(requireString(args, 'archiveId'));
@@ -190,28 +215,54 @@ export function createServer() {
190
215
  }
191
216
  case 'list_images': {
192
217
  const accessor = manager.get(requireString(args, 'archiveId'));
193
- return jsonResult(await listImages(accessor, omit(args, 'archiveId')));
218
+ return jsonResult(await getImagesFastPath(accessor, omit(args, 'archiveId')));
194
219
  }
195
220
  case 'get_violations': {
196
221
  const accessor = manager.get(requireString(args, 'archiveId'));
197
- return jsonResult(await getViolations(accessor, omit(args, 'archiveId')));
222
+ return jsonResult(await getViolations(accessor, {
223
+ validator: optionalString(args, 'validator'),
224
+ severity: optionalString(args, 'severity'),
225
+ rule: optionalString(args, 'rule'),
226
+ urlPattern: optionalString(args, 'urlPattern'),
227
+ sortBy: optionalString(args, 'sortBy'),
228
+ sortOrder: optionalString(args, 'sortOrder'),
229
+ limit: optionalNumber(args, 'limit'),
230
+ offset: optionalNumber(args, 'offset'),
231
+ }));
198
232
  }
199
233
  case 'find_duplicates': {
200
234
  const accessor = manager.get(requireString(args, 'archiveId'));
201
235
  const field = args.field
202
236
  ? validateEnum(String(args.field), VALID_DUPLICATE_FIELDS, 'field')
203
237
  : undefined;
204
- return jsonResult(await findDuplicates(accessor, field, optionalNumber(args, 'limit')));
238
+ return jsonResult(await getDuplicatesFastPath(accessor, {
239
+ field,
240
+ limit: optionalNumber(args, 'limit'),
241
+ offset: optionalNumber(args, 'offset'),
242
+ pagesLimit: optionalNumber(args, 'pagesLimit'),
243
+ cursor: optionalString(args, 'cursor'),
244
+ }));
205
245
  }
206
246
  case 'find_mismatches': {
207
247
  const accessor = manager.get(requireString(args, 'archiveId'));
208
248
  const type = validateEnum(requireString(args, 'type'), VALID_MISMATCH_TYPES, 'mismatch type');
209
- return jsonResult(await findMismatches(accessor, type, optionalNumber(args, 'limit'), optionalNumber(args, 'offset')));
249
+ return jsonResult(await getMismatchesFastPath(accessor, type, {
250
+ limit: optionalNumber(args, 'limit'),
251
+ offset: optionalNumber(args, 'offset'),
252
+ urlPattern: optionalString(args, 'urlPattern'),
253
+ sortBy: optionalString(args, 'sortBy'),
254
+ sortOrder: optionalString(args, 'sortOrder'),
255
+ cursor: optionalString(args, 'cursor'),
256
+ }));
210
257
  }
211
258
  case 'get_resource_referrers': {
212
259
  const accessor = manager.get(requireString(args, 'archiveId'));
213
260
  const resourceUrl = requireString(args, 'resourceUrl');
214
- const result = await getResourceReferrers(accessor, resourceUrl);
261
+ const result = await getResourceReferrers(accessor, {
262
+ resourceUrl,
263
+ limit: optionalNumber(args, 'limit'),
264
+ cursor: optionalString(args, 'cursor'),
265
+ });
215
266
  if (!result) {
216
267
  return textResult('Resource not found.');
217
268
  }
@@ -219,25 +270,25 @@ export function createServer() {
219
270
  }
220
271
  case 'check_headers': {
221
272
  const accessor = manager.get(requireString(args, 'archiveId'));
222
- return jsonResult(await checkHeaders(accessor, omit(args, 'archiveId')));
273
+ return jsonResult(await getHeaderChecksFastPath(accessor, omit(args, 'archiveId')));
223
274
  }
224
275
  case 'list_isolated_pages': {
225
276
  const accessor = manager.get(requireString(args, 'archiveId'));
226
- return jsonResult(await listIsolatedPages(accessor, {
277
+ return jsonResult(await listIsolatedPagesFastPath(accessor, {
227
278
  limit: optionalNumber(args, 'limit'),
228
279
  offset: optionalNumber(args, 'offset'),
229
280
  }));
230
281
  }
231
282
  case 'list_isolated_clusters': {
232
283
  const accessor = manager.get(requireString(args, 'archiveId'));
233
- return jsonResult(await listIsolatedClusters(accessor, {
284
+ return jsonResult(await listIsolatedClustersFastPath(accessor, {
234
285
  limit: optionalNumber(args, 'limit'),
235
286
  offset: optionalNumber(args, 'offset'),
236
287
  }));
237
288
  }
238
289
  case 'get_isolated_cluster': {
239
290
  const accessor = manager.get(requireString(args, 'archiveId'));
240
- const result = await getIsolatedCluster(accessor, requireString(args, 'representativeUrl'));
291
+ const result = await getIsolatedClusterFastPath(accessor, requireString(args, 'representativeUrl'));
241
292
  if (result === null) {
242
293
  return textResult('Isolated cluster not found.');
243
294
  }
@@ -314,6 +365,14 @@ export function createServer() {
314
365
  /**
315
366
  * Starts the MCP server using stdio transport.
316
367
  * This is the entry point for the `nitpicker-mcp` binary.
368
+ * @returns Resolves once the stdio transport is connected; the server then
369
+ * keeps serving requests until the process exits.
370
+ * @example
371
+ * ```ts
372
+ * import { startServer } from '@nitpicker/mcp-server';
373
+ *
374
+ * await startServer();
375
+ * ```
317
376
  */
318
377
  export async function startServer() {
319
378
  const server = createServer();
@@ -48,7 +48,7 @@ export const toolDefinitions = [
48
48
  },
49
49
  {
50
50
  name: 'list_pages',
51
- description: 'List pages with rich filtering: by status code (exact or range), missing metadata (title, description), noindex flag, URL patterns, directory paths. Supports sorting and pagination. Use for questions like "show me all 404 pages" or "pages without descriptions". For large sites, set `limit` to keep the response bounded — to dump the whole list use the CLI (`nitpicker query pages`) and pipe through `jq` instead of pulling everything through MCP.',
51
+ description: 'List pages with rich filtering: by status code (exact or range), missing metadata (title, description), noindex flag, security header presence (CSP / X-Frame-Options / X-Content-Type-Options / HSTS), URL patterns, directory paths. Supports sorting and pagination. Use for questions like "show me all 404 pages", "pages without descriptions", or "internal pages missing CSP". For large sites, set `limit` to keep the response bounded — to dump the whole list use the CLI (`nitpicker query pages`) and pipe through `jq` instead of pulling everything through MCP.',
52
52
  inputSchema: {
53
53
  type: 'object',
54
54
  properties: {
@@ -75,6 +75,22 @@ export const toolDefinitions = [
75
75
  description: 'Filter to pages missing description',
76
76
  },
77
77
  noindex: { type: 'boolean', description: 'Filter to pages with noindex set' },
78
+ hasCSP: {
79
+ type: 'boolean',
80
+ description: 'Filter by Content-Security-Policy header presence',
81
+ },
82
+ hasXFrameOptions: {
83
+ type: 'boolean',
84
+ description: 'Filter by X-Frame-Options header presence',
85
+ },
86
+ hasXContentTypeOptions: {
87
+ type: 'boolean',
88
+ description: 'Filter by X-Content-Type-Options header presence',
89
+ },
90
+ hasHSTS: {
91
+ type: 'boolean',
92
+ description: 'Filter by Strict-Transport-Security header presence',
93
+ },
78
94
  contentTypeCategory: {
79
95
  type: 'string',
80
96
  enum: [
@@ -159,7 +175,7 @@ export const toolDefinitions = [
159
175
  },
160
176
  {
161
177
  name: 'list_links',
162
- description: 'Analyse links: find **broken** links (4xx/5xx status or no status) or **external** links. Anchor destinations are resolved through `pages.redirectDestId` to the canonical final destination before judgment, so a 301 intermediate that lands on a 404 reports as broken with the 404 URL — not as a stale 301. Pass `includeRedirectSources: true` to disable the resolution and see the literal anchor target (diagnostic view). For orphan analysis, use `list_isolated_pages` (singletons) or `list_isolated_clusters` (interconnected orphan groups) — the previous `orphaned` type was removed in favour of those two well-separated concepts.',
178
+ description: 'Analyse links: find **broken** links (canonical destination is exactly HTTP 404 Not Found — 403 Forbidden, 5xx server errors, and destinations excluded from crawling are deliberately NOT counted as broken, since those are separate concerns) or **external** links. Anchor destinations are resolved through `pages.redirectDestId` to the canonical final destination before judgment, so a 301 intermediate that lands on a 404 reports as broken with the 404 URL — not as a stale 301. Pass `includeRedirectSources: true` to disable the resolution and see the literal anchor target (diagnostic view). For orphan analysis, use `list_isolated_pages` (singletons) or `list_isolated_clusters` (interconnected orphan groups) — the previous `orphaned` type was removed in favour of those two well-separated concepts.',
163
179
  inputSchema: {
164
180
  type: 'object',
165
181
  properties: {
@@ -170,7 +186,7 @@ export const toolDefinitions = [
170
186
  type: {
171
187
  type: 'string',
172
188
  enum: ['broken', 'external'],
173
- description: 'Type of link analysis: broken (4xx/5xx or no status) or external (anchor leaves the in-scope hostname). Judged against the redirect-resolved canonical destination by default.',
189
+ description: 'Type of link analysis: broken (canonical destination is exactly HTTP 404) or external (anchor leaves the in-scope hostname). Judged against the redirect-resolved canonical destination by default.',
174
190
  },
175
191
  includeRedirectSources: {
176
192
  type: 'boolean',
@@ -254,6 +270,20 @@ export const toolDefinitions = [
254
270
  },
255
271
  severity: { type: 'string', description: 'Filter by severity level' },
256
272
  rule: { type: 'string', description: 'Filter by rule ID' },
273
+ urlPattern: {
274
+ type: 'string',
275
+ description: 'Filter URLs by SQL LIKE pattern',
276
+ },
277
+ sortBy: {
278
+ type: 'string',
279
+ enum: ['url', 'validator', 'severity', 'rule', 'message', 'code'],
280
+ description: 'Sort field',
281
+ },
282
+ sortOrder: {
283
+ type: 'string',
284
+ enum: ['asc', 'desc'],
285
+ description: 'Sort direction',
286
+ },
257
287
  limit: { type: 'number', description: 'Max results (default: 100)' },
258
288
  offset: { type: 'number', description: 'Results to skip (default: 0)' },
259
289
  },
@@ -276,6 +306,11 @@ export const toolDefinitions = [
276
306
  description: 'Metadata field to check for duplicates (default: "title")',
277
307
  },
278
308
  limit: { type: 'number', description: 'Max duplicate groups (default: 50)' },
309
+ offset: { type: 'number', description: 'Duplicate groups to skip (default: 0)' },
310
+ pagesLimit: {
311
+ type: 'number',
312
+ description: 'Max inline sample URLs per duplicate group (default: 20)',
313
+ },
279
314
  },
280
315
  required: ['archiveId'],
281
316
  },
@@ -297,13 +332,27 @@ export const toolDefinitions = [
297
332
  },
298
333
  limit: { type: 'number', description: 'Max results (default: 100)' },
299
334
  offset: { type: 'number', description: 'Results to skip (default: 0)' },
335
+ urlPattern: {
336
+ type: 'string',
337
+ description: 'SQL LIKE pattern to filter results by page URL',
338
+ },
339
+ sortBy: {
340
+ type: 'string',
341
+ enum: ['url', 'actual', 'expected'],
342
+ description: 'Field to sort results by (default: "url")',
343
+ },
344
+ sortOrder: {
345
+ type: 'string',
346
+ enum: ['asc', 'desc'],
347
+ description: 'Sort direction (default: "asc")',
348
+ },
300
349
  },
301
350
  required: ['archiveId', 'type'],
302
351
  },
303
352
  },
304
353
  {
305
354
  name: 'get_resource_referrers',
306
- description: 'Find which pages reference a specific resource (CSS, JS, image). Useful for impact analysis when considering removal or updates of a resource.',
355
+ description: 'Find which pages reference a specific resource (CSS, JS, image). Useful for impact analysis when considering removal or updates of a resource. Results are bounded and cursor-paginated (default 100 per call) — pass the returned `nextCursor` back in to fetch the rest for a resource referenced by many pages.',
307
356
  inputSchema: {
308
357
  type: 'object',
309
358
  properties: {
@@ -315,6 +364,11 @@ export const toolDefinitions = [
315
364
  type: 'string',
316
365
  description: 'The exact URL of the resource to look up',
317
366
  },
367
+ limit: { type: 'number', description: 'Max referring pages (default: 100)' },
368
+ cursor: {
369
+ type: 'string',
370
+ description: 'Opaque cursor from a previous call, taken from its `nextCursor`',
371
+ },
318
372
  },
319
373
  required: ['archiveId', 'resourceUrl'],
320
374
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitpicker/mcp-server",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "MCP server for querying .nitpicker archive files via AI assistants",
5
5
  "author": "D-ZERO",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@modelcontextprotocol/sdk": "1.29.0",
35
- "@nitpicker/query": "0.12.0"
35
+ "@nitpicker/query": "0.13.0"
36
36
  },
37
- "gitHead": "58b68416e0b6e3dcdd92772bee754f186a35505f"
37
+ "gitHead": "2cd462ea6b183f4462b7caba27b4db04aaba7c70"
38
38
  }