mcp

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package mcp is a minimal Model Context Protocol server over stdio: enough of the protocol (initialize, ping, tools/list, tools/call as newline-delimited JSON-RPC 2.0) for an agent to call notenv's tools, and nothing more. Hand-rolled deliberately: like internal/ui, it adds zero new supply-chain surface, and the subset it speaks is small enough to audit in one sitting.

Requests are handled sequentially in arrival order; there is no cancellation and no server-initiated traffic. Handlers' results travel as text content. The transport's stdin/stdout belong to the protocol; prompts and logging elsewhere in notenv already go to /dev/tty and stderr, so a handler can run the full app stack without corrupting the stream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	Name    string
	Version string
	Tools   []Tool
}

Server serves a fixed tool set over one stdio session.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, in io.Reader, out io.Writer) error

Serve runs the session until in closes (the client hanging up) or ctx is canceled between messages. Malformed lines get a parse error where an ID is recoverable and are dropped otherwise; unknown notifications are ignored, per JSON-RPC.

type Tool

type Tool struct {
	Name         string
	Description  string
	ReadOnly     bool
	InputSchema  map[string]any
	OutputSchema map[string]any
	Handler      func(ctx context.Context, args json.RawMessage) (any, error)
}

Tool is one callable tool: a name, the description an agent picks it by, JSON-Schema input and output declarations, and the handler. A handler error becomes a tool-level error result (isError), not a protocol error: the agent gets to read it and adapt. A non-string handler result is returned both ways the spec wants it: serialized into text content and, when an OutputSchema is declared, as structuredContent. ReadOnly renders as the readOnlyHint annotation, so clients can skip confirmation for tools that cannot change anything.

Jump to

Keyboard shortcuts

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