Developer GuideSystem Design

Architecture

Standalone service topology for taicket-mcp: single PM2 process on port 4130, 11-database Mongoose layer with isolated taicket_mcp, Express Streamable HTTP transport, and bundled static docs.

Single-service runtime architecture

The Taicket MCP platform runs inside mcp/ as a standalone ESM TypeScript service compiled with Node.js 22+ and managed by one PM2 process named taicket-mcp bound to 127.0.0.1:4130. It sits behind one dedicated Nginx virtual host (nginx/mcp.taicket.xyz.conf) and makes zero modifications to dashboard/, bot/, docs/, profile/, tournament/, activity/, or club/.

Public origin
https://mcp.taicket.xyz
Internal bind address
127.0.0.1:4130 (configured via MCP_HOST and MCP_PORT)
HTTP framework
Express 5 with helmet, cors, cookie-parser, and Pino structured logging
MCP SDK & transport
@modelcontextprotocol/sdk Streamable HTTP on /mcp (POST, GET, DELETE)
Static docs bundle
Next.js 14 static export built in mcp/docs-site/ and served from mcp/dist/site/
PM2 process
Single instance (instances: 1, max_memory_restart: 1G)

11-database Mongoose topology

mcp/src/db/connections.ts lazily initializes and pools 11 Mongoose connections. All MCP authentication state, OAuth grants, hashed tokens, setup previews, and HMAC hash-chained audit logs live in a physically isolated database (MCP_MONGODB_URI / taicket_mcp). Configuration and read-only diagnostic queries connect directly to Taicket main MongoDB and nine dedicated module databases.

#Database RoleURI VariableDefault DB NameMCP Access Mode
1Isolated MCP Auth & AuditMCP_MONGODB_URItaicket_mcpRead / Write (append-only on mcp_audit_logs)
2Main Taicket CoreMONGODB_URIMain cluster DBRead / Write (module configs & panels) + Read-Only (billing, blacklist, logs)
3Anti-Nuke EngineANTINUKE_MONGODB_URItaicket_antinukeRead / Write (modules & backup schedule) + Read-Only (trusted staff & logs)
4Booster PerksBOOSTER_MONGODB_URItaicket_boosterRead / Write (setup & panel deployment)
5Economy SystemECONOMY_MONGODB_URItaicket_economyRead / Write (guild config, store, recipes, income, custom replies)
6GiveawaysGIVEAWAYS_MONGODB_URItaicket_giveawaysRead / Write (guild defaults only; active giveaways untouched)
7JARVIS AuditorJARVIS_MONGODB_URItaicket_jarvisRead / Write (Enterprise config) + Read-Only (saved reports)
8Match TogetherMATCH_TOGETHER_MONGODB_URItaicket_match_togetherRead / Write (lobby & module setup)
9Reaction RolesREACTION_ROLES_MONGODB_URItaicket_reaction_rolesRead / Write (role-safe panels)
10Reaction TriggersREACTION_TRIGGER_MONGODB_URItaicket_reaction_triggerRead / Write (trigger rules with ReDoS guard)
11StarboardSTARBOARD_MONGODB_URItaicket_starboardRead / Write (starboard configuration)

Repository directory structure

Standalone mcp/ directory layouttext
mcp/
  package.json                    # Runtime & build scripts (build:all, typecheck, test)
  tsconfig.json                   # Strict TypeScript ESM configuration
  vitest.config.ts                # Automated Vitest runner configuration
  scripts/
    generate-docs-manifest.ts     # Extracts Zod schemas from registry.ts to JSON
  src/
    index.ts                      # Process entrypoint, graceful shutdown
    server.ts                     # Express app wiring: /mcp, /oauth/*, /account, /health, static docs
    config/env.ts                 # Zod-validated root .env loader + redacted summary
    db/
      connections.ts              # 11 lazy pooled Mongoose connections
      models/mcpAuth.ts           # 8 collections strictly bound to taicket_mcp
      models/taicketCore.ts       # Main DB models (excluding internal admin collections)
      models/taicketDedicated.ts  # 9 dedicated module DB models
    security/                     # crypto, validation, errors, rateLimit, discord, permissions, premium, audit
    oauth/                        # metadata, clients, routes, bearerAuth, accountRoutes, views
    tools/                        # registry + domain tool modules + resources & prompts
  tests/                          # oauth, security, premium, governance, docs-quality suites
  docs-site/                      # Next.js 14 static export app compiled into mcp/dist/site/

Request lifecycle on /mcp

  1. 1

    Edge termination and IP restoration

    Cloudflare routes https://mcp.taicket.xyz to Nginx, which terminates TLS 1.2/1.3, validates Cloudflare CIDRs, restores real client IP, enforces taicket_mcp_limit (25r/s), and proxies to 127.0.0.1:4130 with proxy_buffering off.

  2. 2

    Bearer authentication and identity binding

    requireMcpBearerAuth hashes the Authorization Bearer token via SHA-256, loads the active McpAccessToken from taicket_mcp, checks expiry, revocation, RFC 8707 resource, and derives immutable ctx.userId.

  3. 3

    Guard pipeline before tool execution

    The tool dispatcher checks scope coverage, BotBlacklist, grant allowedGuildIds, sliding-window rate limits, live Discord RBAC, and 18-surface tier gates.

  4. 4

    DTO projection, error sanitization, and HMAC audit

    Tool output is mapped through an explicit DTO, unexpected exceptions are scrubbed via sanitizeMcpError, and the outcome is appended to taicket_mcp.mcp_audit_logs with hash chaining and HMAC-SHA256.

Related documentation