{
  "openapi": "3.1.0",
  "info": {
    "title": "Theory of Computation Simulator — MCP API",
    "description": "HTTP MCP (Model Context Protocol) endpoint for simulating and building formal language automata. Implements JSON-RPC 2.0. build_*_link tools return a simulator URL that loads the automaton directly on the canvas. Account/Teams tools (list_my_teams, create_team, join_team, list_team_members, list_team_projects, create_project, list_my_automatons, save_automaton, submit_automaton_to_project) additionally require an 'Authorization: Bearer <personal-access-token>' header.",
    "version": "2.0.0",
    "license": { "name": "MIT" },
    "contact": {
      "url": "https://github.com/KebanFiru/theory_of_computation_simulator"
    }
  },
  "servers": [
    {
      "url": "https://www.theoryofcomputationsimulator.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/mcp": {
      "post": {
        "summary": "MCP JSON-RPC 2.0 endpoint",
        "description": "Model Context Protocol endpoint. Send JSON-RPC 2.0 requests to simulate automata, build automata, and convert between representations.",
        "operationId": "mcpCall",
        "security": [{}, { "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/JsonRpcRequest" },
              "examples": {
                "initialize": {
                  "summary": "Initialize MCP session",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "initialize",
                    "params": {}
                  }
                },
                "tools_list": {
                  "summary": "List available tools",
                  "value": { "jsonrpc": "2.0", "id": 2, "method": "tools/list" }
                },
                "build_fa_link": {
                  "summary": "Build a simulator URL for a DFA",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 3,
                    "method": "tools/call",
                    "params": {
                      "name": "build_fa_link",
                      "arguments": {
                        "states": ["q0", "q1"],
                        "alphabet": ["a", "b"],
                        "transitions": [
                          { "from": "q0", "to": "q1", "symbol": "a" },
                          { "from": "q1", "to": "q1", "symbol": "b" }
                        ],
                        "start_state": "q0",
                        "accept_states": ["q1"]
                      }
                    }
                  }
                },
                "simulate_fa": {
                  "summary": "Test a DFA",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 3,
                    "method": "tools/call",
                    "params": {
                      "name": "simulate_fa",
                      "arguments": {
                        "states": ["q0", "q1"],
                        "alphabet": ["a", "b"],
                        "transitions": [
                          { "from": "q0", "to": "q0", "symbol": "a" },
                          { "from": "q0", "to": "q1", "symbol": "b" },
                          { "from": "q1", "to": "q1", "symbol": "b" }
                        ],
                        "start_state": "q0",
                        "accept_states": ["q1"],
                        "input": "ab"
                      }
                    }
                  }
                },
                "list_my_teams": {
                  "summary": "List the authenticated user's teams (requires Authorization: Bearer <token>)",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 4,
                    "method": "tools/call",
                    "params": { "name": "list_my_teams", "arguments": {} }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response (success or error)",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/JsonRpcSuccess" },
                    { "$ref": "#/components/schemas/JsonRpcError" }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal access token, required only for the account/Teams tools (list_my_teams, create_team, join_team, list_team_members, list_team_projects, create_project, list_my_automatons, save_automaton, submit_automaton_to_project). Token self-service UI is planned but not shipped yet."
      }
    },
    "schemas": {
      "JsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "id", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "oneOf": [{ "type": "integer" }, { "type": "string" }] },
          "method": {
            "type": "string",
            "enum": ["initialize", "tools/list", "tools/call"],
            "description": "MCP protocol method"
          },
          "params": {
            "type": "object",
            "description": "For tools/call: { name: string, arguments: object }"
          }
        }
      },
      "JsonRpcSuccess": {
        "type": "object",
        "required": ["jsonrpc", "id", "result"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "oneOf": [{ "type": "integer" }, { "type": "string" }] },
          "result": { "type": "object" }
        }
      },
      "JsonRpcError": {
        "type": "object",
        "required": ["jsonrpc", "id", "error"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": {
            "oneOf": [
              { "type": "integer" },
              { "type": "string" },
              { "type": "null" }
            ]
          },
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "integer" },
              "message": { "type": "string" }
            }
          }
        }
      },
      "FaTransition": {
        "type": "object",
        "required": ["from", "to", "symbol"],
        "properties": {
          "from": { "type": "string", "description": "Source state label" },
          "to": { "type": "string", "description": "Target state label" },
          "symbol": {
            "type": "string",
            "description": "Transition symbol (use 'ε' for epsilon)"
          }
        }
      },
      "FaDefinition": {
        "type": "object",
        "required": [
          "states",
          "alphabet",
          "transitions",
          "start_state",
          "accept_states"
        ],
        "properties": {
          "states": { "type": "array", "items": { "type": "string" } },
          "alphabet": { "type": "array", "items": { "type": "string" } },
          "transitions": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/FaTransition" }
          },
          "start_state": { "type": "string" },
          "accept_states": { "type": "array", "items": { "type": "string" } }
        }
      },
      "PdaTransition": {
        "type": "object",
        "required": ["from", "to", "input", "pop", "push"],
        "properties": {
          "from": { "type": "string" },
          "to": { "type": "string" },
          "input": { "type": "string", "description": "Input symbol or 'ε'" },
          "pop": {
            "type": "string",
            "description": "Stack symbol to pop or 'ε'"
          },
          "push": {
            "type": "string",
            "description": "Stack string to push or 'ε'"
          }
        }
      },
      "TmTransition": {
        "type": "object",
        "required": ["from", "to", "reads", "writes", "moves"],
        "properties": {
          "from": { "type": "string" },
          "to": { "type": "string" },
          "reads": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Symbols read (one per tape)"
          },
          "writes": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Symbols written (one per tape)"
          },
          "moves": {
            "type": "array",
            "items": { "type": "string", "enum": ["L", "R", "N"] },
            "description": "Head move directions"
          }
        }
      },
      "MealyTransition": {
        "type": "object",
        "required": ["from", "to", "input", "output"],
        "properties": {
          "from": { "type": "string" },
          "to": { "type": "string" },
          "input": { "type": "string" },
          "output": { "type": "string" }
        }
      },
      "MooreState": {
        "type": "object",
        "required": ["name", "output"],
        "properties": {
          "name": { "type": "string" },
          "output": { "type": "string" }
        }
      },
      "MooreTransition": {
        "type": "object",
        "required": ["from", "to", "input"],
        "properties": {
          "from": { "type": "string" },
          "to": { "type": "string" },
          "input": { "type": "string" }
        }
      }
    }
  }
}
