Documentation
¶
Overview ¶
Package mcpkit runs a stdio MCP server whose tools are read-only and answer with the JSON envelope of --format json, split into pages with an opaque cursor when an answer passes the size cap.
Index ¶
Constants ¶
const MaxBytes = 50_000
MaxBytes is the default cap on the JSON text of one tool result. Claude Code saves larger text results to a file instead of showing them to the model.
Variables ¶
var ErrArgument = errors.New("missing required argument")
ErrArgument is returned when a call lacks a required argument.
var ErrCursor = errors.New("unknown or expired cursor")
ErrCursor is returned for a cursor the server doesn't know, has dropped, or issued for another tool.
Functions ¶
func AddTool ¶
AddTool registers a tool as read-only, idempotent and not destructive. A call with a cursor gets the next page of an earlier result and never reaches h. It panics when In has no valid input schema, as mcp.AddTool does.
func ClientRoots ¶
func ClientRoots(req *mcp.CallToolRequest) ([]string, error)
ClientRoots returns the local directories the client listed as its roots for a tool with Tool.Roots set, or nil when the client doesn't support roots. Claude Code lists its launch directory and the directories added with --add-dir.
Types ¶
type Handler ¶
Handler answers one call. Its error becomes a tool error, which the client shows to the model.
type Options ¶
type Options struct {
Name string // server_info name
Version string // server_info version
Instructions string // sent to the client at initialization
Logger *slog.Logger
Clock func() time.Time
MaxBytes int // 0 means [MaxBytes]; below 0 turns the cap off
CursorTTL time.Duration // how long a split result stays after its last use; 0 means 15 minutes
MaxSnapshots int // split results kept at once, least recently used dropped first; 0 means 16
}
Options configures a Server.
type Pager ¶
type Pager interface {
Len() int
Noun() string // names the items in the page field, such as "entries"
Order() []int // item indexes in the order pages take them; nil means 0 to Len-1
Data(keep []int) any // the data with only the items at keep, which is sorted
}
Pager splits an envelope's data into items, so a result over the cap can be sent in pages.
type Paging ¶
type Paging struct {
Cursor string `json:"cursor,omitempty" jsonschema:"The next_cursor of an earlier result of this tool. Other arguments are then ignored."` //nolint:lll // struct tag
}
Paging is embedded in the input of a tool whose result can be split.