# TraconMcpBuilderExtensions

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.traconmcpbuilderextensions/
> Summary: TraconMcpBuilderExtensions: Extensions that register tool discovery from remote MCP servers.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Mcp.dll</code></div>

Extensions that register tool discovery from remote MCP servers.

```csharp
public static class TraconMcpBuilderExtensions
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.traconmcpbuilderextensions/">TraconMcpBuilderExtensions</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Methods

### <a id="Tracon_TraconMcpBuilderExtensions_UseMcp_Tracon_ITraconBuilder_"></a> UseMcp\(ITraconBuilder\)

Registers the Model Context Protocol client. Tools from every registered
and enabled MCP server are discovered and listed alongside the tools
registered in code.

```csharp
public static ITraconBuilder UseMcp(this ITraconBuilder builder)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon configuration chain.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The chain, for further configuration.

#### Remarks

**Security boundary.** Adding an MCP server means accepting
tool definitions from an external source, and is a deliberate exception
to the code-only tools rule ("tools are defined only in code"). It comes with the
following safeguards:

- Only *remote* HTTP servers; there is no local process (stdio) transport.
- MCP tools **require approval** by default.
- A tool name already registered in code can never be hijacked by MCP.
- The server definition carries no secret; the authentication value is resolved from configuration.
- Every call is written to the `tool_invocations` table with the source server name.

```csharp
builder.AddTracon()
       .UseOpenAI(apiKey)
       .UsePostgreSql(connectionString)
       .UseMcp()
       .UseUI();
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### <a id="Tracon_TraconMcpBuilderExtensions_UseMcp_Tracon_ITraconBuilder_System_Action_Tracon_TraconMcpOptions__"></a> UseMcp\(ITraconBuilder, Action<TraconMcpOptions\>\)

Registers the Model Context Protocol client with settings given in code.

```csharp
public static ITraconBuilder UseMcp(this ITraconBuilder builder, Action<TraconMcpOptions> configure)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon configuration chain.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[TraconMcpOptions](/api/tracon.traconmcpoptions/)\>

The option modifier.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The chain, for further configuration.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### <a id="Tracon_TraconMcpBuilderExtensions_UseMcp_Tracon_ITraconBuilder_Microsoft_Extensions_Configuration_IConfiguration_System_Action_Tracon_TraconMcpOptions__"></a> UseMcp\(ITraconBuilder, IConfiguration, Action<TraconMcpOptions\>?\)

Registers the MCP client, reading options from the `Tracon:Mcp` section.

```csharp
public static ITraconBuilder UseMcp(this ITraconBuilder builder, IConfiguration configurationSection, Action<TraconMcpOptions>? configure)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon configuration chain.

`configurationSection` [IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)

The section options are read from. Typically
`configuration.GetSection(TraconMcpOptions.SectionName)`.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[TraconMcpOptions](/api/tracon.traconmcpoptions/)\>?

The option modifier that runs AFTER the section is bound. A value given
in code overrides the value coming from configuration. Pass
[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when configuration alone is enough.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The chain, for further configuration.

#### Remarks

Configuration is provided **explicitly**; Tracon never
reads `IConfiguration` on its own. This follows the no-surprises rule
and stays consistent with the other `Use*`
extensions in the repository.

```csharp
builder.AddTracon()
       .UseMcp(builder.Configuration.GetSection(TraconMcpOptions.SectionName), configure: null);
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder` or `configurationSection`
is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).
