fixes the issues where exceptions from MCP server tools aren't serial…#6482
fixes the issues where exceptions from MCP server tools aren't serial…#6482victordibia merged 13 commits intomicrosoft:mainfrom
Conversation
…ized properly Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
|
This is how the non-error/exc response looks like now: And an error response/exception (the text value is coming from the mcp server tool): |
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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() |
victordibia
left a comment
There was a problem hiding this comment.
PR is looking good overall.
Let me know if you need any help addressing the pyright/mypy/codecov remaining sections.
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
|
will fix these |
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
…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)
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
|
one of these days I'll be able to fix all lining errors :) |
|
Haha, This is mostly ready to get merged, thanks again! |
|
Sorry I mention this here, I encountered a problem when using serialization that would cause Chinese programming unicode encoding, which would make the print look weird (although the result is correct) return json.dumps([serialize_item(item) for item in value], ensure_ascil=False) However, it may not be very convenient for service deployment and packaging, as repackaging would require obtaining new dependencies again. In the context of building a multi-agent system, multiple rounds of conversation history may introduce Unicode-encoded text, which could potentially affect model inference — though the exact impact is hard to quantify. Is this something that will be addressed in future versions? |
…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