@nitpicker/mcp-server 0.23.1 → 0.25.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
@@ -21,22 +21,32 @@ Claude Desktop の設定ファイルに以下を追加します。
21
21
 
22
22
  stdio トランスポートで起動し、`.nitpicker` アーカイブを開いてページ、リンク、リソース、分析結果などを問い合わせます。
23
23
 
24
+ `search_html` と `match_selector` は、クライアントがリクエストをキャンセルしたとき、または接続が切れたときに、走査を途中で止めます。
25
+
26
+ ネイティブ処理は、次の環境変数で調整できます。複数の呼び出しが並行したときは、上限を超えた分が順番に待ちます。正の整数でない値は、起動時にエラーにします。詳細は [@nitpicker/core](../core/README.md) を参照してください。
27
+
28
+ - `NITPICKER_NATIVE_THREADS`: スレッド数(既定は論理コア数)
29
+ - `NITPICKER_NATIVE_CONCURRENCY`: 同時に走らせる非同期のネイティブ呼び出しの数(既定は 1)
30
+
24
31
  ## 主なツール
25
32
 
26
- | ツール | 説明 |
27
- | -------------------- | ----------------------------------------------------------------- |
28
- | `open_archive` | `.nitpicker` ファイルを開き、archiveIdを返す |
29
- | `close_archive` | アーカイブを閉じる |
30
- | `get_summary` | サイト全体の概要統計 |
31
- | `list_pages` | ページ一覧 |
32
- | `get_page_detail` | 指定ページの詳細 |
33
- | `list_inbound_links` | 指定ページへの被リンク一覧 |
34
- | `get_page_html` | HTMLスナップショット |
35
- | `list_links` | リンク一覧 |
36
- | `list_resources` | リソース一覧 |
37
- | `list_images` | 画像一覧 |
38
- | `get_violations` | 分析プラグインの違反結果 |
39
- | `list_console_logs` | 捕捉したconsoleログ・ページエラー(内容ごとに全ページ横断で集約) |
33
+ | ツール | 説明 |
34
+ | ----------------------------- | ----------------------------------------------------------------- |
35
+ | `open_archive` | `.nitpicker` ファイルを開き、archiveIdを返す |
36
+ | `close_archive` | アーカイブを閉じる |
37
+ | `get_summary` | サイト全体の概要統計 |
38
+ | `list_pages` | ページ一覧 |
39
+ | `get_page_detail` | 指定ページの詳細 |
40
+ | `list_inbound_links` | 指定ページへの被リンク一覧 |
41
+ | `get_page_html` | HTMLスナップショット |
42
+ | `search_html` | 保存済みHTMLの文字列/正規表現検索(書き込みなし) |
43
+ | `match_selector` | 保存済みHTMLにCSSセレクタ一致要素を持つページを列挙(構造で探す) |
44
+ | `list_links` | リンク一覧(broken / external / 全件、URLパターンで絞り込み) |
45
+ | `list_resources` | リソース一覧(URLパターン・Content-Typeカテゴリで絞り込み) |
46
+ | `list_pages_by_resource` | 条件に一致するリソースを読み込むページ一覧(フォント利用など) |
47
+ | `get_resource_host_inventory` | リソースのホスト別集計(サードパーティ依存の棚卸し) |
48
+ | `list_images` | 画像一覧 |
49
+ | `list_console_logs` | 捕捉したconsoleログ・ページエラー(内容ごとに全ページ横断で集約) |
40
50
 
41
51
  ## 関連リンク
42
52
 
@@ -52,6 +52,8 @@ export declare function createServer(): Server<{
52
52
  * This is the entry point for the `nitpicker-mcp` binary.
53
53
  * @returns Resolves once the stdio transport is connected; the server then
54
54
  * keeps serving requests until the process exits.
55
+ * @throws {Error} Before connecting, if `NITPICKER_NATIVE_THREADS` or
56
+ * `NITPICKER_NATIVE_CONCURRENCY` is not a positive integer.
55
57
  * @example
56
58
  * ```ts
57
59
  * import { startServer } from '@nitpicker/mcp-server';
package/lib/mcp-server.js CHANGED
@@ -1,7 +1,8 @@
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, countPagesByJsonLdType, countPagesByTechnology, findDuplicateBodies, getDuplicatesFastPath, getHeaderChecksFastPath, getImagesFastPath, getIsolatedClusterFastPath, getMismatchesFastPath, getPageConsoleLogs, getPageDetail, getPageHtml, getPageJsonLd, getPageJsonLdOverview, getPageMainContents, getPageTechnologies, getResourceReferrers, getSummaryFastPath, getTechnologyInventoryFastPath, getViolations, listConsoleLogs, listDedupeCapEvents, listDuplicateBodyClusters, listInboundLinks, listIsolatedClustersFastPath, listIsolatedPagesFastPath, listLinks, listNetworkOutages, listPages, listPagesByJsonLdType, listPagesByTechnology, listResources, listUnusedResources, } from '@nitpicker/query';
4
+ import { checkNativeExecutorConfig } from '@nitpicker/archive/native-executor/check-native-executor-config';
5
+ import { ArchiveManager, countPagesByJsonLdType, CONTENT_TYPE_CATEGORIES, countPagesByTechnology, findDuplicateBodies, getDuplicatesFastPath, getHeaderChecksFastPath, getImagesFastPath, getIsolatedClusterFastPath, getMismatchesFastPath, getPageConsoleLogs, getPageDetail, getPageHtml, getPageJsonLd, getPageJsonLdOverview, getPageMainContents, getPageTechnologies, getResourceHostInventory, getResourceReferrers, getSummaryFastPath, getTechnologyInventoryFastPath, listConsoleLogs, listDedupeCapEvents, listDuplicateBodyClusters, listInboundLinks, listIsolatedClustersFastPath, listIsolatedPagesFastPath, listLinks, listNetworkOutages, listPages, listPagesByJsonLdType, listPagesByResource, listPagesByTechnology, listResources, listUnusedResources, matchSelector, searchHtml, } from '@nitpicker/query';
5
6
  import { formatExtractProgressLine } from './format-extract-progress-line.js';
6
7
  import { toolDefinitions } from './tool-definitions.js';
7
8
  /**
@@ -80,7 +81,31 @@ function optionalString(args, key) {
80
81
  return value;
81
82
  }
82
83
  /** Valid link analysis types. */
83
- const VALID_LINK_TYPES = ['broken', 'external'];
84
+ const VALID_LINK_TYPES = ['broken', 'external', 'all'];
85
+ /** Valid sort directions. */
86
+ const VALID_SORT_ORDERS = ['asc', 'desc'];
87
+ /** Valid `list_links` sort fields. */
88
+ const VALID_LINK_SORT_FIELDS = [
89
+ 'sourceUrl',
90
+ 'destUrl',
91
+ 'status',
92
+ 'isExternal',
93
+ 'textContent',
94
+ ];
95
+ /** Valid `list_resources` sort fields. */
96
+ const VALID_RESOURCE_SORT_FIELDS = [
97
+ 'url',
98
+ 'status',
99
+ 'statusText',
100
+ 'contentType',
101
+ 'contentLength',
102
+ 'isExternal',
103
+ 'referrerCount',
104
+ 'compress',
105
+ 'cdn',
106
+ ];
107
+ /** Valid `get_resource_host_inventory` sort fields. */
108
+ const VALID_HOST_SORT_FIELDS = ['resourceCount', 'pageCount', 'host'];
84
109
  /** Valid mismatch types. */
85
110
  const VALID_MISMATCH_TYPES = ['canonical', 'og:title', 'og:description'];
86
111
  /** Valid duplicate check fields. */
@@ -99,6 +124,19 @@ function validateEnum(value, allowed, label) {
99
124
  }
100
125
  return value;
101
126
  }
127
+ /**
128
+ * Extracts an optional string argument that must be one of `allowed`.
129
+ * @param args - The arguments object.
130
+ * @param key - The argument key.
131
+ * @param allowed - The list of allowed values.
132
+ * @param label - A label for the argument (used in error messages).
133
+ * @returns The validated value, or `undefined` if not present.
134
+ * @throws {Error} If the value is present but not in the allowed list.
135
+ */
136
+ function optionalEnum(args, key, allowed, label) {
137
+ const value = optionalString(args, key);
138
+ return value === undefined ? undefined : validateEnum(value, allowed, label);
139
+ }
102
140
  /**
103
141
  * Returns a shallow copy of args with the specified keys removed.
104
142
  * @param args - The arguments object.
@@ -165,7 +203,11 @@ export function createServer() {
165
203
  });
166
204
  const server = new Server({ name: 'nitpicker', version: '0.13.0' }, { capabilities: { tools: {} } });
167
205
  server.setRequestHandler(ListToolsRequestSchema, () => Promise.resolve({ tools: toolDefinitions }));
168
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
206
+ server.setRequestHandler(CallToolRequestSchema, async (request,
207
+ // Optional so a handler called without a transport (the unit specs call
208
+ // it directly) still works; the SDK always passes it. `signal` aborts when
209
+ // the client cancels the request or the transport closes.
210
+ extra) => {
169
211
  const { name } = request.params;
170
212
  const args = request.params.arguments ?? {};
171
213
  try {
@@ -241,9 +283,14 @@ export function createServer() {
241
283
  }
242
284
  case 'list_links': {
243
285
  const accessor = manager.get(requireString(args, 'archiveId'));
244
- const type = validateEnum(requireString(args, 'type'), VALID_LINK_TYPES, 'link type');
245
286
  return jsonResult(await listLinks(accessor, {
246
- type,
287
+ type: optionalEnum(args, 'type', VALID_LINK_TYPES, 'link type'),
288
+ urlPattern: optionalString(args, 'urlPattern'),
289
+ sourceUrlPattern: optionalString(args, 'sourceUrlPattern'),
290
+ destUrlPattern: optionalString(args, 'destUrlPattern'),
291
+ status: optionalNumber(args, 'status'),
292
+ sortBy: optionalEnum(args, 'sortBy', VALID_LINK_SORT_FIELDS, 'sortBy'),
293
+ sortOrder: optionalEnum(args, 'sortOrder', VALID_SORT_ORDERS, 'sortOrder'),
247
294
  limit: optionalNumber(args, 'limit'),
248
295
  offset: optionalNumber(args, 'offset'),
249
296
  includeRedirectSources: optionalBoolean(args, 'includeRedirectSources'),
@@ -251,25 +298,73 @@ export function createServer() {
251
298
  }
252
299
  case 'list_resources': {
253
300
  const accessor = manager.get(requireString(args, 'archiveId'));
254
- return jsonResult(await listResources(accessor, omit(args, 'archiveId')));
301
+ return jsonResult(await listResources(accessor, {
302
+ urlPattern: optionalString(args, 'urlPattern'),
303
+ status: optionalNumber(args, 'status'),
304
+ contentType: optionalString(args, 'contentType'),
305
+ contentTypeCategory: optionalEnum(args, 'contentTypeCategory', CONTENT_TYPE_CATEGORIES, 'contentTypeCategory'),
306
+ isExternal: optionalBoolean(args, 'isExternal'),
307
+ sortBy: optionalEnum(args, 'sortBy', VALID_RESOURCE_SORT_FIELDS, 'sortBy'),
308
+ sortOrder: optionalEnum(args, 'sortOrder', VALID_SORT_ORDERS, 'sortOrder'),
309
+ limit: optionalNumber(args, 'limit'),
310
+ offset: optionalNumber(args, 'offset'),
311
+ }));
255
312
  }
256
- case 'list_images': {
313
+ case 'list_pages_by_resource': {
257
314
  const accessor = manager.get(requireString(args, 'archiveId'));
258
- return jsonResult(await getImagesFastPath(accessor, omit(args, 'archiveId')));
315
+ const urlPattern = optionalString(args, 'urlPattern');
316
+ const contentTypeCategory = optionalEnum(args, 'contentTypeCategory', CONTENT_TYPE_CATEGORIES, 'contentTypeCategory');
317
+ if (!urlPattern && !contentTypeCategory) {
318
+ throw new Error('At least one of urlPattern or contentTypeCategory is required.');
319
+ }
320
+ return jsonResult(await listPagesByResource(accessor, {
321
+ urlPattern,
322
+ contentTypeCategory,
323
+ isExternal: optionalBoolean(args, 'isExternal'),
324
+ status: optionalNumber(args, 'status'),
325
+ resourcesLimit: optionalNumber(args, 'resourcesLimit'),
326
+ limit: optionalNumber(args, 'limit'),
327
+ offset: optionalNumber(args, 'offset'),
328
+ }));
259
329
  }
260
- case 'get_violations': {
330
+ case 'get_resource_host_inventory': {
261
331
  const accessor = manager.get(requireString(args, 'archiveId'));
262
- return jsonResult(await getViolations(accessor, {
263
- validator: optionalString(args, 'validator'),
264
- severity: optionalString(args, 'severity'),
265
- rule: optionalString(args, 'rule'),
332
+ return jsonResult(await getResourceHostInventory(accessor, {
333
+ isExternal: optionalBoolean(args, 'isExternal'),
334
+ sortBy: optionalEnum(args, 'sortBy', VALID_HOST_SORT_FIELDS, 'sortBy'),
335
+ sortOrder: optionalEnum(args, 'sortOrder', VALID_SORT_ORDERS, 'sortOrder'),
336
+ limit: optionalNumber(args, 'limit'),
337
+ offset: optionalNumber(args, 'offset'),
338
+ }));
339
+ }
340
+ case 'search_html': {
341
+ const accessor = manager.get(requireString(args, 'archiveId'));
342
+ return jsonResult(await searchHtml(accessor, {
343
+ pattern: requireString(args, 'pattern'),
344
+ literal: optionalBoolean(args, 'literal'),
266
345
  urlPattern: optionalString(args, 'urlPattern'),
267
- sortBy: optionalString(args, 'sortBy'),
268
- sortOrder: optionalString(args, 'sortOrder'),
346
+ directory: optionalString(args, 'directory'),
347
+ snippetLength: optionalNumber(args, 'snippetLength'),
269
348
  limit: optionalNumber(args, 'limit'),
270
349
  offset: optionalNumber(args, 'offset'),
350
+ signal: extra?.signal,
271
351
  }));
272
352
  }
353
+ case 'match_selector': {
354
+ const accessor = manager.get(requireString(args, 'archiveId'));
355
+ return jsonResult(await matchSelector(accessor, {
356
+ selector: requireString(args, 'selector'),
357
+ urlPattern: optionalString(args, 'urlPattern'),
358
+ directory: optionalString(args, 'directory'),
359
+ limit: optionalNumber(args, 'limit'),
360
+ offset: optionalNumber(args, 'offset'),
361
+ signal: extra?.signal,
362
+ }));
363
+ }
364
+ case 'list_images': {
365
+ const accessor = manager.get(requireString(args, 'archiveId'));
366
+ return jsonResult(await getImagesFastPath(accessor, omit(args, 'archiveId')));
367
+ }
273
368
  case 'list_console_logs': {
274
369
  const accessor = manager.get(requireString(args, 'archiveId'));
275
370
  return jsonResult(await listConsoleLogs(accessor, {
@@ -459,6 +554,8 @@ export function createServer() {
459
554
  * This is the entry point for the `nitpicker-mcp` binary.
460
555
  * @returns Resolves once the stdio transport is connected; the server then
461
556
  * keeps serving requests until the process exits.
557
+ * @throws {Error} Before connecting, if `NITPICKER_NATIVE_THREADS` or
558
+ * `NITPICKER_NATIVE_CONCURRENCY` is not a positive integer.
462
559
  * @example
463
560
  * ```ts
464
561
  * import { startServer } from '@nitpicker/mcp-server';
@@ -467,6 +564,9 @@ export function createServer() {
467
564
  * ```
468
565
  */
469
566
  export async function startServer() {
567
+ // Refuse a bad `NITPICKER_NATIVE_*` setting before the server accepts
568
+ // requests, not at the first search a client sends.
569
+ checkNativeExecutorConfig();
470
570
  const server = createServer();
471
571
  const transport = new StdioServerTransport();
472
572
  await server.connect(transport);
@@ -1,3 +1,4 @@
1
+ import { CONTENT_TYPE_CATEGORIES, SUPPORTED_SELECTOR_GRAMMAR } from '@nitpicker/query';
1
2
  /**
2
3
  * All MCP tool definitions for the Nitpicker archive query server.
3
4
  * Each tool includes a name, description with LLM guidance, and JSON Schema
@@ -6,7 +7,7 @@
6
7
  export const toolDefinitions = [
7
8
  {
8
9
  name: 'open_archive',
9
- description: 'Load a Nitpicker archive source for querying. Accepts either a finished `.nitpicker` archive file OR a crawl stub directory (an `._nitpicker-*` working directory left behind when a crawl is interrupted). Returns an archiveId, the detected `mode` (`"archive"` or `"stub"`), and `crawlerPid` (the PID of a crawler currently writing the stub, or `null` for finished archives and interrupted-but-no-longer-running crawls). When `mode === "stub"`, treat the data as a point-in-time snapshot: any counts/violations may shift if the user resumes the crawl. Always call this first before using any other tools.',
10
+ description: 'Load a Nitpicker archive source for querying. Accepts either a finished `.nitpicker` archive file OR a crawl stub directory (an `._nitpicker-*` working directory left behind when a crawl is interrupted). Returns an archiveId, the detected `mode` (`"archive"` or `"stub"`), and `crawlerPid` (the PID of a crawler currently writing the stub, or `null` for finished archives and interrupted-but-no-longer-running crawls). When `mode === "stub"`, treat the data as a point-in-time snapshot: any counts may shift if the user resumes the crawl. Always call this first before using any other tools.',
10
11
  inputSchema: {
11
12
  type: 'object',
12
13
  properties: {
@@ -139,7 +140,10 @@ export const toolDefinitions = [
139
140
  type: 'string',
140
141
  description: 'URL pattern to search (SQL LIKE: use % as wildcard)',
141
142
  },
142
- directory: { type: 'string', description: 'Directory path prefix to filter by' },
143
+ directory: {
144
+ type: 'string',
145
+ description: 'Directory to filter by: the page itself and everything under it ("/blog" matches /blog and /blog/post, not /blogging or /en/blog/). A full URL ("https://example.com/blog") also restricts the host.',
146
+ },
143
147
  sortBy: {
144
148
  type: 'string',
145
149
  enum: ['url', 'status', 'title'],
@@ -231,8 +235,34 @@ export const toolDefinitions = [
231
235
  },
232
236
  type: {
233
237
  type: 'string',
234
- enum: ['broken', 'external'],
235
- 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.',
238
+ enum: ['broken', 'external', 'all'],
239
+ description: 'Type of link analysis: broken (canonical destination is exactly HTTP 404), external (anchor leaves the in-scope hostname), or all (no type restriction — the default). Judged against the redirect-resolved canonical destination by default.',
240
+ },
241
+ urlPattern: {
242
+ type: 'string',
243
+ description: 'SQL LIKE pattern matched against the source URL OR the destination URL (e.g. "%/blog/%").',
244
+ },
245
+ sourceUrlPattern: {
246
+ type: 'string',
247
+ description: 'SQL LIKE pattern restricted to the source page URL.',
248
+ },
249
+ destUrlPattern: {
250
+ type: 'string',
251
+ description: 'SQL LIKE pattern restricted to the (redirect-resolved) destination URL. Example: "%.pdf" lists every link pointing at a PDF.',
252
+ },
253
+ status: {
254
+ type: 'number',
255
+ description: 'Filter by the destination HTTP status (exact match).',
256
+ },
257
+ sortBy: {
258
+ type: 'string',
259
+ enum: ['sourceUrl', 'destUrl', 'status', 'isExternal', 'textContent'],
260
+ description: 'Field to sort by (default: sourceUrl).',
261
+ },
262
+ sortOrder: {
263
+ type: 'string',
264
+ enum: ['asc', 'desc'],
265
+ description: 'Sort direction.',
236
266
  },
237
267
  includeRedirectSources: {
238
268
  type: 'boolean',
@@ -241,12 +271,12 @@ export const toolDefinitions = [
241
271
  limit: { type: 'number', description: 'Max results (default: 100)' },
242
272
  offset: { type: 'number', description: 'Results to skip (default: 0)' },
243
273
  },
244
- required: ['archiveId', 'type'],
274
+ required: ['archiveId'],
245
275
  },
246
276
  },
247
277
  {
248
278
  name: 'list_resources',
249
- description: 'List sub-resources (CSS, JS, images, fonts) with filtering by content type and origin. Shows compression and CDN status. Use for tech stack analysis, library detection (jQuery, React), and performance checks.',
279
+ description: 'List sub-resources (CSS, JS, images, fonts) with filtering by URL pattern, status, content type (prefix or category) and origin. Shows compression, CDN status and referrer count. Use for tech stack analysis, library detection (jQuery, React), web font inventory (contentTypeCategory "font"), and performance checks. Only resource metadata is stored — CSS/JS bodies are not, so @font-face / font-family inside a stylesheet cannot be searched; font FILES the browser fetched are listed here, and `list_pages_by_resource` finds the pages that load them. To find which pages use a given resource, use `list_pages_by_resource` or `get_resource_referrers`.',
250
280
  inputSchema: {
251
281
  type: 'object',
252
282
  properties: {
@@ -254,14 +284,44 @@ export const toolDefinitions = [
254
284
  type: 'string',
255
285
  description: 'The archive ID returned by open_archive',
256
286
  },
287
+ urlPattern: {
288
+ type: 'string',
289
+ description: 'SQL LIKE pattern matched against the resource URL (e.g. "%fonts.example.net%", "%jquery%.js").',
290
+ },
291
+ status: { type: 'number', description: 'Filter by HTTP status (exact match).' },
257
292
  contentType: {
258
293
  type: 'string',
259
294
  description: 'Filter by content type prefix (e.g., "text/css", "application/javascript")',
260
295
  },
296
+ contentTypeCategory: {
297
+ type: 'string',
298
+ enum: [...CONTENT_TYPE_CATEGORIES],
299
+ description: 'Filter by Content-Type category (e.g. "font" covers font/*, application/font-*, application/vnd.ms-fontobject). ANDed with contentType.',
300
+ },
261
301
  isExternal: {
262
302
  type: 'boolean',
263
303
  description: 'Filter by external (true) or internal (false)',
264
304
  },
305
+ sortBy: {
306
+ type: 'string',
307
+ enum: [
308
+ 'url',
309
+ 'status',
310
+ 'statusText',
311
+ 'contentType',
312
+ 'contentLength',
313
+ 'isExternal',
314
+ 'referrerCount',
315
+ 'compress',
316
+ 'cdn',
317
+ ],
318
+ description: 'Field to sort by (default: url).',
319
+ },
320
+ sortOrder: {
321
+ type: 'string',
322
+ enum: ['asc', 'desc'],
323
+ description: 'Sort direction.',
324
+ },
265
325
  limit: { type: 'number', description: 'Max results (default: 100)' },
266
326
  offset: { type: 'number', description: 'Results to skip (default: 0)' },
267
327
  },
@@ -269,8 +329,8 @@ export const toolDefinitions = [
269
329
  },
270
330
  },
271
331
  {
272
- name: 'list_images',
273
- description: 'List images with quality checks: missing alt text, missing width/height dimensions, oversized images (exceeding threshold). Use for accessibility and performance auditing.',
332
+ name: 'list_pages_by_resource',
333
+ description: 'List the pages that load at least one resource matching a URL pattern and/or Content-Type category — the reverse of `list_resources`. Answers "which pages use a web font" (contentTypeCategory "font"), "which pages load anything from fonts.example.net" (urlPattern "%fonts.example.net%"), or "which pages include jquery" (urlPattern "%jquery%"). Works on resource URLs/MIME types the browser actually fetched; resource bodies are not stored, so it cannot see @font-face rules that were never fetched. At least one of urlPattern / contentTypeCategory is required. Each page carries matchedResourceCount and a bounded sample of matched resource URLs (resourcesLimit). For an exact resource URL use `get_resource_referrers`.',
274
334
  inputSchema: {
275
335
  type: 'object',
276
336
  properties: {
@@ -278,31 +338,63 @@ export const toolDefinitions = [
278
338
  type: 'string',
279
339
  description: 'The archive ID returned by open_archive',
280
340
  },
281
- missingAlt: {
282
- type: 'boolean',
283
- description: 'Filter to images missing alt attribute',
341
+ urlPattern: {
342
+ type: 'string',
343
+ description: 'SQL LIKE pattern matched against the resource URL.',
284
344
  },
285
- missingDimensions: {
345
+ contentTypeCategory: {
346
+ type: 'string',
347
+ enum: [...CONTENT_TYPE_CATEGORIES],
348
+ description: 'Restrict to resources of this Content-Type category.',
349
+ },
350
+ isExternal: {
286
351
  type: 'boolean',
287
- description: 'Filter to images missing width/height',
352
+ description: 'Restrict to external (true) or internal (false) resources.',
288
353
  },
289
- oversizedThreshold: {
354
+ status: { type: 'number', description: 'Restrict to this resource HTTP status.' },
355
+ resourcesLimit: {
290
356
  type: 'number',
291
- description: 'Filter to images with naturalWidth or naturalHeight exceeding this pixel count',
357
+ description: 'Max matched resource URLs sampled per page (default: 20)',
292
358
  },
293
- urlPattern: {
359
+ limit: { type: 'number', description: 'Max pages (default: 100)' },
360
+ offset: { type: 'number', description: 'Pages to skip (default: 0)' },
361
+ },
362
+ required: ['archiveId'],
363
+ },
364
+ },
365
+ {
366
+ name: 'get_resource_host_inventory',
367
+ description: 'Aggregate sub-resources by serving host (host + port): distinct resource count, distinct referencing page count, and the Content-Type category mix per host. Use for third-party dependency questions ("which external hosts does the site load scripts/fonts from?") in one call instead of paging through `list_resources`. Resources whose URL is a large data: URI have no host and are excluded.',
368
+ inputSchema: {
369
+ type: 'object',
370
+ properties: {
371
+ archiveId: {
294
372
  type: 'string',
295
- description: 'Filter source URLs by pattern (SQL LIKE)',
373
+ description: 'The archive ID returned by open_archive',
296
374
  },
297
- limit: { type: 'number', description: 'Max results (default: 100)' },
298
- offset: { type: 'number', description: 'Results to skip (default: 0)' },
375
+ isExternal: {
376
+ type: 'boolean',
377
+ description: 'Restrict to external (true) or internal (false) resources.',
378
+ },
379
+ sortBy: {
380
+ type: 'string',
381
+ enum: ['resourceCount', 'pageCount', 'host'],
382
+ description: 'Field to sort by (default: resourceCount, descending).',
383
+ },
384
+ sortOrder: {
385
+ type: 'string',
386
+ enum: ['asc', 'desc'],
387
+ description: 'Sort direction.',
388
+ },
389
+ limit: { type: 'number', description: 'Max hosts (default: 100)' },
390
+ offset: { type: 'number', description: 'Hosts to skip (default: 0)' },
299
391
  },
300
392
  required: ['archiveId'],
301
393
  },
302
394
  },
303
395
  {
304
- name: 'get_violations',
305
- description: 'Get analysis violations from plugins (axe, markuplint, textlint). Filter by validator, severity, or rule. Use for accessibility and code quality reports.',
396
+ name: 'search_html',
397
+ description: 'Search the stored HTML snapshots of all pages for a string or regular expression, without writing to the archive. The search runs on the raw markup `get_page_html` returns, so <script>, <style>, inline style and every attribute are searchable (e.g. `fonts.example.org`, `font-family`, `gtag(`, `/UA-\\d+-\\d+/`). `pattern` is a plain literal substring, or `/regex/flags` (pass `literal: true` to search text such as `/static/images/` as it is) for a regular expression in Rust `regex` syntax: no backreferences or look-around and no JavaScript-only syntax such as a bare `{` or `[^]` (rejected with an error that says which), `\\<` is a word boundary, matching in time linear in the page; the match unit is a Unicode scalar value (`.` matches an emoji once), `\\d` `\\w` `\\s` `\\b` follow Unicode, `.` stops at `\\r` and `\\n` (not at U+2028), `m` anchors at `\\n`, `\\r` and `\\r\\n`; flags `i` `m` `s` take effect, `g` and `u` are always on, `d` `v` `y` are rejected; `matchCount` counts non-overlapping matches. Returns matching pages in page-id order with matchCount and a snippet around the first hit (cut from the whitespace-collapsed page, snippetLength Unicode scalar values), plus `total`, `scannedSnapshots` and `candidatePages` (in-scope pages with a stored snapshot; if it is 0 or far below the page count, HTML was not stored and "no match" is meaningless). This is a linear scan over every distinct snapshot, so large archives can take tens of seconds: call once with `limit: 0` to size `total`, narrow with urlPattern/directory, and prefer the CLI for bulk extraction: `nitpicker query <file> search-html --pattern "..." | jq`. Cannot search CSS/JS file bodies (not stored). To find pages by DOM structure (a CSS selector) rather than by text, use `match_selector`.',
306
398
  inputSchema: {
307
399
  type: 'object',
308
400
  properties: {
@@ -310,25 +402,93 @@ export const toolDefinitions = [
310
402
  type: 'string',
311
403
  description: 'The archive ID returned by open_archive',
312
404
  },
313
- validator: {
405
+ pattern: {
314
406
  type: 'string',
315
- description: 'Filter by validator name (e.g., "axe", "markuplint", "textlint")',
407
+ description: 'Literal substring, or /regex/flags for a regular expression in Rust regex syntax (flags i, m, s; no backreferences or look-around).',
408
+ },
409
+ literal: {
410
+ type: 'boolean',
411
+ description: 'Take `pattern` as plain text even if it looks like /…/flags, e.g. to find the text `/static/images/` (default: false).',
316
412
  },
317
- severity: { type: 'string', description: 'Filter by severity level' },
318
- rule: { type: 'string', description: 'Filter by rule ID' },
319
413
  urlPattern: {
320
414
  type: 'string',
321
- description: 'Filter URLs by SQL LIKE pattern',
415
+ description: 'SQL LIKE pattern restricting the page URLs to scan.',
322
416
  },
323
- sortBy: {
417
+ directory: {
324
418
  type: 'string',
325
- enum: ['url', 'validator', 'severity', 'rule', 'message', 'code'],
326
- description: 'Sort field',
419
+ description: 'Directory the scanned pages must be in or under, with the same meaning as list_pages (e.g. "/blog").',
327
420
  },
328
- sortOrder: {
421
+ snippetLength: {
422
+ type: 'number',
423
+ description: 'Snippet window size in Unicode scalar values, a non-negative integer (default: 160; 0 gives an empty snippet).',
424
+ },
425
+ limit: {
426
+ type: 'number',
427
+ description: 'Max matching pages (default: 100). 0 returns only the counts.',
428
+ },
429
+ offset: { type: 'number', description: 'Matching pages to skip (default: 0)' },
430
+ },
431
+ required: ['archiveId', 'pattern'],
432
+ },
433
+ },
434
+ {
435
+ name: 'match_selector',
436
+ description: 'Find pages whose stored HTML snapshot contains at least one element matching a CSS selector (e.g. `img:not([alt])`, `nav > a[href^="/products/"]`, `a[target="_blank"]:not([rel~="noopener"])`), without writing to the archive. Use it to search by DOM structure; use `search_html` to search by text. It is an existence check per page: matching element positions and counts are not returned. Returns matching pages in page-id order as `{ pageId, url }`, plus `total`, `scannedSnapshots` and `candidatePages` (in-scope pages with a stored snapshot; if it is 0 or far below the page count, HTML was not stored and "no match" is meaningless). Only the subset of CSS that can be evaluated exactly in a single pass over the markup is supported; anything else is rejected with an error that lists this grammar, never approximated.\n\n' +
437
+ SUPPORTED_SELECTOR_GRAMMAR +
438
+ '\n\nThis is a linear scan over every distinct snapshot, so large archives can take tens of seconds: call once with `limit: 0` to size `total`, narrow with urlPattern/directory, and prefer the CLI for bulk extraction: `nitpicker query <file> match-selector --selector "..." | jq`. Cannot inspect CSS/JS file bodies (not stored).',
439
+ inputSchema: {
440
+ type: 'object',
441
+ properties: {
442
+ archiveId: {
329
443
  type: 'string',
330
- enum: ['asc', 'desc'],
331
- description: 'Sort direction',
444
+ description: 'The archive ID returned by open_archive',
445
+ },
446
+ selector: {
447
+ type: 'string',
448
+ description: 'CSS selector list to look for in the stored HTML (comma-separated alternatives allowed). Limited to the supported grammar described above.',
449
+ },
450
+ urlPattern: {
451
+ type: 'string',
452
+ description: 'SQL LIKE pattern restricting the page URLs to scan.',
453
+ },
454
+ directory: {
455
+ type: 'string',
456
+ description: 'Directory the scanned pages must be in or under, with the same meaning as list_pages (e.g. "/blog").',
457
+ },
458
+ limit: {
459
+ type: 'number',
460
+ description: 'Max matching pages (default: 100). 0 returns only the counts.',
461
+ },
462
+ offset: { type: 'number', description: 'Matching pages to skip (default: 0)' },
463
+ },
464
+ required: ['archiveId', 'selector'],
465
+ },
466
+ },
467
+ {
468
+ name: 'list_images',
469
+ description: 'List images with quality checks: missing alt text, missing width/height dimensions, oversized images (exceeding threshold). Use for accessibility and performance auditing.',
470
+ inputSchema: {
471
+ type: 'object',
472
+ properties: {
473
+ archiveId: {
474
+ type: 'string',
475
+ description: 'The archive ID returned by open_archive',
476
+ },
477
+ missingAlt: {
478
+ type: 'boolean',
479
+ description: 'Filter to images missing alt attribute',
480
+ },
481
+ missingDimensions: {
482
+ type: 'boolean',
483
+ description: 'Filter to images missing width/height',
484
+ },
485
+ oversizedThreshold: {
486
+ type: 'number',
487
+ description: 'Filter to images with naturalWidth or naturalHeight exceeding this pixel count',
488
+ },
489
+ urlPattern: {
490
+ type: 'string',
491
+ description: 'Filter source URLs by pattern (SQL LIKE)',
332
492
  },
333
493
  limit: { type: 'number', description: 'Max results (default: 100)' },
334
494
  offset: { type: 'number', description: 'Results to skip (default: 0)' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitpicker/mcp-server",
3
- "version": "0.23.1",
3
+ "version": "0.25.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",
@@ -34,8 +34,9 @@
34
34
  "clean": "tsc --build --clean"
35
35
  },
36
36
  "dependencies": {
37
- "@modelcontextprotocol/sdk": "1.31.0",
38
- "@nitpicker/query": "0.23.0"
37
+ "@modelcontextprotocol/sdk": "1.32.1",
38
+ "@nitpicker/archive": "0.25.0",
39
+ "@nitpicker/query": "0.25.0"
39
40
  },
40
- "gitHead": "f86ab90a28332dc431324780d8298741739db847"
41
+ "gitHead": "fb258acf112366504c6dbb44b69a25bbc528fa30"
41
42
  }