Documentation
¶
Overview ¶
Package mcpstdio is a small MCP client over a child process's stdio, for the programs under scripts/ that drive the built server: the smoke gate, the live driver and the evals. It speaks exactly the frames those need and nothing else, but it is one client, because hand-written JSON-RPC loops are places for the handshake to drift apart.
Every line the server writes to stdout must be a JSON-RPC frame; a line that is not is kept and reported by Stray, because a stray line on stdout is a protocol violation the client would otherwise skip.
Index ¶
- Constants
- Variables
- func Encode(args map[string]any) string
- func Environ(base []string, extra ...string) []string
- type Config
- type RPCError
- type Session
- func (s *Session) Await(method string, id int) (map[string]any, error)
- func (s *Session) CallTool(name string, args map[string]any) (ToolResult, error)
- func (s *Session) Close() error
- func (s *Session) Initialize(protocol, clientName string) (map[string]any, error)
- func (s *Session) ListTools() ([]Tool, error)
- func (s *Session) Notify(method string, params any) error
- func (s *Session) OnCall(f func(tool string, args map[string]any))
- func (s *Session) Options() map[string][]string
- func (s *Session) ReadResource(uri string) (text, mime string, err error)
- func (s *Session) Request(method string, params any) (map[string]any, error)
- func (s *Session) Send(frame any) error
- func (s *Session) StderrTail(n int) []string
- func (s *Session) Stray() []string
- type Tool
- type ToolResult
Constants ¶
const CallTimeout = 2 * time.Minute
CallTimeout bounds one request when Config.Timeout is zero.
const Protocol = "2025-11-25"
Protocol is the revision Initialize asks for when none is given.
Variables ¶
var ErrClosed = errors.New("the server closed the connection")
ErrClosed is the server closing stdout before a reply arrived.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Args follow the binary on the command line.
Args []string
// Env is added to the environment, which is the parent's minus every
// GITLAB_MCP_ variable. An MCP client passes command, args and env,
// and nothing else.
Env []string
// Timeout bounds each request; zero means CallTimeout.
Timeout time.Duration
}
Config says how to start the server.
type RPCError ¶
RPCError is the server answering with an error object rather than a result. A tool call reports a refusal inside its result, but a resource read reports one as a JSON-RPC error, and a driver that could not tell the two apart would count every expected refusal as a broken connection.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one stdio conversation with the server.
func (*Session) Close ¶
Close closes stdin and waits for the server to exit, killing it after the timeout. It returns the exit error, if any. Both pipes are read to the end before Wait, as os/exec requires: Wait closes them, and a read still in progress would lose the last lines.
func (*Session) Initialize ¶
Initialize completes the handshake at protocol (Protocol when empty) and lists the tool surface. It returns the initialize result.
func (*Session) Options ¶
Options is the tool surface the server published at initialize: each registered tool and the option names its schema declares.
func (*Session) ReadResource ¶
ReadResource reads one resource and returns its text and media type. A refusal comes back as an *RPCError.
func (*Session) Request ¶
Request sends one request and waits for its reply, returning the result object. Frames the server sends on its own account — notifications, logs — are skipped.
func (*Session) StderrTail ¶
StderrTail returns the last n log lines the server wrote.
type Tool ¶
Tool is one listed tool: its name, its input option names sorted, and the whole listing entry.
type ToolResult ¶
type ToolResult struct {
// Text is every text content block, joined.
Text string
// IsError is the tool refusing, as opposed to the protocol failing.
IsError bool
// Structured is structuredContent, raw; nil when absent.
Structured json.RawMessage
}
ToolResult is one tool call's reply.