Skip to main content

Definition

Assembly: Microsoft.OData.Mcp.Core.dll Namespace: Microsoft.OData.Mcp.Core.Tools Inheritance: System.Object

Syntax

Microsoft.OData.Mcp.Core.Tools.McpToolFactory

Summary

Factory for creating MCP tools dynamically from OData metadata.

Remarks

This factory generates MCP tools based on the parsed OData model, creating tools for CRUD operations, queries, and navigation between entities. The tools are generated dynamically to match the structure and capabilities of the OData service.

Constructors

.ctor

Initializes a new instance of the McpToolFactory class.

Syntax

public McpToolFactory(Microsoft.Extensions.Logging.ILogger<Microsoft.OData.Mcp.Core.Tools.McpToolFactory> logger, System.Net.Http.IHttpClientFactory httpClientFactory)

Parameters

NameTypeDescription
loggerMicrosoft.Extensions.Logging.ILogger<Microsoft.OData.Mcp.Core.Tools.McpToolFactory>The logger instance.
httpClientFactorySystem.Net.Http.IHttpClientFactoryThe HTTP client factory for OData requests.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when logger or httpClientFactory is null.

.ctor Inherited

Inherited from object

Syntax

public Object()

Methods

BuildDefaultSelectForEntityType

Builds a default $select statement for an entity type, excluding binary and stream fields.

Syntax

