> ## Documentation Index
> Fetch the complete documentation index at: https://ai.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

## Definition

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

**Namespace:** Microsoft.Extensions.DependencyInjection

## Syntax

```csharp theme={null}
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

### &#x20;AddODataMcp Extension

> [!NOTE]
>
> Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions`

Registers OData MCP services. Call `UseODataMcp` after mapping OData routes
to turn MCP on at `{prefix}/mcp`. Discovers prefixes from ASP.NET Core endpoint
routing (OData 7 `MapODataRoute` / Restier `MapApiRoute` and OData 8
conventional endpoints), plus any routes registered with
[IEdmModel)](https://learn.microsoft.com/dotnet/api/microsoft.odata.mcp.aspnetcore.hosting.odatamcphostoptions.addroute\(system.string,microsoft.odata.edm.iedmmodel\)). Prefer this unless a prefix must stay
hidden from agents; then set [ODataMcpHostOptions.IncludePrefixes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpHostOptions.md#includeprefixes) or
[ODataMcpHostOptions.ExcludeRoutes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpHostOptions.md#excluderoutes).

#### Syntax

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

#### Examples

```csharp theme={null}
builder.Services
    .AddControllers()
    .AddOData(options =&gt;
    {
        options.AddRouteComponents("odata", GetPublicModel());
        options.AddRouteComponents("reporting", GetReportingModel());
    });

builder.Services.AddODataMcp();

var app = builder.Build();
app.MapControllers();
app.UseODataMcp();
```

#### Remarks

This package does not reference Microsoft.AspNetCore.OData. The app brings OData 7 or 8.
This method does not map endpoints. Call `UseODataMcp` to map MCP. Do not call
the SDK `MapMcp` yourself.

### &#x20;AddODataMcp Extension

> [!NOTE]
>
> Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions`

Registers OData MCP services. Call `UseODataMcp` after mapping OData routes
to turn MCP on at `{prefix}/mcp`. Discovers prefixes from ASP.NET Core endpoint
routing (OData 7 `MapODataRoute` / Restier `MapApiRoute` and OData 8
conventional endpoints), plus any routes registered with
[IEdmModel)](https://learn.microsoft.com/dotnet/api/microsoft.odata.mcp.aspnetcore.hosting.odatamcphostoptions.addroute\(system.string,microsoft.odata.edm.iedmmodel\)). Prefer this unless a prefix must stay
hidden from agents; then set [ODataMcpHostOptions.IncludePrefixes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpHostOptions.md#includeprefixes) or
[ODataMcpHostOptions.ExcludeRoutes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpHostOptions.md#excluderoutes).

#### Syntax

```csharp theme={null}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcp(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpHostOptions> configure)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `services` | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |
| `configure` | `System.Action<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpHostOptions>` | Configures host options. |

#### Returns

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

#### Examples

```csharp theme={null}
builder.Services.AddODataMcp(options =&gt;
{
    options.IncludePrefixes.Add("odata");
    options.RateLimitingPolicyName = "mcp";
});

var app = builder.Build();
app.MapControllers();
app.UseODataMcp();
```

#### Remarks

This package does not reference Microsoft.AspNetCore.OData. The app brings OData 7 or 8.
This method does not map endpoints. Call `UseODataMcp` to map MCP. Do not call
the SDK `MapMcp` yourself.

### &#x20;AddODataMcp Extension

> [!NOTE]
>
> Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions`

Registers OData MCP services. Call `UseODataMcp` after mapping OData routes
to turn MCP on at `{prefix}/mcp`. Discovers prefixes from ASP.NET Core endpoint
routing (OData 7 `MapODataRoute` / Restier `MapApiRoute` and OData 8
conventional endpoints), plus any routes registered with
[IEdmModel)](https://learn.microsoft.com/dotnet/api/microsoft.odata.mcp.aspnetcore.hosting.odatamcphostoptions.addroute\(system.string,microsoft.odata.edm.iedmmodel\)). Prefer this unless a prefix must stay
hidden from agents; then set [ODataMcpHostOptions.IncludePrefixes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpHostOptions.md#includeprefixes) or
[ODataMcpHostOptions.ExcludeRoutes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpHostOptions.md#excluderoutes).

#### Syntax

```csharp theme={null}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcp(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpHostOptions> configure, System.Action<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpServerBuilder> configureServer)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `services` | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |
| `configure` | `System.Action<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpHostOptions>` | Configures host options. |
| `configureServer` | `System.Action<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpServerBuilder>?` | Optional Tasks configuration (`WithTasks`, |
| `WaitForAnnotatedAction`). Null means no Tasks wrapping. | | |

#### Returns

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

#### Examples

```csharp theme={null}
builder.Services.AddODataMcp(options =&gt; { }, mcp =&gt;
{
    mcp.WithTasks();
    mcp.WaitForAnnotatedAction&lt;HostAuthorizeWaiter&gt;();
});
```

#### Remarks

This package does not reference Microsoft.AspNetCore.OData. The app brings OData 7 or 8.
This method does not map endpoints. Call `UseODataMcp` to map MCP. Do not call
the SDK `MapMcp` yourself. Configure Tasks here, not on `UseODataMcp`.

### &#x20;AddODataMcpCore Extension

> [!NOTE]
>
> Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_Core_ServiceCollectionExtensions`

Adds the CSDL parser and a named OData [HttpClient](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient).

#### Syntax

```csharp theme={null}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddODataMcpCore(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<System.Net.Http.HttpClient> configureClient = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `services` | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |
| `configureClient` | `System.Action<System.Net.Http.HttpClient>?` | Optional named-client configuration. |

#### Returns

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

### &#x20;AddProtectedResourceMetadata Extension

> [!NOTE]
>
> Extension method from `Microsoft.Extensions.DependencyInjection.ODataMcp_AspNetCore_ServiceCollectionExtensions`

Publishes RFC 9728 protected resource metadata for this host, and annotates the
`WWW-Authenticate` challenge on a `401` beneath a covered route base with the URL of
that document. This is how a client such as `dotnet odata-mcp start` discovers how to sign in
without being told.

#### Syntax

```csharp theme={null}
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddProtectedResourceMetadata(Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.OData.Mcp.AspNetCore.Authentication.ProtectedResourceMetadataOptions> configure)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `services` | `Microsoft.Extensions.DependencyInjection.IServiceCollection` | The service collection. |
| `configure` | `System.Action<Microsoft.OData.Mcp.AspNetCore.Authentication.ProtectedResourceMetadataOptions>` | Configures what the API publishes about itself. |

#### Returns

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

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | Thrown when *services* or *configure* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

#### Examples

```csharp theme={null}
builder.Services.AddProtectedResourceMetadata(options =&gt;
{
    options.AuthorizationServers.Add(new Uri("https://login.microsoftonline.com/contoso.com/v2.0"));
    options.ScopesSupported.Add("api://contoso-odata/Data.Read");
});

// GET /.well-known/oauth-protected-resource now answers 200, anonymously.
// The protected resource is the application root.
```

#### Remarks

Independent of [IServiceCollection)](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.odatamcp_aspnetcore_servicecollectionextensions.addodatamcp\(microsoft.extensions.dependencyinjection.iservicecollection\)): an API that hosts no MCP server at all
still benefits, because the discovery this feeds is the client's, not ours. The default route base
is the application root. Set [ProtectedResourceMetadataOptions.Prefixes](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Authentication/ProtectedResourceMetadataOptions.md#prefixes) to any route
base Endpoint Routing or Minimal APIs accept, including an empty string, when the resource is not
the whole host.

The middleware is inserted at the front of the pipeline through an `IStartupFilter`, which is
what keeps the metadata document anonymously readable. There is no `Use` call to add. Calling
this more than once adds the extra configuration and registers the filter once.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.