MCP

Configuration

Config structs, YAML examples, and option helpers for MCP

YAML Configuration Example

config.yaml
extensions:
  mcp:
    enabled: true
    basePath: "/_/mcp"
    serverName: ""                   # defaults to app name
    serverVersion: ""                # defaults to app version

    # Auto-exposure
    autoExposeRoutes: true
    toolPrefix: ""
    excludePatterns: []
    includePatterns: []
    maxToolNameLength: 64

    # Capabilities
    enableResources: false
    enablePrompts: false

    # Security
    requireAuth: false
    authHeader: "Authorization"
    authTokens: []
    rateLimitPerMinute: 0            # 0 = unlimited

    # Performance
    enableMetrics: true
    schemaCache: true

The extension loads config from extensions.mcp first, falling back to mcp.

Programmatic Configuration

ext := mcp.NewExtension(
    mcp.WithBasePath("/_/mcp"),
    mcp.WithAutoExpose(true),
    mcp.WithToolPrefix("myapp_"),
    mcp.WithResources(true),
    mcp.WithPrompts(true),
)

Config Struct Reference

Config

FieldTypeDefaultDescription
EnabledbooltrueEnable the extension
BasePathstring"/_/mcp"Base path for MCP endpoints
ServerNamestring""Server name (defaults to app name)
ServerVersionstring""Server version (defaults to app version)
AutoExposeRoutesbooltrueAuto-expose HTTP routes as tools
ToolPrefixstring""Prefix for generated tool names
ExcludePatterns[]stringnilRoute patterns to exclude
IncludePatterns[]stringnilRoute patterns to include (whitelist)
MaxToolNameLengthint64Maximum tool name length
EnableResourcesboolfalseEnable MCP resources
EnablePromptsboolfalseEnable MCP prompts
RequireAuthboolfalseRequire authentication
AuthHeaderstring"Authorization"Auth header name
AuthTokens[]stringnilValid authentication tokens
RateLimitPerMinuteint0Rate limit (0 = unlimited)
EnableMetricsbooltrueEnable metrics
SchemaCachebooltrueCache generated schemas

Option Helpers

FunctionDescription
WithEnabled(enabled)Toggle the extension
WithBasePath(path)Set the base path for MCP endpoints
WithAutoExpose(enabled)Toggle auto-exposure of routes
WithToolPrefix(prefix)Set tool name prefix
WithExcludePatterns(patterns...)Set route exclude patterns
WithResources(enabled)Toggle MCP resources
WithPrompts(enabled)Toggle MCP prompts
WithAuth(header, tokens...)Enable authentication
WithRateLimit(perMinute)Set rate limit
WithConfig(config)Provide a complete config struct

How is this guide?

On this page