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.
Files changed (119) hide show
  1. package/README.md +635 -0
  2. package/dist/clients/reddit.d.ts +74 -0
  3. package/dist/clients/reddit.d.ts.map +1 -0
  4. package/dist/clients/reddit.js +305 -0
  5. package/dist/clients/reddit.js.map +1 -0
  6. package/dist/clients/research.d.ts +67 -0
  7. package/dist/clients/research.d.ts.map +1 -0
  8. package/dist/clients/research.js +252 -0
  9. package/dist/clients/research.js.map +1 -0
  10. package/dist/clients/scraper.d.ts +71 -0
  11. package/dist/clients/scraper.d.ts.map +1 -0
  12. package/dist/clients/scraper.js +321 -0
  13. package/dist/clients/scraper.js.map +1 -0
  14. package/dist/clients/search.d.ts +62 -0
  15. package/dist/clients/search.d.ts.map +1 -0
  16. package/dist/clients/search.js +219 -0
  17. package/dist/clients/search.js.map +1 -0
  18. package/dist/config/index.d.ts +62 -0
  19. package/dist/config/index.d.ts.map +1 -0
  20. package/dist/config/index.js +142 -0
  21. package/dist/config/index.js.map +1 -0
  22. package/dist/config/loader.d.ts +40 -0
  23. package/dist/config/loader.d.ts.map +1 -0
  24. package/dist/config/loader.js +305 -0
  25. package/dist/config/loader.js.map +1 -0
  26. package/dist/config/types.d.ts +81 -0
  27. package/dist/config/types.d.ts.map +1 -0
  28. package/dist/config/types.js +6 -0
  29. package/dist/config/types.js.map +1 -0
  30. package/dist/config/yaml/tools.yaml +130 -0
  31. package/dist/index.d.ts +7 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +271 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/schemas/deep-research.d.ts +64 -0
  36. package/dist/schemas/deep-research.d.ts.map +1 -0
  37. package/dist/schemas/deep-research.js +224 -0
  38. package/dist/schemas/deep-research.js.map +1 -0
  39. package/dist/schemas/scrape-links.d.ts +32 -0
  40. package/dist/schemas/scrape-links.d.ts.map +1 -0
  41. package/dist/schemas/scrape-links.js +34 -0
  42. package/dist/schemas/scrape-links.js.map +1 -0
  43. package/dist/schemas/web-search.d.ts +22 -0
  44. package/dist/schemas/web-search.d.ts.map +1 -0
  45. package/dist/schemas/web-search.js +21 -0
  46. package/dist/schemas/web-search.js.map +1 -0
  47. package/dist/services/file-attachment.d.ts +30 -0
  48. package/dist/services/file-attachment.d.ts.map +1 -0
  49. package/dist/services/file-attachment.js +199 -0
  50. package/dist/services/file-attachment.js.map +1 -0
  51. package/dist/services/llm-processor.d.ts +27 -0
  52. package/dist/services/llm-processor.d.ts.map +1 -0
  53. package/dist/services/llm-processor.js +179 -0
  54. package/dist/services/llm-processor.js.map +1 -0
  55. package/dist/services/markdown-cleaner.d.ts +8 -0
  56. package/dist/services/markdown-cleaner.d.ts.map +1 -0
  57. package/dist/services/markdown-cleaner.js +44 -0
  58. package/dist/services/markdown-cleaner.js.map +1 -0
  59. package/dist/tools/definitions.d.ts +16 -0
  60. package/dist/tools/definitions.d.ts.map +1 -0
  61. package/dist/tools/definitions.js +17 -0
  62. package/dist/tools/definitions.js.map +1 -0
  63. package/dist/tools/reddit.d.ts +14 -0
  64. package/dist/tools/reddit.d.ts.map +1 -0
  65. package/dist/tools/reddit.js +213 -0
  66. package/dist/tools/reddit.js.map +1 -0
  67. package/dist/tools/registry.d.ts +71 -0
  68. package/dist/tools/registry.d.ts.map +1 -0
  69. package/dist/tools/registry.js +242 -0
  70. package/dist/tools/registry.js.map +1 -0
  71. package/dist/tools/research.d.ts +14 -0
  72. package/dist/tools/research.d.ts.map +1 -0
  73. package/dist/tools/research.js +194 -0
  74. package/dist/tools/research.js.map +1 -0
  75. package/dist/tools/scrape.d.ts +14 -0
  76. package/dist/tools/scrape.d.ts.map +1 -0
  77. package/dist/tools/scrape.js +201 -0
  78. package/dist/tools/scrape.js.map +1 -0
  79. package/dist/tools/search.d.ts +10 -0
  80. package/dist/tools/search.d.ts.map +1 -0
  81. package/dist/tools/search.js +137 -0
  82. package/dist/tools/search.js.map +1 -0
  83. package/dist/tools/utils.d.ts +105 -0
  84. package/dist/tools/utils.d.ts.map +1 -0
  85. package/dist/tools/utils.js +159 -0
  86. package/dist/tools/utils.js.map +1 -0
  87. package/dist/utils/concurrency.d.ts +29 -0
  88. package/dist/utils/concurrency.d.ts.map +1 -0
  89. package/dist/utils/concurrency.js +73 -0
  90. package/dist/utils/concurrency.js.map +1 -0
  91. package/dist/utils/errors.d.ts +77 -0
  92. package/dist/utils/errors.d.ts.map +1 -0
  93. package/dist/utils/errors.js +335 -0
  94. package/dist/utils/errors.js.map +1 -0
  95. package/dist/utils/logger.d.ts +39 -0
  96. package/dist/utils/logger.d.ts.map +1 -0
  97. package/dist/utils/logger.js +57 -0
  98. package/dist/utils/logger.js.map +1 -0
  99. package/dist/utils/markdown-formatter.d.ts +5 -0
  100. package/dist/utils/markdown-formatter.d.ts.map +1 -0
  101. package/dist/utils/markdown-formatter.js +15 -0
  102. package/dist/utils/markdown-formatter.js.map +1 -0
  103. package/dist/utils/response.d.ts +88 -0
  104. package/dist/utils/response.d.ts.map +1 -0
  105. package/dist/utils/response.js +151 -0
  106. package/dist/utils/response.js.map +1 -0
  107. package/dist/utils/url-aggregator.d.ts +90 -0
  108. package/dist/utils/url-aggregator.d.ts.map +1 -0
  109. package/dist/utils/url-aggregator.js +502 -0
  110. package/dist/utils/url-aggregator.js.map +1 -0
  111. package/dist/version.d.ts +30 -0
  112. package/dist/version.d.ts.map +1 -0
  113. package/dist/version.js +60 -0
  114. package/dist/version.js.map +1 -0
  115. package/dist/worker.d.ts +17 -0
  116. package/dist/worker.d.ts.map +1 -0
  117. package/dist/worker.js +53 -0
  118. package/dist/worker.js.map +1 -0
  119. package/package.json +73 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Shared Tool Utilities
3
+ * Extracted from individual handlers to eliminate duplication
4
+ */
5
+ export { mcpLog, safeLog as safeLogSimple, createToolLogger, type LogLevel, type ToolLogger as SimpleToolLogger, } from '../utils/logger.js';
6
+ export { formatSuccess, formatError, formatBatchHeader, formatList, formatDuration, truncateText, type SuccessOptions, type ErrorOptions, type BatchHeaderOptions, type ListItem, } from '../utils/response.js';
7
+ /**
8
+ * Centralized token budgets for all tools
9
+ */
10
+ export declare const TOKEN_BUDGETS: {
11
+ /** Deep research total budget */
12
+ readonly RESEARCH: 32000;
13
+ /** Web scraper total budget */
14
+ readonly SCRAPER: 32000;
15
+ /** Reddit comment budget per batch */
16
+ readonly REDDIT_COMMENTS: 1000;
17
+ };
18
+ /**
19
+ * Logger function type used by tools
20
+ */
21
+ export type ToolLogger = (level: 'info' | 'error' | 'debug', message: string, sessionId: string) => Promise<void>;
22
+ /**
23
+ * Standard tool options passed to handlers
24
+ */
25
+ export interface ToolOptions {
26
+ sessionId?: string;
27
+ logger?: ToolLogger;
28
+ }
29
+ /**
30
+ * Safe logger wrapper - NEVER throws
31
+ * Logs to provided logger or falls back to console.error
32
+ *
33
+ * @param logger - Optional logger function
34
+ * @param sessionId - Session ID for logging context
35
+ * @param level - Log level
36
+ * @param message - Message to log
37
+ * @param toolName - Name of the tool for prefixing
38
+ */
39
+ export declare function safeLog(logger: ToolLogger | undefined, sessionId: string | undefined, level: 'info' | 'error' | 'debug', message: string, toolName: string): Promise<void>;
40
+ /**
41
+ * Calculate token allocation for batch operations
42
+ * Distributes a fixed budget across multiple items
43
+ *
44
+ * @param count - Number of items to distribute budget across
45
+ * @param budget - Total token budget
46
+ * @returns Tokens per item
47
+ */
48
+ export declare function calculateTokenAllocation(count: number, budget: number): number;
49
+ /**
50
+ * Format retry hint based on error retryability
51
+ *
52
+ * @param retryable - Whether the error is retryable
53
+ * @returns Hint string or empty string
54
+ */
55
+ export declare function formatRetryHint(retryable: boolean): string;
56
+ /**
57
+ * Create a standard error markdown response
58
+ *
59
+ * @param toolName - Name of the tool that errored
60
+ * @param errorCode - Error code
61
+ * @param message - Error message
62
+ * @param retryable - Whether error is retryable
63
+ * @param tip - Optional tip for resolution
64
+ * @returns Formatted markdown error string
65
+ */
66
+ export declare function formatToolError(toolName: string, errorCode: string, message: string, retryable: boolean, tip?: string): string;
67
+ /**
68
+ * Validate that a value is a non-empty array
69
+ *
70
+ * @param value - Value to check
71
+ * @param fieldName - Field name for error message
72
+ * @returns Error message or undefined if valid
73
+ */
74
+ export declare function validateNonEmptyArray(value: unknown, fieldName: string): string | undefined;
75
+ /**
76
+ * Validate array length is within bounds
77
+ *
78
+ * @param arr - Array to check
79
+ * @param min - Minimum length
80
+ * @param max - Maximum length
81
+ * @param fieldName - Field name for error message
82
+ * @returns Error message or undefined if valid
83
+ */
84
+ export declare function validateArrayBounds(arr: unknown[], min: number, max: number, fieldName: string): string | undefined;
85
+ /**
86
+ * Build standard header for batch operation results
87
+ *
88
+ * @param title - Title of the results section
89
+ * @param count - Number of items processed
90
+ * @param tokensPerItem - Tokens allocated per item
91
+ * @param totalBudget - Total token budget
92
+ * @returns Formatted header string
93
+ */
94
+ export declare function buildBatchHeader(title: string, count: number, tokensPerItem: number, totalBudget: number): string;
95
+ /**
96
+ * Build status line for batch results
97
+ *
98
+ * @param successful - Number of successful items
99
+ * @param failed - Number of failed items
100
+ * @param batches - Number of batches processed
101
+ * @param extras - Optional extra status items
102
+ * @returns Formatted status line
103
+ */
104
+ export declare function buildStatusLine(successful: number, failed: number, batches: number, extras?: string[]): string;
105
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,MAAM,EACN,OAAO,IAAI,aAAa,EACxB,gBAAgB,EAChB,KAAK,QAAQ,EACb,KAAK,UAAU,IAAI,gBAAgB,GACpC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACv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AE,EACd,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAQpB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM,CAMR"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Shared Tool Utilities
3
+ * Extracted from individual handlers to eliminate duplication
4
+ */
5
+ // Re-export from centralized modules
6
+ export { mcpLog, safeLog as safeLogSimple, createToolLogger, } from '../utils/logger.js';
7
+ export { formatSuccess, formatError, formatBatchHeader, formatList, formatDuration, truncateText, } from '../utils/response.js';
8
+ // ============================================================================
9
+ // Token Budget Constants
10
+ // ============================================================================
11
+ /**
12
+ * Centralized token budgets for all tools
13
+ */
14
+ export const TOKEN_BUDGETS = {
15
+ /** Deep research total budget */
16
+ RESEARCH: 32_000,
17
+ /** Web scraper total budget */
18
+ SCRAPER: 32_000,
19
+ /** Reddit comment budget per batch */
20
+ REDDIT_COMMENTS: 1_000,
21
+ };
22
+ // ============================================================================
23
+ // Logging Utilities
24
+ // ============================================================================
25
+ /**
26
+ * Safe logger wrapper - NEVER throws
27
+ * Logs to provided logger or falls back to console.error
28
+ *
29
+ * @param logger - Optional logger function
30
+ * @param sessionId - Session ID for logging context
31
+ * @param level - Log level
32
+ * @param message - Message to log
33
+ * @param toolName - Name of the tool for prefixing
34
+ */
35
+ export async function safeLog(logger, sessionId, level, message, toolName) {
36
+ if (!logger || !sessionId)
37
+ return;
38
+ try {
39
+ await logger(level, `[${toolName}] ${message}`, sessionId);
40
+ }
41
+ catch {
42
+ // Silently ignore logger errors - they should never crash the tool
43
+ console.error(`[${toolName}] Logger failed: ${message}`);
44
+ }
45
+ }
46
+ // ============================================================================
47
+ // Token Allocation
48
+ // ============================================================================
49
+ /**
50
+ * Calculate token allocation for batch operations
51
+ * Distributes a fixed budget across multiple items
52
+ *
53
+ * @param count - Number of items to distribute budget across
54
+ * @param budget - Total token budget
55
+ * @returns Tokens per item
56
+ */
57
+ export function calculateTokenAllocation(count, budget) {
58
+ if (count <= 0)
59
+ return budget;
60
+ return Math.floor(budget / count);
61
+ }
62
+ // ============================================================================
63
+ // Error Formatting
64
+ // ============================================================================
65
+ /**
66
+ * Format retry hint based on error retryability
67
+ *
68
+ * @param retryable - Whether the error is retryable
69
+ * @returns Hint string or empty string
70
+ */
71
+ export function formatRetryHint(retryable) {
72
+ return retryable
73
+ ? '\n\n💡 This error may be temporary. Try again in a moment.'
74
+ : '';
75
+ }
76
+ /**
77
+ * Create a standard error markdown response
78
+ *
79
+ * @param toolName - Name of the tool that errored
80
+ * @param errorCode - Error code
81
+ * @param message - Error message
82
+ * @param retryable - Whether error is retryable
83
+ * @param tip - Optional tip for resolution
84
+ * @returns Formatted markdown error string
85
+ */
86
+ export function formatToolError(toolName, errorCode, message, retryable, tip) {
87
+ const retryHint = formatRetryHint(retryable);
88
+ const tipSection = tip ? `\n\n**Tip:** ${tip}` : '';
89
+ return `# ❌ ${toolName}: Operation Failed\n\n**${errorCode}:** ${message}${retryHint}${tipSection}`;
90
+ }
91
+ // ============================================================================
92
+ // Validation Helpers
93
+ // ============================================================================
94
+ /**
95
+ * Validate that a value is a non-empty array
96
+ *
97
+ * @param value - Value to check
98
+ * @param fieldName - Field name for error message
99
+ * @returns Error message or undefined if valid
100
+ */
101
+ export function validateNonEmptyArray(value, fieldName) {
102
+ if (!Array.isArray(value)) {
103
+ return `${fieldName} must be an array`;
104
+ }
105
+ if (value.length === 0) {
106
+ return `${fieldName} must not be empty`;
107
+ }
108
+ return undefined;
109
+ }
110
+ /**
111
+ * Validate array length is within bounds
112
+ *
113
+ * @param arr - Array to check
114
+ * @param min - Minimum length
115
+ * @param max - Maximum length
116
+ * @param fieldName - Field name for error message
117
+ * @returns Error message or undefined if valid
118
+ */
119
+ export function validateArrayBounds(arr, min, max, fieldName) {
120
+ if (arr.length < min) {
121
+ return `${fieldName} requires at least ${min} items. Received: ${arr.length}`;
122
+ }
123
+ if (arr.length > max) {
124
+ return `${fieldName} allows at most ${max} items. Received: ${arr.length}. Please remove ${arr.length - max} item(s).`;
125
+ }
126
+ return undefined;
127
+ }
128
+ // ============================================================================
129
+ // Response Builders
130
+ // ============================================================================
131
+ /**
132
+ * Build standard header for batch operation results
133
+ *
134
+ * @param title - Title of the results section
135
+ * @param count - Number of items processed
136
+ * @param tokensPerItem - Tokens allocated per item
137
+ * @param totalBudget - Total token budget
138
+ * @returns Formatted header string
139
+ */
140
+ export function buildBatchHeader(title, count, tokensPerItem, totalBudget) {
141
+ return `# ${title} (${count} items)\n\n**Token Allocation:** ${tokensPerItem.toLocaleString()} tokens/item (${count} items, ${totalBudget.toLocaleString()} total budget)`;
142
+ }
143
+ /**
144
+ * Build status line for batch results
145
+ *
146
+ * @param successful - Number of successful items
147
+ * @param failed - Number of failed items
148
+ * @param batches - Number of batches processed
149
+ * @param extras - Optional extra status items
150
+ * @returns Formatted status line
151
+ */
152
+ export function buildStatusLine(successful, failed, batches, extras) {
153
+ let status = `**Status:** ✅ ${successful} successful | ❌ ${failed} failed | 📦 ${batches} batch(es)`;
154
+ if (extras && extras.length > 0) {
155
+ status += ` | ${extras.join(' | ')}`;
156
+ }
157
+ return status;
158
+ }
159
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qCAAqC;AACrC,OAAO,EACL,MAAM,EACN,OAAO,IAAI,aAAa,EACxB,gBAAgB,GAGjB,MAAM,oBAAo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+EAA+E;AAE/E;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,KAAa,EACb,aAAqB,EACrB,WAAmB;IAEnB,OAAO,KAAK,KAAK,KAAK,KAAK,oCAAoC,aAAa,CAAC,cAAc,EAAE,iBAAiB,KAAK,WAAW,WAAW,CAAC,cAAc,EAAE,gBAAgB,CAAC;AAC7K,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,UAAkB,EAClB,MAAc,EACd,OAAe,EACf,MAAiB;IAEjB,IAAI,MAAM,GAAG,iBAAiB,UAAU,mBAAmB,MAAM,gBAAgB,OAAO,YAAY,CAAC;IACrG,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IACvC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Concurrency utilities for bounded parallel execution
3
+ * Prevents CPU spikes and API rate limiting from unbounded Promise.all
4
+ */
5
+ /**
6
+ * Execute async tasks with a concurrency limit (like p-map).
7
+ * Processes items from the input array through the mapper function,
8
+ * running at most `concurrency` tasks simultaneously.
9
+ *
10
+ * NEVER throws - if the mapper throws, the error propagates per-item
11
+ * (caller should handle via try/catch in mapper or use Promise.allSettled pattern).
12
+ *
13
+ * @param items - Array of items to process
14
+ * @param mapper - Async function to apply to each item
15
+ * @param concurrency - Maximum number of concurrent tasks (default: 6)
16
+ * @returns Array of results in the same order as input items
17
+ */
18
+ export declare function pMap<T, R>(items: T[], mapper: (item: T, index: number) => Promise<R>, concurrency?: number): Promise<R[]>;
19
+ /**
20
+ * Like pMap but uses Promise.allSettled semantics — never rejects,
21
+ * returns PromiseSettledResult for each item.
22
+ *
23
+ * @param items - Array of items to process
24
+ * @param mapper - Async function to apply to each item
25
+ * @param concurrency - Maximum number of concurrent tasks (default: 6)
26
+ * @returns Array of PromiseSettledResult in the same order as input items
27
+ */
28
+ export declare function pMapSettled<T, R>(items: T[], mapper: (item: T, index: number) => Promise<R>, concurrency?: number): Promise<PromiseSettledResult<R>[]>;
29
+ //# sourceMappingURL=concurrency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.d.ts","sourceRoot":"","sources":["../../src/utils/concurrency.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,CAAC,EAC7B,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9C,WAAW,GAAE,MAAU,GACtB,OAAO,CAAC,CAAC,EAAE,CAAC,CAwBd;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9C,WAAW,GAAE,MAAU,GACtB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,CA2BpC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Concurrency utilities for bounded parallel execution
3
+ * Prevents CPU spikes and API rate limiting from unbounded Promise.all
4
+ */
5
+ /**
6
+ * Execute async tasks with a concurrency limit (like p-map).
7
+ * Processes items from the input array through the mapper function,
8
+ * running at most `concurrency` tasks simultaneously.
9
+ *
10
+ * NEVER throws - if the mapper throws, the error propagates per-item
11
+ * (caller should handle via try/catch in mapper or use Promise.allSettled pattern).
12
+ *
13
+ * @param items - Array of items to process
14
+ * @param mapper - Async function to apply to each item
15
+ * @param concurrency - Maximum number of concurrent tasks (default: 6)
16
+ * @returns Array of results in the same order as input items
17
+ */
18
+ export async function pMap(items, mapper, concurrency = 6) {
19
+ if (items.length === 0)
20
+ return [];
21
+ // Clamp concurrency to reasonable bounds
22
+ const limit = Math.max(1, Math.min(concurrency, items.length));
23
+ const results = new Array(items.length);
24
+ let nextIndex = 0;
25
+ async function worker() {
26
+ while (nextIndex < items.length) {
27
+ const index = nextIndex++;
28
+ results[index] = await mapper(items[index], index);
29
+ }
30
+ }
31
+ // Spawn `limit` workers that pull from the shared index
32
+ const workers = [];
33
+ for (let i = 0; i < limit; i++) {
34
+ workers.push(worker());
35
+ }
36
+ await Promise.all(workers);
37
+ return results;
38
+ }
39
+ /**
40
+ * Like pMap but uses Promise.allSettled semantics — never rejects,
41
+ * returns PromiseSettledResult for each item.
42
+ *
43
+ * @param items - Array of items to process
44
+ * @param mapper - Async function to apply to each item
45
+ * @param concurrency - Maximum number of concurrent tasks (default: 6)
46
+ * @returns Array of PromiseSettledResult in the same order as input items
47
+ */
48
+ export async function pMapSettled(items, mapper, concurrency = 6) {
49
+ if (items.length === 0)
50
+ return [];
51
+ const limit = Math.max(1, Math.min(concurrency, items.length));
52
+ const results = new Array(items.length);
53
+ let nextIndex = 0;
54
+ async function worker() {
55
+ while (nextIndex < items.length) {
56
+ const index = nextIndex++;
57
+ try {
58
+ const value = await mapper(items[index], index);
59
+ results[index] = { status: 'fulfilled', value };
60
+ }
61
+ catch (reason) {
62
+ results[index] = { status: 'rejected', reason };
63
+ }
64
+ }
65
+ }
66
+ const workers = [];
67
+ for (let i = 0; i < limit; i++) {
68
+ workers.push(worker());
69
+ }
70
+ await Promise.all(workers);
71
+ return results;
72
+ }
73
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../../src/utils/concurrency.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,KAAU,EACV,MAA8C,EAC9C,cAAsB,CAAC;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,CAAC,CAAC;IACnE,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,KAAK,UAAU,MAAM;QACnB,OAAO,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;gBAChD,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;YAClD,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAoB,EAAE,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Robust error handling utilities for MCP server
3
+ * Ensures the server NEVER crashes and always returns structured responses
4
+ */
5
+ export declare const ErrorCode: {
6
+ readonly RATE_LIMITED: "RATE_LIMITED";
7
+ readonly TIMEOUT: "TIMEOUT";
8
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
9
+ readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
10
+ readonly AUTH_ERROR: "AUTH_ERROR";
11
+ readonly INVALID_INPUT: "INVALID_INPUT";
12
+ readonly NOT_FOUND: "NOT_FOUND";
13
+ readonly QUOTA_EXCEEDED: "QUOTA_EXCEEDED";
14
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
15
+ readonly PARSE_ERROR: "PARSE_ERROR";
16
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
17
+ };
18
+ type ErrorCodeType = typeof ErrorCode[keyof typeof ErrorCode];
19
+ export interface StructuredError {
20
+ code: ErrorCodeType;
21
+ message: string;
22
+ retryable: boolean;
23
+ statusCode?: number;
24
+ cause?: string;
25
+ }
26
+ /**
27
+ * Classify any error into a structured format
28
+ * NEVER throws - always returns a valid StructuredError
29
+ */
30
+ export declare function classifyError(error: unknown): StructuredError;
31
+ /**
32
+ * Sleep utility that respects abort signals
33
+ */
34
+ export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
35
+ /**
36
+ * Wrap a fetch call with timeout via AbortController
37
+ */
38
+ export declare function fetchWithTimeout(url: string, options?: RequestInit & {
39
+ timeoutMs?: number;
40
+ }): Promise<Response>;
41
+ /**
42
+ * MCP-compliant error codes for tool responses
43
+ * These codes are exposed to clients for programmatic error handling
44
+ */
45
+ export declare const MCP_ERROR_CODES: {
46
+ readonly RATE_LIMITED: "RATE_LIMITED";
47
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
48
+ readonly TIMEOUT: "TIMEOUT";
49
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
50
+ readonly AUTH_ERROR: "AUTH_ERROR";
51
+ readonly NOT_FOUND: "NOT_FOUND";
52
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
53
+ readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
54
+ };
55
+ export type McpErrorCodeType = typeof MCP_ERROR_CODES[keyof typeof MCP_ERROR_CODES];
56
+ /**
57
+ * Structured response type for MCP tool errors
58
+ * Per MCP spec: tools return isError:true for recoverable/tool-level failures
59
+ * Uses index signature for SDK compatibility with additional fields
60
+ */
61
+ interface ToolErrorResponse {
62
+ content: Array<{
63
+ type: 'text';
64
+ text: string;
65
+ }>;
66
+ isError: true;
67
+ errorCode?: McpErrorCodeType;
68
+ retryAfter?: number;
69
+ [key: string]: unknown;
70
+ }
71
+ /**
72
+ * Create a tool error response from a StructuredError
73
+ * Automatically maps error codes and calculates retryAfter for rate limits
74
+ */
75
+ export declare function createToolErrorFromStructured(structuredError: StructuredError, attempt?: number): ToolErrorResponse;
76
+ export {};
77
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,eAAO,MAAM,SAAS;;;;;;;;;;;;CAiBZ,CAAC;AAEX,KAAK,aAAa,GAAG,OAAO,SAAS,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAM9D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAqBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CA4F7D;AAkDD;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAcrE;AAiDD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAW,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACjD,OAAO,CAAC,QAAQ,CAAC,CAcnB;AAsCD;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,OAAO,eAAe,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAEpF;;;;GAIG;AACH,UAAU,iBAAiB;IACzB,OAAO,EAAE,KAAK,CAAC;QAAE,IAA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