Documentation
¶
Overview ¶
Package runtime wires the clockify-mcp process: it loads the config-derived dependencies (policy, rate limit, dedupe, dry-run, truncation, bootstrap) and owns transport dispatch. It sits ABOVE the transports in the import graph — internal/runtime may import internal/mcp, internal/authn, internal/controlplane, internal/clockify, and the tools layer; none of those may import runtime. main.go is reduced to process-global concerns (logging, signals, OTel, metrics listener) and a single Runtime.Run call.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildStore ¶ added in v1.0.1
func BuildStore(cfg config.Config) (controlplane.Store, error)
BuildStore opens the control-plane store for the given config and enforces the C1 fail-closed guard: streamable_http against a dev-only backend (memory/file) requires MCP_ALLOW_DEV_BACKEND=1. The file-backed store honours cfg.ControlPlaneAuditCap; the Postgres backend ignores it and relies on the B2 retention reaper instead (see RetainAuditLoop).
Extracted from cmd/clockify-mcp/main.go as part of C2 so the control-plane wiring is unit-testable and reusable across transports.
func IsDevControlPlaneDSN ¶ added in v1.0.1
IsDevControlPlaneDSN reports whether dsn names one of the dev-only control-plane backends. "memory" / "memory://" keep state in process memory; a bare path or "file://..." rewrites a JSON file on every mutation. Neither is correct for a multi-process production deployment of streamable_http; C1 fails closed unless the operator acknowledges the tradeoff via MCP_ALLOW_DEV_BACKEND=1.
Extracted from cmd/clockify-mcp so other packages (runtime builders, tests, future transports) can share the same predicate without re-importing main.
func RetainAuditLoop ¶ added in v1.0.1
RetainAuditLoop is the background reaper for the control-plane audit log. It wakes on a fixed interval, asks the store to drop events older than maxAge, and updates clockify_mcp_audit_events_retained_total. Mirrors the session reaper pattern in internal/mcp/transport_streamable_http.go:515-526 — one ticker, one ctx.Done() branch, one synchronous step per tick.
Exits silently when ctx is cancelled. The last in-flight RetainAudit is bounded by the store's own per-op timeout and never holds open external resources.
Types ¶
type NewOpts ¶ added in v1.0.1
type NewOpts struct {
Version string
ExtraHandlers []mcp.ExtraHandler
}
NewOpts bundles process-level inputs that main owns: the version string (threaded into the MCP initialize response and HTTP User-Agent) and transport-agnostic extra HTTP handlers (e.g. /debug/pprof/* from pprofExtras() under -tags=pprof). A zero-value NewOpts is valid.
type Runtime ¶ added in v1.0.1
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is the boot-time integrator for clockify-mcp. Callers build it once in main (after logging/OTel/signal setup) and invoke Run, which dispatches to the configured transport. The struct is opaque to callers beyond a handful of accessors used for the startup log line and the per-subject rate-limit reaper.
func New ¶ added in v1.0.1
New constructs a Runtime from cfg and opts. It loads policy, bootstrap, dedupe, dry-run, truncation, and rate limit state from the environment; any config error aborts boot before the transport is selected.
func (*Runtime) Bootstrap ¶ added in v1.0.1
Bootstrap returns the bootstrap config (exposed for the same server_start log line).
func (*Runtime) Policy ¶ added in v1.0.1
Policy returns the process-level policy so main can include it in the server_start log line without peeking inside runtimeDeps.
func (*Runtime) RateLimit ¶ added in v1.0.1
func (r *Runtime) RateLimit() *ratelimit.RateLimiter
RateLimit returns the rate limiter so main can start its per-subject reaper (CLOCKIFY_SUBJECT_IDLE_TTL / CLOCKIFY_SUBJECT_SWEEP_INTERVAL).