@nanogpt/mcp 1.0.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/dist/activeRequests.d.ts +26 -0
- package/dist/activeRequests.d.ts.map +1 -0
- package/dist/activeRequests.js +39 -0
- package/dist/activeRequests.js.map +1 -0
- package/dist/config.d.ts +35 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +136 -0
- package/dist/config.js.map +1 -0
- package/dist/httpClient.d.ts +36 -0
- package/dist/httpClient.d.ts.map +1 -0
- package/dist/httpClient.js +211 -0
- package/dist/httpClient.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +1 -0
- package/dist/resources.d.ts +68 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +198 -0
- package/dist/resources.js.map +1 -0
- package/dist/toolUtils.d.ts +115 -0
- package/dist/toolUtils.d.ts.map +1 -0
- package/dist/toolUtils.js +369 -0
- package/dist/toolUtils.js.map +1 -0
- package/dist/tools/balance.d.ts +48 -0
- package/dist/tools/balance.d.ts.map +1 -0
- package/dist/tools/balance.js +78 -0
- package/dist/tools/balance.js.map +1 -0
- package/dist/tools/chat.d.ts +89 -0
- package/dist/tools/chat.d.ts.map +1 -0
- package/dist/tools/chat.js +125 -0
- package/dist/tools/chat.js.map +1 -0
- package/dist/tools/imageGenerate.d.ts +116 -0
- package/dist/tools/imageGenerate.d.ts.map +1 -0
- package/dist/tools/imageGenerate.js +220 -0
- package/dist/tools/imageGenerate.js.map +1 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/listModels.d.ts +149 -0
- package/dist/tools/listModels.d.ts.map +1 -0
- package/dist/tools/listModels.js +224 -0
- package/dist/tools/listModels.js.map +1 -0
- package/dist/tools/scrapeUrls.d.ts +51 -0
- package/dist/tools/scrapeUrls.d.ts.map +1 -0
- package/dist/tools/scrapeUrls.js +100 -0
- package/dist/tools/scrapeUrls.js.map +1 -0
- package/dist/tools/webSearch.d.ts +69 -0
- package/dist/tools/webSearch.d.ts.map +1 -0
- package/dist/tools/webSearch.js +120 -0
- package/dist/tools/webSearch.js.map +1 -0
- package/dist/tools/youtubeTranscribe.d.ts +45 -0
- package/dist/tools/youtubeTranscribe.d.ts.map +1 -0
- package/dist/tools/youtubeTranscribe.js +88 -0
- package/dist/tools/youtubeTranscribe.js.map +1 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* NanoGPT MCP Server
|
|
4
|
+
*
|
|
5
|
+
* An MCP server that provides access to NanoGPT's API capabilities:
|
|
6
|
+
* - Chat completion
|
|
7
|
+
* - Image generation
|
|
8
|
+
* - Web search
|
|
9
|
+
* - URL scraping
|
|
10
|
+
* - YouTube transcription
|
|
11
|
+
* - Model listing
|
|
12
|
+
*
|
|
13
|
+
* Uses stdio transport for communication with MCP clients.
|
|
14
|
+
*
|
|
15
|
+
* Pinned MCP SDK version: @modelcontextprotocol/sdk@^1.23.0
|
|
16
|
+
*/
|
|
17
|
+
import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
18
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
19
|
+
import { loadConfig, log } from './config.js';
|
|
20
|
+
import { read, clearCache } from './resources.js';
|
|
21
|
+
import { abortAllRequests, getActiveRequestCount } from './activeRequests.js';
|
|
22
|
+
import { balance, chat, imageGenerate, webSearch, scrapeUrls, youtubeTranscribe, listTextModels, listImageModels, listAudioModels, listVideoModels, } from './tools/index.js';
|
|
23
|
+
/**
|
|
24
|
+
* Main entry point
|
|
25
|
+
*/
|
|
26
|
+
async function main() {
|
|
27
|
+
// Load and validate configuration
|
|
28
|
+
const config = loadConfig();
|
|
29
|
+
log('info', 'NanoGPT MCP server starting', { baseUrl: config.baseUrl });
|
|
30
|
+
// Create MCP server
|
|
31
|
+
const server = new McpServer({
|
|
32
|
+
name: 'nanogpt-mcp',
|
|
33
|
+
version: '1.0.0',
|
|
34
|
+
});
|
|
35
|
+
// Register tools
|
|
36
|
+
registerTools(server);
|
|
37
|
+
// Register resource handlers
|
|
38
|
+
registerResources(server);
|
|
39
|
+
// Setup graceful shutdown
|
|
40
|
+
setupShutdown();
|
|
41
|
+
// Connect via stdio transport
|
|
42
|
+
const transport = new StdioServerTransport();
|
|
43
|
+
await server.connect(transport);
|
|
44
|
+
log('info', 'NanoGPT MCP server connected and ready');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register all tools with the MCP server
|
|
48
|
+
*/
|
|
49
|
+
function registerTools(server) {
|
|
50
|
+
const tools = [
|
|
51
|
+
balance,
|
|
52
|
+
chat,
|
|
53
|
+
imageGenerate,
|
|
54
|
+
webSearch,
|
|
55
|
+
scrapeUrls,
|
|
56
|
+
youtubeTranscribe,
|
|
57
|
+
listTextModels,
|
|
58
|
+
listImageModels,
|
|
59
|
+
listAudioModels,
|
|
60
|
+
listVideoModels,
|
|
61
|
+
];
|
|
62
|
+
for (const tool of tools) {
|
|
63
|
+
server.registerTool(tool.name, {
|
|
64
|
+
description: tool.description,
|
|
65
|
+
// MCP SDK v1.23+ accepts Zod schemas and converts to JSON Schema internally
|
|
66
|
+
inputSchema: tool.inputSchema,
|
|
67
|
+
}, tool.handler);
|
|
68
|
+
}
|
|
69
|
+
log('info', `Registered ${tools.length} tools`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Register resource handlers for reading stored resources
|
|
73
|
+
*/
|
|
74
|
+
function registerResources(server) {
|
|
75
|
+
// Resource template for raw JSON responses
|
|
76
|
+
const rawTemplate = new ResourceTemplate('nanogpt://raw/{id}', { list: undefined });
|
|
77
|
+
server.registerResource('nanogpt-raw', rawTemplate, {
|
|
78
|
+
description: 'Raw JSON response from NanoGPT API',
|
|
79
|
+
mimeType: 'application/json',
|
|
80
|
+
}, async (uri, _variables) => {
|
|
81
|
+
const uriString = uri.toString();
|
|
82
|
+
const result = read(uriString);
|
|
83
|
+
if (!result || !result.text) {
|
|
84
|
+
return {
|
|
85
|
+
contents: [
|
|
86
|
+
{
|
|
87
|
+
uri: uriString,
|
|
88
|
+
mimeType: 'text/plain',
|
|
89
|
+
text: `Resource not found (may have been evicted): ${uriString}`,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
contents: [
|
|
96
|
+
{
|
|
97
|
+
uri: uriString,
|
|
98
|
+
mimeType: result.mimeType,
|
|
99
|
+
text: result.text,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
// Resource template for stored images
|
|
105
|
+
const imageTemplate = new ResourceTemplate('nanogpt://image/{id}', { list: undefined });
|
|
106
|
+
server.registerResource('nanogpt-image', imageTemplate, {
|
|
107
|
+
description: 'Image generated by NanoGPT',
|
|
108
|
+
mimeType: 'image/*',
|
|
109
|
+
}, async (uri, _variables) => {
|
|
110
|
+
const uriString = uri.toString();
|
|
111
|
+
const result = read(uriString);
|
|
112
|
+
if (!result || !result.blob) {
|
|
113
|
+
return {
|
|
114
|
+
contents: [
|
|
115
|
+
{
|
|
116
|
+
uri: uriString,
|
|
117
|
+
mimeType: 'text/plain',
|
|
118
|
+
text: `Resource not found (may have been evicted): ${uriString}`,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
contents: [
|
|
125
|
+
{
|
|
126
|
+
uri: uriString,
|
|
127
|
+
mimeType: result.mimeType,
|
|
128
|
+
blob: result.blob,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
log('info', 'Registered resource handlers for nanogpt://raw/* and nanogpt://image/*');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Setup graceful shutdown handlers
|
|
137
|
+
*/
|
|
138
|
+
function setupShutdown() {
|
|
139
|
+
const shutdown = async (signal) => {
|
|
140
|
+
const activeCount = getActiveRequestCount();
|
|
141
|
+
log('info', `Received ${signal}, shutting down...`, { activeRequests: activeCount });
|
|
142
|
+
// Abort all active HTTP requests
|
|
143
|
+
abortAllRequests();
|
|
144
|
+
// Clear resource cache
|
|
145
|
+
clearCache();
|
|
146
|
+
log('info', 'Shutdown complete');
|
|
147
|
+
process.exit(0);
|
|
148
|
+
};
|
|
149
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
150
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
151
|
+
// Handle uncaught errors
|
|
152
|
+
process.on('uncaughtException', (err) => {
|
|
153
|
+
log('error', 'Uncaught exception', { error: err.message });
|
|
154
|
+
process.exit(1);
|
|
155
|
+
});
|
|
156
|
+
process.on('unhandledRejection', (reason) => {
|
|
157
|
+
log('error', 'Unhandled rejection', {
|
|
158
|
+
error: reason instanceof Error ? reason.message : String(reason),
|
|
159
|
+
});
|
|
160
|
+
process.exit(1);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// Run the server
|
|
164
|
+
main().catch((err) => {
|
|
165
|
+
console.error('Fatal error:', err);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
});
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,aAA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;IAC/C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IAEjD,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;QAC1C,GAAG,CAAC,OAAO,EAAE,qBAAqB,EAAE;YAClC,KAAK,EAAE,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;SACjE,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,iBAAiB;AACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory LRU resource cache for NanoGPT MCP server
|
|
3
|
+
*
|
|
4
|
+
* Stores large payloads (images, raw JSON) that are too big to inline.
|
|
5
|
+
* Resources are ephemeral and will be evicted when the cache is full.
|
|
6
|
+
*/
|
|
7
|
+
export type ResourceType = 'raw' | 'image';
|
|
8
|
+
/**
|
|
9
|
+
* Generate a resource URI
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeUri(type: ResourceType, id: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Parse a resource URI
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseUri(uri: string): {
|
|
16
|
+
type: ResourceType;
|
|
17
|
+
id: string;
|
|
18
|
+
} | null;
|
|
19
|
+
/**
|
|
20
|
+
* Store raw text/JSON as a resource
|
|
21
|
+
*/
|
|
22
|
+
export declare function putRawText(text: string, mimeType?: string): {
|
|
23
|
+
uri: string;
|
|
24
|
+
bytes: number;
|
|
25
|
+
} | null;
|
|
26
|
+
/**
|
|
27
|
+
* Store binary data (image) as a resource
|
|
28
|
+
*/
|
|
29
|
+
export declare function putBlob(buffer: Buffer, mimeType: string): {
|
|
30
|
+
uri: string;
|
|
31
|
+
bytes: number;
|
|
32
|
+
} | null;
|
|
33
|
+
/**
|
|
34
|
+
* Store base64-encoded image data
|
|
35
|
+
*/
|
|
36
|
+
export declare function putBase64Image(base64: string, mimeType: string): {
|
|
37
|
+
uri: string;
|
|
38
|
+
bytes: number;
|
|
39
|
+
} | null;
|
|
40
|
+
export interface ResourceReadResult {
|
|
41
|
+
mimeType: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
blob?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Read a resource by URI
|
|
47
|
+
*/
|
|
48
|
+
export declare function read(uri: string): ResourceReadResult | null;
|
|
49
|
+
/**
|
|
50
|
+
* List all cached resources (for resources/list)
|
|
51
|
+
*/
|
|
52
|
+
export declare function listResources(): Array<{
|
|
53
|
+
uri: string;
|
|
54
|
+
name: string;
|
|
55
|
+
mimeType: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Clear all cached resources (for graceful shutdown)
|
|
59
|
+
*/
|
|
60
|
+
export declare function clearCache(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get cache statistics (for debugging)
|
|
63
|
+
*/
|
|
64
|
+
export declare function getCacheStats(): {
|
|
65
|
+
count: number;
|
|
66
|
+
totalBytes: number;
|
|
67
|
+
};
|
|
68
|
+
//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AAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAYtF;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAGjC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CASrE"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory LRU resource cache for NanoGPT MCP server
|
|
3
|
+
*
|
|
4
|
+
* Stores large payloads (images, raw JSON) that are too big to inline.
|
|
5
|
+
* Resources are ephemeral and will be evicted when the cache is full.
|
|
6
|
+
*/
|
|
7
|
+
import { randomUUID } from 'crypto';
|
|
8
|
+
import { getConfig } from './config.js';
|
|
9
|
+
// In-memory LRU cache
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
const accessOrder = [];
|
|
12
|
+
/**
|
|
13
|
+
* Generate a resource URI
|
|
14
|
+
*/
|
|
15
|
+
export function makeUri(type, id) {
|
|
16
|
+
return `nanogpt://${type}/${id}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse a resource URI
|
|
20
|
+
*/
|
|
21
|
+
export function parseUri(uri) {
|
|
22
|
+
const match = uri.match(/^nanogpt:\/\/(raw|image)\/([a-f0-9-]+)$/);
|
|
23
|
+
if (!match)
|
|
24
|
+
return null;
|
|
25
|
+
return {
|
|
26
|
+
type: match[1],
|
|
27
|
+
id: match[2],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Update access order for LRU eviction
|
|
32
|
+
*/
|
|
33
|
+
function updateAccessOrder(id) {
|
|
34
|
+
const index = accessOrder.indexOf(id);
|
|
35
|
+
if (index > -1) {
|
|
36
|
+
accessOrder.splice(index, 1);
|
|
37
|
+
}
|
|
38
|
+
accessOrder.push(id);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Evict oldest entries if cache is full
|
|
42
|
+
*/
|
|
43
|
+
function evictIfNeeded() {
|
|
44
|
+
const config = getConfig();
|
|
45
|
+
while (cache.size >= config.maxResourceCacheItems && accessOrder.length > 0) {
|
|
46
|
+
const oldestId = accessOrder.shift();
|
|
47
|
+
cache.delete(oldestId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Store raw text/JSON as a resource
|
|
52
|
+
*/
|
|
53
|
+
export function putRawText(text, mimeType = 'application/json') {
|
|
54
|
+
const config = getConfig();
|
|
55
|
+
const bytes = Buffer.byteLength(text, 'utf-8');
|
|
56
|
+
// Check size limit
|
|
57
|
+
if (bytes > config.maxResourceBytes) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
// Evict if needed
|
|
61
|
+
evictIfNeeded();
|
|
62
|
+
const id = randomUUID();
|
|
63
|
+
const entry = {
|
|
64
|
+
id,
|
|
65
|
+
type: 'raw',
|
|
66
|
+
mimeType,
|
|
67
|
+
data: text,
|
|
68
|
+
bytes,
|
|
69
|
+
createdAt: Date.now(),
|
|
70
|
+
};
|
|
71
|
+
cache.set(id, entry);
|
|
72
|
+
updateAccessOrder(id);
|
|
73
|
+
return {
|
|
74
|
+
uri: makeUri('raw', id),
|
|
75
|
+
bytes,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Store binary data (image) as a resource
|
|
80
|
+
*/
|
|
81
|
+
export function putBlob(buffer, mimeType) {
|
|
82
|
+
const config = getConfig();
|
|
83
|
+
// Convert to base64 first, then check size limit against actual stored size
|
|
84
|
+
// (base64 encoding expands data by ~33%)
|
|
85
|
+
const base64Data = buffer.toString('base64');
|
|
86
|
+
const storedBytes = base64Data.length;
|
|
87
|
+
// Check size limit against actual stored size
|
|
88
|
+
if (storedBytes > config.maxResourceBytes) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
// Evict if needed
|
|
92
|
+
evictIfNeeded();
|
|
93
|
+
const id = randomUUID();
|
|
94
|
+
const entry = {
|
|
95
|
+
id,
|
|
96
|
+
type: 'image',
|
|
97
|
+
mimeType,
|
|
98
|
+
data: base64Data,
|
|
99
|
+
bytes: storedBytes,
|
|
100
|
+
createdAt: Date.now(),
|
|
101
|
+
};
|
|
102
|
+
cache.set(id, entry);
|
|
103
|
+
updateAccessOrder(id);
|
|
104
|
+
return {
|
|
105
|
+
uri: makeUri('image', id),
|
|
106
|
+
bytes: storedBytes,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Store base64-encoded image data
|
|
111
|
+
*/
|
|
112
|
+
export function putBase64Image(base64, mimeType) {
|
|
113
|
+
const config = getConfig();
|
|
114
|
+
// Remove data URL prefix if present
|
|
115
|
+
const cleanBase64 = base64.replace(/^data:[^,]+,/, '');
|
|
116
|
+
const bytes = cleanBase64.length; // Track actual stored string size
|
|
117
|
+
// Check size limit
|
|
118
|
+
if (bytes > config.maxResourceBytes) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
// Evict if needed
|
|
122
|
+
evictIfNeeded();
|
|
123
|
+
const id = randomUUID();
|
|
124
|
+
const entry = {
|
|
125
|
+
id,
|
|
126
|
+
type: 'image',
|
|
127
|
+
mimeType,
|
|
128
|
+
data: cleanBase64,
|
|
129
|
+
bytes,
|
|
130
|
+
createdAt: Date.now(),
|
|
131
|
+
};
|
|
132
|
+
cache.set(id, entry);
|
|
133
|
+
updateAccessOrder(id);
|
|
134
|
+
return {
|
|
135
|
+
uri: makeUri('image', id),
|
|
136
|
+
bytes,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Read a resource by URI
|
|
141
|
+
*/
|
|
142
|
+
export function read(uri) {
|
|
143
|
+
const parsed = parseUri(uri);
|
|
144
|
+
if (!parsed)
|
|
145
|
+
return null;
|
|
146
|
+
const entry = cache.get(parsed.id);
|
|
147
|
+
if (!entry)
|
|
148
|
+
return null;
|
|
149
|
+
// Update access order
|
|
150
|
+
updateAccessOrder(parsed.id);
|
|
151
|
+
if (entry.type === 'raw') {
|
|
152
|
+
return {
|
|
153
|
+
mimeType: entry.mimeType,
|
|
154
|
+
text: entry.data,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return {
|
|
159
|
+
mimeType: entry.mimeType,
|
|
160
|
+
blob: entry.data,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* List all cached resources (for resources/list)
|
|
166
|
+
*/
|
|
167
|
+
export function listResources() {
|
|
168
|
+
const result = [];
|
|
169
|
+
for (const [id, entry] of cache.entries()) {
|
|
170
|
+
result.push({
|
|
171
|
+
uri: makeUri(entry.type, id),
|
|
172
|
+
name: entry.type === 'raw' ? 'Raw response' : 'Generated image',
|
|
173
|
+
mimeType: entry.mimeType,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Clear all cached resources (for graceful shutdown)
|
|
180
|
+
*/
|
|
181
|
+
export function clearCache() {
|
|
182
|
+
cache.clear();
|
|
183
|
+
accessOrder.length = 0;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get cache statistics (for debugging)
|
|
187
|
+
*/
|
|
188
|
+
export function getCacheStats() {
|
|
189
|
+
let totalBytes = 0;
|
|
190
|
+
for (const entry of cache.values()) {
|
|
191
|
+
totalBytes += entry.bytes;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
count: cache.size,
|
|
195
|
+
totalBytes,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAE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E,EAAE,CAAC;QACnC,UAAU,IAAI,KAAK,CAAC,KAAK,CAAC;IAC5B,CAAC;IACD,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,IAAI;QACjB,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common utilities for tool handlers
|
|
3
|
+
*
|
|
4
|
+
* WARNING: The zodTypeToJsonSchema function accesses Zod internal structures (_def)
|
|
5
|
+
* which are not part of Zod's public API and may break with Zod updates.
|
|
6
|
+
* Consider switching to a maintained converter like 'zod-to-json-schema' package
|
|
7
|
+
* for production use with full Zod type coverage.
|
|
8
|
+
*/
|
|
9
|
+
import { z, type ZodTypeAny } from 'zod';
|
|
10
|
+
import { McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
11
|
+
import { type HttpError } from './httpClient.js';
|
|
12
|
+
export interface ResourceLink {
|
|
13
|
+
type: 'resource_link';
|
|
14
|
+
uri: string;
|
|
15
|
+
name: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TextContent {
|
|
19
|
+
type: 'text';
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
export type ContentItem = TextContent | ResourceLink;
|
|
23
|
+
/**
|
|
24
|
+
* Map HTTP error to MCP error
|
|
25
|
+
*/
|
|
26
|
+
export declare function httpErrorToMcpError(err: HttpError): McpError;
|
|
27
|
+
/**
|
|
28
|
+
* Handle errors in tool handlers.
|
|
29
|
+
*
|
|
30
|
+
* This function ALWAYS throws and never returns (return type: never).
|
|
31
|
+
* Use as: `return handleToolError(err)` in catch blocks to make control flow
|
|
32
|
+
* explicit and satisfy TypeScript's type checker.
|
|
33
|
+
*/
|
|
34
|
+
export declare function handleToolError(err: unknown): never;
|
|
35
|
+
export interface RawResponse {
|
|
36
|
+
status: number;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
body?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/** Error returned when raw response cannot be stored */
|
|
41
|
+
export interface RawResponseError {
|
|
42
|
+
error: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Union type for the 'raw' field in processRawResponse result.
|
|
46
|
+
* - RawResponse: The full response object (when small enough to inline)
|
|
47
|
+
* - string: A URI reference to the stored resource (when stored successfully)
|
|
48
|
+
* - RawResponseError: An error object (when storage fails)
|
|
49
|
+
*/
|
|
50
|
+
export type ProcessedRawValue = RawResponse | string | RawResponseError;
|
|
51
|
+
/** Result type for processRawResponse */
|
|
52
|
+
export interface ProcessRawResponseResult {
|
|
53
|
+
/** The raw response - can be inline object, URI string, or error */
|
|
54
|
+
raw?: ProcessedRawValue;
|
|
55
|
+
/** Resource link if response was stored as a resource */
|
|
56
|
+
resourceLink?: ResourceLink;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type guard to check if raw value is an error
|
|
60
|
+
*/
|
|
61
|
+
export declare function isRawResponseError(value: ProcessedRawValue): value is RawResponseError;
|
|
62
|
+
/**
|
|
63
|
+
* Type guard to check if raw value is a URI string
|
|
64
|
+
*/
|
|
65
|
+
export declare function isRawResponseUri(value: ProcessedRawValue): value is string;
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if raw value is an inline RawResponse
|
|
68
|
+
*/
|
|
69
|
+
export declare function isRawResponseInline(value: ProcessedRawValue): value is RawResponse;
|
|
70
|
+
/**
|
|
71
|
+
* Process raw response - inline if small, store as resource if large
|
|
72
|
+
*
|
|
73
|
+
* @returns Object with:
|
|
74
|
+
* - raw: Either the inline RawResponse, a URI string to stored resource, or an error object
|
|
75
|
+
* - resourceLink: Present only when response was stored as a resource
|
|
76
|
+
*/
|
|
77
|
+
export declare function processRawResponse(response: RawResponse, includeRaw?: boolean): ProcessRawResponseResult;
|
|
78
|
+
/**
|
|
79
|
+
* Build content array with text and optional resource link
|
|
80
|
+
*/
|
|
81
|
+
export declare function buildContent(text: string, resourceLink?: ResourceLink): ContentItem[];
|
|
82
|
+
/**
|
|
83
|
+
* Common input schema for include_raw parameter
|
|
84
|
+
*/
|
|
85
|
+
export declare const includeRawSchema: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
86
|
+
export interface JsonSchema {
|
|
87
|
+
type?: string | string[];
|
|
88
|
+
properties?: Record<string, JsonSchema>;
|
|
89
|
+
items?: JsonSchema;
|
|
90
|
+
required?: string[];
|
|
91
|
+
additionalProperties?: boolean;
|
|
92
|
+
enum?: unknown[];
|
|
93
|
+
const?: unknown;
|
|
94
|
+
oneOf?: JsonSchema[];
|
|
95
|
+
minimum?: number;
|
|
96
|
+
maximum?: number;
|
|
97
|
+
minLength?: number;
|
|
98
|
+
maxLength?: number;
|
|
99
|
+
minItems?: number;
|
|
100
|
+
maxItems?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Zod to JSON Schema converter (simplified)
|
|
104
|
+
*
|
|
105
|
+
* WARNING: This function accesses Zod internal structures (_def) which are not
|
|
106
|
+
* part of Zod's public API. This implementation:
|
|
107
|
+
* - May break with future Zod versions
|
|
108
|
+
* - Does not support all Zod types (see UNSUPPORTED_ZOD_TYPES)
|
|
109
|
+
* - Uses defensive checks but may still fail on edge cases
|
|
110
|
+
*
|
|
111
|
+
* For production use with full Zod type coverage, consider using the
|
|
112
|
+
* 'zod-to-json-schema' package instead.
|
|
113
|
+
*/
|
|
114
|
+
export declare function zodToJsonSchema(schema: ZodTypeAny): JsonSchema;
|
|
115
|
+
//# sourceMappingURL=toolUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolUtils.d.ts","sourceRoot":"","sources":["../src/toolUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAa,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,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