Description
Problem Statement
I'm writing an MCP client that performs a Tool call.
It does not know upfront about the output format of the Tool - it could be Text, Image, Audio - anything.
This makes it hard for me to typecast the response into the appropriate object mcp.AsTextContent()
or mcp.AsImageContent()
, etc. because there is no way to know the type of the response content.
In python, it is easy because I can directly access the type
field from the response object. eg-
tool_result = await session.call_tool("return_image")
print(tool_result.content[0].type)
But this is currently not possible in Go with mcp-go because the Content
interface doesn't allow us to examine the type.
Proposed Solution
Ideally, I'd like to do something like:
callToolResp, _ := mcpClient.CallTool(ctx, callToolReq)
if callToolResp.Content[0].Type() == mcp.ContentTypeText {
tc, _ := mcp.AsTextContent(callToolResp.Content[0])
} else if callToolResp.Content[0].Type() == mcp.ContentTypeImage {
tc, _ := mcp.AsImageContent(callToolResp.Content[0])
}
So I propose to add the Type()
method to the Content
interface that returns a string or even better, if you can define constants like mcp.ContentTypeImage
, etc.