Skip to content

McpTool only supports returning text types, not image #68

Closed

Description

@aaronpowell

Is your feature request related to a problem? Please describe.
I'm attempting to build out a .NET implementation of server-everything and one of the features is the Tiny Image Tool which returns a combination of text and image messages (https://github.com/modelcontextprotocol/servers/blob/e328131d99847e1eae33c7a6a8156fd217cf984f/src/everything/everything.ts#L460-L479). If you implement a McpTool method you are unable to return something that can have different content types, as the return value is always serialized to a content type of text.

Describe the solution you'd like
Some way in which you can return a different content type/collection of content types, without having to fallback to implementing a CallToolHandler.

Describe alternatives you've considered
Implementing as a CallToolHandler.

Additional context
Sample: https://github.com/aaronpowell/modelcontextprotocol-csharp-sdk/blob/dotnet-everything/samples/EverythingServer/Tools/TinyImageTool.cs

Activity

  1. self-assigned this
    on Mar 23, 2025
  2. aaronpowell commented on Mar 25, 2025

    @aaronpowell
    ContributorAuthor

    Just checking that this is now supported, as I couldn't grasp from #89 how to return different stuff from McpServerTool - is it a case of creating a Content object and returning that?

  3. stephentoub commented on Mar 26, 2025

    @stephentoub
    Contributor

    You can return a DataContent:

    case DataContent dataContent:
    return new()
    {
    Content = [new()
    {
    Data = dataContent.GetBase64Data(),
    MimeType = dataContent.MediaType,
    Type = dataContent.HasTopLevelMediaType("image") ? "image" : "resource",
    }]
    };

    and it'll be mapped either to "image" or "resource" based on its mime type.

    We can augment this list with other types as well. I believe that's what #41 is tracking. Content might be a good candidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions