Skip to content

AgentPrismMcpBuilderExtensions

Namespace AgentPrism · Assembly AgentPrism.Mcp.dll

Extensions that register tool discovery from remote MCP servers.

public static class AgentPrismMcpBuilderExtensions

objectAgentPrismMcpBuilderExtensions

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

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

public static IAgentPrismBuilder UseMcp(this IAgentPrismBuilder builder)

builder IAgentPrismBuilder

The AgentPrism configuration chain.

IAgentPrismBuilder

The chain, for further configuration.

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.
builder.AddAgentPrism()
.UseOpenAI(apiKey)
.UsePostgreSql(connectionString)
.UseMcp()
.UseUI();

ArgumentNullException

builder is null.

UseMcp(IAgentPrismBuilder, Action<AgentPrismMcpOptions>)

Section titled “ UseMcp(IAgentPrismBuilder, Action<AgentPrismMcpOptions>)”

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

public static IAgentPrismBuilder UseMcp(this IAgentPrismBuilder builder, Action<AgentPrismMcpOptions> configure)

builder IAgentPrismBuilder

The AgentPrism configuration chain.

configure Action<AgentPrismMcpOptions>

The option modifier.

IAgentPrismBuilder

The chain, for further configuration.

ArgumentNullException

One of the parameters is null.

UseMcp(IAgentPrismBuilder, IConfiguration, Action<AgentPrismMcpOptions>?)

Section titled “ UseMcp(IAgentPrismBuilder, IConfiguration, Action<AgentPrismMcpOptions>?)”

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

public static IAgentPrismBuilder UseMcp(this IAgentPrismBuilder builder, IConfiguration configurationSection, Action<AgentPrismMcpOptions>? configure)

builder IAgentPrismBuilder

The AgentPrism configuration chain.

configurationSection IConfiguration

The section options are read from. Typically configuration.GetSection(AgentPrismMcpOptions.SectionName).

configure Action<AgentPrismMcpOptions>?

The option modifier that runs AFTER the section is bound. A value given in code overrides the value coming from configuration. Pass null when configuration alone is enough.

IAgentPrismBuilder

The chain, for further configuration.

Configuration is provided explicitly; AgentPrism never reads IConfiguration on its own. This follows from reason the no-surprises rule (zero surprises) and stays consistent with the other Use* extensions in the repository.

builder.AddAgentPrism()
.UseMcp(builder.Configuration.GetSection(AgentPrismMcpOptions.SectionName), configure: null);

ArgumentNullException

builder or configurationSection is null.