@anyshift/mcp-proxy 0.3.5 → 0.3.6
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/index.js +24 -29
- package/dist/jq/tool.d.ts +3 -9
- package/dist/jq/tool.js +4 -4
- package/dist/types/index.d.ts +0 -21
- package/dist/utils/filename.d.ts +0 -8
- package/dist/utils/filename.js +0 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -50,6 +50,13 @@ function injectProxyParams(tool) {
|
|
|
50
50
|
modifiedTool.inputSchema.properties[key] = value;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
// Ensure isRetryAttempt is required (not optional)
|
|
54
|
+
if (!modifiedTool.inputSchema.required) {
|
|
55
|
+
modifiedTool.inputSchema.required = [];
|
|
56
|
+
}
|
|
57
|
+
if (!modifiedTool.inputSchema.required.includes('isRetryAttempt')) {
|
|
58
|
+
modifiedTool.inputSchema.required = [...modifiedTool.inputSchema.required, 'isRetryAttempt'];
|
|
59
|
+
}
|
|
53
60
|
return modifiedTool;
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
@@ -64,6 +71,18 @@ function addRetryMetadata(response, toolArgs) {
|
|
|
64
71
|
}
|
|
65
72
|
return response;
|
|
66
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Create an error response with consistent structure
|
|
76
|
+
*/
|
|
77
|
+
function createErrorResponse(tool_id, error, toolArgs) {
|
|
78
|
+
return addRetryMetadata({ tool_id, wroteToFile: false, error }, toolArgs);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a success response with content (not written to file)
|
|
82
|
+
*/
|
|
83
|
+
function createContentResponse(tool_id, outputContent, toolArgs) {
|
|
84
|
+
return addRetryMetadata({ tool_id, wroteToFile: false, outputContent }, toolArgs);
|
|
85
|
+
}
|
|
67
86
|
/**
|
|
68
87
|
* ENVIRONMENT VARIABLE CONTRACT
|
|
69
88
|
* =============================
|
|
@@ -351,11 +370,7 @@ async function main() {
|
|
|
351
370
|
});
|
|
352
371
|
// JQ tool returns directly, wrap in unified format
|
|
353
372
|
const tool_id = generateToolId(toolName, toolArgs, fileWriterConfig.toolAbbreviations);
|
|
354
|
-
const unifiedResponse =
|
|
355
|
-
tool_id,
|
|
356
|
-
wroteToFile: false,
|
|
357
|
-
outputContent: result.content?.[0]?.text
|
|
358
|
-
}, toolArgs);
|
|
373
|
+
const unifiedResponse = createContentResponse(tool_id, result.content?.[0]?.text, toolArgs);
|
|
359
374
|
return {
|
|
360
375
|
content: [{
|
|
361
376
|
type: 'text',
|
|
@@ -367,15 +382,10 @@ async function main() {
|
|
|
367
382
|
// Forward all other tools to child MCP (if child exists)
|
|
368
383
|
if (!childClient) {
|
|
369
384
|
const tool_id = generateToolId(toolName, toolArgs, fileWriterConfig.toolAbbreviations);
|
|
370
|
-
const errorResponse = addRetryMetadata({
|
|
371
|
-
tool_id,
|
|
372
|
-
wroteToFile: false,
|
|
373
|
-
error: `Tool ${toolName} not available in standalone mode (no child MCP)`
|
|
374
|
-
}, toolArgs);
|
|
375
385
|
return {
|
|
376
386
|
content: [{
|
|
377
387
|
type: 'text',
|
|
378
|
-
text: JSON.stringify(
|
|
388
|
+
text: JSON.stringify(createErrorResponse(tool_id, `Tool ${toolName} not available in standalone mode (no child MCP)`, toolArgs), null, 2)
|
|
379
389
|
}],
|
|
380
390
|
isError: true
|
|
381
391
|
};
|
|
@@ -397,18 +407,13 @@ async function main() {
|
|
|
397
407
|
// If child returned error, pass through directly without file writing
|
|
398
408
|
if (childReturnedError) {
|
|
399
409
|
const tool_id = generateToolId(toolName, toolArgs, fileWriterConfig.toolAbbreviations);
|
|
400
|
-
const errorResponse = addRetryMetadata({
|
|
401
|
-
tool_id,
|
|
402
|
-
wroteToFile: false,
|
|
403
|
-
error: item.text
|
|
404
|
-
}, toolArgs);
|
|
405
410
|
if (ENABLE_LOGGING) {
|
|
406
411
|
console.debug(`[mcp-proxy] Child MCP returned error for ${toolName}: ${item.text.substring(0, 100)}...`);
|
|
407
412
|
}
|
|
408
413
|
return {
|
|
409
414
|
content: [{
|
|
410
415
|
type: 'text',
|
|
411
|
-
text: JSON.stringify(
|
|
416
|
+
text: JSON.stringify(createErrorResponse(tool_id, item.text, toolArgs), null, 2)
|
|
412
417
|
}],
|
|
413
418
|
isError: true
|
|
414
419
|
};
|
|
@@ -457,15 +462,10 @@ async function main() {
|
|
|
457
462
|
}
|
|
458
463
|
// Fallback: return result with generated tool_id
|
|
459
464
|
const tool_id = generateToolId(toolName, toolArgs, fileWriterConfig.toolAbbreviations);
|
|
460
|
-
const fallbackResponse = addRetryMetadata({
|
|
461
|
-
tool_id,
|
|
462
|
-
wroteToFile: false,
|
|
463
|
-
outputContent: result
|
|
464
|
-
}, toolArgs);
|
|
465
465
|
return {
|
|
466
466
|
content: [{
|
|
467
467
|
type: 'text',
|
|
468
|
-
text: JSON.stringify(
|
|
468
|
+
text: JSON.stringify(createContentResponse(tool_id, result, toolArgs), null, 2)
|
|
469
469
|
}],
|
|
470
470
|
isError: childReturnedError
|
|
471
471
|
};
|
|
@@ -473,15 +473,10 @@ async function main() {
|
|
|
473
473
|
catch (error) {
|
|
474
474
|
console.error(`[mcp-proxy] Error executing tool ${toolName}:`, error);
|
|
475
475
|
const tool_id = generateToolId(toolName, toolArgs, fileWriterConfig.toolAbbreviations);
|
|
476
|
-
const errorResponse = addRetryMetadata({
|
|
477
|
-
tool_id,
|
|
478
|
-
wroteToFile: false,
|
|
479
|
-
error: `Error executing ${toolName}: ${error.message || String(error)}`
|
|
480
|
-
}, toolArgs);
|
|
481
476
|
return {
|
|
482
477
|
content: [{
|
|
483
478
|
type: 'text',
|
|
484
|
-
text: JSON.stringify(
|
|
479
|
+
text: JSON.stringify(createErrorResponse(tool_id, `Error executing ${toolName}: ${error.message || String(error)}`, toolArgs), null, 2)
|
|
485
480
|
}],
|
|
486
481
|
isError: true
|
|
487
482
|
};
|
package/dist/jq/tool.d.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
3
|
* Zod schema for JQ query execution
|
|
4
|
+
* Note: Proxy params (description, isRetryAttempt, originalToolId) are handled
|
|
5
|
+
* by the proxy layer, not validated here. They're defined in JQ_TOOL_DEFINITION's
|
|
6
|
+
* inputSchema for LLM visibility.
|
|
4
7
|
*/
|
|
5
8
|
export declare const ExecuteJqQuerySchema: z.ZodObject<{
|
|
6
9
|
jq_query: z.ZodString;
|
|
7
10
|
file_path: z.ZodString;
|
|
8
|
-
description: z.ZodOptional<z.ZodString>;
|
|
9
|
-
isRetryAttempt: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
-
originalToolId: z.ZodOptional<z.ZodString>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
jq_query: string;
|
|
13
13
|
file_path: string;
|
|
14
|
-
description?: string | undefined;
|
|
15
|
-
isRetryAttempt?: boolean | undefined;
|
|
16
|
-
originalToolId?: string | undefined;
|
|
17
14
|
}, {
|
|
18
15
|
jq_query: string;
|
|
19
16
|
file_path: string;
|
|
20
|
-
description?: string | undefined;
|
|
21
|
-
isRetryAttempt?: boolean | undefined;
|
|
22
|
-
originalToolId?: string | undefined;
|
|
23
17
|
}>;
|
|
24
18
|
/**
|
|
25
19
|
* Tool definition for JQ query execution with enhanced prompts
|
package/dist/jq/tool.js
CHANGED
|
@@ -2,6 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
import { PROXY_PARAMS } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Zod schema for JQ query execution
|
|
5
|
+
* Note: Proxy params (description, isRetryAttempt, originalToolId) are handled
|
|
6
|
+
* by the proxy layer, not validated here. They're defined in JQ_TOOL_DEFINITION's
|
|
7
|
+
* inputSchema for LLM visibility.
|
|
5
8
|
*/
|
|
6
9
|
export const ExecuteJqQuerySchema = z.object({
|
|
7
10
|
jq_query: z
|
|
@@ -10,9 +13,6 @@ export const ExecuteJqQuerySchema = z.object({
|
|
|
10
13
|
file_path: z
|
|
11
14
|
.string()
|
|
12
15
|
.describe('Absolute path starting with "/" pointing to the JSON or JSONL file to process. Must be a valid, existing file with .json or .jsonl extension. The file will be validated for existence and readability before processing.'),
|
|
13
|
-
description: z.string().optional().describe(PROXY_PARAMS.description.description),
|
|
14
|
-
isRetryAttempt: z.boolean().optional().describe(PROXY_PARAMS.isRetryAttempt.description),
|
|
15
|
-
originalToolId: z.string().optional().describe(PROXY_PARAMS.originalToolId.description),
|
|
16
16
|
});
|
|
17
17
|
/**
|
|
18
18
|
* Tool definition for JQ query execution with enhanced prompts
|
|
@@ -113,6 +113,6 @@ export const JQ_TOOL_DEFINITION = {
|
|
|
113
113
|
},
|
|
114
114
|
...PROXY_PARAMS,
|
|
115
115
|
},
|
|
116
|
-
required: ['jq_query', 'file_path'],
|
|
116
|
+
required: ['jq_query', 'file_path', 'isRetryAttempt'],
|
|
117
117
|
},
|
|
118
118
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -53,27 +53,6 @@ export interface FileWriterResult {
|
|
|
53
53
|
text: string;
|
|
54
54
|
}>;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Schema analysis result for a JSON structure
|
|
58
|
-
*/
|
|
59
|
-
export interface JsonSchema {
|
|
60
|
-
type: string;
|
|
61
|
-
properties?: Record<string, unknown>;
|
|
62
|
-
items?: unknown;
|
|
63
|
-
length?: number;
|
|
64
|
-
_hasNulls?: boolean;
|
|
65
|
-
_keysAreNumeric?: boolean;
|
|
66
|
-
_accessPattern?: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Nullable fields extracted from schema
|
|
70
|
-
*/
|
|
71
|
-
export interface NullableFields {
|
|
72
|
-
/** Fields that are always null */
|
|
73
|
-
alwaysNull: string[];
|
|
74
|
-
/** Fields that can be null (mixed types) */
|
|
75
|
-
nullable: string[];
|
|
76
|
-
}
|
|
77
56
|
/**
|
|
78
57
|
* Unified response format for all tool calls
|
|
79
58
|
* Provides a consistent structure for LLM consumption
|
package/dist/utils/filename.d.ts
CHANGED
|
@@ -6,11 +6,3 @@
|
|
|
6
6
|
* @returns Tool ID like "1697834567123_met_qry_a3b4c5"
|
|
7
7
|
*/
|
|
8
8
|
export declare const generateToolId: (toolName: string, args: Record<string, unknown>, toolAbbreviations?: Record<string, string>) => string;
|
|
9
|
-
/**
|
|
10
|
-
* Generate LLM-friendly compact filename
|
|
11
|
-
* @param toolName - Name of the tool that generated the data
|
|
12
|
-
* @param args - Arguments passed to the tool
|
|
13
|
-
* @param toolAbbreviations - Optional custom abbreviations for tool names
|
|
14
|
-
* @returns Compact filename like "1697834567123_met_qry_a3b4c5.json"
|
|
15
|
-
*/
|
|
16
|
-
export declare const generateCompactFilename: (toolName: string, args: Record<string, unknown>, toolAbbreviations?: Record<string, string>) => string;
|
package/dist/utils/filename.js
CHANGED
|
@@ -40,13 +40,3 @@ export const generateToolId = (toolName, args, toolAbbreviations) => {
|
|
|
40
40
|
const argsHash = hashArgs(args);
|
|
41
41
|
return `${timestamp}_${toolAbbrev}_${argsHash}`;
|
|
42
42
|
};
|
|
43
|
-
/**
|
|
44
|
-
* Generate LLM-friendly compact filename
|
|
45
|
-
* @param toolName - Name of the tool that generated the data
|
|
46
|
-
* @param args - Arguments passed to the tool
|
|
47
|
-
* @param toolAbbreviations - Optional custom abbreviations for tool names
|
|
48
|
-
* @returns Compact filename like "1697834567123_met_qry_a3b4c5.json"
|
|
49
|
-
*/
|
|
50
|
-
export const generateCompactFilename = (toolName, args, toolAbbreviations) => {
|
|
51
|
-
return `${generateToolId(toolName, args, toolAbbreviations)}.json`;
|
|
52
|
-
};
|