{
  "openapi": "3.1.0",
  "info": {
    "title": "Circuitfield API",
    "version": "1.0.0",
    "summary": "AI component search, datasheet parameters and BOM management.",
    "description": "The Circuitfield catalog and workspace are exposed to agents through a Model Context Protocol (MCP) server. Component search, datasheet parameter extraction, distributor pricing, BOMs, approved-part libraries and design rulesets are reached as MCP tools over the streamable HTTP transport at /mcp. The endpoints below are the HTTP surface of that server plus its health and discovery endpoints.",
    "contact": {
      "name": "Via Engineering Inc.",
      "email": "legal@viabom.com",
      "url": "https://circuitfield.com/contact"
    },
    "termsOfService": "https://circuitfield.com/terms"
  },
  "externalDocs": {
    "description": "Circuitfield documentation",
    "url": "https://docs.circuitfield.com"
  },
  "servers": [
    {
      "url": "https://api.circuitfield.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "viaBomOAuth": [
        "mcp:read"
      ]
    }
  ],
  "paths": {
    "/mcp": {
      "post": {
        "operationId": "invokeMcp",
        "summary": "Invoke the Circuitfield MCP server",
        "description": "Sends a Model Context Protocol JSON-RPC message over the streamable HTTP transport. Use tools/list to enumerate the available tools and tools/call to invoke one. Read-only tools such as search_components, get_component_details, get_datasheet_overview and get_component_pricing require the mcp:read scope; tools that create or modify projects, BOM lines, libraries, rulesets or settings require mcp:write.",
        "security": [
          {
            "viaBomOAuth": [
              "mcp:read",
              "mcp:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/McpRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A JSON-RPC result, or an SSE stream of them.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/McpResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired access token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The token is not authorized for this workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mcp-health": {
      "get": {
        "operationId": "getMcpHealth",
        "summary": "Report MCP server health",
        "description": "Unauthenticated liveness check for the MCP server. Use it to confirm the endpoint is reachable before starting an OAuth flow.",
        "security": [],
        "responses": {
          "200": {
            "description": "Health report.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    },
    "/.well-known/oauth-protected-resource": {
      "get": {
        "operationId": "getProtectedResourceMetadata",
        "summary": "Get OAuth protected-resource metadata",
        "description": "RFC 9728 metadata naming the resource identifier and the authorization servers that issue tokens for it. An MCP client reads this to discover where to authorize.",
        "security": [],
        "responses": {
          "200": {
            "description": "Protected-resource metadata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProtectedResourceMetadata"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "viaBomOAuth": {
        "type": "oauth2",
        "description": "OAuth 2.0 with WorkOS AuthKit as the authorization server. Tokens are presented as a Bearer credential in the Authorization header.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://login.circuitfield.com/oauth2/authorize",
            "tokenUrl": "https://login.circuitfield.com/oauth2/token",
            "scopes": {
              "mcp:read": "Read components, datasheet parameters, pricing, projects, libraries, rulesets and settings.",
              "mcp:write": "Create and modify projects, BOM lines, libraries, rulesets and settings."
            }
          }
        }
      }
    },
    "schemas": {
      "McpRequest": {
        "type": "object",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "number"
            ]
          },
          "method": {
            "type": "string",
            "description": "A JSON-RPC method, for example tools/list or tools/call."
          },
          "params": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "McpResponse": {
        "type": "object",
        "required": [
          "jsonrpc"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "number",
              "null"
            ]
          },
          "result": {
            "type": "object",
            "additionalProperties": true
          },
          "error": {
            "$ref": "#/components/schemas/Error"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "operational",
              "degraded"
            ]
          },
          "checkedAt": {
            "type": "string",
            "format": "date-time"
          },
          "details": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ProtectedResourceMetadata": {
        "type": "object",
        "required": [
          "resource",
          "authorization_servers"
        ],
        "properties": {
          "resource": {
            "type": "string",
            "format": "uri"
          },
          "authorization_servers": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "bearer_methods_supported": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "A stable, machine-readable error code."
          },
          "message": {
            "type": "string",
            "description": "A human-readable description of what went wrong."
          },
          "hint": {
            "type": "string",
            "description": "How a caller can resolve the error."
          },
          "documentation": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    }
  }
}
