@anyshift/mcp-proxy 0.4.0 → 0.4.1
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 +56 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -452,26 +452,72 @@ async function main() {
|
|
|
452
452
|
const childReturnedError = !!result.isError;
|
|
453
453
|
// Process result through file writer to get unified response
|
|
454
454
|
if (result.content && Array.isArray(result.content) && result.content.length > 0) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
455
|
+
// Extract text content and embedded resources from all content items
|
|
456
|
+
const textContents = [];
|
|
457
|
+
const resources = [];
|
|
458
|
+
for (const item of result.content) {
|
|
459
|
+
if (item.type === 'text' && typeof item.text === 'string') {
|
|
460
|
+
textContents.push(item.text);
|
|
461
|
+
}
|
|
462
|
+
else if (item.type === 'resource' && item.resource) {
|
|
463
|
+
// Handle EmbeddedResource - extract content from resource field
|
|
464
|
+
const resource = item.resource;
|
|
465
|
+
const resourceObj = {};
|
|
466
|
+
if (resource.uri)
|
|
467
|
+
resourceObj.uri = resource.uri;
|
|
468
|
+
if (resource.mimeType)
|
|
469
|
+
resourceObj.mimeType = resource.mimeType;
|
|
470
|
+
// Content can be in 'text' (string) or 'blob' (base64 binary)
|
|
471
|
+
if (resource.text) {
|
|
472
|
+
resourceObj.content = resource.text;
|
|
473
|
+
}
|
|
474
|
+
else if (resource.blob) {
|
|
475
|
+
// For binary content, keep as base64 or decode based on mimeType
|
|
476
|
+
resourceObj.content = typeof resource.blob === 'string'
|
|
477
|
+
? resource.blob
|
|
478
|
+
: Buffer.from(resource.blob).toString('base64');
|
|
479
|
+
}
|
|
480
|
+
resources.push(resourceObj);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
// Build combined content object
|
|
484
|
+
let combinedContent;
|
|
485
|
+
if (resources.length > 0) {
|
|
486
|
+
// Has resources - combine text and resources into single object
|
|
487
|
+
combinedContent = {
|
|
488
|
+
text: textContents.length === 1 ? textContents[0] : textContents,
|
|
489
|
+
resources: resources.length === 1 ? resources[0] : resources
|
|
490
|
+
};
|
|
491
|
+
if (ENABLE_LOGGING) {
|
|
492
|
+
console.debug(`[mcp-proxy] Combined ${textContents.length} text items and ${resources.length} resources`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
else if (textContents.length > 0) {
|
|
496
|
+
// Text only - use first text content (original behavior)
|
|
497
|
+
combinedContent = textContents[0];
|
|
498
|
+
}
|
|
499
|
+
if (combinedContent !== undefined) {
|
|
500
|
+
const contentStr = typeof combinedContent === 'string'
|
|
501
|
+
? combinedContent
|
|
502
|
+
: JSON.stringify(combinedContent);
|
|
503
|
+
const originalLength = contentStr.length;
|
|
458
504
|
// If child returned error, pass through directly without file writing
|
|
459
505
|
if (childReturnedError) {
|
|
460
506
|
const tool_id = generateToolId(toolName, toolArgs, fileWriterConfig.toolAbbreviations);
|
|
461
507
|
if (ENABLE_LOGGING) {
|
|
462
|
-
console.debug(`[mcp-proxy] Child MCP returned error for ${toolName}: ${
|
|
508
|
+
console.debug(`[mcp-proxy] Child MCP returned error for ${toolName}: ${contentStr.substring(0, 100)}...`);
|
|
463
509
|
}
|
|
464
510
|
return {
|
|
465
511
|
content: [{
|
|
466
512
|
type: 'text',
|
|
467
|
-
text: JSON.stringify(createErrorResponse(tool_id,
|
|
513
|
+
text: JSON.stringify(createErrorResponse(tool_id, contentStr, toolArgs), null, 2)
|
|
468
514
|
}],
|
|
469
515
|
isError: true
|
|
470
516
|
};
|
|
471
517
|
}
|
|
472
518
|
// Get unified response from file writer
|
|
473
519
|
const unifiedResponse = await fileWriter.handleResponse(toolName, toolArgs, {
|
|
474
|
-
content: [{ type: 'text', text:
|
|
520
|
+
content: [{ type: 'text', text: contentStr }]
|
|
475
521
|
});
|
|
476
522
|
if (ENABLE_LOGGING) {
|
|
477
523
|
if (unifiedResponse.wroteToFile) {
|
|
@@ -483,13 +529,13 @@ async function main() {
|
|
|
483
529
|
}
|
|
484
530
|
// If not written to file, apply truncation to outputContent
|
|
485
531
|
if (!unifiedResponse.wroteToFile && unifiedResponse.outputContent) {
|
|
486
|
-
const
|
|
532
|
+
const outputStr = typeof unifiedResponse.outputContent === 'string'
|
|
487
533
|
? unifiedResponse.outputContent
|
|
488
534
|
: JSON.stringify(unifiedResponse.outputContent);
|
|
489
|
-
const truncated = truncateResponseIfNeeded(truncationConfig,
|
|
490
|
-
if (truncated.length <
|
|
535
|
+
const truncated = truncateResponseIfNeeded(truncationConfig, outputStr);
|
|
536
|
+
if (truncated.length < outputStr.length) {
|
|
491
537
|
if (ENABLE_LOGGING) {
|
|
492
|
-
console.debug(`[mcp-proxy] Truncated response: ${
|
|
538
|
+
console.debug(`[mcp-proxy] Truncated response: ${outputStr.length} → ${truncated.length} chars`);
|
|
493
539
|
}
|
|
494
540
|
// Re-parse if it was JSON, otherwise keep as string
|
|
495
541
|
try {
|