How oneiroi/aegir works
Purpose and runtime
Aegir is a Go MCP security gateway: a transport-layer proxy between MCP clients and upstream MCP servers. It authenticates requests, inspects MCP traffic, redacts regulated data, records tamper-evident audit events, and blocks or judges suspicious content before forwarding. Main executable: cmd/server/main.go; the proxy/runtime implementation is centered in internal/server/server.go.
Process entry and configuration
cmd/server/main.go loads configuration, initializes security subsystems, and starts the gateway. Configuration is represented and validated in internal/config/config.go, with deployment defaults/examples in aegir.yaml and docker-compose.yml. The service can run with TLS and is containerized through Dockerfile; local development can disable TLS.
MCP ingress, protocol handling, and upstream boundary
internal/server/server.go owns HTTP server routing and the request security pipeline. MCP transport-specific forwarding is split across internal/server/mcp_proxy.go, internal/server/mcp_sse.go, and internal/server/mcp_stdio.go, supporting proxy, SSE, and stdio-related flows. The outbound trust boundary is managed by internal/upstream/manager.go, including secure dialing/mTLS concerns. Aegir treats both client input and upstream tool results as untrusted.
Identity and request admission
Authentication and identity management are implemented in internal/auth/manager.go; administrative WebAuthn/FIDO2 support is under internal/auth/webauthn/handler.go. Admission controls in internal/server/ratelimit.go enforce per-identity limits, while internal/server/header_scan.go and server-level handlers apply protocol/header validation. This is the first fail-closed boundary before payload forwarding.
Detection and semantic escalation
Content detection is built around IOC/prompt-injection patterns in internal/detection/patterns.go and scanning orchestration in internal/detection/detection.go. internal/anomaly/detector.go adds entropy and encoding-evasion signals. Suspicious traffic is synchronously sent to internal/judge/judge.go; this layer supports local-first Ollama plus opt-in OpenAI-compatible and Anthropic-style backends, with fail-closed behavior on judge failure or timeout.
Sanitization, compliance, and response protection
internal/sanitizer/manager.go coordinates request and response safety checks, including suspicious routing and compliance payload handling. internal/sanitizer/compliance.go and internal/redaction/redactor.go identify/redact GDPR/CCPA PII, HIPAA PHI, and PCI data. The proxy also scans upstream tool-call results for indirect prompt injection before they re-enter an MCP client/model context.
State, auditability, and operations
Sensitive state protection is provided by internal/crypto/encryption.go and signed-state support in internal/statesign/statesign.go. internal/session/analyzer.go evaluates session-level behavior; internal/tasks/registry.go supports tracked task/status work. Observability is supplied through internal/logging/logger.go, internal/metrics/collector.go, and OpenTelemetry integration in internal/telemetry/otel.go; Prometheus deployment configuration is in prometheus.yml. An optional administrative dashboard is implemented in internal/dashboard/web.go and internal/dashboard/handlers.go.
Key architectural constraints
The hot path keeps clean traffic off the LLM judge to preserve low latency. Detection is intentionally bounded by transport-layer visibility; semantic and cross-session threats remain partial or external-control concerns. DNS-rebinding-resistant egress enforcement is not a proxy-only guarantee, so production deployments need network-level controls in addition to internal/upstream/manager.go.
Main entry points: server.go HTTP security gateway · detection.go Content detection · sanitizer/manager.go Safety sanitizer · auth/manager.go Identity authentication
Components 19
Gateway Runtime
- Server entrypoint
cmd/server/main.go - Configuration
internal/config/config.go - HTTP security gateway · Owns routing and the security pipeline.
internal/server/server.go - MCP transports
internal/server/mcp_proxy.go
Admission & Detection
- Identity authentication
internal/auth/manager.go - Admin WebAuthn
internal/auth/webauthn/handler.go - Admission controls · Fail-closed per-identity and protocol checks.
internal/server/ratelimit.go - Content detection
internal/detection/detection.go - Evasion anomaly detector
internal/anomaly/detector.go - Semantic judge · Invoked only for suspicious traffic; failures block.
internal/judge/judge.go
Data Protection
- Safety sanitizer
internal/sanitizer/manager.go - PII/PHI/PCI redaction
internal/redaction/redactor.go
Upstream Boundary
- Secure upstream egress · Applies dialing and mTLS boundary controls.
internal/upstream/manager.go
State & Operations
- Protected audit state · Secures sensitive and tamper-evident state.
internal/crypto/encryption.go - Session analysis
internal/session/analyzer.go - Observability
internal/telemetry/otel.go - Admin dashboard
internal/dashboard/web.go
Other components
- MCP clients · Untrusted request and tool-result context.
- Upstream MCP servers · Untrusted tool-result source.
Connections 22
- Server entrypoint → Configuration: loads
- Server entrypoint → HTTP security gateway: starts
- Configuration → HTTP security gateway: configures
- MCP clients → HTTP security gateway: MCP traffic
- HTTP security gateway → Identity authentication: authenticates
- Identity authentication → Admin WebAuthn: admin auth
- Identity authentication → Admission controls: identity
- Admission controls → Content detection: admitted payloads
- Content detection → Evasion anomaly detector: evasion signals
- Content detection → Semantic judge: suspicious only
- Evasion anomaly detector → Semantic judge: escalates
- Content detection → Safety sanitizer: clean or approved
- Semantic judge → Safety sanitizer: allow decision
- Safety sanitizer → PII/PHI/PCI redaction: regulated data
- PII/PHI/PCI redaction → MCP transports: safe payload
- MCP transports → Secure upstream egress: forwards
- Secure upstream egress → Upstream MCP servers: secure connection
- Upstream MCP servers → Safety sanitizer: tool results rescanned
- HTTP security gateway → Protected audit state: audit events
- HTTP security gateway → Session analysis: session signals
- HTTP security gateway → Observability: telemetry
- Admin dashboard → HTTP security gateway: admin operations