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
- Variables
- func StepUpNeedsAPIKey(authPref string) bool
- func StepUpReachesOperatorOnStdio(authPref string) bool
- func VerifyManifestStream(r io.Reader, trustedPubkey ed25519.PublicKey) (int, error)
- type Options
- type SSEConfig
- type Server
- func (s *Server) ListToolNames() []string
- func (s *Server) Listener() net.Addr
- func (s *Server) MCPServer() *mcp.Server
- func (s *Server) Run(ctx context.Context) error
- func (s *Server) RunSSE(ctx context.Context, cfg SSEConfig) error
- func (s *Server) RunStreamableHTTP(ctx context.Context, cfg SSEConfig) error
- func (s *Server) RunWithTransport(ctx context.Context, t mcp.Transport) error
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ListToolNames returns the names of all registered tools, sorted.
func (*Server) Run ¶
Run starts the MCP server on stdio transport. It blocks until the client disconnects or the context is cancelled.
func (*Server) RunSSE ¶
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 ¶
RunStreamableHTTP starts the MCP server as a Streamable HTTP server. This transport is required for Claude Desktop custom connectors and MCP Apps rendering.
Source Files
¶
- access_cert.go
- ad_translation_rules.go
- agents.go
- agents_writes.go
- ai_gateway.go
- api_gap_areas.go
- apple_mdm_ade.go
- apple_mdm_ade_writes.go
- apple_mdm_device_actions.go
- apple_mdm_devices.go
- apps.go
- apps_apple_mdm_payloads.go
- apps_bundle.go
- apps_compliance.go
- apps_device.go
- apps_insights.go
- apps_user.go
- apps_windows_mdm.go
- apps_windows_mdm_csp.go
- devices_settings.go
- feature_settings.go
- google_emm.go
- identity_risk.go
- password_manager.go
- password_policies.go
- password_vault.go
- privileged_access.go
- privileged_access_writes.go
- prompts.go
- recipe_dispatcher.go
- resources.go
- server.go
- sign.go
- stepup.go
- stepup_touchid_other.go
- stepup_webhook.go
- toolfilter.go
- tools.go
- vocabulary.go
- workday.go
- workflows.go