api

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api serves an operation registry over HTTP:

GET  /ops           the registry metadata (toolkit.metadata.v1)
POST /ops/{name}    run one operation with a JSON input
GET  /openapi.json  an OpenAPI 3.1 document of the routes

Every operation is a POST so structured input keeps its body; the effect, not the HTTP verb, says whether it changes state. A success returns the operation output as the body. A failure returns {"error": {code, message, suggestions}} with the status of the error kind, plus the provider details of op.Error that are set.

Index

Constants

View Source
const MaxBodyBytes = 1 << 20

MaxBodyBytes bounds a request body.

Variables

This section is empty.

Functions

func Handler

func Handler(reg *op.Registry, opts Options) http.Handler

Handler returns the HTTP handler for reg. Mount MCP at /mcp next to it if the tool serves MCP over HTTP.

func OpenAPI

func OpenAPI(reg *op.Registry) map[string]any

OpenAPI returns the OpenAPI 3.1 document for reg. Request and response schemas are the registry's own JSON Schemas, inlined, so the document and the metadata cannot drift. Each operation's id is its MCP name, and its effect is in the x-effect extension. An operation with CLIImmediate also has "x-cli-immediate": true, and one with CLIConfirmed "x-cli-confirmed": true; the HTTP route still needs apply, and confirm when destructive.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError writes err as an ErrorBody with the status of its kind. An error with RetryAfterSeconds also gets a Retry-After header.

Types

type ErrorBody

type ErrorBody struct {
	Error  *op.Error `json:"error"`
	Result any       `json:"result,omitempty"`
}

ErrorBody is the JSON body of a failed call. Result is the operation's partial output when the error carries one (op.Error.Result).

type Options

type Options struct {
	// Authorizer decides whether a caller may run an operation. Nil means
	// op.DenyWrites: reads and previews are allowed, applied writes are not.
	Authorizer op.Authorizer
}

Options configures the HTTP surface.

Jump to

Keyboard shortcuts

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