{"record":{"id":"4b6e93563fd1e5f3","repo":"OpenNHP/opennhp","slug":"unexpected-content-type-t","errorCode":null,"errorMessage":"unexpected content type: %T","messagePattern":"unexpected content type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/agent/ta.go","lineNumber":165,"sourceCode":"func (ta *TrustedApplication) CallFunction(function string, params map[string]any) (string, error) {\n\tcallRequest := mcp.CallToolRequest{\n\t\tParams: mcp.CallToolParams{\n\t\t\tName:      function,\n\t\t\tArguments: params,\n\t\t},\n\t}\n\n\tcallResponse, err := ta.Client.CallTool(ta.Ctx, callRequest)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// check the type of content\n\tswitch firstContent := callResponse.Content[0].(type) {\n\tcase mcp.TextContent:\n\t\treturn firstContent.Text, nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unexpected content type: %T\", callResponse.Content[0])\n\t}\n}\n","sourceCodeStart":147,"sourceCodeEnd":168,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/agent/ta.go#L147-L168","documentation":"CallFunction dispatches on the MCP response content type and currently only handles mcp.TextContent. If the first element of callResponse.Content is another MCP content type (e.g. ImageContent, EmbeddedResource), it returns \"unexpected content type: %T\" including the Go type of the offending element.","triggerScenarios":"Calling a TA function whose MCP tool returns non-text content — callResponse.Content[0] is not mcp.TextContent, hitting the switch's default branch.","commonSituations":"Tool updated server-side to return structured/binary output (images, JSON resources) while the client still assumes text; wrong function invoked that returns an error payload object; MCP SDK version change introducing new content types.","solutions":["Inspect the printed %T to see the actual content type and add a case for it (e.g. mcp.ImageContent, mcp.EmbeddedResource).","Adjust the TA function or server tool to return mcp.TextContent if text is expected.","If binary/structured data is intended, decode the specific content type rather than assuming Text.","Check MCP SDK version alignment between client and server for content-type definitions."],"exampleFix":"// before\ncase mcp.TextContent:\n    return firstContent.Text, nil\n\n// after\ncase mcp.TextContent:\n    return firstContent.Text, nil\ncase mcp.EmbeddedResource:\n    return string(firstContent.Resource.Data), nil","handlingStrategy":"type-guard","validationCode":"if len(callResponse.Content) == 0 {\n    return \"\", fmt.Errorf(\"empty content\")\n}\nif _, ok := callResponse.Content[0].(mcp.TextContent); !ok {\n    return \"\", fmt.Errorf(\"expected text content, got %T\", callResponse.Content[0])\n}","typeGuard":"func asText(c mcp.Content) (string, bool) {\n    tc, ok := c.(mcp.TextContent)\n    return tc.Text, ok\n}","tryCatchPattern":"text, err := callFunction(ta, fn, args)\nif err != nil {\n    return fmt.Errorf(\"ta function %s: %w\", fn, err)\n}","preventionTips":["Keep TA functions returning mcp.TextContent for text-oriented clients.","Extend the switch when introducing new MCP content types.","Pin matching MCP SDK versions on client and server."],"tags":["mcp","type-mismatch","trusted-application","go"],"backgroundTag":"unexpected-response-shape","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}