Skip to Content
Deneva MCPComponentsComponent documentation

Component documentation

This folder is the first place to read when learning the codebase. Each file describes one logical unit (a service, a plugin, a module), what it owns, what it depends on, and the security invariants it enforces.

Index

Phase 1 — Foundation

ComponentSourcePurpose
Databasesrc/db/Drizzle schema, RLS policies, role separation, TIMESTAMP parser override
Secrets loadersrc/security/secrets.loader.tsLoads sensitive material from systemd-creds (prod) or secrets/ (dev)
API key servicesrc/security/api-key.service.tsGenerates, hashes (HMAC-SHA256), and constant-time verifies API keys
Tenant middlewaresrc/security/tenant.middleware.tsResolves the tenant from X-Api-Key on /mcp/* and /auth/*/start
Rate limitersrc/security/rate-limiter.plugin.tsPer-IP + per-tenant + per-route rate limits
IP blocksrc/security/ip-block.service.tsTracks auth-failure bursts, blocks offending IPs
Audit logsrc/security/audit-log.service.tsAppend-only security event trail
Log scrubbersrc/security/log-scrubber.tsRedacts token-shaped strings from logs
OAuth statesrc/auth/oauth-state.service.tsPKCE + state parameter storage and cleanup
Admin routessrc/auth/admin-routes.tsAPI key rotation endpoint
MCP serversrc/mcp/server.tsTool registry + Streamable HTTP transport
MCP toolssrc/mcp/tools/Phase 1 stub tools: ping, get_account_health
Entry pointsrc/index.tsBootstrap order, plugin registration, listener

Phase 2 — Google Ads adapter

ComponentSourcePurpose
Cache servicesrc/cache/TTL cache + thundering-herd advisory lock + per-platform hit/miss metrics (PR-1)
Credentials servicesrc/security/credentials.service.tsPer-tenant DEKs wrapped under the process KEK; envelope encryption for OAuth tokens (PR-2)
OAuth routessrc/auth/oauth-routes.ts/auth/:platform/start + /callback (PR-4)
Google adaptersrc/adapters/google/ + registry.tsOAuth code exchange + token refresh (PR-4); GAQL queries (PR-5); revoke (PR-7)

How the request flows

HTTP → helmet (headers) → @fastify/rate-limit (Layer 1: per-IP) → tenantAuthPlugin (X-Api-Key → req.tenantId, audit row; covers /mcp/* AND /auth/*/start) → tenantLimiter (Layer 2: per-tenant) → adminRoutes / oauthRoutes / mountMcp / /health ├── /auth/google/start → 302 to Google (PKCE) ├── /auth/google/callback → adapter.exchangeAuthCode (no auth) ├── adminRoutes → /admin/api-keys/rotate └── mountMcp delegates to McpServer └── tool handler (audit row + business logic; cache + adapters in Phase 2)

Reading order recommended for new contributors:

  1. entry-point.md — see how everything is wired.
  2. database.md — understand RLS + role separation, the heart of multi-tenancy.
  3. secrets-loader.md — understand why nothing reads from process.env.
  4. tenant-middleware.mdaudit-log.mdapi-key-service.md — the auth chain end-to-end.
  5. mcp-server.mdmcp-tools.md — how tools plug into the registry.
  6. Phase 2 reading order: cache-service.mdcredentials-service.mdoauth-routes.mdgoogle-adapter.md.