{
  "openapi": "3.1.1",
  "info": {
    "title": "Ohmforge AC Sweep (Bode plot) API",
    "version": "1.0.0",
    "summary": "Frequency response of a circuit: Bode magnitude/phase, −3 dB corner and unity gain.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://ohmforgeacsweep.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Frequency response of a circuit: Bode magnitude/phase, −3 dB corner and unity gain.",
        "description": "Linearises the circuit at its DC operating point and solves the complex MNA equations across a logarithmic frequency sweep. Returns magnitude in dB and unwrapped phase of an output node (optionally relative to an input node), the peak gain, lower/upper −3 dB frequencies, the unity-gain frequency, a Bode chart and CSV.\n\nMethodology:\n- The DC operating point is solved first; every nonlinear device is replaced by its small-signal conductances at that point (diode gd, BJT gm/gπ/go, MOSFET gm/gds, op-amp output slope).\n- Capacitors become admittances jωC, inductors impedances jωL in their branch equations, coupled inductors jωM; the complex system is solved by dense LU with partial pivoting at every frequency.\n- Magnitude is 20·log10|H|, phase is unwrapped to be continuous. The −3 dB points are found 3.01 dB below the peak by logarithmic interpolation; unity gain is the 0 dB crossing.\n\nTeaching-grade simulation: device models are simplified (Ebers–Moll BJT, level-1 MOSFET, behavioural op-amps and 555) and part ratings are typical values. Verify real designs on the bench and against manufacturer data before building anything connected to mains voltage.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ohmforge_ac_sweep",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OhmforgeAcSweepInput"
              },
              "examples": {
                "example1": {
                  "summary": "RC low-pass (fc ≈ 1.59 kHz)",
                  "value": {
                    "netlist": "* RC low-pass, fc = 1/(2*pi*1k*100n) = 1591.5 Hz\nV1 in 0 DC 0 AC 1\nR1 in out 1k\nC1 out 0 100n\n.ac dec 20 10 1meg",
                    "output": "out",
                    "input": "V1"
                  }
                },
                "example2": {
                  "summary": "Inverting op-amp, gain −10",
                  "value": {
                    "netlist": "* Inverting amplifier, gain -10 (ideal op-amp as VCVS)\nV1 in 0 AC 1\nR1 in m 1k\nR2 m out 10k\nE1 out 0 0 m 100k\n.ac dec 10 10 10meg",
                    "output": "out",
                    "input": "V1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OhmforgeAcSweepResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "OhmforgeAcSweepInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "netlist": {
            "title": "SPICE netlist",
            "description": "Subset: R C L V I D Q M E G K, .model, SIN/PULSE/PWL sources, engineering suffixes (k, m, u, n, p, meg). Node 0 is ground. Leave empty when you pass an Ohmforge project instead.",
            "type": "string",
            "maxLength": 60000
          },
          "project": {
            "title": "Ohmforge project JSON (optional)",
            "description": "Alternative to the netlist: a .ohmforge.json project as saved by the app (format \"ohmforge\", version 1).",
            "type": "string",
            "maxLength": 200000
          },
          "output": {
            "title": "Output node",
            "type": "string",
            "maxLength": 64,
            "default": "out"
          },
          "input": {
            "title": "Input source (gets AC = 1)",
            "description": "Name of the V or I source to excite (e.g. V1). Empty = keep the AC magnitudes from the netlist.",
            "type": "string",
            "maxLength": 64
          },
          "inputNode": {
            "title": "Reference node (optional)",
            "description": "Report V(out)/V(ref) instead of V(out).",
            "type": "string",
            "maxLength": 64
          },
          "fstart": {
            "title": "Start frequency",
            "description": "Empty = .ac line or 1 Hz.",
            "type": "number",
            "minimum": 0.001,
            "maximum": 10000000000,
            "x-unit": "Hz"
          },
          "fstop": {
            "title": "Stop frequency",
            "description": "Empty = .ac line or 10 MHz.",
            "type": "number",
            "minimum": 0.001,
            "maximum": 100000000000,
            "x-unit": "Hz"
          },
          "pointsPerDecade": {
            "title": "Points per decade",
            "description": "Empty = .ac line or 20.",
            "type": "integer",
            "minimum": 1,
            "maximum": 200
          }
        },
        "required": [
          "output"
        ]
      },
      "OhmforgeAcSweepResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "required": [
              "output",
              "frequencies",
              "magnitudeDb",
              "phaseDeg",
              "peakDb"
            ],
            "properties": {
              "output": {
                "type": "string"
              },
              "input": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "frequencies": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              },
              "magnitudeDb": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              },
              "phaseDeg": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              },
              "peakDb": {
                "type": "number"
              },
              "peakFrequency": {
                "type": "number"
              },
              "lowGainDb": {
                "type": "number"
              },
              "lower3dB": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "upper3dB": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "unityGainFrequency": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "diagnostics": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}