{
  "openapi": "3.1.0",
  "info": {
    "title": "NeuroNest API",
    "version": "2.0.0-beta.1",
    "description": "Autonomous AI Engineering Workspace. Run multiple AI agents locally using any model, any provider, and your existing subscriptions. NeuroNest routes tasks to whichever model fits, on-device or in the cloud, without touching your billing or leaking your keys.",
    "contact": {
      "name": "NeuroNest Support",
      "email": "support@neuronest.cc",
      "url": "https://neuronest.cc/support"
    },
    "license": {
      "name": "Community — Free Forever",
      "url": "https://neuronest.cc/terms"
    },
    "x-logo": {
      "url": "https://neuronest.cc/android-icon-192x192.png"
    }
  },
  "servers": [
    {
      "url": "https://neuronest.cc",
      "description": "Production (Cloudflare Workers)"
    }
  ],
  "tags": [
    {
      "name": "Discovery",
      "description": "Self-describing capability endpoints for LLM and agent ecosystems"
    },
    {
      "name": "MCP",
      "description": "Model Context Protocol — tool registry and execution gateway"
    },
    {
      "name": "Agents",
      "description": "Agent registration, heartbeat, and public stats"
    },
    {
      "name": "Support",
      "description": "AI-powered support chat"
    },
    {
      "name": "Versions",
      "description": "Platform version manifest"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "Worker health check",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/capabilities": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "Platform capabilities summary",
        "operationId": "getCapabilities",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CapabilitiesResponse"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "List supported AI models",
        "operationId": "listModels",
        "parameters": [
          {
            "name": "provider",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by provider id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/providers": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "List AI providers",
        "operationId": "listProviders",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "cloud",
                "local",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProvidersResponse"
                }
              }
            }
          }
        }
      }
    },
    "/skills": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "summary": "NeuroNest skill registry",
        "operationId": "listSkills",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SkillsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": [
          "MCP"
        ],
        "summary": "MCP JSON-RPC 2.0 endpoint",
        "operationId": "mcpJsonRpc",
        "description": "Canonical MCP Streamable HTTP transport (spec 2024-11-05). Accepts JSON-RPC 2.0 requests and returns JSON-RPC 2.0 responses. Supported methods: initialize, tools/list, tools/call, ping, notifications/initialized. Batch requests (array) are supported.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JsonRpcRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                }
              }
            }
          },
          "202": {
            "description": "Notification accepted (no body)"
          },
          "400": {
            "description": "Parse error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcError"
                }
              }
            }
          }
        }
      }
    },
    "/mcp/tools": {
      "get": {
        "tags": [
          "MCP"
        ],
        "summary": "List MCP tools (legacy REST)",
        "operationId": "listMcpTools",
        "description": "Returns the raw tool registry array. Kept for backward compatibility — prefer the JSON-RPC 2.0 endpoint at POST /mcp with method tools/list.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ToolsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/mcp/execute": {
      "post": {
        "tags": [
          "MCP"
        ],
        "summary": "Execute an MCP tool",
        "operationId": "executeMcpTool",
        "description": "Execute a named tool from the registry with supplied arguments.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExecuteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExecuteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Unknown tool",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/agents/register": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "Register an AI agent",
        "operationId": "registerAgent",
        "description": "Register a new AI agent. All four top-level fields are required. Returns a wrapped agent object — save the api_key immediately, it will not be shown again.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterAgentRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent registered",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegisterAgentResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input — missing required field or invalid team"
          }
        }
      }
    },
    "/api/agents/stats": {
      "get": {
        "tags": [
          "Agents"
        ],
        "summary": "Public agent stats",
        "operationId": "getAgentStats",
        "description": "Returns the total number of registered agents and total completed tasks.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentStatsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/client/heartbeat": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "Desktop client heartbeat",
        "operationId": "clientHeartbeat",
        "description": "Called by the NeuroNest desktop app to record a check-in (license validation, version ping). Requires the service-level NEURONEST_API_KEY as a Bearer token (not the agent api_key). Note: original task brief referenced /api/agents/heartbeat — the canonical live route is /api/client/heartbeat.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HeartbeatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Heartbeat recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid code"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/api/support/chat": {
      "post": {
        "tags": [
          "Support"
        ],
        "summary": "AI support chat",
        "operationId": "supportChat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SupportChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SupportChatResponse"
                }
              }
            }
          }
        }
      }
    },
    "/versions.json": {
      "get": {
        "tags": [
          "Versions"
        ],
        "summary": "Platform version manifest",
        "operationId": "getVersions",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Service API key (NEURONEST_API_KEY) — used by the desktop client for /api/client/heartbeat. Not the same as the agent api_key from agent registration."
      },
      "agentBearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Agent api_key returned from POST /api/agents/register — used for agent-scoped operations."
      }
    },
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "version": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CapabilitiesResponse": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string"
          },
          "summary": {
            "type": "object",
            "description": "Aggregate counts",
            "properties": {
              "tools": {
                "type": "integer"
              },
              "providers": {
                "type": "integer"
              },
              "topologies": {
                "type": "integer"
              },
              "departments": {
                "type": "integer"
              },
              "total_agents": {
                "type": "integer"
              },
              "skills": {
                "type": "integer"
              }
            }
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "tags": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "providers": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "topologies": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "departments": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "skills": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "ModelsResponse": {
        "type": "object",
        "properties": {
          "models": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "ProvidersResponse": {
        "type": "object",
        "properties": {
          "providers": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "SkillsResponse": {
        "type": "object",
        "properties": {
          "skills": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "JsonRpcRequest": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "jsonrpc",
              "method"
            ],
            "properties": {
              "jsonrpc": {
                "type": "string",
                "example": "2.0"
              },
              "id": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "method": {
                "type": "string",
                "example": "tools/list"
              },
              "params": {
                "type": "object"
              }
            }
          },
          {
            "type": "array",
            "description": "Batch request"
          }
        ]
      },
      "JsonRpcResponse": {
        "type": "object",
        "properties": {
          "jsonrpc": {
            "type": "string",
            "example": "2.0"
          },
          "id": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "result": {
            "type": "object"
          },
          "error": {
            "$ref": "#/components/schemas/JsonRpcError"
          }
        }
      },
      "JsonRpcError": {
        "type": "object",
        "properties": {
          "jsonrpc": {
            "type": "string",
            "example": "2.0"
          },
          "id": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "ToolsResponse": {
        "type": "array",
        "items": {
          "type": "object"
        }
      },
      "ExecuteRequest": {
        "type": "object",
        "required": [
          "tool",
          "arguments"
        ],
        "properties": {
          "tool": {
            "type": "string",
            "description": "Tool name from /mcp/tools"
          },
          "arguments": {
            "type": "object"
          }
        }
      },
      "ExecuteResponse": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "success": {
                "type": "boolean",
                "example": true
              },
              "result": {
                "type": "object"
              }
            }
          },
          {
            "type": "object",
            "properties": {
              "success": {
                "type": "boolean",
                "example": false
              },
              "error": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            }
          }
        ]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      },
      "RegisterAgentRequest": {
        "type": "object",
        "required": [
          "name",
          "description",
          "model",
          "team"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Human-readable agent name"
          },
          "description": {
            "type": "string",
            "description": "Short description of what this agent does (required)"
          },
          "model": {
            "type": "string",
            "description": "Model identifier (e.g. gpt-4o, llama3.2)"
          },
          "team": {
            "type": "string",
            "description": "Department id — must be a valid team value"
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Optional list of capability strings"
          },
          "github_handle": {
            "type": "string",
            "description": "Optional GitHub username for attribution"
          }
        }
      },
      "RegisterAgentResponse": {
        "type": "object",
        "properties": {
          "agent": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "api_key": {
                "type": "string",
                "description": "Save immediately — will not be shown again"
              },
              "team": {
                "type": "string"
              },
              "claim_url": {
                "type": "string",
                "format": "uri"
              },
              "verification_code": {
                "type": "string"
              }
            }
          },
          "message": {
            "type": "string"
          },
          "important": {
            "type": "string"
          }
        }
      },
      "AgentStatsResponse": {
        "type": "object",
        "properties": {
          "total_agents": {
            "type": "integer",
            "description": "Total number of registered agents"
          },
          "completed_tasks": {
            "type": "integer",
            "description": "Total number of tasks marked completed across all agents"
          }
        }
      },
      "HeartbeatRequest": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Invite/license code (PQC-XXXXXXXX-XXXXXXXX format)"
          },
          "platform": {
            "type": "string",
            "description": "Client platform identifier (e.g. darwin, win32, linux)"
          },
          "version": {
            "type": "string",
            "description": "Desktop app version string"
          }
        }
      },
      "SupportChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "role": {
                  "type": "string"
                },
                "content": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SupportChatResponse": {
        "type": "object",
        "properties": {
          "reply": {
            "type": "string"
          },
          "escalated": {
            "type": "boolean"
          }
        }
      }
    }
  }
}