Skip to content

Resources-enhancements #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Tyler-R-Kendrick
Copy link
Contributor

@Tyler-R-Kendrick Tyler-R-Kendrick commented Apr 9, 2025

Added DI builder enhancements to resources to emulate registration of other MCP list primitives (like tools and prompts).

Motivation and Context

Enhances the api to provide a more consistent way to add resources.

How Has This Been Tested?

I wrote additional tests to cover the cases.

Breaking Changes

Yes. ReadResourceRequest marked its property as nullable instead of required. This was a bug because the spec specified it as not optional. That is changed in the PR.

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

Simplified registration of other MCP primitives for future commits.

@Tyler-R-Kendrick Tyler-R-Kendrick marked this pull request as ready for review April 10, 2025 14:28
@Tyler-R-Kendrick
Copy link
Contributor Author

The failing test appears to indicate that it will sometimes fail accidentally. I don't appear to be able to requeue the tests for evaluation. @PederHP or @stephentoub, would you be able to look into this?

The test is in ClientIntegrationTests on line 312.
It reads:

        // wait a bit to validate we don't receive another. this is best effort only;
        // false negatives are possible.
        await Assert.ThrowsAsync<TimeoutException>(() => receivedNotification.Task.WaitAsync(TimeSpan.FromSeconds(1), TestContext.Current.CancellationToken));

I would expect that this test should be broadcasting the notifications it expects to intercept instead of random sampling leading to indeterminate output.

@stephentoub
Copy link
Contributor

That's #228

@Tyler-R-Kendrick
Copy link
Contributor Author

Tyler-R-Kendrick commented Apr 10, 2025

This is for addressing #72. I've implemented a portion of the issue that can be extended to support the entire feature request.
I believe this implementation minimizes the necessary public types exposed through the API.

@alainkaiser
Copy link

Nice stuff. Will be a lot simpler to work with Resources like that!

Comment on lines 206 to 210
var isMissingListResourceHandlers = originalListResourcesHandler is not { } && listResourceTemplatesHandler is not { };
if (resourceCollection is not { IsEmpty: false } && (isMissingListResourceHandlers || readResourceHandler is not { }))
{
throw new McpException("Resources capability was enabled, but ListResources, ListResourceTemplates, and/or ReadResource handlers were not specified.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this logic. Why is "is missing" true if both originalListResourcesHandler and listResourceTemplatesHandler are non-null?

Comment on lines +480 to +481
// https://modelcontextprotocol.io/specification/2024-11-05/server/tools#capabilities
// Look to spec for guidance on ListChanged over collection existance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

// https://modelcontextprotocol.io/specification/2024-11-05/server/tools#capabilities
// Look to spec for guidance on ListChanged over collection existance.
if (capability?.Collection is { } collection)
//&& capability.ListChanged is true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@stephentoub
Copy link
Contributor

This has been sitting for a while. I've started working on a replacement that encompasses equivalents of McpServerTool, McpClientTool, etc.

@stephentoub
Copy link
Contributor

Thanks for the effort here.

Replaced by #391.

@stephentoub stephentoub closed this May 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.

3 participants