-
Notifications
You must be signed in to change notification settings - Fork 315
Add McpServer/ClientResource{Template} and friends #391
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
Merged
stephentoub
merged 2 commits into
modelcontextprotocol:main
from
stephentoub:mcpresource
May 9, 2025
+4,146
−308
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
617 changes: 617 additions & 0 deletions
617
src/Common/Polyfills/System/Runtime/CompilerServices/DefaultInterpolatedStringHandler.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using ModelContextProtocol.Protocol.Types; | ||
|
||
namespace ModelContextProtocol.Client; | ||
|
||
/// <summary> | ||
/// Represents a named resource that can be retrieved from an MCP server. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This class provides a client-side wrapper around a resource defined on an MCP server. It allows | ||
/// retrieving the resource's content by sending a request to the server with the resource's URI. | ||
/// Instances of this class are typically obtained by calling <see cref="McpClientExtensions.ListResourcesAsync"/> | ||
/// or <see cref="McpClientExtensions.EnumerateResourcesAsync"/>. | ||
/// </para> | ||
/// </remarks> | ||
public sealed class McpClientResource | ||
{ | ||
private readonly IMcpClient _client; | ||
|
||
internal McpClientResource(IMcpClient client, Resource resource) | ||
{ | ||
_client = client; | ||
ProtocolResource = resource; | ||
} | ||
|
||
/// <summary>Gets the underlying protocol <see cref="Resource"/> type for this instance.</summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This property provides direct access to the underlying protocol representation of the resource, | ||
/// which can be useful for advanced scenarios or when implementing custom MCP client extensions. | ||
/// </para> | ||
/// <para> | ||
/// For most common use cases, you can use the more convenient <see cref="Name"/> and | ||
/// <see cref="Description"/> properties instead of accessing the <see cref="ProtocolResource"/> directly. | ||
/// </para> | ||
/// </remarks> | ||
public Resource ProtocolResource { get; } | ||
|
||
/// <summary>Gets the URI of the resource.</summary> | ||
public string Uri => ProtocolResource.Uri; | ||
|
||
/// <summary>Gets the name of the resource.</summary> | ||
public string Name => ProtocolResource.Name; | ||
|
||
/// <summary>Gets a description of the resource.</summary> | ||
public string? Description => ProtocolResource.Description; | ||
|
||
/// <summary>Gets a media (MIME) type of the resource.</summary> | ||
public string? MimeType => ProtocolResource.MimeType; | ||
|
||
/// <summary> | ||
/// Gets this resource's content by sending a request to the server. | ||
/// </summary> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param> | ||
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource's result with content and messages.</returns> | ||
/// <remarks> | ||
/// <para> | ||
/// This is a convenience method that internally calls <see cref="McpClientExtensions.ReadResourceAsync(IMcpClient, string, CancellationToken)"/>. | ||
/// </para> | ||
/// </remarks> | ||
public ValueTask<ReadResourceResult> ReadAsync( | ||
CancellationToken cancellationToken = default) => | ||
_client.ReadResourceAsync(Uri, cancellationToken); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.