Skip to content

Proposal: Give receiving middleware access to tool errors. #64

@jba

Description

@jba

Is your feature request related to a problem? Please describe.
Middleware for tool calls won't see the actual error (value of type error) that the ToolHandler returns, because it is turned into text with IsError: true by the ToolHandler. (At least, when the ToolHandler is created with NewServerTool.) Therefore, middleware can't make decisions based on the error value.

Describe the solution you'd like
Middleware can see the error value.

Ideas:

  1. Use an interface:
type CallToolResult interface {
	ToResult() *CallToolResult
}

See https://github.com/orgs/modelcontextprotocol/discussions/364#discussioncomment-13574919.

  1. Add a method or field to CallToolResult holding the error. The field wouldn't serialize, but could be inspected by middleware.
// SetError sets the Content and IsError fields to reflect err. It also stores err itself for retrieval by GetError.
// SetError is a no-op if err == nil.
func (c *CallToolResult[In, Out]) SetError(err error) 

// GetError returns the error set by SetError, or nil if none.
func (c *CallToolResult[In, Out]) GetError() error

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions