Skip to content

fixes the issues where exceptions from MCP server tools aren't serial… #6482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 12, 2025

Conversation

peterj
Copy link
Contributor

@peterj peterj commented May 7, 2025

…ized properly

Why are these changes needed?

The exceptions thrown by MCP server tools weren't being serialized properly - the user would see [{}, {}, ... {}] instead of an actual error/exception message.

Related issue number

Fixes #6481

Checks

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
peterj Peter Jausovec
…ized properly

Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
@peterj
Copy link
Contributor Author

peterj commented May 7, 2025

This is how the non-error/exc response looks like now:

[{"type": "text", "text": "The weather in Seattle, WA is sunny.", "annotations": null}]

And an error response/exception (the text value is coming from the mcp server tool):

[{"type": "text", "text": "Error occured while fetching weather", "annotations": null}]

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.

Project coverage is 79.29%. Comparing base (9118f9b) to head (dbc0adb).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...n-core/src/autogen_core/tools/_static_workbench.py 81.81% 2 Missing ⚠️
...ges/autogen-ext/src/autogen_ext/tools/mcp/_base.py 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6482      +/-   ##
==========================================
+ Coverage   79.23%   79.29%   +0.06%     
==========================================
  Files         225      225              
  Lines       16666    16679      +13     
==========================================
+ Hits        13205    13226      +21     
+ Misses       3461     3453       -8     
Flag Coverage Δ
unittests 79.29% <89.65%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@victordibia
Copy link
Collaborator

victordibia commented May 9, 2025

Hi @peterj ,

Can you add a minimum repro example in the PR description, thanks.

Edit: able to repro

# server.py 
import logging
from mcp.server.fastmcp import FastMCP
 
# Create an MCP server
mcp = FastMCP("Demo")
 

# create an error agent that raises an error
@mcp.tool() 
async def error_agent(task: str) -> str:
    """An agent that raises an error"""
    raise Exception("This is an error agent") 

if __name__ == "__main__":
    mcp.run()
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import StdioServerParams, mcp_server_tools
from autogen_agentchat.agents import AssistantAgent
from autogen_core import CancellationToken
from autogen_agentchat.ui import Console

async def main() -> None:
    # Setup server params for local filesystem access
    fetch_mcp_server = StdioServerParams(command="/pathtopython/python", args=["pathtoserver/server.py"])
    tools = await mcp_server_tools(fetch_mcp_server)

    # Create an agent that can use the fetch tool.
    model_client = OpenAIChatCompletionClient(model="gpt-4o")
    agent = AssistantAgent(name="fetcher", model_client=model_client, tools=tools, reflect_on_tool_use=True)   

    await Console(agent.run_stream(task="raise an error withthe errror agent", cancellation_token=CancellationToken()))
    
await main()

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Collaborator

@victordibia victordibia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is looking good overall.
Let me know if you need any help addressing the pyright/mypy/codecov remaining sections.

peterj and others added 2 commits May 9, 2025 14:14

Verified

This commit was signed with the committer’s verified signature.
peterj Peter Jausovec
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@peterj
Copy link
Contributor Author

peterj commented May 9, 2025

will fix these

peterj added 3 commits May 9, 2025 16:32

Verified

This commit was signed with the committer’s verified signature.
peterj Peter Jausovec
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>

Verified

This commit was signed with the committer’s verified signature.
peterj Peter Jausovec
…j/fix6481

* 'peterj/fix6481' of github.com:peterj/autogen:
  improve Otel tracing (microsoft#6499)
  Fix header icons focus and hover style for better accessibility (microsoft#6409)

Verified

This commit was signed with the committer’s verified signature.
peterj Peter Jausovec
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>

Verified

This commit was signed with the committer’s verified signature.
peterj Peter Jausovec
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
@peterj
Copy link
Contributor Author

peterj commented May 12, 2025

one of these days I'll be able to fix all lining errors :)

@victordibia
Copy link
Collaborator

victordibia commented May 12, 2025

Haha,
I can take over from here (help with final test/lint fixes, merge conflicts).
Do you mind giving me push access to your repo (https://github.com/peterj/autogen)?
I seem to be getting auth issues when I try to update this PR (possibly related to git lfs).

This is mostly ready to get merged, thanks again!

@victordibia victordibia self-requested a review May 12, 2025 22:00
@victordibia victordibia merged commit 867194a into microsoft:main May 12, 2025
61 checks passed
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.

Exceptions from MCP server tool calls aren't serialized properly
2 participants