Agent MCP (Admin)

Internal agent infrastructure — 45 MCP tools across 12 domains for 10 autonomous AI agents. This is the private admin system, not the public MCP server.

Overview

LinkTime runs 10 autonomous AI agents that handle support, analytics, infrastructure monitoring, growth, and more. These agents communicate through a private MCP (Model Context Protocol) server that gives them scoped access to platform data and operations.

3-Layer Architecture

🧠

OpenClaw

Agent brains, Slack interface, cron scheduling. Runs on Railway.

🔧

LinkTime MCP

45 tools, budget enforcement, audit logging. This server.

🗄️

PostgreSQL

State, cost tracking, tool call history, audit trail.

Agents call tools viaPOST /api/admin/agent-mcp→ JSON-RPC 2.0

Each agent authenticates with a dedicated API key that grants specific scopes. The server enforces scope-based access control, logs every call to an audit table, and requires explicit confirmation on destructive operations.

Authentication

Agent API Key Format

lt_agent_{agentName}_{64hexChars}

Example: lt_agent_support_a1b2c3d4e5f6... (64 hex characters)

Authentication Flow

  1. Agent sends POST /api/admin/agent-mcp with Authorization: Bearer lt_agent_...
  2. Server validates key format (cheap, no DB hit)
  3. Server hashes key with SHA-256, looks up hash in AgentApiKey table
  4. If valid and active: creates McpHandler with the agent's scopes
  5. Handler processes JSON-RPC request, checking tool scope before execution
  6. Every tool call logged to AgentToolCall table

Scope Model

Format: {domain}:{action} — e.g., analytics:read, bookings:write. Write implies read — an agent with flags:write automatically gets flags:read.

Protocol

The server uses JSON-RPC 2.0 over HTTP POST. All requests go to /api/admin/agent-mcp.

MethodPurpose
initializeMCP handshake — returns protocol version and server info
pingHealth check
tools/listReturns tools the agent has access to (filtered by scopes)
tools/callExecute a tool with arguments (scope check + audit log)

Safety Gates

  • Scope enforcement — Agent can only call tools matching its scopes
  • confirm: true — All destructive write tools require explicit confirmation
  • Field whitelists — Write tools only accept specific fields
  • Audit trail — Every call logged with agent identity, tool name, input hash, status, latency
  • Rate limits — Built into the agent key system

Tool Domains

45 tools organized into 12 domains. Full API signatures are in the LLM markdown reference.

DomainToolsScopesDescription
Analytics9analytics:readKPI dashboard, revenue, traffic, booking metrics, signup funnel
Feature Flags6flags:read/writeList, check, toggle flags; per-user overrides
Infrastructure4infra:read/writeCron health, system tests, messaging kill switch
Audit1audit:readCross-user audit log search with filters
Users7users:read/writeUser lookup, activity, plan changes, settings, disable
Bookings4bookings:read/writeList, detail, admin cancel/reschedule with all side effects
Contacts3contacts:read/writeCross-user contact list, detail, metadata updates
Events3events:readEvent type listing, detail, availability checking
Budget2budget:readPer-agent daily budget check, global budget status
Codebase4codebase:readGitHub-backed file search, read, directory listing, git history
Email1email:writeBranded email sending with per-agent category permissions
Images1images:writeAI image generation via Scenario API (Gemini 3.1)
Total4517 scopes across 12 domains

Budget System

Every agent has a daily spending cap enforced via the Cap Gate pattern. Agents must call check_budget before taking actions that cost money (LLM calls, email sends, image generation).

Per-Agent Limits

  • Support agent: $0.20/day (high volume, low cost per call)
  • All other agents: $5.00/day
  • Warning threshold at 80% spent

Global Cap

  • Global daily limit: $50/day
  • check_global_budget shows cross-agent spend
  • Budget resets at midnight UTC

Budget Tools

ToolScopeDescription
check_budgetbudget:readCheck remaining budget for the calling agent
check_global_budgetbudget:readView cross-agent budget breakdown and global cap status

Agent Email

Agents can send branded emails via the send_email tool (scope: email:write). Each agent has category restrictions and rate limits to prevent abuse.

Category Permissions

AgentAllowed Categories
Supportsupport, transactional, internal
CTO, DevOpstransactional, internal
Orchestratorsupport, transactional, internal
Data, SEOinternal only
Growth, Outbound, CS, Contentmarketing, internal

Rate Limits

  • Level 1 (Support, DevOps, Outbound, Orchestrator): 20/day, 5/hour
  • Level 0 (CTO, Data, SEO, Growth, CS, Content): 5/day, 2/hour

