runtime

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 24 Imported by: 0

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

View Source
const GRPCBuildAvailable = false

GRPCBuildAvailable reports whether this binary links the real gRPC transport. False in the default build, where runtime.runGRPC is only a diagnostic stub.

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 as defence-in-depth: streamable_http or grpc against a dev-only backend (memory/file) requires MCP_ALLOW_DEV_BACKEND=1. The primary guard lives in config.Load() so operators see the error at startup, not at first request; this second check catches any caller that bypasses Load().

Both transports are deployed multi-replica behind a load balancer in production, and the private-network-grpc profile pairs grpc with fail_closed audit — a memory backend cannot honour fail_closed across pod restarts. The predicate matches config.Load() exactly.

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 RetainAuditLoop added in v1.0.1

func RetainAuditLoop(ctx context.Context, store controlplane.Store, maxAge, interval time.Duration)

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

func New(cfg config.Config, opts NewOpts) (*Runtime, error)

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

func (r *Runtime) Bootstrap() bootstrap.Config

Bootstrap returns the bootstrap config (exposed for the same server_start log line).

func (*Runtime) Policy added in v1.0.1

func (r *Runtime) Policy() *policy.Policy

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).

func (*Runtime) Run added in v1.0.1

func (r *Runtime) Run(ctx context.Context) error

Run dispatches on cfg.Transport. Streamable HTTP owns its own per-session client lifecycle via tenantRuntime; the other arms share a single process-level Clockify client built inside Run so each transport method can focus on protocol concerns.

Jump to

Keyboard shortcuts

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