{
  "openapi": "3.1.0",
  "info": {
    "title": "Sim Lab Alpha Intelligence API",
    "version": "3.1.0",
    "summary": "Zero-hallucination pre-trade risk firewall, macro regime sentinel, and MCP intelligence server for autonomous AI trading agents.",
    "description": "Sim Lab provides deterministic pre-trade risk gating, 6-pillar microstructure validation, VPIN/spoof protection, AI-controlled starvation gating, and verifiable on-chain execution telemetry via remote Streamable HTTP MCP, SSE, and x402/MPP micropayments. Includes 100 free onboarding tool calls before pay-per-call ($0.01-$0.15 USDC on Base or Solana Pay).",
    "termsOfService": "https://simlab.measmony.me/llms.txt",
    "contact": {
      "name": "Alpha Sim Lab Support",
      "url": "https://alpha.measmony.me",
      "email": "alpha@measmony.me"
    },
    "license": {
      "name": "MIT",
      "url": "https://github.com/Measmonysuon/simlab-mcp-for-trading-agents/blob/main/LICENSE"
    }
  },
  "servers": [
    {
      "url": "https://simlab.measmony.me",
      "description": "Production Sim Lab Server (Remote MCP + x402 + SSE)"
    }
  ],
  "tags": [
    { "name": "MCP", "description": "Remote Streamable HTTP & SSE Model Context Protocol endpoints" },
    { "name": "Payments", "description": "x402 (Base USDC) & Solana Pay (SPL USDC) credit settlement" },
    { "name": "Telemetry", "description": "Market regime, protected telemetry, and real-time SSE streams" },
    { "name": "Operations", "description": "Health, status, and machine-readable discovery" }
  ],
  "x-service-info": {
    "categories": [
      "financial-services",
      "artificial-intelligence",
      "trading-infrastructure"
    ],
    "protocols": [
      "mcp",
      "mpp",
      "x402",
      "acp",
      "ucp"
    ]
  },
  "security": [
    { "ApiKeyAuth": [] },
    { "BearerAuth": [] }
  ],
  "paths": {
    "/mcp": {
      "post": {
        "tags": ["MCP"],
        "summary": "Execute MCP Tool Call (Streamable HTTP JSON-RPC)",
        "description": "Invoke quantitative trading intelligence tools (pre_trade_gate, trap_shield, regime, alpha_bundle, dynamic_exit, diagnose_trade_situation) over remote HTTPS JSON-RPC 2.0. Supports Idempotency-Key for safe retries and includes 100 free trial calls.",
        "operationId": "executeMcpTool",
        "parameters": [
          { "$ref": "#/components/parameters/IdempotencyKey" }
        ],
        "x-payment-info": {
          "intent": "charge",
          "method": "tempo",
          "amount": 0.15,
          "currency": "USD",
          "description": "Pre-trade risk firewall & quantitative signal verification ($0.01-$0.15 per call after 100 free trial calls)"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/McpJsonRpcRequest" },
              "examples": {
                "preTradeGate": {
                  "summary": "Evaluate BTC/USD LONG trade with pre_trade_gate",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "tools/call",
                    "params": {
                      "name": "pre_trade_gate",
                      "arguments": { "symbol": "BTC/USD", "side": "LONG", "confidence": 82 }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tool execution successful",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" },
              "X-RateLimit-Reset": { "$ref": "#/components/headers/X-RateLimit-Reset" }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/McpJsonRpcResponse" },
                "examples": {
                  "approved": {
                    "summary": "Deterministic gate result",
                    "value": {
                      "jsonrpc": "2.0",
                      "id": 1,
                      "result": {
                        "content": [{ "type": "text", "text": "{\"verdict\":\"ALLOW\",\"effectiveGate\":68,\"bannedSide\":\"NONE\"}" }]
                      }
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment Required - Insufficient credit after 100 free trial calls",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProblemDetails" },
                "examples": {
                  "paymentRequired": {
                    "value": {
                      "type": "https://simlab.measmony.me/errors/payment-required",
                      "title": "Payment Required",
                      "status": 402,
                      "detail": "Error -32042: Insufficient credit. POST /x402/topup or /x402/solana/request."
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "headers": {
              "Retry-After": { "$ref": "#/components/headers/Retry-After" },
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProblemDetails" }
              }
            }
          }
        }
      }
    },
    "/mcp/sse": {
      "get": {
        "tags": ["MCP"],
        "summary": "Remote MCP Server-Sent Events (SSE) Transport",
        "description": "Establishes a persistent Server-Sent Events stream for MCP tool discovery, session notifications, and asynchronous inference updates.",
        "operationId": "connectMcpSse",
        "responses": {
          "200": {
            "description": "SSE event stream opened (events: endpoint, message, heartbeat)",
            "content": {
              "text/event-stream": {
                "schema": { "type": "string" },
                "examples": {
                  "endpointEvent": {
                    "value": "event: endpoint\ndata: /mcp/messages?sessionId=abc123\n\n"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "headers": { "Retry-After": { "$ref": "#/components/headers/Retry-After" } }
          }
        }
      }
    },
    "/x402/topup": {
      "post": {
        "tags": ["Payments"],
        "summary": "x402 Credit Settlement & Topup",
        "description": "Settle USDC on Base mainnet (or use /x402/solana/request for SPL USDC) to purchase non-expiring agent call credit.",
        "operationId": "topupCredit",
        "parameters": [
          { "$ref": "#/components/parameters/IdempotencyKey" }
        ],
        "x-payment-info": {
          "intent": "session",
          "method": "tempo",
          "amount": 1.00,
          "currency": "USD",
          "description": "Sim Lab agent call credit purchase"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/TopupRequest" },
              "examples": {
                "topup1Usd": {
                  "value": { "amountUsd": 1.0, "network": "eip155:8453" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Credit issued with spend key",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/TopupResponse" },
                "examples": {
                  "credited": {
                    "value": { "success": true, "balanceUsd": 1.0, "creditsNeverExpire": true }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment challenge with recipient wallet and quote",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProblemDetails" }
              }
            }
          }
        }
      }
    },
    "/api/protected": {
      "get": {
        "tags": ["Telemetry"],
        "summary": "Protected Quantitative Telemetry",
        "description": "Real-time institutional volume profile, macro regime classification, and delta orderflow.",
        "operationId": "getProtectedTelemetry",
        "x-payment-info": {
          "intent": "charge",
          "method": "tempo",
          "amount": 0.05,
          "currency": "USD",
          "description": "Per-request quantitative telemetry access"
        },
        "responses": {
          "200": {
            "description": "Telemetry stream payload",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "regime": { "type": "string", "example": "SIMULTANEOUS_OUTFLOW" },
                    "bannedSide": { "type": "string", "enum": ["LONG", "SHORT", "NONE"], "example": "LONG" },
                    "timestamp": { "type": "integer", "example": 1796540000000 }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment Required",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProblemDetails" }
              }
            }
          }
        }
      }
    },
    "/api/stream": {
      "get": {
        "tags": ["Telemetry"],
        "summary": "Real-Time Fleet & Macro State SSE Stream",
        "description": "Server-Sent Events stream broadcasting live state, fleet telemetry, and execution log events.",
        "operationId": "streamSimLabEvents",
        "responses": {
          "200": {
            "description": "Live SSE event stream (events: state, fleet, message)",
            "content": {
              "text/event-stream": {
                "schema": { "type": "string" },
                "examples": {
                  "stateEvent": {
                    "value": "event: state\ndata: {\"regime\":\"TRENDING_BEAR\",\"altPolicy\":\"SHORT_ONLY\"}\n\n"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": ["Operations"],
        "summary": "Service Health & Readiness Check",
        "description": "Returns operational health, uptime, and service version without authentication.",
        "operationId": "getHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" },
                "examples": {
                  "healthy": {
                    "value": { "status": "ok", "service": "alpha-forge-sim-lab", "uptimeSec": 3600 }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Sim Lab API key or x402 spend key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "OAuth 2.0 Bearer token or fleet licence token"
      },
      "x402Micropayment": {
        "type": "apiKey",
        "in": "header",
        "name": "PAYMENT-SIGNATURE",
        "description": "x402 v2 cryptographic USDC payment proof header"
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Unique client-generated key (UUID v4) ensuring safe, idempotent retries without duplicate billing or execution.",
        "schema": { "type": "string", "format": "uuid", "example": "550e8400-e29b-41d4-a716-446655440000" }
      }
    },
    "headers": {
      "X-RateLimit-Limit": {
        "description": "Maximum requests allowed per 60-second window",
        "schema": { "type": "integer", "example": 120 }
      },
      "X-RateLimit-Remaining": {
        "description": "Remaining requests in the current window",
        "schema": { "type": "integer", "example": 119 }
      },
      "X-RateLimit-Reset": {
        "description": "UTC epoch timestamp when the rate-limit window resets",
        "schema": { "type": "integer", "example": 1796540060 }
      },
      "Retry-After": {
        "description": "Seconds to wait before retrying after HTTP 429",
        "schema": { "type": "integer", "example": 30 }
      }
    },
    "schemas": {
      "McpJsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "id", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "type": ["string", "integer"] },
          "method": { "type": "string", "example": "tools/call" },
          "params": { "type": "object" }
        }
      },
      "McpJsonRpcResponse": {
        "type": "object",
        "required": ["jsonrpc", "id"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "type": ["string", "integer"] },
          "result": { "type": "object" },
          "error": { "type": "object" }
        }
      },
      "TopupRequest": {
        "type": "object",
        "required": ["amountUsd"],
        "properties": {
          "amountUsd": { "type": "number", "minimum": 0.1, "example": 1.0 },
          "network": { "type": "string", "enum": ["eip155:8453", "solana:mainnet"], "example": "eip155:8453" }
        }
      },
      "TopupResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "balanceUsd": { "type": "number" },
          "creditsNeverExpire": { "type": "boolean" }
        }
      },
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "example": "ok" },
          "service": { "type": "string" },
          "uptimeSec": { "type": "number" }
        }
      },
      "ProblemDetails": {
        "type": "object",
        "required": ["title", "status"],
        "properties": {
          "type": { "type": "string", "format": "uri" },
          "title": { "type": "string" },
          "status": { "type": "integer" },
          "detail": { "type": "string" }
        }
      }
    }
  }
}
