mcp

package
v0.0.0-...-1d6103c Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 76 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcp provides the MCP (Model Context Protocol) server for jc. It wraps the CLI infrastructure to expose JumpCloud operations as MCP tools and resources over stdio and SSE transports.

Index

Constants

View Source
const PlanShapeDoc = "Without execute it returns a plan: {plan:true, action, resource, target, resolved_id} " +
	"plus effects where the change has any. Nothing is written. Call again with execute=true to apply."

planResult creates a plan preview result for destructive operations. PlanShapeDoc describes what a write tool returns when execute is not set.

21 tools changed to plan-by-default at once, and none of their descriptions said what a plan looks like — "returns a plan" leaves the next consumer guessing at the keys. Stated once and reused, so the answer cannot drift between tools the way `total` did.

Variables

View Source
var RecipeDispatcher recipe.CommandDispatcher

RecipeDispatcher is the command dispatcher used to execute recipe steps from the MCP `recipe_run` tool (when called with Execute: true) and from the recipe_runner_view MCP App. Mirrors the internal/tui/screen.RecipeDispatcher hook: the cmd package wires it at startup with recipe.NewDispatcher(newRootCmdForRecipeStep), keeping the dependency one-way (cmd → mcp) and avoiding an import cycle.

When nil (e.g. MCP server constructed in tests without the cmd wiring), recipe_run with Execute: true fails closed with a clear error rather than panicking. Plan-mode (Execute: false) doesn't need the dispatcher and works regardless.

Functions

func StepUpNeedsAPIKey

func StepUpNeedsAPIKey(authPref string) bool

StepUpNeedsAPIKey reports whether the resolved step-up authenticator will derive its challenge from the API key. Only the TTY authenticator does — it asks the operator for the last N chars of the key. The webhook authenticator uses out-of-band approval; Touch ID uses the OS biometric stack. Both ignore the key.

The "auto" and unknown prefs resolve at runtime, so we conservatively report key-needed when Touch ID isn't probably available — that's the path that falls back to TTY. Same for explicit "touchid" when the hardware is missing (newStepUp also falls back to TTY there).

Called by cmd/mcp.go to decide whether to fail the server start when the operator opted into step-up but never configured an API key. Per Bugbot on PR #34, gating that check on requireStepUp alone confused webhook operators with a misleading "to derive the challenge answer" error that didn't apply to their authenticator.

func StepUpReachesOperatorOnStdio

func StepUpReachesOperatorOnStdio(authPref string) bool

StepUpReachesOperatorOnStdio reports whether the resolved step-up authenticator can present a challenge to the operator while the MCP transport owns stdin/stdout. Touch ID renders an OS-level modal so it's transport-independent — but only when biometric hardware is actually usable. On a darwin host without Touch ID (Mac mini, Mac Pro, VM) we'd fall back to TTY, which can't reach an stdio-bound operator. The probe (touchIDAvailable) is what makes the check honest in that case. The webhook authenticator is also transport-independent — the operator approves through an out-of-band channel — so it satisfies the same "reaches operator over stdio" property.

Called from cmd/mcp.go to decide whether to print the "TTY prompts cannot reach the operator" startup warning.

func VerifyManifestStream

func VerifyManifestStream(r io.Reader, trustedPubkey ed25519.PublicKey) (int, error)

VerifyManifestStream reads JSON-encoded signedManifests from r and returns nil if every record's signature checks out against the supplied trusted public key. The first invalid record (or read error) short-circuits with an error naming the offending record's nonce so operators can grep the file.

Exposed for the `jc audit verify` CLI command and tests.

Types

type Options

