@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.
Files changed (2) hide show
  1. package/dist/index.js +56 -10
  2. 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
- const item = result.content[0];
456
- if (item.type === 'text' && typeof item.text === 'string') {
457
- const originalLength = item.text.length;
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}: ${item.text.substring(0, 100)}...`);
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, item.text, toolArgs), null, 2)
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: item.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 contentStr = typeof unifiedResponse.outputContent === 'string'
532
+ const outputStr = typeof unifiedResponse.outputContent === 'string'
487
533
  ? unifiedResponse.outputContent
488
534
  : JSON.stringify(unifiedResponse.outputContent);
489
- const truncated = truncateResponseIfNeeded(truncationConfig, contentStr);
490
- if (truncated.length < contentStr.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: ${contentStr.length} → ${truncated.length} chars`);
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyshift/mcp-proxy",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Generic MCP proxy that adds truncation, file writing, and JQ capabilities to any MCP server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",