kubb-labs/kubb: The Pluggable Compiler for OpenAPI

How a flexible virtual file system and a native MCP server turned API code generation from a brittle build step into a dependency-free, agentic workflow.

8 min read • View on GitHub • More from kubb-labs

A massive mechanical loom organizing tangled threads into perfect parallel textiles. This represents Kubb's virtual file system organizing chaotic OpenAPI specs into clean, linked code.
Kubb operates less like a template engine and more like a compiler, resolving dependencies before writing a single line to disk.
Key Takeaways

The Abstract Syntax Tree for APIs

Traditional code generation is often just glorified string concatenation. You feed it a Swagger file, and it spits out a massive, monolithic file of boilerplate. This approach breaks down quickly when you need to generate interdependent files, like a React Query hook that needs to import a Zod validator, which in turn needs to import core TypeScript types.

Kubb solves this by treating OpenAPI specifications like an Abstract Syntax Tree (AST). It parses the raw JSON into an internal representation and passes it through a Vite-like plugin lifecycle. Plugins can tap into specific stages like resolveId, load, and transform. This allows developers to swap out the TypeScript generator for a different language or add a custom validator without touching the core logic.

Kubb's Virtual File Manager resolves cross-file dependencies internally before any code is written to disk.

The Virtual File Manager

The magic of Kubb lies in its Virtual File Manager. Before touching the hard drive, the system maintains a virtual tree of the generated output. If the React Query plugin needs to know where the user schema will live, it simply asks the Zod plugin. The virtual file system dynamically resolves the import path.

This guarantees perfectly linked, type-safe code across dozens of generated files. It prevents the dreaded circular dependency issues that plague naive code generators.

The Zero-Dependency Ejection

Developers hate code generators that force them to install proprietary runtime libraries. If a tool generates an API client, that client should own its execution.

With the 4.5.x release, Kubb pivoted to a zero-runtime-dependency model. It now generates a self-contained folder with native Fetch or Axios clients. The generated code works in isolation without polluting your package.json with heavy third-party vendor libraries.

We've completely removed the @kubb dependency from all generated files!

Kubb Labs, Company · LinkedIn Announcement
A close-up of a disassembled pocket watch mechanism resting on a pristine white jeweler's table, functioning perfectly without external power cords.
Kubb's generated code is entirely self-contained, requiring zero external runtime libraries to function.

Code Generation in the Agentic Era

Kubb is one of the first major developer tools to ship with a native Model Context Protocol (MCP) server and an explicit directory for AI skills. This represents a fundamental shift in how we think about tooling.

Instead of a human developer running a CLI command, an AI agent running in Claude or Cursor can read the OpenAPI spec, interact with the Kubb MCP server, and surgically update an endpoint's types, validators, and mocks in one continuous workflow. It transforms codegen from a static build step into a collaborative, AI-driven process.

Escaping the Java Monolith

For years, the industry standard for this task was the OpenAPI Generator, a massive Java-based monolith. While powerful, it often produces bloated, uncanny-valley code that feels alien in a modern TypeScript codebase.

Kubb takes the opposite approach. It is hyper-focused on the TypeScript ecosystem, producing idiomatic code that looks like a human wrote it.

ToolArchitectureOutput ScopeRuntime DependenciesAgent-Ready (MCP)
openapi-generatorJava MonolithBroad (Many Languages)HeavyNo
openapi-typescriptNode CLITypes OnlyNoneNo
KubbTS Plugin EngineTypes, Hooks, Mocks, ValidatorsNoneYes