Skip to content

Exceptions from MCP server tool calls aren't serialized properly #6481

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

Closed
peterj opened this issue May 7, 2025 · 2 comments · Fixed by #6482
Closed

Exceptions from MCP server tool calls aren't serialized properly #6481

peterj opened this issue May 7, 2025 · 2 comments · Fixed by #6482
Assignees

Comments

@peterj
Copy link
Contributor

peterj commented May 7, 2025

What happened?

Describe the bug

The exception that comes from the _format_errors in the MCP tools _base .py file is ok; however, that exception is then caught in the StaticWorkbench (

) and is cast to a string (e.g. unhandled errors in a TaskGroup)

The return_value_as_string gets called and tries to iterate through the items in the above string and serialize them (return_value_as_string in McpToolAdapter class); since items are not TextContent or EmbeddedResource (they are chars), it returns '{}' for each character in the string, so the actual error that gets returned to the user looks like this:

[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]

To Reproduce

Call an MCP server tool that throws an exception.

Expected behavior
An actual exception should be displayed, but we get:

[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]

Which packages was the bug in?

Python Extensions (autogen-ext)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

None

.NET version

None

Operating system

None

@peterj
Copy link
Contributor Author

peterj commented May 8, 2025

@victordibia I submitted a PR for this issue here: #6482

@victordibia
Copy link
Collaborator

Thanks @peterj , will take a look later today!

victordibia added a commit that referenced this issue May 12, 2025
#6482)

…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

- [ ] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [x] I've made sure all auto checks have passed.

---------

Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
Co-authored-by: Victor Dibia <victordibia@microsoft.com>
Co-authored-by: Victor Dibia <victor.dibia@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants