# WithMcpServer

- Module: [Aspire.Hosting](/reference/api/go/aspire.hosting.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`ResourceWithEndpoints`](/reference/api/go/aspire.hosting/resourcewithendpoints.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

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

## Remarks

This method adds an `McpServerEndpointAnnotation` to the resource, enabling the Aspire tooling
to discover and proxy the MCP server exposed by the resource.
It does not create an endpoint, start an MCP server, or configure its transport or authentication.
The resource must already expose an MCP server at the selected endpoint and path.
Endpoint selection and URL resolution occur when tooling consumes the annotation, not when this method is called.
A missing selected endpoint causes resolution to throw a `DistributedApplicationException`.

## Definition

```go
func (ResourceWithEndpoints) WithMcpServer(options ...*WithMcpServerOptions) ResourceWithEndpoints
```

## Parameters

- `options` (`...*WithMcpServerOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithMcpServerOptions` argument.

- `Path` (`*string`) -- An optional path to append to the endpoint URL when forming the MCP server address. Defaults to `"/mcp"`. A leading slash is added if missing. A null or empty value uses the endpoint URL without an additional path.
- `EndpointName` (`*string`) -- An optional name of the endpoint that hosts the MCP server. If not specified, selects the endpoint named `https`, falling back to the endpoint named `http`. Names are matched case-insensitively; endpoints with other names must be selected explicitly, regardless of their URI scheme.

## Returns

[`ResourceWithEndpoints`](/reference/api/go/aspire.hosting/resourcewithendpoints.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`CSharpAppResource`](/reference/api/go/aspire.hosting/csharpappresource.md)
- [`ContainerResource`](/reference/api/go/aspire.hosting/containerresource.md)
- [`DotnetToolResource`](/reference/api/go/aspire.hosting/dotnettoolresource.md)
- [`ExecutableResource`](/reference/api/go/aspire.hosting/executableresource.md)
- [`ProjectResource`](/reference/api/go/aspire.hosting/projectresource.md)
