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

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. If and only if this McpServerResource doesn't match the Uri, the method returns null.

Exceptions

ArgumentNullException

request is null.

InvalidOperationException

The resource implementation returned null or 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.