openapi: 3.1.0
info:
  title: FastJudge0 API
  version: 0.4.0
  description: >
    Drop-in, Judge0 1.13.1-compatible sandboxed code execution engine in Rust
    across 11 native fast languages with Prometheus /metrics/prometheus,
    Streamable HTTP MCP (/mcp), A2A Agent Card (/.well-known/agent-card.json),
    and llms.txt discovery.
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: http://127.0.0.1:2358
    description: Local Docker Compose endpoint
security:
  - ApiKeyHeader: []
  - {}
paths:
  /mcp:
    post:
      summary: Native MCP Streamable HTTP JSON-RPC 2.0 endpoint
      description: Supports initialize, notifications/initialized, ping, tools/list, and tools/call (execute_code, execute_test_suite).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [jsonrpc, method]
              properties:
                jsonrpc:
                  type: string
                  example: "2.0"
                id:
                  oneOf:
                    - type: integer
                    - type: string
                method:
                  type: string
                  example: tools/list
                params:
                  type: object
      responses:
        "200":
          description: JSON-RPC 2.0 response
        "202":
          description: JSON-RPC notification accepted
  /.well-known/agent-card.json:
    get:
      summary: A2A (Agent2Agent) discovery card
      security: []
      responses:
        "200":
          description: Agent capability manifest
  /llms.txt:
    get:
      summary: Compact LLM-friendly capability & endpoint index
      security: []
      responses:
        "200":
          description: Markdown discovery summary
  /llms-full.txt:
    get:
      summary: Complete single-file reference for AI agents
      security: []
      responses:
        "200":
          description: Full Markdown API & MCP reference
  /healthz:
    get:
      summary: Health check
      security: []
      responses:
        "200":
          description: Service healthy
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: ok
                  engine:
                    type: string
                    example: fastjudge0-rust
  /submissions:
    post:
      summary: Execute a single code submission
      parameters:
        - $ref: "#/components/parameters/Base64Encoded"
        - $ref: "#/components/parameters/Wait"
        - $ref: "#/components/parameters/Fields"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SubmissionRequest"
      responses:
        "201":
          description: Terminal submission result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SubmissionResult"
        "503":
          description: Queue full backpressure
  /submissions/batch:
    post:
      summary: Execute a batch of submissions
      parameters:
        - $ref: "#/components/parameters/Base64Encoded"
        - $ref: "#/components/parameters/Fields"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [submissions]
              properties:
                submissions:
                  type: array
                  items:
                    $ref: "#/components/schemas/SubmissionRequest"
      responses:
        "201":
          description: Terminal results in submission order
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/SubmissionResult"
        "503":
          description: Queue full backpressure
    get:
      summary: Fetch batch submission results by token
      parameters:
        - name: tokens
          in: query
          required: true
          schema:
            type: string
            description: Comma-separated submission tokens
        - $ref: "#/components/parameters/Base64Encoded"
        - $ref: "#/components/parameters/Fields"
      responses:
        "200":
          description: Batch lookup response
          content:
            application/json:
              schema:
                type: object
                properties:
                  submissions:
                    type: array
                    items:
                      $ref: "#/components/schemas/SubmissionResult"
  /submissions/{token}:
    get:
      summary: Get a submission result by token
      parameters:
        - name: token
          in: path
          required: true
          schema:
            type: string
        - $ref: "#/components/parameters/Base64Encoded"
        - $ref: "#/components/parameters/Fields"
      responses:
        "200":
          description: Stored submission result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SubmissionResult"
        "404":
          description: Submission not found or expired
    delete:
      summary: Delete a submission token from memory (or upstream)
      parameters:
        - name: token
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Deletion receipt
  /languages:
    get:
      summary: List supported languages
      responses:
        "200":
          description: Language list
  /languages/{id}:
    get:
      summary: Get language details by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Language object
        "404":
          description: Language not found
  /statuses:
    get:
      summary: List Judge0 status IDs (1..13)
      responses:
        "200":
          description: Status code table
  /workers:
    get:
      summary: Worker pool status
      responses:
        "200":
          description: Worker telemetry
  /metrics:
    get:
      summary: Engine throughput, latency, and compile cache telemetry (JSON or Prometheus via Accept header)
      responses:
        "200":
          description: JSON metrics snapshot or Prometheus exposition text
  /metrics/prometheus:
    get:
      summary: Prometheus / OpenMetrics text exposition endpoint
      responses:
        "200":
          description: Prometheus text metrics (version 0.0.4)
          content:
            text/plain:
              schema:
                type: string
  /about:
    get:
      summary: Engine version metadata
      responses:
        "200":
          description: Version object
  /config_info:
    get:
      summary: Runtime defaults and limit configuration
      responses:
        "200":
          description: Configuration object
components:
  securitySchemes:
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-Auth-Token
  parameters:
    Base64Encoded:
      name: base64_encoded
      in: query
      schema:
        type: boolean
        default: false
    Wait:
      name: wait
      in: query
      schema:
        type: boolean
        default: true
    Fields:
      name: fields
      in: query
      schema:
        type: string
        description: Use "*" or comma-separated fields (e.g. "stdout,status,time")
  schemas:
    SubmissionRequest:
      type: object
      required: [language_id]
      properties:
        language_id:
          oneOf:
            - type: integer
            - type: string
          example: 71
        source_code:
          type: string
        stdin:
          type: string
        expected_output:
          type: string
        compiler_options:
          type: string
        command_line_arguments:
          type: string
        cpu_time_limit:
          type: number
          default: 5.0
        cpu_extra_time:
          type: number
          default: 1.0
        wall_time_limit:
          type: number
          default: 10.0
        memory_limit:
          type: integer
          default: 128000
        stack_limit:
          type: integer
          default: 64000
        max_processes_and_or_threads:
          type: integer
          default: 60
        max_file_size:
          type: integer
          default: 4096
        redirect_stderr_to_stdout:
          type: boolean
          default: false
    Status:
      type: object
      properties:
        id:
          type: integer
        description:
          type: string
    SubmissionResult:
      type: object
      properties:
        token:
          type: string
        status:
          $ref: "#/components/schemas/Status"
        stdout:
          type: [string, "null"]
        stderr:
          type: [string, "null"]
        compile_output:
          type: [string, "null"]
        message:
          type: [string, "null"]
        time:
          type: [string, "null"]
        wall_time:
          type: [string, "null"]
        memory:
          type: [integer, "null"]
        exit_code:
          type: [integer, "null"]
