Skip to content

Conversation

@alexhancock
Copy link
Collaborator

Issue:

Before this change, we wrapped all errors which occured during tool calling in a:

ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None)

There are some issues with this. Only the message (albeit with original code embedded) was included, the error itself has an incorrect code, and no additional information about the error in the third param.

Change:

This change propgates the wrapped ErrorData from ServiceError::McpErrors during tool calling into the ToolCallResult so that the model has better information about what happened. These will contain the proper error codes, original message, and additional data where the mcp sdk provides it.

Testing

I tested with the following prompt:

Call the text_editor str_replace tool to replace the header of the README.md, but leave out the old_str param, which should cause and let me test an arguments error. Tell me exactly what the error says

Before (actual error wrapped and obscured):
Screenshot 2025-10-21 at 10 28 48 AM

After (actual error included directly):
Screenshot 2025-10-21 at 10 24 24 AM

Sonnet 4.5 did a valiant effort trying to include some info about the wrapped error, but other models are likely to be confused.

@alexhancock alexhancock requested a review from DOsinga October 21, 2025 14:34
.map_err(|e| ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None))
.map_err(|e| match e {
ServiceError::McpError(error_data) => error_data,
_ => ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

still thinking a bit. may want to consider further expansion of these things too?

e.maybe_to_value() is another option for the third param instead of None

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can provide even more context in the optional data field. might be useful for debugging and also to send to the agent back

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DOsinga agreed. does 8d7158d look right to you for it?

.map_err(|e| ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None))
.map_err(|e| match e {
ServiceError::McpError(error_data) => error_data,
_ => ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None),
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can provide even more context in the optional data field. might be useful for debugging and also to send to the agent back

@alexhancock alexhancock force-pushed the alexhancock/mcp-error-propagation branch from 8d7158d to eca4c60 Compare October 21, 2025 15:01
@DOsinga
Copy link
Collaborator

DOsinga commented Oct 21, 2025

nice

@alexhancock alexhancock merged commit 3546ddb into main Oct 21, 2025
14 checks passed
@alexhancock alexhancock deleted the alexhancock/mcp-error-propagation branch October 21, 2025 15:28
katzdave added a commit that referenced this pull request Oct 21, 2025
* 'main' of github.com:block/goose:
  roll back vite and electron package upgrades breaking canary win and linux (#5292)
  Revert "Revert "Rewrite extension management tools"" (#5273)
  improvement: propagate McpErrors directly into ToolCallResult (#5289)
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Oct 25, 2025
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Nov 29, 2025
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.

3 participants