mcp: avoid "null" when tools fail to return content
For some reason, this was a regression from v0.3.1, for some of our examples. Fix it and address the existing TODO.
This commit is contained in:
parent
46e767e646
commit
4656930de8
1 changed files with 13 additions and 9 deletions
|
|
@ -496,9 +496,13 @@ func (s *Server) callTool(ctx context.Context, req *CallToolRequest) (*CallToolR
|
|||
Message: fmt.Sprintf("unknown tool %q", req.Params.Name),
|
||||
}
|
||||
}
|
||||
// TODO: if handler returns nil content, it will serialize as null.
|
||||
// Add a test and fix.
|
||||
return st.handler(ctx, req)
|
||||
res, err := st.handler(ctx, req)
|
||||
if err == nil && res != nil && res.Content == nil {
|
||||
res2 := *res
|
||||
res2.Content = []Content{} // avoid "null"
|
||||
res = &res2
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (s *Server) listResources(_ context.Context, req *ListResourcesRequest) (*ListResourcesResult, error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue