Skip to content

Conversation

kant2002
Copy link

@kant2002 kant2002 commented Oct 5, 2025

Motivation and Context

This is to improve compliance with https://modelcontextprotocol.io/specification/2025-06-18/server/resources#data-types

How Has This Been Tested?

dotnet test locally

Breaking Changes

That's non breacking change

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@stephentoub
Copy link
Contributor

@kant2002
Copy link
Author

kant2002 commented Oct 5, 2025

Maybe I'm miss something, but I do not find a way how I can return resource with name. it got missing somewhere. And plain Resource according to documentation is not part of McpServerResourceAttribute machinery. Maybe only if I manually use WithListResourceHandler, but that's too much IMO.

@stephentoub
Copy link
Contributor

And plain Resource according to documentation is not part of McpServerResourceAttribute machinery.

Name and Title are on McpServerResourceAttribute:

public string? Name { get; set; }
/// <summary>Gets or sets the title of the resource.</summary>
public string? Title { get; set; }

@kant2002
Copy link
Author

kant2002 commented Oct 5, 2025

Honestly I don't get it. It seems from spec that Name in case of files, is name of the file, and Title is human readable file description of some sort. But attributes are make these values the same for single resource type.

@stephentoub
Copy link
Contributor

I'm not clear on what issue you're having. Can you start over and elaborate on what the fundamental issue is? I don't know what this PR is addressing. Thanks.

@kant2002
Copy link
Author

kant2002 commented Oct 6, 2025

Okay. Let me explain.

I writing MCP tool for de4dot deobfuscator. The idea is that I can download processed results as files. Right now I have

builder.Services.AddMcpServer()
	.WithHttpTransport()
	.WithTools<ObfuscatorTool>()
	.WithResources<ObfuscatedFileResource>();
....
[McpServerResourceType]
class ObfuscatedFileResource {
[McpServerResource(UriTemplate = "de4dot://files/{id}", Name = "Obfuscated file")]
public static ReadResourceResult TemplateResource(RequestContext<ReadResourceRequestParams> requestContext, int id) {
	return new() {
		Contents = [new BlobResourceContents {
			Blob = Convert.ToBase64String(memoryStream.ToArray()),
			MimeType = "application/octet-stream",
			Uri = $"de4dot://files/{id}",
		}]
	};
}
}

It's not documented, but it works. So far so good. Here how it looks
image

If you notice, it's display 1 as a file name. If I want to change it to something like deobfuscated.dll, to give hint what's inside, and to help save results of work, I guess I can use name attribute on the file. It's not explicilty stated in the spec, but based on sample I imply that this may work
image

Now my problem, I do not see a way to do that.

  1. McpServerResourceAttribute.Name is metadata is constant value.
  2. BlobResourceContents does not have a way to specify name attribute.
  3. AIContent derivatives like DataContent also allow specify blob only and not name. And from cuick glance at source code they converted to BlobResourceContents so no cake.
  4. ReadResourceResult which seems to be low-level result when use WithReadResourceHandler also operate on BlobResourceContents
  5. Resource type does is sealed and does not have ability to specify blob content.

What's the way to return binary file from MCP with specific dynamically changed name?

@kant2002
Copy link
Author

kant2002 commented Oct 7, 2025

Okay. Given modelcontextprotocol/modelcontextprotocol#1621 I think that's misunderstanding of spec on my side.

But one question still remain

  • How can I specify unique names and titles for the resource?

@kant2002
Copy link
Author

kant2002 commented Oct 7, 2025

I will close this PR, but should I open an issue for that question?

@stephentoub
Copy link
Contributor

but should I open an issue for that question?

If there's a discrepancy between the spec and what's achievable with the SDK, an Issue is fine.
If there's something missing in the spec, that'd be a better conversation to have in modelcontextprotocol/modelcontextprotocol.
If it's a general discussion about the best way to achieve something with the C# SDK, a Discussion would be appropriate.

@stephentoub stephentoub closed this Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants