OpenNHP/opennhp · error

unexpected content type: %T

Error message

unexpected content type: %T

What it means

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.

Solutions

  1. Inspect the printed %T to see the actual content type and add a case for it (e.g. mcp.ImageContent, mcp.EmbeddedResource).
  2. Adjust the TA function or server tool to return mcp.TextContent if text is expected.
  3. If binary/structured data is intended, decode the specific content type rather than assuming Text.
  4. Check MCP SDK version alignment between client and server for content-type definitions.

Example fix

// before
case mcp.TextContent:
    return firstContent.Text, nil

// after
case mcp.TextContent:
    return firstContent.Text, nil
case mcp.EmbeddedResource:
    return string(firstContent.Resource.Data), nil
Defensive patterns

Strategy: type-guard

Validate before calling

if len(callResponse.Content) == 0 {
    return "", fmt.Errorf("empty content")
}
if _, ok := callResponse.Content[0].(mcp.TextContent); !ok {
    return "", fmt.Errorf("expected text content, got %T", callResponse.Content[0])
}

Type guard

func asText(c mcp.Content) (string, bool) {
    tc, ok := c.(mcp.TextContent)
    return tc.Text, ok
}

Try / catch

text, err := callFunction(ta, fn, args)
if err != nil {
    return fmt.Errorf("ta function %s: %w", fn, err)
}

Prevention

When it happens

Trigger: Calling a TA function whose MCP tool returns non-text content — callResponse.Content[0] is not mcp.TextContent, hitting the switch's default branch.

Common situations: 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.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/4b6e93563fd1e5f3. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/agent/ta.go:165

func (ta *TrustedApplication) CallFunction(function string, params map[string]any) (string, error) {
	callRequest := mcp.CallToolRequest{
		Params: mcp.CallToolParams{
			Name:      function,
			Arguments: params,
		},
	}

	callResponse, err := ta.Client.CallTool(ta.Ctx, callRequest)
	if err != nil {
		return "", err
	}

	// check the type of content
	switch firstContent := callResponse.Content[0].(type) {
	case mcp.TextContent:
		return firstContent.Text, nil
	default:
		return "", fmt.Errorf("unexpected content type: %T", callResponse.Content[0])
	}
}

View on GitHub (pinned to 6e04ca5ff0)