# McpServerResourceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [McpServerResourceBuilderExtensions](/reference/api/csharp/aspire.hosting/mcpserverresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `1`

Provides extension methods for configuring MCP (Model Context Protocol) server endpoints on resources.

## WithMcpServer(IResourceBuilder<T>, string?, string?)

> **Experimental:** ASPIREMCP001 - [Learn more](/diagnostics/aspiremcp001/)

- Name: `WithMcpServer(IResourceBuilder<T>, string?, string?)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/McpServerResourceBuilderExtensions.cs#L48-L107)

Marks the resource as hosting a Model Context Protocol (MCP) server on the specified endpoint.

```csharp
public static class McpServerResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithMcpServer<T>(
        this IResourceBuilder<T> builder,
        string? path = "/mcp",
        string? endpointName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `path` (`string?`) `optional`
  An optional path to append to the endpoint URL when forming the MCP server address. Defaults to `"/mcp"`.
- `endpointName` (`string?`) `optional`
  An optional name of the endpoint that hosts the MCP server. If not specified, defaults to the first HTTPS or HTTP endpoint.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining additional configuration.

## Remarks

This method adds an [McpServerEndpointAnnotation](/reference/api/csharp/aspire.hosting/mcpserverendpointannotation.md) to the resource, enabling the Aspire tooling to discover and proxy the MCP server exposed by the resource.

## Examples

Mark a resource as hosting an MCP server using the default endpoint: Mark a resource as hosting an MCP server with a custom path and endpoint: var api = builder.AddProject<Projects.MyApi>("api") .WithMcpServer("/sse", endpointName: "https");

```csharp
var api = builder.AddProject<Projects.MyApi>("api")
    .WithMcpServer();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
