Table of Contents

Class McpToolRegistry

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

Registry for Model Context Protocol (MCP) tools, allowing discovery and invocation of tools defined with the McpServerToolAttribute.

public class McpToolRegistry : RegistryBase
Inheritance
McpToolRegistry
Inherited Members
Extension Methods

Constructors

McpToolRegistry()

public McpToolRegistry()

Methods

DiscoverTools(object[])

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

public static void DiscoverTools(object[] toolInstances)

Parameters

toolInstances object[]

An array of object instances to scan for MCP tools.

DiscoverTools(object[], string[])

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

public static void DiscoverTools(object[] toolInstances, string[] toolNamePrefixes)

Parameters

toolInstances object[]

An array of object instances to scan for MCP tools.

toolNamePrefixes string[]

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

DiscoverTools(Type[])

Discovers MCP tools by scanning the provided types for methods decorated with the McpServerToolAttribute. This method should be called once to populate the tool registry.

public static void DiscoverTools(Type[] mcpTools)

Parameters

mcpTools Type[]

An array of types to scan for MCP tools.

GetToolMetadataJson()

Gets the metadata of all registered MCP tools in JSON format. This method should be called after DiscoverTools to retrieve the tool metadata.

public static string GetToolMetadataJson()

Returns

string

A JSON string containing the metadata of all registered tools.

Exceptions

Exception

Thrown if there is an error building the tools list.

InvokeTool(string, Hashtable)

Invokes a registered MCP tool by name with the specified parameters and returns the serialized result.

public static string InvokeTool(string toolName, Hashtable parameter)

Parameters

toolName string

The name of the tool to invoke.

parameter Hashtable

The parameters to pass to the tool as a Hashtable.

Returns

string

A JSON string containing the serialized result of the tool invocation.

Exceptions

Exception

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