mcp-researchpowerpack 3.6.9
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 +635 -0
- package/dist/clients/reddit.d.ts +74 -0
- package/dist/clients/reddit.d.ts.map +1 -0
- package/dist/clients/reddit.js +305 -0
- package/dist/clients/reddit.js.map +1 -0
- package/dist/clients/research.d.ts +67 -0
- package/dist/clients/research.d.ts.map +1 -0
- package/dist/clients/research.js +252 -0
- package/dist/clients/research.js.map +1 -0
- package/dist/clients/scraper.d.ts +71 -0
- package/dist/clients/scraper.d.ts.map +1 -0
- package/dist/clients/scraper.js +321 -0
- package/dist/clients/scraper.js.map +1 -0
- package/dist/clients/search.d.ts +62 -0
- package/dist/clients/search.d.ts.map +1 -0
- package/dist/clients/search.js +219 -0
- package/dist/clients/search.js.map +1 -0
- package/dist/config/index.d.ts +62 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +142 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +40 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +305 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +81 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +6 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/yaml/tools.yaml +130 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +271 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/deep-research.d.ts +64 -0
- package/dist/schemas/deep-research.d.ts.map +1 -0
- package/dist/schemas/deep-research.js +224 -0
- package/dist/schemas/deep-research.js.map +1 -0
- package/dist/schemas/scrape-links.d.ts +32 -0
- package/dist/schemas/scrape-links.d.ts.map +1 -0
- package/dist/schemas/scrape-links.js +34 -0
- package/dist/schemas/scrape-links.js.map +1 -0
- package/dist/schemas/web-search.d.ts +22 -0
- package/dist/schemas/web-search.d.ts.map +1 -0
- package/dist/schemas/web-search.js +21 -0
- package/dist/schemas/web-search.js.map +1 -0
- package/dist/services/file-attachment.d.ts +30 -0
- package/dist/services/file-attachment.d.ts.map +1 -0
- package/dist/services/file-attachment.js +199 -0
- package/dist/services/file-attachment.js.map +1 -0
- package/dist/services/llm-processor.d.ts +27 -0
- package/dist/services/llm-processor.d.ts.map +1 -0
- package/dist/services/llm-processor.js +179 -0
- package/dist/services/llm-processor.js.map +1 -0
- package/dist/services/markdown-cleaner.d.ts +8 -0
- package/dist/services/markdown-cleaner.d.ts.map +1 -0
- package/dist/services/markdown-cleaner.js +44 -0
- package/dist/services/markdown-cleaner.js.map +1 -0
- package/dist/tools/definitions.d.ts +16 -0
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/definitions.js +17 -0
- package/dist/tools/definitions.js.map +1 -0
- package/dist/tools/reddit.d.ts +14 -0
- package/dist/tools/reddit.d.ts.map +1 -0
- package/dist/tools/reddit.js +213 -0
- package/dist/tools/reddit.js.map +1 -0
- package/dist/tools/registry.d.ts +71 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +242 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/research.d.ts +14 -0
- package/dist/tools/research.d.ts.map +1 -0
- package/dist/tools/research.js +194 -0
- package/dist/tools/research.js.map +1 -0
- package/dist/tools/scrape.d.ts +14 -0
- package/dist/tools/scrape.d.ts.map +1 -0
- package/dist/tools/scrape.js +201 -0
- package/dist/tools/scrape.js.map +1 -0
- package/dist/tools/search.d.ts +10 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +137 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/utils.d.ts +105 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +159 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/utils/concurrency.d.ts +29 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +73 -0
- package/dist/utils/concurrency.js.map +1 -0
- package/dist/utils/errors.d.ts +77 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +335 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +39 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +57 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown-formatter.d.ts +5 -0
- package/dist/utils/markdown-formatter.d.ts.map +1 -0
- package/dist/utils/markdown-formatter.js +15 -0
- package/dist/utils/markdown-formatter.js.map +1 -0
- package/dist/utils/response.d.ts +88 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +151 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/utils/url-aggregator.d.ts +90 -0
- package/dist/utils/url-aggregator.d.ts.map +1 -0
- package/dist/utils/url-aggregator.js +502 -0
- package/dist/utils/url-aggregator.js.map +1 -0
- package/dist/version.d.ts +30 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +60 -0
- package/dist/version.js.map +1 -0
- package/dist/worker.d.ts +17 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +53 -0
- package/dist/worker.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Robust error handling utilities for MCP server
|
|
3
|
+
* Ensures the server NEVER crashes and always returns structured responses
|
|
4
|
+
*/
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Error Codes (MCP-compliant)
|
|
7
|
+
// ============================================================================
|
|
8
|
+
export const ErrorCode = {
|
|
9
|
+
// Retryable errors
|
|
10
|
+
RATE_LIMITED: 'RATE_LIMITED',
|
|
11
|
+
TIMEOUT: 'TIMEOUT',
|
|
12
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
13
|
+
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
|
|
14
|
+
// Non-retryable errors
|
|
15
|
+
AUTH_ERROR: 'AUTH_ERROR',
|
|
16
|
+
INVALID_INPUT: 'INVALID_INPUT',
|
|
17
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
18
|
+
QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',
|
|
19
|
+
// Internal errors
|
|
20
|
+
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
21
|
+
PARSE_ERROR: 'PARSE_ERROR',
|
|
22
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
23
|
+
};
|
|
24
|
+
const DEFAULT_RETRY_OPTIONS = {
|
|
25
|
+
maxRetries: 3,
|
|
26
|
+
baseDelayMs: 1000,
|
|
27
|
+
maxDelayMs: 30000,
|
|
28
|
+
retryableStatuses: [408, 429, 500, 502, 503, 504, 510],
|
|
29
|
+
};
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Error Classification
|
|
32
|
+
// ============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* Classify any error into a structured format
|
|
35
|
+
* NEVER throws - always returns a valid StructuredError
|
|
36
|
+
*/
|
|
37
|
+
export function classifyError(error) {
|
|
38
|
+
// Handle null/undefined
|
|
39
|
+
if (error == null) {
|
|
40
|
+
return {
|
|
41
|
+
code: ErrorCode.UNKNOWN_ERROR,
|
|
42
|
+
message: 'An unknown error occurred',
|
|
43
|
+
retryable: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Handle abort errors (timeout via AbortController)
|
|
47
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
48
|
+
return {
|
|
49
|
+
code: ErrorCode.TIMEOUT,
|
|
50
|
+
message: 'Request timed out',
|
|
51
|
+
retryable: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Extract error properties safely
|
|
55
|
+
const err = error;
|
|
56
|
+
const message = err.message || String(error);
|
|
57
|
+
const statusCode = err.response?.status || err.status;
|
|
58
|
+
const errCode = err.code;
|
|
59
|
+
const errName = err.name;
|
|
60
|
+
// Network errors (Node.js specific)
|
|
61
|
+
if (errCode === 'ECONNREFUSED' || errCode === 'ENOTFOUND' || errCode === 'ECONNRESET') {
|
|
62
|
+
return {
|
|
63
|
+
code: ErrorCode.NETWORK_ERROR,
|
|
64
|
+
message: `Network error: ${errCode}`,
|
|
65
|
+
retryable: true,
|
|
66
|
+
cause: message,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Timeout errors
|
|
70
|
+
if (errCode === 'ECONNABORTED' ||
|
|
71
|
+
errCode === 'ETIMEDOUT' ||
|
|
72
|
+
errName === 'AbortError' ||
|
|
73
|
+
message.toLowerCase().includes('timeout') ||
|
|
74
|
+
message.toLowerCase().includes('timed out')) {
|
|
75
|
+
return {
|
|
76
|
+
code: ErrorCode.TIMEOUT,
|
|
77
|
+
message: 'Request timed out',
|
|
78
|
+
retryable: true,
|
|
79
|
+
cause: message,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// HTTP status code errors
|
|
83
|
+
if (statusCode) {
|
|
84
|
+
return classifyHttpError(statusCode, message);
|
|
85
|
+
}
|
|
86
|
+
// API key errors
|
|
87
|
+
if (message.includes('API_KEY') || message.includes('api_key') || message.includes('Invalid API')) {
|
|
88
|
+
return {
|
|
89
|
+
code: ErrorCode.AUTH_ERROR,
|
|
90
|
+
message: 'API key missing or invalid',
|
|
91
|
+
retryable: false,
|
|
92
|
+
cause: message,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Parse errors
|
|
96
|
+
if (message.includes('JSON') || message.includes('parse') || message.includes('Unexpected token')) {
|
|
97
|
+
return {
|
|
98
|
+
code: ErrorCode.PARSE_ERROR,
|
|
99
|
+
message: 'Failed to parse response',
|
|
100
|
+
retryable: false,
|
|
101
|
+
cause: message,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// Default to unknown
|
|
105
|
+
return {
|
|
106
|
+
code: ErrorCode.UNKNOWN_ERROR,
|
|
107
|
+
message: message.substring(0, 500), // Truncate long messages
|
|
108
|
+
retryable: false,
|
|
109
|
+
cause: err.cause ? String(err.cause) : undefined,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Classify HTTP status codes into structured errors
|
|
114
|
+
*/
|
|
115
|
+
function classifyHttpError(status, message) {
|
|
116
|
+
switch (status) {
|
|
117
|
+
case 400:
|
|
118
|
+
return { code: ErrorCode.INVALID_INPUT, message: 'Bad request', retryable: false, statusCode: status };
|
|
119
|
+
case 401:
|
|
120
|
+
return { code: ErrorCode.AUTH_ERROR, message: 'Invalid API key', retryable: false, statusCode: status };
|
|
121
|
+
case 403:
|
|
122
|
+
return { code: ErrorCode.QUOTA_EXCEEDED, message: 'Access forbidden or quota exceeded', retryable: false, statusCode: status };
|
|
123
|
+
case 404:
|
|
124
|
+
return { code: ErrorCode.NOT_FOUND, message: 'Resource not found', retryable: false, statusCode: status };
|
|
125
|
+
case 408:
|
|
126
|
+
return { code: ErrorCode.TIMEOUT, message: 'Request timeout', retryable: true, statusCode: status };
|
|
127
|
+
case 429:
|
|
128
|
+
return { code: ErrorCode.RATE_LIMITED, message: 'Rate limit exceeded', retryable: true, statusCode: status };
|
|
129
|
+
case 500:
|
|
130
|
+
return { code: ErrorCode.INTERNAL_ERROR, message: 'Server error', retryable: true, statusCode: status };
|
|
131
|
+
case 502:
|
|
132
|
+
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: 'Bad gateway', retryable: true, statusCode: status };
|
|
133
|
+
case 503:
|
|
134
|
+
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: 'Service unavailable', retryable: true, statusCode: status };
|
|
135
|
+
case 504:
|
|
136
|
+
return { code: ErrorCode.TIMEOUT, message: 'Gateway timeout', retryable: true, statusCode: status };
|
|
137
|
+
case 510:
|
|
138
|
+
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: 'Request canceled', retryable: true, statusCode: status };
|
|
139
|
+
default:
|
|
140
|
+
if (status >= 500) {
|
|
141
|
+
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: `Server error: ${status}`, retryable: true, statusCode: status };
|
|
142
|
+
}
|
|
143
|
+
return { code: ErrorCode.UNKNOWN_ERROR, message: `HTTP ${status}: ${message}`, retryable: false, statusCode: status };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// Retry Logic with Exponential Backoff
|
|
148
|
+
// ============================================================================
|
|
149
|
+
/**
|
|
150
|
+
* Calculate delay with exponential backoff and jitter
|
|
151
|
+
*/
|
|
152
|
+
function calculateBackoff(attempt, options) {
|
|
153
|
+
const exponentialDelay = options.baseDelayMs * Math.pow(2, attempt);
|
|
154
|
+
const jitter = Math.random() * 0.3 * exponentialDelay; // 0-30% jitter
|
|
155
|
+
return Math.min(exponentialDelay + jitter, options.maxDelayMs);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Sleep utility that respects abort signals
|
|
159
|
+
*/
|
|
160
|
+
export function sleep(ms, signal) {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
if (signal?.aborted) {
|
|
163
|
+
reject(new DOMException('Aborted', 'AbortError'));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const timeout = setTimeout(resolve, ms);
|
|
167
|
+
signal?.addEventListener('abort', () => {
|
|
168
|
+
clearTimeout(timeout);
|
|
169
|
+
reject(new DOMException('Aborted', 'AbortError'));
|
|
170
|
+
}, { once: true });
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Execute a function with retry logic
|
|
175
|
+
* NEVER throws on final failure - returns error result instead
|
|
176
|
+
* @internal - Currently unused but kept for future retry implementations
|
|
177
|
+
*/
|
|
178
|
+
async function withRetry(fn, options = {}) {
|
|
179
|
+
const opts = { ...DEFAULT_RETRY_OPTIONS, ...options };
|
|
180
|
+
let lastError = { code: ErrorCode.UNKNOWN_ERROR, message: 'No attempts made', retryable: false };
|
|
181
|
+
for (let attempt = 0; attempt <= opts.maxRetries; attempt++) {
|
|
182
|
+
const controller = new AbortController();
|
|
183
|
+
try {
|
|
184
|
+
const data = await fn(controller.signal);
|
|
185
|
+
return { success: true, data };
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
lastError = classifyError(error);
|
|
189
|
+
// Don't retry non-retryable errors
|
|
190
|
+
if (!lastError.retryable) {
|
|
191
|
+
return { success: false, error: lastError, attempts: attempt + 1 };
|
|
192
|
+
}
|
|
193
|
+
// Don't retry if we've exhausted attempts
|
|
194
|
+
if (attempt >= opts.maxRetries) {
|
|
195
|
+
return { success: false, error: lastError, attempts: attempt + 1 };
|
|
196
|
+
}
|
|
197
|
+
// Calculate backoff and wait
|
|
198
|
+
const delayMs = calculateBackoff(attempt, opts);
|
|
199
|
+
opts.onRetry?.(attempt + 1, lastError, delayMs);
|
|
200
|
+
try {
|
|
201
|
+
await sleep(delayMs);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// Sleep was aborted, return immediately
|
|
205
|
+
return { success: false, error: lastError, attempts: attempt + 1 };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return { success: false, error: lastError, attempts: opts.maxRetries + 1 };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Wrap a fetch call with timeout via AbortController
|
|
213
|
+
*/
|
|
214
|
+
export function fetchWithTimeout(url, options = {}) {
|
|
215
|
+
const { timeoutMs = 30000, signal: externalSignal, ...fetchOptions } = options;
|
|
216
|
+
const controller = new AbortController();
|
|
217
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
218
|
+
// Combine with external signal if provided
|
|
219
|
+
if (externalSignal) {
|
|
220
|
+
externalSignal.addEventListener('abort', () => controller.abort(), { once: true });
|
|
221
|
+
}
|
|
222
|
+
return fetch(url, { ...fetchOptions, signal: controller.signal }).finally(() => {
|
|
223
|
+
clearTimeout(timeoutId);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// ============================================================================
|
|
227
|
+
// Safe Execution Wrappers
|
|
228
|
+
// ============================================================================
|
|
229
|
+
/**
|
|
230
|
+
* Safely execute any function, NEVER throws
|
|
231
|
+
* @internal - Currently unused but kept for future safe execution patterns
|
|
232
|
+
*/
|
|
233
|
+
async function safeExecute(fn, fallback) {
|
|
234
|
+
try {
|
|
235
|
+
const data = await fn();
|
|
236
|
+
return { data };
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return { data: fallback, error: classifyError(error) };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Safely parse JSON, NEVER throws
|
|
244
|
+
* @internal - Currently unused but kept for future JSON parsing needs
|
|
245
|
+
*/
|
|
246
|
+
function safeJsonParse(text, fallback) {
|
|
247
|
+
try {
|
|
248
|
+
return { data: JSON.parse(text) };
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
return { data: fallback, error: error instanceof Error ? error.message : String(error) };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// ============================================================================
|
|
255
|
+
// MCP Tool Error Response Types (for client-facing error responses)
|
|
256
|
+
// ============================================================================
|
|
257
|
+
/**
|
|
258
|
+
* MCP-compliant error codes for tool responses
|
|
259
|
+
* These codes are exposed to clients for programmatic error handling
|
|
260
|
+
*/
|
|
261
|
+
export const MCP_ERROR_CODES = {
|
|
262
|
+
RATE_LIMITED: 'RATE_LIMITED',
|
|
263
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
264
|
+
TIMEOUT: 'TIMEOUT',
|
|
265
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
266
|
+
AUTH_ERROR: 'AUTH_ERROR',
|
|
267
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
268
|
+
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
269
|
+
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Map internal ErrorCode to client-facing MCP_ERROR_CODES
|
|
273
|
+
*/
|
|
274
|
+
function mapErrorCodeToMCP(code) {
|
|
275
|
+
switch (code) {
|
|
276
|
+
case ErrorCode.RATE_LIMITED:
|
|
277
|
+
case ErrorCode.QUOTA_EXCEEDED:
|
|
278
|
+
return MCP_ERROR_CODES.RATE_LIMITED;
|
|
279
|
+
case ErrorCode.TIMEOUT:
|
|
280
|
+
return MCP_ERROR_CODES.TIMEOUT;
|
|
281
|
+
case ErrorCode.NETWORK_ERROR:
|
|
282
|
+
return MCP_ERROR_CODES.NETWORK_ERROR;
|
|
283
|
+
case ErrorCode.SERVICE_UNAVAILABLE:
|
|
284
|
+
return MCP_ERROR_CODES.SERVICE_UNAVAILABLE;
|
|
285
|
+
case ErrorCode.AUTH_ERROR:
|
|
286
|
+
return MCP_ERROR_CODES.AUTH_ERROR;
|
|
287
|
+
case ErrorCode.NOT_FOUND:
|
|
288
|
+
return MCP_ERROR_CODES.NOT_FOUND;
|
|
289
|
+
case ErrorCode.INVALID_INPUT:
|
|
290
|
+
case ErrorCode.PARSE_ERROR:
|
|
291
|
+
return MCP_ERROR_CODES.VALIDATION_ERROR;
|
|
292
|
+
case ErrorCode.INTERNAL_ERROR:
|
|
293
|
+
case ErrorCode.UNKNOWN_ERROR:
|
|
294
|
+
default:
|
|
295
|
+
return MCP_ERROR_CODES.INTERNAL_ERROR;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Create a standardized MCP tool error response
|
|
300
|
+
* @param message - Human-readable error message
|
|
301
|
+
* @param errorCode - Optional MCP error code for programmatic handling
|
|
302
|
+
* @param retryAfter - Optional seconds to wait before retry (for rate limits)
|
|
303
|
+
*/
|
|
304
|
+
function createToolError(message, errorCode, retryAfter) {
|
|
305
|
+
const response = {
|
|
306
|
+
content: [{ type: 'text', text: message }],
|
|
307
|
+
isError: true,
|
|
308
|
+
};
|
|
309
|
+
if (errorCode) {
|
|
310
|
+
response.errorCode = errorCode;
|
|
311
|
+
}
|
|
312
|
+
if (retryAfter !== undefined && retryAfter > 0) {
|
|
313
|
+
response.retryAfter = retryAfter;
|
|
314
|
+
}
|
|
315
|
+
return response;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Create a tool error response from a StructuredError
|
|
319
|
+
* Automatically maps error codes and calculates retryAfter for rate limits
|
|
320
|
+
*/
|
|
321
|
+
export function createToolErrorFromStructured(structuredError, attempt = 0) {
|
|
322
|
+
const errorCode = mapErrorCodeToMCP(structuredError.code);
|
|
323
|
+
// Calculate retryAfter for rate-limited errors
|
|
324
|
+
let retryAfter;
|
|
325
|
+
if (structuredError.retryable && errorCode === MCP_ERROR_CODES.RATE_LIMITED) {
|
|
326
|
+
retryAfter = Math.ceil(calculateBackoff(attempt, DEFAULT_RETRY_OPTIONS) / 1000);
|
|
327
|
+
}
|
|
328
|
+
// Format user-friendly error message
|
|
329
|
+
const retryHint = structuredError.retryable
|
|
330
|
+
? '\n\n💡 This error may be temporary. Try again in a moment.'
|
|
331
|
+
: '';
|
|
332
|
+
const errorText = `## ❌ Error\n\n**${structuredError.code}:** ${structuredError.message}${retryHint}\n\nPlease check your input parameters and try again.`;
|
|
333
|
+
return createToolError(errorText, errorCode, retryAfter);
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,mBAAmB;IACnB,YAAY,EAAE,cAAc;IAC5B,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;IAC9B,mBAAmB,EAAE,qBAAqB;IAE1C,uBAAuB;IACvB,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,cAA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AC,IAAI,OAAO,eAAe,CAAC,OAAO,GAAG,SAAS,uDAAuD,CAAC;IAE3J,OAAO,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP SDK Structured Logging Utility
|
|
3
|
+
*
|
|
4
|
+
* Sends log messages to MCP clients via server.sendLoggingMessage().
|
|
5
|
+
* Falls back to stderr before the server is initialized.
|
|
6
|
+
*/
|
|
7
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
+
export type LogLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
9
|
+
/**
|
|
10
|
+
* Initialize the logger with an MCP server reference.
|
|
11
|
+
* Must be called after server creation and before any tool execution.
|
|
12
|
+
*/
|
|
13
|
+
export declare function initLogger(server: Server): void;
|
|
14
|
+
/**
|
|
15
|
+
* Log message via MCP SDK structured logging.
|
|
16
|
+
* Falls back to stderr if the server isn't initialized yet.
|
|
17
|
+
* @param level - Log level
|
|
18
|
+
* @param message - Message to log
|
|
19
|
+
* @param tool - Tool/logger name for context
|
|
20
|
+
*/
|
|
21
|
+
export declare function mcpLog(level: LogLevel, message: string, tool?: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Safe log that catches any errors (never crashes)
|
|
24
|
+
* @param level - Log level
|
|
25
|
+
* @param message - Message to log
|
|
26
|
+
* @param tool - Tool name for context
|
|
27
|
+
*/
|
|
28
|
+
export declare function safeLog(level: LogLevel, message: string, tool?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Create a bound logger for a specific tool
|
|
31
|
+
*/
|
|
32
|
+
export declare function createToolLogger(tool: string): {
|
|
33
|
+
debug: (msg: string) => void;
|
|
34
|
+
info: (msg: string) => void;
|
|
35
|
+
warning: (msg: string) => void;
|
|
36
|
+
error: (msg: string) => void;
|
|
37
|
+
};
|
|
38
|
+
export type ToolLogger = ReturnType<typeof createToolLogger>;
|
|
39
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAI9D;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAM7E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM;iBAE5B,MAAM;gBACP,MAAM;mBACH,MAAM;iBACR,MAAM;EAEtB;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP SDK Structured Logging Utility
|
|
3
|
+
*
|
|
4
|
+
* Sends log messages to MCP clients via server.sendLoggingMessage().
|
|
5
|
+
* Falls back to stderr before the server is initialized.
|
|
6
|
+
*/
|
|
7
|
+
let serverRef = null;
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the logger with an MCP server reference.
|
|
10
|
+
* Must be called after server creation and before any tool execution.
|
|
11
|
+
*/
|
|
12
|
+
export function initLogger(server) {
|
|
13
|
+
serverRef = server;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Log message via MCP SDK structured logging.
|
|
17
|
+
* Falls back to stderr if the server isn't initialized yet.
|
|
18
|
+
* @param level - Log level
|
|
19
|
+
* @param message - Message to log
|
|
20
|
+
* @param tool - Tool/logger name for context
|
|
21
|
+
*/
|
|
22
|
+
export function mcpLog(level, message, tool) {
|
|
23
|
+
const logger = tool ?? 'research-powerpack';
|
|
24
|
+
if (serverRef) {
|
|
25
|
+
serverRef.sendLoggingMessage({ level, data: message, logger }).catch(() => { });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Fallback to stderr before MCP transport is connected
|
|
29
|
+
console.error(`[${logger}] ${message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Safe log that catches any errors (never crashes)
|
|
34
|
+
* @param level - Log level
|
|
35
|
+
* @param message - Message to log
|
|
36
|
+
* @param tool - Tool name for context
|
|
37
|
+
*/
|
|
38
|
+
export function safeLog(level, message, tool) {
|
|
39
|
+
try {
|
|
40
|
+
mcpLog(level, message, tool);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Swallow logging errors - never crash
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a bound logger for a specific tool
|
|
48
|
+
*/
|
|
49
|
+
export function createToolLogger(tool) {
|
|
50
|
+
return {
|
|
51
|
+
debug: (msg) => safeLog('debug', msg, tool),
|
|
52
|
+
info: (msg) => safeLog('info', msg, tool),
|
|
53
|
+
warning: (msg) => safeLog('warning', msg, tool),
|
|
54
|
+
error: (msg) => safeLog('error', msg, tool),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,IAAI,SAAS,GAAkB,IAAI,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,UAAU,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down-formatter.d.ts","sourceRoot":"","sources":["../../src/utils/markdown-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAYtD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown formatting utilities
|
|
3
|
+
*/
|
|
4
|
+
export function removeMetaTags(content) {
|
|
5
|
+
if (!content || typeof content !== 'string') {
|
|
6
|
+
return content;
|
|
7
|
+
}
|
|
8
|
+
const lines = content.split('\n');
|
|
9
|
+
const filteredLines = lines.filter(line => {
|
|
10
|
+
const trimmed = line.trim();
|
|
11
|
+
return !trimmed.startsWith('- Meta:') && !trimmed.startsWith('Meta:');
|
|
12
|
+
});
|
|
13
|
+
return filteredLines.join('\n');
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=markdown-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-formatter.js","sourceRoot":"","sources":["../../src/utils/markdown-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Response Formatters - 70/20/10 Pattern
|
|
3
|
+
*
|
|
4
|
+
* All tool responses should follow this structure:
|
|
5
|
+
* - 70% Summary: Key insights, status, metrics
|
|
6
|
+
* - 20% Data: Structured results (lists, tables)
|
|
7
|
+
* - 10% Next Steps: Actionable follow-up commands
|
|
8
|
+
*/
|
|
9
|
+
export interface SuccessOptions {
|
|
10
|
+
/** Title/header for the response */
|
|
11
|
+
title: string;
|
|
12
|
+
/** Summary section (70% of content) */
|
|
13
|
+
summary: string;
|
|
14
|
+
/** Optional data section (20% of content) */
|
|
15
|
+
data?: string;
|
|
16
|
+
/** Optional next steps (10% of content) */
|
|
17
|
+
nextSteps?: string[];
|
|
18
|
+
/** Optional metadata footer */
|
|
19
|
+
metadata?: Record<string, string | number>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Format a successful response using 70/20/10 pattern
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatSuccess(opts: SuccessOptions): string;
|
|
25
|
+
export interface ErrorOptions {
|
|
26
|
+
/** Error code (e.g., RATE_LIMITED, TIMEOUT) */
|
|
27
|
+
code: string;
|
|
28
|
+
/** Human-readable error message */
|
|
29
|
+
message: string;
|
|
30
|
+
/** Is this error retryable? */
|
|
31
|
+
retryable?: boolean;
|
|
32
|
+
/** How to fix the error */
|
|
33
|
+
howToFix?: string[];
|
|
34
|
+
/** Alternative actions */
|
|
35
|
+
alternatives?: string[];
|
|
36
|
+
/** Tool name for context */
|
|
37
|
+
toolName?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Format an error response with recovery guidance
|
|
41
|
+
*/
|
|
42
|
+
export declare function formatError(opts: ErrorOptions): string;
|
|
43
|
+
export interface BatchHeaderOptions {
|
|
44
|
+
/** Batch operation title */
|
|
45
|
+
title: string;
|
|
46
|
+
/** Total items attempted */
|
|
47
|
+
totalItems: number;
|
|
48
|
+
/** Successfully processed count */
|
|
49
|
+
successful: number;
|
|
50
|
+
/** Failed count */
|
|
51
|
+
failed: number;
|
|
52
|
+
/** Optional tokens per item */
|
|
53
|
+
tokensPerItem?: number;
|
|
54
|
+
/** Optional batch count */
|
|
55
|
+
batches?: number;
|
|
56
|
+
/** Extra stats to include */
|
|
57
|
+
extras?: Record<string, string | number>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Format a batch operation header with stats
|
|
61
|
+
*/
|
|
62
|
+
export declare function formatBatchHeader(opts: BatchHeaderOptions): string;
|
|
63
|
+
export interface ListItem {
|
|
64
|
+
/** Item title/name */
|
|
65
|
+
title: string;
|
|
66
|
+
/** Optional description */
|
|
67
|
+
description?: string;
|
|
68
|
+
/** Optional metadata */
|
|
69
|
+
meta?: string;
|
|
70
|
+
/** Optional URL */
|
|
71
|
+
url?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Format a numbered list with optional metadata
|
|
75
|
+
*/
|
|
76
|
+
export declare function formatList(items: ListItem[], options?: {
|
|
77
|
+
maxItems?: number;
|
|
78
|
+
numbered?: boolean;
|
|
79
|
+
}): string;
|
|
80
|
+
/**
|
|
81
|
+
* Format duration in human-readable form
|
|
82
|
+
*/
|
|
83
|
+
export declare function formatDuration(ms: number): string;
|
|
84
|
+
/**
|
|
85
|
+
* Truncate text to max length with ellipsis
|
|
86
|
+
*/
|
|
87
|
+
export declare function truncateText(text: string, maxLength: number): string;
|
|
88
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,SA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