Compliance

  • Marketing emails include CAN-SPAM headers
  • RFC 8058 one-click unsubscribe
  • Opt-out enforcement for marketing category
  • All sends logged to AgentEmailLog table

Agent Roster

10 agents running on OpenClaw. All 10 connected via Slack with dedicated bot identities.

AgentPersonaModelAutonomyStatus
SupportThe Front LineSonnetL1Connected
CTOThe BuilderOpusL1Connected
DataThe AnalystSonnetL1Connected
DevOpsThe GuardianSonnetL1Connected
OrchestratorThe Chief of StaffSonnetL1Connected
SEOThe CartographerSonnetL0Connected
GrowthThe ExperimenterSonnetL0Connected
OutboundThe HunterSonnetL0Connected
Customer SuccessThe GardenerSonnetL0Connected
ContentThe VoiceSonnetL0Connected

Connected = Slack app installed, Socket Mode active, agent responding. L0 = connected, read-only / internal-only email. L1 = operates autonomously within scope.

Autonomy Framework

Agent actions are classified by reversibility into three tiers. Higher tiers require more oversight.

T1 — Fully Autonomous

Read-only actions. No human approval needed.

  • • Reading analytics dashboards
  • • Listing users, bookings, contacts
  • • Checking feature flags
  • • Searching codebase
  • • Budget checks

T2 — Supervised

Reversible writes. Require confirm: true.

  • • Toggling feature flags
  • • Updating user settings
  • • Updating contact metadata
  • • Sending emails
  • • Generating images

T3 — Human-in-the-Loop

Irreversible or high-impact. Orchestrator approval required.

  • • Cancelling bookings
  • • Changing user plans
  • • Disabling user accounts
  • • Messaging kill switch

Autonomy Levels

L0 — Agent is connected but read-only / internal-only email (5 agents). L1 — Agent operates autonomously within its scope with budget constraints (5 agents). Higher levels (L2+) will be introduced as agents prove reliable.

Scope Reference

17 scopes across 12 domains. Write scopes always imply the corresponding read scope.

ScopeDomainToolsType
analytics:readAnalytics9Read
flags:readFeature Flags3Read
flags:writeFeature Flags3Write
infra:readInfrastructure2Read
infra:writeInfrastructure2Write
audit:readAudit1Read
users:readUsers4Read
users:writeUsers3Write
bookings:readBookings2Read
bookings:writeBookings2Write
contacts:readContacts2Read
contacts:writeContacts1Write
events:readEvents3Read
budget:readBudget2Read
codebase:readCodebase4Read
email:writeEmail1Write
images:writeImages1Write
Total4517 scopes

API Examples

Calling a Tool

POST /api/admin/agent-mcp Authorization: Bearer lt_agent_support_a1b2c3d4... { "jsonrpc": "2.0", "id": "req-1", "method": "tools/call", "params": { "name": "search_users_by_email", "arguments": { "email": "[email protected]" } } }

Success Response

{ "jsonrpc": "2.0", "id": "req-1", "result": { "content": [{ "type": "text", "text": "{\"success\":true,\"data\":{\"users\":[{\"id\":\"clx...\",\"email\":\"[email protected]\",\"name\":\"John Doe\",\"plan\":\"PRO\"}],\"count\":1}}" }] } }

Listing Available Tools

POST /api/admin/agent-mcp Authorization: Bearer lt_agent_support_a1b2c3d4... { "jsonrpc": "2.0", "id": "req-2", "method": "tools/list", "params": {} }

Returns only the tools the authenticated agent has access to, filtered by its key's scopes.

Error Response

{ "jsonrpc": "2.0", "id": "req-3", "error": { "code": -32600, "message": "Scope 'bookings:write' required but agent only has: analytics:read, users:read" } }

Key Files

FilePurpose
src/lib/mcp/types.tsMcpTool, McpToolResult, JsonRpc types
src/lib/mcp/registry.tsToolRegistry class (register, scope filter, access check)
src/lib/mcp/handler.tsJSON-RPC routing, scope enforcement, audit logging
src/lib/mcp/tools.tsGlobal registry initialization (imports all 12 domain files)
src/lib/mcp/tools/*.ts12 domain files: analytics (9), flags (6), infra (4), audit (1), users (7), bookings (4), contacts (3), events (3), budget (2), codebase (4), email (1), images (1)
src/lib/agent-keys.tsAgent key generation, format validation, display formatting
src/lib/require-agent-key.tsAuthentication middleware with scope checking
src/app/api/admin/agent-mcp/route.tsHTTP endpoint (POST handler)
src/lib/admin-agents.tsAgent dashboard service (static roster + Prisma queries)
src/lib/agent-events.tsEvent bus for agent webhook delivery

Related Documentation