Forge documentation
Library referenceGo

github.com/l1fe-labs/forge-go/mcp

Go mcp package.

Go mcp package.

Package contract

FieldValue
Languagego
Source versionmodule source snapshot
Manifestforge-go/go.mod
Source files6
EvidenceSource reference; registry publication and runtime conformance are separate checks

Import boundary

import "github.com/l1fe-labs/forge-go/mcp"

Use a source checkout or your verified private registry. Manifest coordinates identify the package; they do not establish that a public registry release exists.

Source reference

Download package reference JSON. Each original source file and generated declaration artifact has its own SHA-256 digest. Function bodies and constant values are omitted from downloads. These are source declaration inventories, not compiler-resolved rustdoc, TypeDoc, DocC, or Dokka output. Private modules can contain public declarations that are not reachable through the package boundary; consult the entry point before importing.

auth.go

Read declaration text · 3 declaration entries

type OAuthConfig struct

type PkceChallenge struct

func GeneratePkceChallenge() (*PkceChallenge, error)

client.go

Read declaration text · 13 declaration entries

type McpClientConfig struct

type McpClient struct

func NewMcpClient(transport McpTransport, oauth *OAuthConfig) *McpClient

func NewMcpClientFromConfig(config McpClientConfig) (*McpClient, error)

func (c *McpClient) Connect(ctx context.Context) (McpCapabilities, error)

func (c *McpClient) ListTools(ctx context.Context) ([]McpToolDescriptor, error)

func (c *McpClient) CallTool(ctx context.Context, name string, arguments any) (json.RawMessage, error)

func (c *McpClient) ListResources(ctx context.Context) ([]McpResource, error)

func (c *McpClient) GetResource(ctx context.Context, uri string) (json.RawMessage, error)

func (c *McpClient) ListPrompts(ctx context.Context) ([]McpPrompt, error)

func (c *McpClient) GetPrompt(ctx context.Context, name string, arguments map[string]string) (json.RawMessage, error)

func (c *McpClient) Disconnect() error

func (c *McpClient) Capabilities() McpCapabilities

error.go

Read declaration text · 11 declaration entries

type ErrKind string

const (
// ErrKindConnection indicates a connection establishment error.
ErrKindConnection ErrKind;

type McpError struct

func (e *McpError) Error() string

func (e *McpError) Unwrap() error

func (e *McpError) Is(target error) bool

func NewConnectionError(target, message string, cause error) *McpError

func NewTransportError(operation, message string, cause error) *McpError

func NewProtocolError(method, message string) *McpError

func NewToolNotFoundError(toolName string) *McpError

func NewSerializationError(message string, cause error) *McpError

func NewAuthError(message string, cause error) *McpError

server.go

Read declaration text · 11 declaration entries

type ToolHandler func(ctx context.Context, arguments json.RawMessage) (json.RawMessage, error)

// ResourceHandler is a function that handles an MCP resource read.
//
// Parameters:
//   - ctx: context for cancellation and timeout
//
// Returns the resource content as raw JSON or an error.
type ResourceHandler func(ctx context.Context) (json.RawMessage, error)

// PromptHandler is a function that handles an MCP prompt request.
//
// Parameters:
//   - ctx: context for cancellation and timeout
//   - arguments: the prompt arguments as key-value pairs
//
// Returns the rendered prompt as raw JSON or an error.
type PromptHandler func(ctx context.Context, arguments map[string]string) (json.RawMessage, error)

// McpServerConfig configures an MCP server.
//
// ANVIL Spec Section 12.9 -- MCP Server Configuration.
type McpServerConfig struct

type ResourceHandler func(ctx context.Context) (json.RawMessage, error)

// PromptHandler is a function that handles an MCP prompt request.
//
// Parameters:
//   - ctx: context for cancellation and timeout
//   - arguments: the prompt arguments as key-value pairs
//
// Returns the rendered prompt as raw JSON or an error.
type PromptHandler func(ctx context.Context, arguments map[string]string) (json.RawMessage, error)

// McpServerConfig configures an MCP server.
//
// ANVIL Spec Section 12.9 -- MCP Server Configuration.
type McpServerConfig struct

type PromptHandler func(ctx context.Context, arguments map[string]string) (json.RawMessage, error)

// McpServerConfig configures an MCP server.
//
// ANVIL Spec Section 12.9 -- MCP Server Configuration.
type McpServerConfig struct

type McpServerConfig struct

type McpServer struct

func NewMcpServer(config McpServerConfig) *McpServer

func (s *McpServer) RegisterTool(descriptor McpToolDescriptor, handler ToolHandler)

func (s *McpServer) RegisterResource(resource McpResource, handler ResourceHandler)

func (s *McpServer) RegisterPrompt(prompt McpPrompt, handler PromptHandler)

func (s *McpServer) HandleRequest(ctx context.Context, req *McpRequest) *McpResponse

func (s *McpServer) Serve(ctx context.Context, transport McpTransport) error

transport.go

Read declaration text · 20 declaration entries

type TransportType string

const (
// TransportTypeStdio uses standard input/output for communication.
TransportTypeStdio TransportType;

type TransportConfig struct

type McpTransport interface

func CreateTransport(config TransportConfig) (McpTransport, error)

type StdioTransport struct

func NewStdioTransport(r io.Reader, w io.Writer) *StdioTransport

func (t *StdioTransport) Send(_ context.Context, data []byte) error

func (t *StdioTransport) Receive(_ context.Context) ([]byte, error)

func (t *StdioTransport) Close() error

type SSETransport struct

func NewSSETransport(url string) *SSETransport

func (t *SSETransport) Send(ctx context.Context, data []byte) error

func (t *SSETransport) Receive(ctx context.Context) ([]byte, error)

func (t *SSETransport) ConnectSSE(ctx context.Context) error

func (t *SSETransport) Close() error

type HTTPTransport struct

func NewHTTPTransport(url string) *HTTPTransport

func (t *HTTPTransport) Send(ctx context.Context, data []byte) error

func (t *HTTPTransport) Receive(ctx context.Context) ([]byte, error)

func (t *HTTPTransport) Close() error

types.go

Read declaration text · 21 declaration entries

type McpToolDescriptor struct

type McpResource struct

type McpPrompt struct

type McpPromptArgument struct

type McpCapabilities struct

func AllCapabilities() McpCapabilities

func NoCapabilities() McpCapabilities

func DefaultCapabilities() McpCapabilities

type McpRequestID struct

func NumberID(n int64) McpRequestID

func StringID(s string) McpRequestID

func NullID() McpRequestID

func (id McpRequestID) Value() any

func (id McpRequestID) MarshalJSON() ([]byte, error)

func (id *McpRequestID) UnmarshalJSON(data []byte) error

type McpRequest struct

func NewRequest(id McpRequestID, method string, params any) (*McpRequest, error)

type McpResponse struct

func (r *McpResponse) IsError() bool

type McpErrorObject struct

func (e *McpErrorObject) Error() string

Continue

On this page