Skip to content

refactor: improve MCP tool handling and change log level to debug#129

Merged
akshaydeo merged 1 commit intomainfrom
06-24-enhancement_mcp_tool_calling_enhancements
Jun 25, 2025
Merged

refactor: improve MCP tool handling and change log level to debug#129
akshaydeo merged 1 commit intomainfrom
06-24-enhancement_mcp_tool_calling_enhancements

Conversation

@Pratham-Mishra04
Copy link
Copy Markdown
Collaborator

Improved MCP Tool Handling and Logging

This PR makes several improvements to the MCP (Multi-Client Protocol) manager:

  1. Changed tool execution logging from Info to Debug level to reduce log verbosity
  2. Simplified the convertMCPToolToBifrostSchema function by directly using properties from the MCP tool schema
  3. Enhanced extractTextFromMCPResponse to properly handle different content types:
    • Text content
    • Image content
    • Audio content
    • Embedded resources
    • Fallback handling for unknown content types

The improved response extraction provides better formatting and more detailed information about the content type being returned from MCP tool executions.

@Pratham-Mishra04 Pratham-Mishra04 marked this pull request as ready for review June 24, 2025 18:08
Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 24, 2025

Summary by CodeRabbit

  • Refactor

    • Improved handling of various content types in tool responses, providing clearer and more descriptive output for text, image, audio, and embedded resource content.
    • Enhanced fallback mechanisms for extracting text from tool responses.
    • Streamlined internal processing of tool input schemas for better efficiency.
  • Style

    • Adjusted logging details for tool execution to reduce log verbosity for end-users.

Walkthrough

The changes update logging levels in the tool execution process, simplify schema conversion by directly accessing struct fields, and enhance response text extraction to handle multiple content types with improved fallback logic. No changes were made to exported or public entity declarations; only internal method implementations were modified.

Changes

File(s) Change Summary
core/mcp.go Changed logging levels from Info to Debug for tool execution, simplified schema conversion, and refactored response text extraction to support multiple content types with enhanced fallback logic.

Suggested reviewers

  • akshaydeo

Poem

The rabbit taps its clever paw,
Debug logs now show what it saw.
Schemas simplified, no JSON dance,
Extracting content with a glance.
From text to image, all in view—
Code hops ahead, as rabbits do! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1622933 and 4ae82da.

📒 Files selected for processing (1)
  • core/mcp.go (3 hunks)
🔇 Additional comments (3)
core/mcp.go (3)

419-419: LGTM! Logging level adjustment reduces verbosity appropriately.

The change from Info to Debug level for tool execution start/completion messages aligns perfectly with the PR objective to reduce log verbosity while maintaining debugging capability.

Also applies to: 427-427


636-641: Excellent simplification by removing unnecessary JSON marshaling.

The direct field access to mcpTool.InputSchema.Type, Properties, and Required is much cleaner and more efficient than the previous JSON marshaling/unmarshaling approach. This eliminates unnecessary serialization overhead.


652-682: Significant improvement in content type handling with robust fallback logic.

The refactored extractTextFromMCPResponse function now properly handles multiple content types (Text, Image, Audio, Embedded Resources) with descriptive formatting. The fallback mechanism using JSON marshaling for unknown content types is well-implemented and provides good error resilience.

Key improvements:

  • Uses strings.Builder for efficient string concatenation
  • Handles typed content with appropriate formatting
  • Robust fallback for unknown content types
  • Proper trimming and default message handling
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch 06-24-enhancement_mcp_tool_calling_enhancements

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@akshaydeo akshaydeo merged commit 41cdafe into main Jun 25, 2025
2 checks passed
@akshaydeo akshaydeo deleted the 06-24-enhancement_mcp_tool_calling_enhancements branch August 31, 2025 17:30
akshaydeo added a commit that referenced this pull request Nov 17, 2025
# Improved MCP Tool Handling and Logging

This PR makes several improvements to the MCP (Multi-Client Protocol) manager:

1. Changed tool execution logging from `Info` to `Debug` level to reduce log verbosity
2. Simplified the `convertMCPToolToBifrostSchema` function by directly using properties from the MCP tool schema
3. Enhanced `extractTextFromMCPResponse` to properly handle different content types:
   - Text content
   - Image content
   - Audio content
   - Embedded resources
   - Fallback handling for unknown content types

The improved response extraction provides better formatting and more detailed information about the content type being returned from MCP tool executions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants