MCPcopy Create free account
hub / github.com/IBM/mcp-cli / format_tool_response

Method format_tool_response

src/mcp_cli/tools/manager.py:519–551  ·  view source on GitHub ↗

Format a tool response for display.

(response: Any)

Source from the content-addressed store, hash-verified

517
518 @staticmethod
519 def format_tool_response(response: Any) -> str:
520 """Format a tool response for display."""
521 import json
522
523 # Handle list of text records (MCP format)
524 if isinstance(response, list):
525 from mcp_cli.llm.content_models import TextContent
526
527 try:
528 text_blocks = [
529 TextContent.model_validate(item)
530 for item in response
531 if isinstance(item, dict)
532 and item.get("type") == ContentBlockType.TEXT.value
533 ]
534 if text_blocks:
535 return "\n".join(block.text for block in text_blocks)
536 except Exception as e:
537 logger.debug("TextContent parse fallback: %s", e)
538
539 if all(
540 isinstance(item, dict)
541 and item.get("type") == ContentBlockType.TEXT.value
542 for item in response
543 ):
544 return "\n".join(item.get("text", "") for item in response)
545
546 return json.dumps(response, indent=2)
547
548 if isinstance(response, dict):
549 return json.dumps(response, indent=2)
550
551 return str(response)
552
553 def _convert_to_tool_info(self, tool_dict: dict[str, Any]) -> ToolInfo:
554 """Convert chuk tool dict to mcp-cli ToolInfo."""

Callers 1

execute_toolMethod · 0.45

Calls 1

getMethod · 0.45

Tested by

no test coverage detected