bootstrap

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 8 Imported by: 0

README

kite-mcp-bootstrap

Composition root + DI wiring for kite-mcp-server.

What lives here

This module is the composition root of the Kite MCP Server stack. It contains:

Package Purpose
app/ DI wiring, HTTP mux, lifecycle, graceful restart, healthz
app/providers/ Adapter providers (alert, audit, billing, etc.)
app/metrics/ Per-tool latency + error metrics
kc/ Kite client manager, sessions, credential store, OAuth callback handler
kc/ops/ Admin + user dashboards, ops handlers, log buffer, scanner, payoff viz
kc/ports/ Port interface declarations (alert, credential, instrument, order, session)
mcp/ MCP tool registrations + middleware (audit, riskguard, elicitation, paper trading)
plugins/ Plugin scaffolding (example, rolegate, telegramnotify)
testutil/ Test fakes + fixtures (in-memory stores, clock, kite-server fake)

What does NOT live here

The 28 algo2go domain modules (broker, money, alerts, billing, riskguard, papertrading, telegram, ...) are external dependencies, each in their own repo. See go.mod for the canonical list.

The deploy artifacts (Dockerfile, fly.toml, server.json, smithery.yaml, funding.json, litestream.yml, .mcp.json, cmd/ operational binaries) live in kite-mcp-server, which imports this module and exposes only a thin main.go.

Why a separate module?

Per .research/research/github-transfer-bootstrap-2026-05-11.md (the design audit), separating composition root from deploy gives:

  • Reusability: the composition root can be embedded by alternate front-ends (CLI variant, integration-test harness, future fork) without dragging deploy configuration along.
  • Versioning: bootstrap follows semantic-version cadence; deploy repo tags per release.
  • Bounded blast radius for deploy audits: the deploy repo audit surface becomes ~12 files instead of 261 .go files.
  • Algo2go brand alignment: all Go source under algo2go/*; the deploy repo retains its kite-mcp-server name for the install URL stability.

Status

v0.1.0 — initial relocation from kite-mcp-server in-tree.

Build

go build ./...
go test ./...

License

MIT — see LICENSE.

Documentation

Overview

Package bootstrap is the composition root entry point for the kite-mcp-server stack. Deploy repos import this package and call Main(Options{}) from their thin main.go.

All composition + DI wiring + HTTP serving lives in subpackages:

  • app/ : Fx wiring + HTTP mux + lifecycle
  • kc/ : Kite client manager + sessions + credential store
  • kc/ops/ : Admin + user dashboards + scanner + payoff
  • mcp/ : MCP tool registrations + middleware
  • plugins/ : plugin scaffolding sub-module
  • testutil/ : test fixtures sub-module

Index

Constants

View Source
const MemoryLimitBytes int64 = 450 * 1024 * 1024 // 450 MB

MemoryLimitBytes is the soft GC target for the Go runtime — set via runtime/debug.SetMemoryLimit at package init. Path C item per the kite-mcp-server audit 6ee6520: prevents OOM-kill on the 512MB Fly.io machine.

450 MB target leaves ~62 MB headroom on a 512 MB machine — the empirical industry standard is 85-90% of available RAM, so 450/512 = 88% sits in the conservative upper-band.

GOMEMLIMIT env var (read at runtime startup) overrides this — the in-code default is intentionally visible for ops audit + debugging.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger() (*slog.Logger, *ops.LogBuffer)

InitLogger constructs the production logger + log buffer pair. LOG_LEVEL env var controls the slog level via ParseLogLevel. The returned *ops.LogBuffer captures the last 500 log entries for the ops dashboard log streaming endpoint.

func Main

func Main(o Options) int

Main is the composition-root entry point. Deploy repos call this from their thin main.go after parsing --version flags themselves.

Main blocks until shutdown (SIGINT/SIGTERM/SIGUSR2 graceful restart). Returns os.Exit code: 0 on clean shutdown, 1 on config-load failure or server start failure.

Contract: Main does NOT call os.Exit itself — callers should:

func main() {
    os.Exit(bootstrap.Main(bootstrap.Options{
        Version: MCP_SERVER_VERSION,
        BuildString: buildString,
    }))
}

func ParseLogLevel

func ParseLogLevel(raw string) slog.Level

ParseLogLevel maps a raw LOG_LEVEL env value to a slog.Level. Empty string or unrecognised values default to LevelInfo. Pure function.

Valid input values: "debug", "info", "warn", "error", "". Anything else also defaults to info; the "default to INFO if invalid" branch is fail- open: a typo'd LOG_LEVEL must not silence logs.

func PrintVersion

func PrintVersion(o Options)

PrintVersion writes version + build info to stdout — exposed so deploy repos can implement their own --version flag in main without importing fmt themselves.

Types

type Options

type Options struct {
	// Version is the MCP_SERVER_VERSION string (typically set via ldflags
	// at build time: -X main.MCP_SERVER_VERSION=v1.2.3).
	Version string
	// BuildString is the human-readable build identifier (typically set
	// via ldflags at build time: -X 'main.buildString=2026-05-16 abc123').
	BuildString string
}

Options are the runtime parameters a deploy repo's main.go injects when calling Main. Both fields default to dev placeholders when empty.

Directories

Path Synopsis
app
Graceful restart (nginx -s reload style) for kite-mcp-server.
Graceful restart (nginx -s reload style) for kite-mcp-server.
providers module
mcp
plugins module
testutil module

Jump to

Keyboard shortcuts

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