stacklok / stacklok/toolhive-core
mcpcompat drops entire tool/prompt result when it contains an embedded resource
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2
- Forks
- 4
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 46
Description
Summary
mcpcompat.EmbeddedResource has a Resource ResourceContents field where ResourceContents is a non-empty interface, and EmbeddedResource has no custom UnmarshalJSON. So json.Unmarshal of any "type":"resource" content item errors:
json: cannot unmarshal object into Go struct field EmbeddedResource.resource of type mcp.ResourceContents
Because CallToolResult.UnmarshalJSON (and the client's convertResult) propagate that error, any tool result — or prompt message — containing an embedded resource is lost in its entirety, including any sibling text/image parts in the same content array.
Impact
Discovered from a ToolHive vMCP MCP-conformance run (the mcp-go → mcpcompat swap). Two conformance scenarios regressed:
tools-call-embedded-resource→ "No resource content found"tools-call-mixed-content→ "Expected multiple content items; Missing image content; Missing resource content"
The prompts/get path is affected too, since convertGetPromptResult also decodes content via mcp.UnmarshalContent.
Call chain
client.CallToolconverts the go-sdk result via the genericconvertResult→jsonConvert.- That runs
CallToolResult.UnmarshalJSON, which callsUnmarshalContentper item. UnmarshalContent, caseContentTypeResource, doesjson.Unmarshal(data, &EmbeddedResource{})— stdlib cannot populate theResourceContentsinterface field → error.- The error aborts the whole decode;
convertResultdiscards the partially-decoded result.
ReadResource and GetPrompt were hand-written to avoid this exact trap (convertReadResourceResult maps concrete text/blob types explicitly); CallTool was left on the generic path.
Fix
Add a custom UnmarshalJSON to EmbeddedResource that resolves the polymorphic Resource field to a concrete TextResourceContents/BlobResourceContents (blob-precedence, mirroring convertReadResourceResult). UnmarshalContent is the single chokepoint backing both tools/call and prompts/get.
Repro
wire := []byte(`{"type":"resource","resource":{"uri":"file:///x.txt","mimeType":"text/plain","text":"body"}}`)
_, err := mcp.UnmarshalContent(wire)
// err: json: cannot unmarshal object into Go struct field EmbeddedResource.resource of type mcp.ResourceContents
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with EmbeddedResource and UnmarshalContent, then trace CallToolResult.UnmarshalJSON and the convertResult path described in the issue. Reproduce the failure with the supplied wire payload, and verify that resource-only and mixed tool content decode successfully without dropping sibling items; check the prompts/get path as well.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100