@j0hanz/superfetch 2.5.3 → 2.7.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.
Files changed (46) hide show
  1. package/README.md +350 -226
  2. package/dist/assets/logo.svg +24837 -24835
  3. package/dist/cache.d.ts +28 -20
  4. package/dist/cache.js +292 -512
  5. package/dist/config.d.ts +41 -7
  6. package/dist/config.js +316 -154
  7. package/dist/crypto.js +25 -12
  8. package/dist/dom-noise-removal.js +382 -421
  9. package/dist/errors.d.ts +2 -2
  10. package/dist/errors.js +25 -8
  11. package/dist/fetch.d.ts +19 -16
  12. package/dist/fetch.js +1207 -538
  13. package/dist/host-normalization.js +40 -10
  14. package/dist/http-native.js +641 -283
  15. package/dist/index.js +67 -7
  16. package/dist/instructions.md +44 -31
  17. package/dist/ip-blocklist.d.ts +8 -0
  18. package/dist/ip-blocklist.js +65 -0
  19. package/dist/json.js +14 -9
  20. package/dist/language-detection.d.ts +2 -11
  21. package/dist/language-detection.js +313 -280
  22. package/dist/markdown-cleanup.d.ts +0 -1
  23. package/dist/markdown-cleanup.js +391 -429
  24. package/dist/mcp-validator.js +4 -2
  25. package/dist/mcp.js +191 -136
  26. package/dist/observability.js +89 -21
  27. package/dist/resources.js +16 -6
  28. package/dist/server-tuning.d.ts +2 -0
  29. package/dist/server-tuning.js +25 -23
  30. package/dist/session.d.ts +1 -0
  31. package/dist/session.js +41 -33
  32. package/dist/tasks.d.ts +3 -0
  33. package/dist/tasks.js +167 -51
  34. package/dist/timer-utils.d.ts +5 -0
  35. package/dist/timer-utils.js +20 -0
  36. package/dist/tools.d.ts +30 -5
  37. package/dist/tools.js +319 -184
  38. package/dist/transform-types.d.ts +6 -1
  39. package/dist/transform.d.ts +3 -2
  40. package/dist/transform.js +1243 -421
  41. package/dist/type-guards.d.ts +1 -0
  42. package/dist/type-guards.js +7 -0
  43. package/dist/workers/transform-child.d.ts +1 -0
  44. package/dist/workers/transform-child.js +118 -0
  45. package/dist/workers/transform-worker.js +87 -78
  46. package/package.json +14 -6
package/dist/tools.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ import { z } from 'zod';
1
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
3
  import type { CallToolResult, ContentBlock } from '@modelcontextprotocol/sdk/types.js';
3
4
  import type { MarkdownTransformResult } from './transform-types.js';
4
5
  export interface FetchUrlInput {
5
6
  url: string;
7
+ skipNoiseRemoval?: boolean | undefined;
8
+ forceRefresh?: boolean | undefined;
6
9
  }
7
10
  export interface ToolContentBlock {
8
11
  type: 'text';
@@ -29,6 +32,8 @@ export type ToolErrorResponse = CallToolResult & {
29
32
  structuredContent: {
30
33
  error: string;
31
34
  url: string;
35
+ statusCode?: number;
36
+ details?: Record<string, unknown>;
32
37
  };
33
38
  isError: true;
34
39
  };
@@ -38,7 +43,12 @@ export interface FetchPipelineOptions<T> {
38
43
  cacheNamespace: string;
39
44
  signal?: AbortSignal;
40
45
  cacheVary?: Record<string, unknown> | string;
41
- transform: (html: string, url: string) => T | Promise<T>;
46
+ forceRefresh?: boolean;
47
+ transform: (input: {
48
+ buffer: Uint8Array;
49
+ encoding: string;
50
+ truncated?: boolean;
51
+ }, url: string) => T | Promise<T>;
42
52
  serialize?: (result: T) => string;
43
53
  deserialize?: (cached: string) => T | undefined;
44
54
  }
@@ -46,6 +56,7 @@ export interface PipelineResult<T> {
46
56
  data: T;
47
57
  fromCache: boolean;
48
58
  url: string;
59
+ originalUrl?: string;
49
60
  fetchedAt: string;
50
61
  cacheKey?: string | null;
51
62
  }
@@ -68,9 +79,16 @@ export interface ProgressNotification {
68
79
  export interface ToolHandlerExtra {
69
80
  signal?: AbortSignal;
70
81
  requestId?: string | number;
82
+ sessionId?: unknown;
83
+ requestInfo?: unknown;
71
84
  _meta?: RequestMeta;
72
85
  sendNotification?: (notification: ProgressNotification) => Promise<void>;
73
86
  }
87
+ export declare const fetchUrlInputSchema: z.ZodObject<{
88
+ url: z.ZodURL;
89
+ skipNoiseRemoval: z.ZodOptional<z.ZodBoolean>;
90
+ forceRefresh: z.ZodOptional<z.ZodBoolean>;
91
+ }, z.core.$strict>;
74
92
  export declare const FETCH_URL_TOOL_NAME = "fetch-url";
75
93
  interface ProgressReporter {
76
94
  report: (progress: number, message: string) => Promise<void>;
@@ -87,8 +105,6 @@ interface InlineContentResult {
87
105
  export type InlineResult = ReturnType<InlineContentLimiter['apply']>;
88
106
  declare class InlineContentLimiter {
89
107
  apply(content: string, cacheKey: string | null): InlineContentResult;
90
- private resolveResourceUri;
91
- private buildTruncatedFallback;
92
108
  }
93
109
  export declare function executeFetchPipeline<T>(options: FetchPipelineOptions<T>): Promise<PipelineResult<T>>;
94
110
  interface SharedFetchOptions<T extends {
@@ -96,7 +112,13 @@ interface SharedFetchOptions<T extends {
96
112
  }> {
97
113
  readonly url: string;
98
114
  readonly signal?: AbortSignal;
99
- readonly transform: (html: string, normalizedUrl: string) => T | Promise<T>;
115
+ readonly cacheVary?: Record<string, unknown> | string;
116
+ readonly forceRefresh?: boolean;
117
+ readonly transform: (input: {
118
+ buffer: Uint8Array;
119
+ encoding: string;
120
+ truncated?: boolean;
121
+ }, normalizedUrl: string) => T | Promise<T>;
100
122
  readonly serialize?: (result: T) => string;
101
123
  readonly deserialize?: (cached: string) => T | undefined;
102
124
  }
@@ -109,7 +131,10 @@ export declare function performSharedFetch<T extends {
109
131
  pipeline: PipelineResult<T>;
110
132
  inlineResult: InlineResult;
111
133
  }>;
112
- export declare function createToolErrorResponse(message: string, url: string): ToolErrorResponse;
134
+ export declare function createToolErrorResponse(message: string, url: string, extra?: {
135
+ statusCode?: number;
136
+ details?: Record<string, unknown>;
137
+ }): ToolErrorResponse;
113
138
  export declare function handleToolError(error: unknown, url: string, fallbackMessage?: string): ToolErrorResponse;
114
139
  type MarkdownPipelineResult = MarkdownTransformResult & {
115
140
  readonly content: string;