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 ¶
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.
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 ¶
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 ¶
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.