-
Notifications
You must be signed in to change notification settings - Fork 2
Architecture
A concise overview. For the full version (data-flow diagrams, extension points, where to add a new backend), read docs/architecture.md in the repo.
cmd/openapi-go-mcp/ CLI entry point + batch orchestration
pkg/loader/ Spec ingestion: OpenAPI 3.x direct, Swagger 2.0 via openapi2conv
pkg/batch/ Per-spec option derivation (slug → PackageName/OutDir/ClientImport), collision detection
pkg/generator/ Operation collection, JSON Schema conversion, text/template → gofmt
pkg/runtime/ MCPServer interface + decoders + ApplyConfig (library-agnostic)
pkg/runtime/gosdk/ Adapter for modelcontextprotocol/go-sdk
pkg/runtime/mark3labs/ Adapter for mark3labs/mcp-go
examples/ One end-to-end demo per backend / per spec dialect
testdata/ Spec fixtures + golden generator output
tests/e2e/ Black-box tests over MCP stdio; CLI integration tests
loader.Load
↓
generator.CollectOperations (walks paths × methods, sorted)
↓
generator.Render (text/template → gofmt)
↓
write <out>/<pkg>.mcp.go
Determinism — sorted iteration, gofmt, golden test — is a hard requirement. Diff reviews depend on it.
These do most of the architectural work.
Generated code only calls AddTool(Tool, ToolHandler). The choice of MCP library is a one-line import swap. See MCP Backends.
Each operation gets its own converter so each tool's $defs is self-contained. A nameByPtr map is shared across converters within one CollectOperations call to avoid O(P·S) rebuild cost. See Schema Modes.
Batch mode sits in front of the single-spec pipeline rather than changing it:
loader.ExpandSpecArg → sorted, deduped list of SpecRef
batch.PlanFor → derives generator.Options per spec
batch.DetectCollisions → fails up front on slug collisions
↓ for each plan
single-spec pipeline runs
Per-spec failures are accumulated; the process exits with code 3 at the end. See Batch Mode.
For every operation the generator emits an AddTool call wrapping a closure that:
- Decodes path/query/header/body args via
runtime.DecodeBody,DecodePathParam, etc. - Calls the typed
<Op>WithResponse(ctx, ...)method on theoapi-codegenclient. - Returns the response body via
runtime.NewToolResultJSON.
Argument order to the typed client follows oapi-codegen's deterministic convention:
ctx, positional path params, *<Op>Params (only when query/header present), body (only when present), reqEditors...
-
loader.Loaddetects Swagger 2.0 by the top-levelswagger: 2.0and converts viakin-openapi/openapi2conv. - All loaded specs pass
openapi3.Validate. - External
$refs resolve against the spec file's directory. -
WriteV3YAMLJSONOnly(the-emit-v3flag) prunes non-JSON content types on a deep clone — the original document is never mutated.
Request bodies support application/json, application/x-www-form-urlencoded, multipart/form-data, application/octet-stream, text/*, and any other content type as a raw-string / base64 fallback. When an operation declares multiple, the generator picks deterministically in priority order. Only application/json response bodies are decoded; non-JSON responses are surfaced as raw bytes.
- Design Decisions — the why behind these choices
- MCP Backends
- Schema Modes
- Contributing
Repo · Releases · Issues · Discussions · Apache 2.0
Get started
Modes
Features
Deploy
Reference
Project