@j0hanz/superfetch 2.4.2 → 2.4.3
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/dist/cache.d.ts +6 -1
- package/dist/cache.js +4 -14
- package/dist/mcp.js +13 -13
- package/dist/tools.d.ts +2 -1
- package/dist/tools.js +2 -12
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -36,7 +36,12 @@ export declare function get(cacheKey: string | null): CacheEntry | undefined;
|
|
|
36
36
|
export declare function set(cacheKey: string | null, content: string, metadata: CacheEntryMetadata): void;
|
|
37
37
|
export declare function keys(): readonly string[];
|
|
38
38
|
export declare function isEnabled(): boolean;
|
|
39
|
-
export
|
|
39
|
+
export interface McpIcon {
|
|
40
|
+
src: string;
|
|
41
|
+
mimeType: string;
|
|
42
|
+
sizes: string[];
|
|
43
|
+
}
|
|
44
|
+
export declare function registerCachedContentResource(server: McpServer, serverIcons?: McpIcon[]): void;
|
|
40
45
|
export declare function generateSafeFilename(url: string, title?: string, hashFallback?: string, extension?: string): string;
|
|
41
46
|
export declare function handleDownload(res: ServerResponse, namespace: string, hash: string): void;
|
|
42
47
|
export {};
|
package/dist/cache.js
CHANGED
|
@@ -395,34 +395,24 @@ function notifyResourceUpdate(server, uri, subscriptions) {
|
|
|
395
395
|
});
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
|
-
export function registerCachedContentResource(server,
|
|
398
|
+
export function registerCachedContentResource(server, serverIcons) {
|
|
399
399
|
const isInitialized = attachInitializedGate(server);
|
|
400
400
|
const subscriptions = registerResourceSubscriptionHandlers(server);
|
|
401
|
-
registerCacheContentResource(server,
|
|
401
|
+
registerCacheContentResource(server, serverIcons);
|
|
402
402
|
registerCacheUpdateSubscription(server, subscriptions, isInitialized);
|
|
403
403
|
}
|
|
404
404
|
function buildCachedContentResponse(uri, cacheKey) {
|
|
405
405
|
const cached = requireCacheEntry(cacheKey);
|
|
406
406
|
return buildMarkdownContentResponse(uri, cached.content);
|
|
407
407
|
}
|
|
408
|
-
function registerCacheContentResource(server,
|
|
408
|
+
function registerCacheContentResource(server, serverIcons) {
|
|
409
409
|
server.registerResource('cached-content', new ResourceTemplate('superfetch://cache/{namespace}/{urlHash}', {
|
|
410
410
|
list: listCachedResources,
|
|
411
411
|
}), {
|
|
412
412
|
title: 'Cached Content',
|
|
413
413
|
description: 'Access previously fetched web content from cache. Namespace: markdown. UrlHash: SHA-256 hash of the URL.',
|
|
414
414
|
mimeType: 'text/markdown',
|
|
415
|
-
...(
|
|
416
|
-
? {
|
|
417
|
-
icons: [
|
|
418
|
-
{
|
|
419
|
-
src: serverIcon,
|
|
420
|
-
mimeType: 'image/svg+xml',
|
|
421
|
-
sizes: ['any'],
|
|
422
|
-
},
|
|
423
|
-
],
|
|
424
|
-
}
|
|
425
|
-
: {}),
|
|
415
|
+
...(serverIcons ? { icons: serverIcons } : {}),
|
|
426
416
|
}, (uri, params) => {
|
|
427
417
|
const { namespace, urlHash } = resolveCacheParams(params);
|
|
428
418
|
const cacheKey = `${namespace}:${urlHash}`;
|
package/dist/mcp.js
CHANGED
|
@@ -7,28 +7,28 @@ import { destroyAgents } from './fetch.js';
|
|
|
7
7
|
import { logError, logInfo, setMcpServer } from './observability.js';
|
|
8
8
|
import { registerTools } from './tools.js';
|
|
9
9
|
import { shutdownTransformWorkerPool } from './transform.js';
|
|
10
|
-
function
|
|
10
|
+
function getLocalIcons() {
|
|
11
11
|
try {
|
|
12
12
|
const iconPath = new URL('../assets/logo.svg', import.meta.url);
|
|
13
13
|
const buffer = readFileSync(iconPath);
|
|
14
|
-
return
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
src: `data:image/svg+xml;base64,${buffer.toString('base64')}`,
|
|
17
|
+
mimeType: 'image/svg+xml',
|
|
18
|
+
sizes: ['any'],
|
|
19
|
+
},
|
|
20
|
+
];
|
|
15
21
|
}
|
|
16
22
|
catch {
|
|
17
23
|
return undefined;
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
function createServerInfo() {
|
|
21
|
-
const
|
|
27
|
+
const localIcons = getLocalIcons();
|
|
22
28
|
return {
|
|
23
29
|
name: config.server.name,
|
|
24
30
|
version: config.server.version,
|
|
25
|
-
...(
|
|
26
|
-
? {
|
|
27
|
-
icons: [
|
|
28
|
-
{ src: localIcon, mimeType: 'image/svg+xml', sizes: ['any'] },
|
|
29
|
-
],
|
|
30
|
-
}
|
|
31
|
-
: {}),
|
|
31
|
+
...(localIcons ? { icons: localIcons } : {}),
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
function createServerCapabilities() {
|
|
@@ -69,9 +69,9 @@ export function createMcpServer() {
|
|
|
69
69
|
instructions,
|
|
70
70
|
});
|
|
71
71
|
setMcpServer(server);
|
|
72
|
-
const
|
|
73
|
-
registerTools(server,
|
|
74
|
-
registerCachedContentResource(server,
|
|
72
|
+
const localIcons = getLocalIcons();
|
|
73
|
+
registerTools(server, localIcons);
|
|
74
|
+
registerCachedContentResource(server, localIcons);
|
|
75
75
|
registerInstructionsResource(server, instructions);
|
|
76
76
|
return server;
|
|
77
77
|
}
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { CallToolResult, ContentBlock } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import * as cache from './cache.js';
|
|
3
4
|
import type { MarkdownTransformResult } from './transform-types.js';
|
|
4
5
|
export interface FetchUrlInput {
|
|
5
6
|
url: string;
|
|
@@ -121,5 +122,5 @@ type MarkdownPipelineResult = MarkdownTransformResult & {
|
|
|
121
122
|
export declare function parseCachedMarkdownResult(cached: string): MarkdownPipelineResult | undefined;
|
|
122
123
|
export declare function fetchUrlToolHandler(input: FetchUrlInput, extra?: ToolHandlerExtra): Promise<ToolResponseBase>;
|
|
123
124
|
export declare function withRequestContextIfMissing<TParams, TResult, TExtra = unknown>(handler: (params: TParams, extra?: TExtra) => Promise<TResult>): (params: TParams, extra?: TExtra) => Promise<TResult>;
|
|
124
|
-
export declare function registerTools(server: McpServer,
|
|
125
|
+
export declare function registerTools(server: McpServer, serverIcons?: cache.McpIcon[]): void;
|
|
125
126
|
export {};
|
package/dist/tools.js
CHANGED
|
@@ -482,23 +482,13 @@ function resolveRequestIdFromExtra(extra) {
|
|
|
482
482
|
return String(requestId);
|
|
483
483
|
return undefined;
|
|
484
484
|
}
|
|
485
|
-
export function registerTools(server,
|
|
485
|
+
export function registerTools(server, serverIcons) {
|
|
486
486
|
server.registerTool(TOOL_DEFINITION.name, {
|
|
487
487
|
title: TOOL_DEFINITION.title,
|
|
488
488
|
description: TOOL_DEFINITION.description,
|
|
489
489
|
inputSchema: TOOL_DEFINITION.inputSchema,
|
|
490
490
|
outputSchema: TOOL_DEFINITION.outputSchema,
|
|
491
491
|
annotations: TOOL_DEFINITION.annotations,
|
|
492
|
-
...(
|
|
493
|
-
? {
|
|
494
|
-
icons: [
|
|
495
|
-
{
|
|
496
|
-
src: serverIcon,
|
|
497
|
-
mimeType: 'image/svg+xml',
|
|
498
|
-
sizes: ['any'],
|
|
499
|
-
},
|
|
500
|
-
],
|
|
501
|
-
}
|
|
502
|
-
: {}),
|
|
492
|
+
...(serverIcons ? { icons: serverIcons } : {}),
|
|
503
493
|
}, withRequestContextIfMissing(TOOL_DEFINITION.handler));
|
|
504
494
|
}
|
package/package.json
CHANGED