Class McpClientResource
- Namespace
- ModelContextProtocol.Client
- Assembly
- ModelContextProtocol.Core.dll
Represents a named resource that can be retrieved from an MCP server.
public sealed class McpClientResource
- Inheritance
-
McpClientResource
- Inherited Members
Remarks
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 ListResourcesAsync(IMcpClient, CancellationToken) or EnumerateResourcesAsync(IMcpClient, CancellationToken).
Properties
Description
Gets a description of the resource.
public string? Description { get; }
Property Value
MimeType
Gets a media (MIME) type of the resource.
public string? MimeType { get; }
Property Value
Name
Gets the name of the resource.
public string Name { get; }
Property Value
ProtocolResource
Gets the underlying protocol Resource type for this instance.
public Resource ProtocolResource { get; }
Property Value
Remarks
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.
For most common use cases, you can use the more convenient Name and Description properties instead of accessing the ProtocolResource directly.
Uri
Gets the URI of the resource.
public string Uri { get; }
Property Value
Methods
ReadAsync(CancellationToken)
Gets this resource's content by sending a request to the server.
public ValueTask<ReadResourceResult> ReadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- ValueTask<ReadResourceResult>
A ValueTask<TResult> containing the resource's result with content and messages.
Remarks
This is a convenience method that internally calls ReadResourceAsync(IMcpClient, string, CancellationToken).