-
Pre-submission Checklist
Question Category
Your QuestionI am trying to return a []float32 vector from a tool call, this is my code: buf := new(bytes.Buffer)
if err := binary.Write(buf, binary.LittleEndian, v); err != nil {
slog.ErrorContext(job.ctx, "Failed to convert embedding to bytes", "error", err)
job.error <- fmt.Errorf("internal error converting embedding: %w", err)
return
}
embeddingBytes := buf.Bytes()
encodedData := base64.StdEncoding.EncodeToString(embeddingBytes)
dataURI := "data:application/octet-stream;base64," + encodedData
// Send the result back to the dispatcher as a CallToolResult.
job.result <- &mcp.CallToolResultFor[any]{
Content: []mcp.Content{
&mcp.EmbeddedResource{
Resource: &mcp.ResourceContents{
URI: dataURI,
},
},
},
} which fails with many errors! |
Beta Was this translation helpful? Give feedback.
Answered by
jba
Aug 20, 2025
Replies: 2 comments 1 reply
-
I'm not 100% that this is the correct method, but the following works! embeddingJSON, err := json.Marshal(v)
if err != nil {
slog.ErrorContext(job.ctx, "Failed to marshal embedding response", "error", err)
job.error <- fmt.Errorf("internal error marshalling embedding: %w", err)
return
}
// Send the result back to the dispatcher as a CallToolResult.
job.result <- &mcp.CallToolResultFor[any]{
Content: []mcp.Content{
&mcp.TextContent{
Text: string(embeddingJSON),
},
},
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I would use the StructuredContent field to return it as JSON.
where But note, this API will be changing in v0.3.0, due out Friday. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Dabnis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would use the StructuredContent field to return it as JSON.
In our current API, your tool handler would look like:
where
In
is whatever the input to your function is.But note, this API will be changing in v0.3.0, due out Friday.