Documentation
¶
Overview ¶
Package mcpkit is the product-neutral half of a product's MCP server: the server and its stdio transport, the profile a call is for, progress notifications while the human decides, the untrusted-data framing of results, the "no console" answer naming the start command, refusals as structured tool errors and exact large integers. A product declares its own tools with the SDK (mcp.AddTool) and keeps their names, descriptions and texts; mcpkit holds no secret and no connection.
SDK: github.com/modelcontextprotocol/go-sdk/mcp v1.8.0.
Index ¶
- Constants
- func Exact(v any) any
- func ExactRows(rows [][]any) [][]any
- func New(p kit.Product, version, instructions string) *mcp.Server
- func NoConsole(p kit.Product, profile string, err error) (start, hint string, ok bool)
- func NoConsoleLine(profile, hint string) string
- func NonNil[T any](s []T) []T
- func Progress(ctx context.Context, req *mcp.CallToolRequest, every time.Duration, ...) (stop func())
- func ProgressInterval(d time.Duration) time.Duration
- func Refused(err error) (res *mcp.CallToolResult, info *refusal.Info, ok bool)
- func Serve(ctx context.Context, s *mcp.Server, r io.Reader, w io.Writer) error
- func Text(s string) *mcp.CallToolResult
- func Untrusted(what, source string) string
- func WaitingMessage(p kit.Product) func(time.Duration) string
- type Profiles
- type ToolError
Constants ¶
const DefaultProgressEvery = 5 * time.Second
DefaultProgressEvery is how often Progress reports while the human decides. It stays well under the 10 s that clients tolerate.
Variables ¶
This section is empty.
Functions ¶
func Exact ¶
Exact returns v, or, for an integer outside ±2^53, its decimal string. The SDK decodes structured output into float64 values when it validates it, which would silently change such ids; the text rendering keeps them as they are.
func New ¶
New returns p's MCP server, reported to the client as p.Name and version ("dev" when empty), with the server instructions shown to the model.
func NoConsole ¶
NoConsole tells, for an error of a dial to profile's console, whether no console runs; then start is the exact command that starts it and hint what the agent must ask of the user.
func NoConsoleLine ¶
NoConsoleLine is the line a status text gives for a profile without a console.
func NonNil ¶
func NonNil[T any](s []T) []T
NonNil returns s, or an empty slice for nil, so that structured output holds [] and not null.
func Progress ¶
func Progress(ctx context.Context, req *mcp.CallToolRequest, every time.Duration, message func(waited time.Duration) string) (stop func())
Progress sends a progress notification at once and then every ProgressInterval(every) until the returned stop is called, when the request carries a progress token. message gets the time waited so far. It keeps clients from timing out while the human decides.
func ProgressInterval ¶
ProgressInterval is d when it lies in (0, 10s), else DefaultProgressEvery.
func Refused ¶
Refused returns the error result of a refusal (a *ToolError with a Refusal) with its structured form, or ok false for any other error. A tool returns the result with its output, not the error, so the model gets both the text and the structured refusal.
func Serve ¶
Serve runs s on r and w (the agent's stdin and stdout: w carries only the protocol) until the client disconnects or ctx ends; both are a clean end (nil). Neither r nor w is closed.
Types ¶
type Profiles ¶
type Profiles struct {
Product kit.Product
// Pinned pins the server to one profile (`<name> mcp --profile P`).
// Empty lets the tool argument choose among the configured profiles.
Pinned string
// List returns the configured profile names. It is called on every
// call, so profiles added to the config are seen. Nil means only an
// explicit or pinned profile is accepted, unchecked.
List func() ([]string, error)
}
Profiles resolves the profile of a tool call.