Help us shape the future of Go! Take the 2026 Go Developer Survey

mcp

package
v0.18.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Overview

Package mcp is GoRun's official Model Context Protocol server: the streamable HTTP endpoint at /mcp (bearer API keys only) and the stdio transport behind `gorun mcp --key`. Tools are the core set registered here plus every kernel.MCPTool other modules add to Deps.MCP. Each call is scope-checked with auth.Can, audited (mcp.call) and, for sensitive tools, parked in mcp_approvals until a human approves it in "AI Agents → Approvals" (unless the key holds mcp.approve_self).

Index

Constants

View Source
const (
	StatusPending  = "pending"
	StatusApproved = "approved"
	StatusDenied   = "denied"
	StatusExpired  = "expired"
	StatusFailed   = "failed"
)

Approval statuses (mcp_approvals.status) and the agent-facing pending status. "approved" with an empty result means the call is executing; "failed" is an approved call whose execution errored or was interrupted.

View Source
const (
	// PermApprove lets a user decide pending sensitive tool calls.
	PermApprove = "mcp.approve"
	// PermApproveSelf is a key scope: sensitive tools run without approval.
	PermApproveSelf = "mcp.approve_self"
)

Permissions declared by this module.

Variables

View Source
var (
	// ErrApprovalNotFound is returned for unknown approvals (and for
	// approvals of another API key in check_approval).
	ErrApprovalNotFound = errors.New("mcp: approval not found")
	// ErrDecisionForbidden is returned when the decider may not decide: the
	// requesting key itself, another key of the same owner (unless
	// GORUN_MCP_SAME_OWNER_APPROVAL), or an API key without an explicit
	// mcp.approve scope ("*" does not count).
	ErrDecisionForbidden = errors.New("mcp: this principal may not decide approvals")
)

Functions

func RunIO

func RunIO(ctx context.Context, app *kernel.App, apiKey string, in io.ReadCloser, out io.WriteCloser) error

RunIO is RunStdio over the given streams (newline-delimited JSON-RPC), for embedding and tests; apiKey falls back to GORUN_MCP_KEY too.

func RunStdio

func RunStdio(ctx context.Context, app *kernel.App, apiKey string) error

RunStdio serves MCP over stdin/stdout for `gorun mcp --key`, acting as the API key apiKey (or, when empty, the GORUN_MCP_KEY environment variable). The key is validated like a bearer key (hash lookup, revocation, expiry, active owner) at start and again before every call, so revoking it or disabling its owner ends access mid-session. Calls are rate limited per process at the key's rate_per_min.

Types

type Approval

type Approval struct {
	ID          string          `json:"id"`
	APIKeyID    string          `json:"api_key_id"`
	KeyName     string          `json:"key_name"`
	RequestedBy string          `json:"requested_by"`
	Requester   string          `json:"requester"`
	Tool        string          `json:"tool"`
	Args        json.RawMessage `json:"args"`
	Status      string          `json:"status"`
	RequestedAt string          `json:"requested_at"`
	ExpiresAt   string          `json:"expires_at"`
	DecidedAt   string          `json:"decided_at"`
	DecidedBy   string          `json:"decided_by"`
	ExecutedAt  string          `json:"executed_at"`
	Result      json.RawMessage `json:"result,omitempty"`
}

Approval is one mcp_approvals row. Status is the effective status: a pending row past expires_at reads as expired even before the cron runs.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is the mcp kernel.Module.

func New

func New() *Module

New returns the mcp module.

func (*Module) Catalogs

func (*Module) Catalogs() fs.FS

Catalogs implements kernel.CatalogProvider.

func (*Module) Enabled added in v0.16.0

func (*Module) Enabled(ctx context.Context, database *sql.DB) (bool, error)

func (*Module) Migrations

func (*Module) Migrations() fs.FS

Migrations implements kernel.Module.

func (*Module) Name

func (*Module) Name() string

Name implements kernel.Module.

func (*Module) Register

func (m *Module) Register(d *kernel.Deps) error

Register declares the permissions, registers the core tools into Deps.MCP, mounts /mcp, the approvals admin page and API operations, the expiry cron and the health check.

type ToolError

type ToolError struct {
	Code    string            `json:"code"`
	Message string            `json:"message"`
	Fields  map[string]string `json:"fields,omitempty"`
}

ToolError is an error a tool returns to the agent as-is (code, message, optional per-field messages).

func (*ToolError) Error

func (e *ToolError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL