mcp

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mcp implements a Model Context Protocol server over stdio, exposing the CLI's verbs as tools so an MCP-capable agent (Claude, etc.) can drive the Privasys platform natively. Transport is newline-delimited JSON-RPC 2.0 on stdin/stdout (the MCP stdio transport).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WatchParentDeath added in v0.32.0

func WatchParentDeath(ctx context.Context, stop func())

WatchParentDeath calls stop() when the process that spawned this one exits.

An MCP server's lifetime is bound to its client. The primary shutdown signal is stdin EOF (the client closes the pipe), but if the client dies WITHOUT closing our stdin — a Windows pipe-handle leak, or a client crash that leaves a write handle open elsewhere — the stdin read blocks forever and the server lingers. This watchdog is the backstop: when the spawning process is gone, we stop, so an orphaned `privasys mcp serve` cannot pile up.

Types

type Deps

type Deps struct {
	Client   *api.Client
	Token    string
	Issuer   string
	Endpoint string
	Authed   bool
}

Deps is the per-call context a tool handler needs. It is rebuilt per call so tokens refresh transparently. Issuer/Endpoint are always populated; Client + Token are set and Authed is true only when the user is signed in (so onboarding tools can run before there is a session).

type DepsFunc

type DepsFunc func(ctx context.Context) (Deps, error)

DepsFunc returns a fresh Deps. It errors only on hard failures (config load), not on "not signed in" — that surfaces as Authed=false.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves MCP over the given reader/writer.

func NewServer

func NewServer(deps DepsFunc, version string) *Server

NewServer builds the server with the full tool surface.

func (*Server) Serve

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

Serve runs the read/dispatch/write loop until stdin EOF or ctx cancellation.

The scan runs in a goroutine so the main loop can select on ctx.Done(): a blocking stdin read (an orphaned pipe that never delivers EOF) no longer pins the process — a signal or the parent-death watchdog cancels ctx and we return. The reader goroutine may remain parked on that read, but the process is exiting, so it is reaped with us.

Jump to

Keyboard shortcuts

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