type Options struct {
	// RateLimit is the maximum tool calls per minute. 0 means default (60).
	RateLimit int
	// ReadOnly disables all mutation tools.
	ReadOnly bool
	// AuditEnabled enables audit logging. When false and AuditLogPath is empty,
	// no audit log file is created.
	AuditEnabled bool
	// AuditLogPath overrides the default audit log path. If set, audit logging
	// is enabled regardless of AuditEnabled.
	AuditLogPath string
	// AllowedTools is a list of glob patterns for tools that are allowed.
	// If empty, all tools are allowed (subject to BlockedTools).
	AllowedTools []string
	// BlockedTools is a list of glob patterns for tools that are blocked.
	// Block list takes precedence over allow list.
	BlockedTools []string
	// RequireStepUp gates every destructive tool invocation (any tool
	// argument carrying Execute: true) behind a fresh proof of operator
	// presence. When true, the server prompts on its controlling TTY for
	// the last 6 chars of StepUpAPIKey before each destructive call.
	RequireStepUp bool
	// StepUpAPIKey is the credential the TTY authenticator uses to derive
	// the prompt's expected answer. Typically the same key the server is
	// authenticated with (config.APIKey()). Required when RequireStepUp
	// is true; ignored otherwise.
	StepUpAPIKey string
	// StepUpAuthenticator selects which step-up channel handles the
	// challenge. Empty or "auto" picks the strongest available channel
	// (Touch ID on darwin, TTY everywhere else). "tty" forces the API
	// key last-N prompt; "touchid" pins the biometric path with TTY as
	// runtime fallback if biometrics are unavailable. "webhook" routes
	// the approval out-of-band to ApprovalWebhookURL (KLA-413).
	StepUpAuthenticator string
	// ApprovalWebhookURL is the operator-configured destination for
	// out-of-band approval requests when StepUpAuthenticator is
	// "webhook". The MCP server POSTs the redacted op envelope here and
	// blocks on the verdict callback. Required when authenticator is
	// "webhook"; ignored otherwise.
	ApprovalWebhookURL string
	// ApprovalCallbackAddr is the loopback listen address for inbound
	// verdicts from the receiver. Empty defaults to "127.0.0.1:0" so
	// the kernel picks an ephemeral port. Ignored unless the webhook
	// authenticator is selected.
	ApprovalCallbackAddr string
	// ApprovalTimeout is how long the webhook authenticator waits for
	// a verdict before failing closed (timeout = deny). Zero defaults
	// to 5 minutes. Ignored unless the webhook authenticator is
	// selected.
	ApprovalTimeout time.Duration

	// SignDestructiveOps enables Ed25519 op-envelope signing — every
	// successful destructive op (any tool input with Execute: true) is
	// recorded in ~/.config/jc/mcp-audit-signed.log with a per-profile
	// signature. Verifiable post-hoc via `jc audit verify`. Layers on
	// top of (does not replace) RequireStepUp. Default false.
	SignDestructiveOps bool
	// SigningProfile selects which profile's keychain entry holds the
	// signing key. Empty defaults to the active profile. Required when
	// SignDestructiveOps is true.
	SigningProfile string
	// contains filtered or unexported fields
}

Options configures the MCP server.

type SSEConfig

type SSEConfig struct {
	// Addr is the listen address (e.g., ":8080").
	Addr string
	// CORSOrigin is the allowed CORS origin. Empty means no CORS headers.
	CORSOrigin string
	// TLSCert is the path to the TLS certificate file.
	TLSCert string
	// TLSKey is the path to the TLS private key file.
	TLSKey string
	// APIKey is the required API key for authentication. Empty means no auth.
	APIKey string
}

SSEConfig configures the SSE HTTP server.

type Server

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

Server wraps the MCP SDK server with rate limiting and audit logging.

func MustNewServer

func MustNewServer(opts Options) *Server

MustNewServer is the construction-error-elides variant for test code and call sites that don't configure the fallible authenticators. Panics on error; production callers should use NewServer and surface the error to the operator with a clear "fix your config" message.

func NewServer

func NewServer(opts Options) (*Server, error)

NewServer creates a new MCP server with the given options. Returns an error only when a step-up authenticator that's fallible at construction time (currently: webhook) fails to start — for example because the operator left ApprovalWebhookURL empty or the loopback listener can't bind. Callers that want to keep the existing always-succeeds shape (tests, prior callers) can use MustNewServer instead.

func (*Server) ListToolNames

func (s *Server) ListToolNames() []string

ListToolNames returns the names of all registered tools, sorted.

func (*Server) Listener

func (s *Server) Listener() net.Addr

Listener returns the active SSE listener address, or nil if not running.

func (*Server) MCPServer

func (s *Server) MCPServer() *mcp.Server

MCPServer returns the underlying MCP server (for testing).

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the MCP server on stdio transport. It blocks until the client disconnects or the context is cancelled.

func (*Server) RunSSE

func (s *Server) RunSSE(ctx context.Context, cfg SSEConfig) error

RunSSE starts the MCP server as an HTTP+SSE server. It blocks until the context is cancelled or the server encounters a fatal error.

func (*Server) RunStreamableHTTP

func (s *Server) RunStreamableHTTP(ctx context.Context, cfg SSEConfig) error

RunStreamableHTTP starts the MCP server as a Streamable HTTP server. This transport is required for Claude Desktop custom connectors and MCP Apps rendering.

func (*Server) RunWithTransport

func (s *Server) RunWithTransport(ctx context.Context, t mcp.Transport) error

RunWithTransport starts the MCP server with a custom transport (for testing).

Jump to

Keyboard shortcuts

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