> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# IServiceCollection

> Extension methods for IServiceCollection from Microsoft.Extensions.DependencyInjection.Abstractions

export function DocsBadge({text, variant = 'neutral'}) {
  const variantClasses = {
    success: 'mint-bg-green-500/10 mint-text-green-600 dark:mint-text-green-400 mint-border-green-500/20',
    neutral: 'mint-bg-slate-500/10 mint-text-slate-600 dark:mint-text-slate-400 mint-border-slate-500/20',
    info: 'mint-bg-blue-500/10 mint-text-blue-600 dark:mint-text-blue-400 mint-border-blue-500/20',
    warning: 'mint-bg-amber-500/10 mint-text-amber-600 dark:mint-text-amber-400 mint-border-amber-500/20',
    danger: 'mint-bg-red-500/10 mint-text-red-600 dark:mint-text-red-400 mint-border-red-500/20'
  };
  const classes = variantClasses[variant] || variantClasses.neutral;
  return <span className={`mint-inline-flex mint-items-center mint-px-2 mint-py-0.5 mint-rounded-full mint-text-xs mint-font-medium mint-tracking-wide mint-border mint-ml-1.5 mint-align-middle mint-whitespace-nowrap ${classes}`}>
      {text}
    </span>;
}

## Definition

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

**Namespace:** Microsoft.Extensions.DependencyInjection

## Syntax

```csharp theme={"dark"}
Microsoft.Extensions.DependencyInjection.IServiceCollection
```

## Summary

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

## Remarks

See [Microsoft documentation](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) for more information about the rest of the API.

## Methods

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AddODataHttpClient <DocsBadge text="Extension" variant="success" />

<Note>Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions`</Note>

Adds a configured HTTP client for OData service communication.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
```

#### Parameters

| Name       | Type                                                          | Description             |
| ---------- | ------------------------------------------------------------- | ----------------------- |
| `services` | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |

#### Returns

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

#### Examples

```csharp theme={"dark"}
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.

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AddODataHttpClient <DocsBadge text="Extension" variant="success" />

<Note>Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions`</Note>

Adds a configured HTTP client for OData service communication with a custom name.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection services, string clientName)
```

#### Parameters

| Name         | Type                                                          | Description                   |
| ------------ | ------------------------------------------------------------- | ----------------------------- |
| `services`   | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection.       |
| `clientName` | `string`                                                      | The name for the HTTP client. |

#### Returns

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

#### Exceptions

| Exception               | Description                                     |
| ----------------------- | ----------------------------------------------- |
| `ArgumentNullException` | Thrown when *services* is null.                 |
| `ArgumentException`     | Thrown when *clientName* is null or whitespace. |

#### Examples

```csharp theme={"dark"}
// 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

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AddODataMcp <DocsBadge text="Extension" variant="success" />

<Note>Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions`</Note>

Adds OData MCP automatic routing services to the service collection.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcp(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
```

#### Parameters

| Name       | Type                                                          | Description             |
| ---------- | ------------------------------------------------------------- | ----------------------- |
| `services` | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |

#### Returns

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

#### Examples

```csharp theme={"dark"}
builder.Services.AddControllers()
    .AddOData(options =&gt; options
        .AddRouteComponents("api/v1", GetV1Model())
        .AddRouteComponents("api/v2", GetV2Model()));

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

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AddODataMcp <DocsBadge text="Extension" variant="success" />

<Note>Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions`</Note>

Adds OData MCP automatic routing services to the service collection with configuration.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcp(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.Core.ODataMcpOptions> configureOptions)
```

#### Parameters

| Name               | Type                                                          | Description                         |
| ------------------ | ------------------------------------------------------------- | ----------------------------------- |
| `services`         | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection.             |
| `configureOptions` | `System.Action<Microsoft.OData.Mcp.Core.ODataMcpOptions>`     | The options configuration delegate. |

#### Returns

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

#### Exceptions

| Exception               | Description                                           |
| ----------------------- | ----------------------------------------------------- |
| `ArgumentNullException` | Thrown when *services* or *configureOptions* is null. |

#### Examples

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

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AddODataMcpCore <DocsBadge text="Extension" variant="success" />

<Note>Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions`</Note>

Adds core OData MCP Server services to the service collection.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcpCore(Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration)
```

#### Parameters

| Name            | Type                                                          | Description             |
| --------------- | ------------------------------------------------------------- | ----------------------- |
| `services`      | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |
| `configuration` | `Microsoft.Extensions.Configuration.IConfiguration`           | The configuration root. |

#### Returns

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

#### Exceptions

| Exception               | Description                                        |
| ----------------------- | -------------------------------------------------- |
| `ArgumentNullException` | Thrown when *services* or *configuration* is null. |

#### Examples

```csharp theme={"dark"}
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.

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AddODataMcpCore <DocsBadge text="Extension" variant="success" />

<Note>Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions`</Note>

Adds OData MCP Server with custom configuration.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcpCore(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.Core.Configuration.McpServerConfiguration> configureOptions)
```

#### Parameters

| Name               | Type                                                                           | Description                         |
| ------------------ | ------------------------------------------------------------------------------ | ----------------------------------- |
| `services`         | `Microsoft.Extensions.DependencyInjection.IServiceCollection`                  | The service collection.             |
| `configureOptions` | `System.Action<Microsoft.OData.Mcp.Core.Configuration.McpServerConfiguration>` | Action to configure server options. |

#### Returns

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

#### Exceptions

| Exception               | Description                                           |
| ----------------------- | ----------------------------------------------------- |
| `ArgumentNullException` | Thrown when *services* or *configureOptions* is null. |

#### Examples

```csharp theme={"dark"}
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.
