stacklok / stacklok/toolhive-core

mcpcompat drops entire tool/prompt result when it contains an embedded resource

Open
#170 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
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

  1. client.CallTool converts the go-sdk result via the generic convertResultjsonConvert.
  2. That runs CallToolResult.UnmarshalJSON, which calls UnmarshalContent per item.
  3. UnmarshalContent, case ContentTypeResource, does json.Unmarshal(data, &EmbeddedResource{}) — stdlib cannot populate the ResourceContents interface field → error.
  4. The error aborts the whole decode; convertResult discards 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.