Table of Contents

Class DelegatingMcpServerResource

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Provides an McpServerResource that delegates all operations to an inner McpServerResource.

public abstract class DelegatingMcpServerResource : McpServerResource, IMcpServerPrimitive
Inheritance
DelegatingMcpServerResource
Implements
Inherited Members

Remarks

This is recommended as a base type when building resources that can be chained around an underlying McpServerResource. The default implementation simply passes each call to the inner resource instance.

Constructors

DelegatingMcpServerResource(McpServerResource)

Initializes a new instance of the DelegatingMcpServerResource class around the specified innerResource.

protected DelegatingMcpServerResource(McpServerResource innerResource)

Parameters

innerResource McpServerResource

The inner resource wrapped by this delegating resource.

Properties

ProtocolResource

Gets the protocol Resource type for this instance.

public override Resource? ProtocolResource { get; }

Property Value

Resource

Remarks

The ProtocolResourceTemplate property represents the underlying resource template definition as defined in the Model Context Protocol specification. It contains metadata like the resource templates's URI template, name, and description.

ProtocolResourceTemplate

Gets the protocol ResourceTemplate type for this instance.

public override ResourceTemplate ProtocolResourceTemplate { get; }

Property Value

ResourceTemplate

Remarks

The ProtocolResourceTemplate property represents the underlying resource template definition as defined in the Model Context Protocol specification. It contains metadata like the resource templates's URI template, name, and description.

Every valid resource URI is a valid resource URI template, and thus this property always returns an instance. In contrast, the ProtocolResource property may return null if the resource template contains a parameter, in which case the resource template URI is not a valid resource URI.

Methods

IsMatch(string)

Evaluates whether the uri matches the ProtocolResourceTemplate and can be used as the Uri passed to ReadAsync(RequestContext<ReadResourceRequestParams>, CancellationToken).

public override bool IsMatch(string uri)

Parameters

uri string

The URI being evaluated for this resource.

Returns

bool

true if the uri matches the ProtocolResourceTemplate; otherwise, false.

ReadAsync(RequestContext<ReadResourceRequestParams>, CancellationToken)

Gets the resource, rendering it with the provided request parameters and returning the resource result.

public override ValueTask<ReadResourceResult> ReadAsync(RequestContext<ReadResourceRequestParams> request, CancellationToken cancellationToken = default)

Parameters

request RequestContext<ReadResourceRequestParams>

The request context containing information about the resource invocation, including any arguments passed to the resource. This object provides access to both the request parameters and the server context.

cancellationToken CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

ValueTask<ReadResourceResult>

A ValueTask<TResult> representing the asynchronous operation, containing a ReadResourceResult with the resource content and messages.

Exceptions

ArgumentNullException

request is null.

InvalidOperationException

The Uri did not match the ProtocolResourceTemplate for this resource, the resource implementation returned null, or the resource implementation returned an unsupported result type.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.