Skip to main content

Definition

Assembly: Microsoft.Extensions.DependencyInjection.Abstractions.dll Namespace: Microsoft.Extensions.DependencyInjection

Syntax

Microsoft.Extensions.DependencyInjection.IServiceCollection

Summary

This type is defined in Microsoft.Extensions.DependencyInjection.Abstractions.

Remarks

See Microsoft documentation for more information about the rest of the API.

Methods

AddODataHttpClient Extension

Extension method from Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions
Adds a configured HTTP client for OData service communication.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection services)

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for chaining.

Examples

services.AddODataHttpClient();

Remarks

Registers a named HTTP client “OData” configured with standard OData headers and authentication. This method is called automatically by AddODataMcpCore but can be used independently if needed.

AddODataHttpClient Extension

Extension method from Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions
Adds a configured HTTP client for OData service communication with a custom name.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection services, string clientName)

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection.
clientNamestringThe name for the HTTP client.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for chaining.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when services is null.
ArgumentExceptionThrown when clientName is null or whitespace.

Examples

// Register multiple OData clients for different services
services.AddODataHttpClient("NorthwindClient");
services.AddODataHttpClient("AdventureWorksClient");

// Use the named client
var client = httpClientFactory.CreateClient("NorthwindClient");

Remarks

Registers a named HTTP client configured for OData communication. The client is configured with:
  • Standard OData headers (Accept, OData-Version, OData-MaxVersion)
  • Base URL from configuration
  • Authentication headers based on configuration (Bearer, API Key, or Basic)
  • Timeout settings from configuration

AddODataMcp Extension

Extension method from Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions
Adds OData MCP automatic routing services to the service collection.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcp(Microsoft.Extensions.DependencyInjection.IServiceCollection services)

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for chaining.

Examples

builder.Services.AddControllers()
    .AddOData(options => options
        .AddRouteComponents("api/v1", GetV1Model())
        .AddRouteComponents("api/v2", GetV2Model()));

builder.Services.AddODataMcp(); // Automatically enables MCP for all routes

AddODataMcp Extension

Extension method from Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions
Adds OData MCP automatic routing services to the service collection with configuration.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcp(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.Core.ODataMcpOptions> configureOptions)

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection.
configureOptionsSystem.Action<Microsoft.OData.Mcp.Core.ODataMcpOptions>The options configuration delegate.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for chaining.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when services or configureOptions is null.

Examples

builder.Services.AddODataMcp(options =&gt;
{
    options.AutoRegisterRoutes = true;
    options.ExcludeRoutes = new[] { "internal", "legacy" };
    options.EnableDynamicModels = false;
});

AddODataMcpCore Extension

Extension method from Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions
Adds core OData MCP Server services to the service collection.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcpCore(Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration)

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection.
configurationMicrosoft.Extensions.Configuration.IConfigurationThe configuration root.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for chaining.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when services or configuration is null.

Examples

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddODataMcpCore(builder.Configuration);

Remarks

Registers all core services required for OData MCP functionality, including parsers, tool generators, and HTTP clients. Configuration is loaded from the “McpServer” section of the provided IConfiguration.

AddODataMcpCore Extension

Extension method from Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions
Adds OData MCP Server with custom configuration.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcpCore(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.Core.Configuration.McpServerConfiguration> configureOptions)

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection.
configureOptionsSystem.Action<Microsoft.OData.Mcp.Core.Configuration.McpServerConfiguration>Action to configure server options.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for chaining.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when services or configureOptions is null.

Examples

services.AddODataMcpCore(config =&gt;
{
    config.ODataService.BaseUrl = Environment.GetEnvironmentVariable("ODATA_URL");
    config.ODataService.RequestTimeout = TimeSpan.FromMinutes(5);
    config.Caching.Enabled = true;
});

Remarks

Registers all core services required for OData MCP functionality with programmatic configuration. This overload is useful when configuration needs to be built dynamically or when not using IConfiguration.