MCP

Functions

Public API reference for the MCP extension

Extension Entry Points

FunctionDescription
NewExtension(opts ...ConfigOption) forge.ExtensionCreate the MCP extension with functional options
NewExtensionWithConfig(config Config) forge.ExtensionCreate the MCP extension with a complete config
DefaultConfig() ConfigReturns the default configuration

Server -- Tool Operations

MethodDescription
RegisterTool(tool Tool) errorRegister a tool with name, description, schema, and handler
ListTools() []ToolList all registered tools
ExecuteTool(ctx, name, arguments) (*ToolResult, error)Execute a named tool with arguments
GenerateToolFromRoute(route) (*Tool, error)Generate a tool definition from a Forge HTTP route

Server -- Resource Operations

MethodDescription
RegisterResource(resource Resource, reader ResourceReader) errorRegister a resource with a reader function
ListResources() []ResourceList all registered resources
ReadResource(ctx, uri) (*ResourceContents, error)Read a resource by URI

Server -- Prompt Operations

MethodDescription
RegisterPrompt(prompt Prompt, generator PromptGenerator) errorRegister a prompt template with a generator function
ListPrompts() []PromptList all registered prompts
GetPrompt(ctx, name, arguments) ([]PromptMessage, error)Generate prompt messages from a template

Server -- Info

MethodDescription
GetServerInfo() ServerInfoGet server name, version, and capabilities

Middleware

FunctionDescription
AuthMiddleware(config, logger) forge.PureMiddlewareCreate authentication middleware for MCP endpoints
RateLimitMiddleware(config, logger, metrics) forge.PureMiddlewareCreate rate limiting middleware

Key Types

Tool

FieldTypePurpose
NamestringTool identifier
DescriptionstringHuman-readable description for AI agents
InputSchemaJSONSchemaJSON Schema describing expected arguments

Resource

FieldTypePurpose
URIstringResource identifier (e.g. file:///path)
NamestringDisplay name
DescriptionstringHuman-readable description
MimeTypestringContent type

Prompt

FieldTypePurpose
NamestringPrompt identifier
DescriptionstringHuman-readable description
Arguments[]PromptArgumentTyped arguments the prompt accepts

PromptMessage

FieldTypePurpose
RolestringMessage role (user, assistant, system)
ContentContentMessage content (text, image, or resource)

How is this guide?

On this page