Table of Contents

Class McpResourceRegistry

Namespace
nanoFramework.WebServer.Mcp
Assembly
nanoFramework.WebServer.Mcp.dll

Registry for Model Context Protocol (MCP) resources, allowing discovery and reading of resources defined with the McpServerResourceAttribute.

public class McpResourceRegistry : RegistryBase
Inheritance
McpResourceRegistry
Inherited Members
Extension Methods

Constructors

McpResourceRegistry()

public McpResourceRegistry()

Methods

DiscoverResources(object[])

Discovers MCP resources by scanning the provided object instances for methods decorated with the McpServerResourceAttribute. Instance methods are invoked against the object they were discovered on, allowing live device objects to expose resources. This overload is additive and can be called in addition to the static DiscoverResources(Type[]) discovery.

public static void DiscoverResources(object[] resourceInstances)

Parameters

resourceInstances object[]

An array of object instances to scan for MCP resources.

DiscoverResources(object[], string[])

Discovers MCP resources on the provided object instances, prepending an optional per-instance URI prefix to every discovered resource URI so that several instances of the same type can be registered without URI collisions. This overload is additive and can be called in addition to the static DiscoverResources(Type[]) discovery.

public static void DiscoverResources(object[] resourceInstances, string[] uriPrefixes)

Parameters

resourceInstances object[]

An array of object instances to scan for MCP resources.

uriPrefixes string[]

An optional parallel array of relative URI prefixes; a null or empty entry means no prefix. May be null to apply no prefixes.

DiscoverResources(Type[])

Discovers MCP resources by scanning the provided types for methods decorated with the McpServerResourceAttribute. This method should be called once to populate the resource registry.

public static void DiscoverResources(Type[] mcpResources)

Parameters

mcpResources Type[]

An array of types to scan for MCP resources.

GetResourceMetadataJson()

Gets the metadata of all registered MCP resources in JSON format. This method should be called after DiscoverResources to retrieve the resource metadata.

public static string GetResourceMetadataJson()

Returns

string

A JSON string containing the metadata of all registered resources.

Exceptions

Exception

Thrown if there is an error building the resources list.

ReadResource(string)

Reads a registered MCP resource by URI and returns the serialized result.

public static string ReadResource(string uri)

Parameters

uri string

The URI of the resource to read.

Returns

string

A JSON string containing the serialized contents of the resource.

Exceptions

Exception

Thrown when the specified resource is not found in the registry.