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. Its prompts return one user message that tells the agent which tools to call.
Index ¶
- Constants
- Variables
- func AddPrompt(s *Server, p Prompt, f PromptFunc)
- func AddTool[In any](s *Server, t Tool, h Handler[In])
- func ClientRoots(req *mcp.CallToolRequest) ([]string, error)
- func FilePath(uri, goos string) (string, error)
- type Handler
- type Options
- type Pager
- type Paging
- type Prompt
- type PromptArgument
- type PromptFunc
- type Result
- type Server
- type Tool
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.
var ErrUnknownArgument = errors.New("unknown argument")
ErrUnknownArgument is returned when a prompt gets an argument it doesn't declare.
Functions ¶
func AddPrompt ¶ added in v0.4.0
func AddPrompt(s *Server, p Prompt, f PromptFunc)
AddPrompt registers a prompt whose answer is one user message. A get with an unknown argument or without a required one fails before f runs, because the SDK checks neither. It panics when two arguments share a name.
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.
type Prompt ¶ added in v0.4.0
type Prompt struct {
Name string
Title string
Description string // one sentence
Arguments []PromptArgument
}
Prompt describes a prompt template that a client offers its user, such as a slash command.
type PromptArgument ¶ added in v0.4.0
PromptArgument is one string argument of a Prompt.
type PromptFunc ¶ added in v0.4.0
PromptFunc returns the text of a prompt's user message. args holds the arguments the client set, trimmed, without blank ones.