public static string BuildDefaultSelectForEntityType(Microsoft.OData.Mcp.Core.Models.EdmEntityType entityType, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
entityTypeMicrosoft.OData.Mcp.Core.Models.EdmEntityTypeThe entity type to build the select for.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?The generation options.

Returns

Type: string? A comma-separated list of property names to select, or null if all properties should be included.

Equals Inherited Virtual

Inherited from object

Syntax

public virtual bool Equals(object obj)

Parameters

NameTypeDescription
objobject?-

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

public static bool Equals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

FilterToolsForUser

Filters tools based on user authorization context.

Syntax

public System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition> FilterToolsForUser(System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition> tools, System.Collections.Generic.IEnumerable<string> userScopes, System.Collections.Generic.IEnumerable<string> userRoles, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
toolsSystem.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>The tools to filter.
userScopesSystem.Collections.Generic.IEnumerable<string>The user’s OAuth2 scopes.
userRolesSystem.Collections.Generic.IEnumerable<string>The user’s roles.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for authorization filtering.

Returns

Type: System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition> A collection of tools the user is authorized to access.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when tools is null.

GenerateCrudToolsAsync

Generates CRUD operation tools for a specific entity type.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> GenerateCrudToolsAsync(Microsoft.OData.Mcp.Core.Models.EdmEntityType entityType, Microsoft.OData.Mcp.Core.Models.EdmModel model, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
entityTypeMicrosoft.OData.Mcp.Core.Models.EdmEntityTypeThe entity type to generate CRUD tools for.
modelMicrosoft.OData.Mcp.Core.Models.EdmModelThe complete OData model for context.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for tool generation.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> A collection of CRUD tool definitions.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when entityType or model is null.

GenerateEntitySetToolsAsync

Generates tools for entity set operations (collection-level operations).

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> GenerateEntitySetToolsAsync(Microsoft.OData.Mcp.Core.Models.EdmEntitySet entitySet, Microsoft.OData.Mcp.Core.Models.EdmModel model, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
entitySetMicrosoft.OData.Mcp.Core.Models.EdmEntitySetThe entity set to generate tools for.
modelMicrosoft.OData.Mcp.Core.Models.EdmModelThe complete OData model for context.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for tool generation.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> A collection of entity set tool definitions.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when entitySet or model is null.

GenerateEntityToolsAsync

Generates MCP tools for a specific entity type.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> GenerateEntityToolsAsync(Microsoft.OData.Mcp.Core.Models.EdmEntityType entityType, Microsoft.OData.Mcp.Core.Models.EdmModel model, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
entityTypeMicrosoft.OData.Mcp.Core.Models.EdmEntityTypeThe entity type to generate tools for.
modelMicrosoft.OData.Mcp.Core.Models.EdmModelThe complete OData model for context.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for tool generation.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> A collection of generated MCP tool definitions for the entity type.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when entityType or model is null.

GenerateNavigationToolsAsync

Generates navigation tools for entity relationships.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> GenerateNavigationToolsAsync(Microsoft.OData.Mcp.Core.Models.EdmEntityType entityType, Microsoft.OData.Mcp.Core.Models.EdmModel model, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
entityTypeMicrosoft.OData.Mcp.Core.Models.EdmEntityTypeThe entity type to generate navigation tools for.
modelMicrosoft.OData.Mcp.Core.Models.EdmModelThe complete OData model for context.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for tool generation.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> A collection of navigation tool definitions.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when entityType or model is null.

GenerateQueryToolsAsync

Generates query tools for the OData model.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> GenerateQueryToolsAsync(Microsoft.OData.Mcp.Core.Models.EdmModel model, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
modelMicrosoft.OData.Mcp.Core.Models.EdmModelThe OData model to generate query tools for.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for tool generation.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> A collection of query tool definitions.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when model is null.

GenerateToolsAsync

Generates all MCP tools for the specified OData model.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> GenerateToolsAsync(Microsoft.OData.Mcp.Core.Models.EdmModel model, Microsoft.OData.Mcp.Core.Tools.McpToolGenerationOptions options = null)

Parameters

NameTypeDescription
modelMicrosoft.OData.Mcp.Core.Models.EdmModelThe OData model to generate tools for.
optionsMicrosoft.OData.Mcp.Core.Tools.McpToolGenerationOptions?Options for tool generation.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>> A collection of generated MCP tool definitions.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when model is null.

GetAvailableToolNames

Gets all available tool names.

Syntax

public System.Collections.Generic.IEnumerable<string> GetAvailableToolNames()

Returns

Type: System.Collections.Generic.IEnumerable<string> A collection of all tool names that have been generated.

GetHashCode Inherited Virtual

Inherited from object

Syntax

public virtual int GetHashCode()

Returns

Type: int

GetTool

Gets the tool definition by name.

Syntax

public Microsoft.OData.Mcp.Core.Tools.McpToolDefinition GetTool(string toolName)

Parameters

NameTypeDescription
toolNamestringThe name of the tool to retrieve.

Returns

Type: Microsoft.OData.Mcp.Core.Tools.McpToolDefinition? The tool definition if found; otherwise, null.

GetType Inherited

Inherited from object

Syntax

public System.Type GetType()

Returns

Type: System.Type

IsBinaryOrStreamField

Determines if a property is a binary or stream field that should be excluded by default.

Syntax

public static bool IsBinaryOrStreamField(Microsoft.OData.Mcp.Core.Models.EdmProperty property)

Parameters

NameTypeDescription
propertyMicrosoft.OData.Mcp.Core.Models.EdmPropertyThe property to check.

Returns

Type: bool True if the property is a binary or stream field; otherwise, false.

MemberwiseClone Inherited

Inherited from object

Syntax

protected internal object MemberwiseClone()

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

public static bool ReferenceEquals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

ToString Inherited Virtual

Inherited from object

Syntax

public virtual string ToString()

Returns

Type: string?

ValidateTools

Validates that the generated tools are compatible with the MCP specification.

Syntax

public System.Collections.Generic.IEnumerable<string> ValidateTools(System.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition> tools)

Parameters

NameTypeDescription
toolsSystem.Collections.Generic.IEnumerable<Microsoft.OData.Mcp.Core.Tools.McpToolDefinition>The tools to validate.

Returns

Type: System.Collections.Generic.IEnumerable<string> A collection of validation errors, or empty if all tools are valid.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when tools is null.
  • Microsoft.OData.Mcp.Core.Tools.IMcpToolFactory