Import an OpenAPI API
Import selected operations with validated parameters, JSON bodies, and runtime credentials into ordinary xmcp tool files.
For the complete documentation index, see llms.txt. Markdown variants of every page are available by appending .md to the URL.Generate tools from a local OpenAPI JSON file:
The command writes one TypeScript file per GET operation into src/tools.
Each file exports a Zod schema, tool metadata, and a handler using fetch.
Build and run your project as usual; no importer runtime or wrapper is needed.
Select operations and the API URL
--operations accepts comma-separated, case-sensitive operationId values.
Without this flag, all GET operations are selected; other methods are skipped.
For an operation without an ID, use its method and path, for example
--operations 'GET /pets/{id}'. Unknown selectors and explicitly selected
unsupported methods fail. GET, POST, PUT, PATCH, and DELETE are supported; write
operations must be explicitly selected.
Tool names and filenames use the existing filename normalization: lowercase,
with punctuation replaced by hyphens. For example, get-pet produces
get-pet.ts; an operation without an ID at GET /pets/{id} produces
get-pets-id.ts. Collisions fail instead of silently replacing a tool.
The API URL comes from the first server declared on the operation, path, or document, in that order. Override it when the spec uses a relative URL, server variables, or another deployment:
The base path is retained: /pets/{id} becomes /v1/pets/{id} in this example.
The URL must be absolute HTTP(S), without embedded credentials, query, or fragment.
The importer reads the local document; it does not fetch specs, references, or API data.
Supported inputs
- OpenAPI 3.0.x and 3.1.x JSON documents.
- GET and DELETE without bodies; POST, PUT, and PATCH with optional or required JSON bodies.
- Required scalar path parameters using
simpleserialization. - Required or optional scalar query parameters and arrays of scalars using
formserialization. Arrays support both repeated keys (explode: true, the default) and comma-separated values (explode: false). - Scalar headers and arrays of scalars using
simpleserialization. - JSON bodies containing nested objects, arrays, and scalars.
- String, number, integer, and boolean schemas; scalar enums; numeric bounds and
multipleOf; string length and pattern constraints; array length constraints. - Numeric formats
int32,int64,float, anddouble. Integer inputs use JavaScript's safe integer range;int32adds its narrower bounds. - Local
#/...references for parameter, schema, request-body, and security-scheme definitions, including JSON Pointer escaping. Recursive and external references are rejected. - Path-level parameters, with operation-level overrides by name and location.
Path and query values are percent-encoded separately. Header values are sent as
text without percent-encoding; header arrays use comma separators. Optional values are omitted
only when absent, so 0 and false are sent correctly. Query array separators stay
distinct from encoded commas inside values. Path values . and .. are rejected
because URL normalization would change the target route.
Input names become top-level tool arguments. A name shared by parameters in different locations is rejected. Header overrides use case-insensitive names. Schema descriptions are preserved; annotations such as examples and defaults do not supply runtime values. Omitted query parameters let the API apply its own defaults.
This subset follows the OpenAPI parameter serialization rules.
The importer rejects unsupported selected inputs rather than weakening their
schemas. These include object/nested-array parameters, unions, nullable inputs,
unsupported formats or schema keywords, cookie parameters, custom styles,
allowReserved, and allowEmptyValue. Non-JSON bodies, callbacks, path-item
references, and custom schema dialects are also unsupported.
Use --operations to import supported operations from a larger document.
Response schemas are not converted or validated. Generated handlers return the
response body as MCP text, including JSON text, and throw a tool error for
non-success HTTP statuses. The MCP request's cancellation signal is forwarded
to fetch.
JSON bodies and headers
A JSON request body becomes the tool's body argument. A parameter already named
body conflicts and is rejected. The importer selects application/json from the
request body's content map. Required properties and body presence are validated;
optional values are sent only when supplied. JSON values retain their types and
Unicode characters. Content-Type: application/json is set only when a body is
sent. GET and DELETE bodies, form data, multipart, and custom encoding overrides
are unsupported.
Object bodies preserve additional properties by default. additionalProperties: false rejects unknown keys; a schema there validates them. Properties listed in
required must be declared in properties. Recursive schemas, unions, nullable
schemas, and unsupported constraints fail during import.
As required by OpenAPI, header parameters named Authorization, Accept, and
Content-Type are ignored. Authentication uses --auth-env, and JSON content type
is set by the generated handler. Transport-controlled Host, Content-Length,
Transfer-Encoding, and Connection parameters are rejected. Invalid header
values produce an error without including the value.
Runtime credentials
--auth-env names an environment variable containing the complete Authorization
header value, including Bearer or Basic when needed. The generated handler
reads it on every call. The credential is never read during generation or exposed
as a tool argument.
Each operation's effective security decides whether its tool uses the credential, so public and authenticated operations can be imported in one command:
- Required (every alternative names a scheme): Authorization is always sent. Missing or empty values fail before the API request.
- Optional (an empty
{}alternative is listed): Authorization is sent only when the variable is set; otherwise the request is anonymous. - Public (no requirement, or
security: []): the tool never reads the variable or sends Authorization.
Incoming MCP client credentials are not forwarded.
Supported security requirements are HTTP basic/bearer and API-key schemes using
the Authorization header. At least one alternative must be supported; requirements
combining multiple schemes are unsupported. Operation-level security overrides
the document, and an empty requirement alternative allows anonymous access.
Other API-key locations, OAuth flows, and other security schemes are unsupported.
The importer does not acquire or refresh credentials.
Review and build the generated files
Every selected operation and destination is checked before files are created.
Existing .ts or .tsx tools cause the command to fail unless --overwrite is
supplied. Preview regenerated files in another directory, or explicitly replace
regular .ts files:
--overwrite replaces the entire generated file, including manual edits. It never
replaces .tsx files, symlinks, or directories. All new contents are staged before
writing destinations, and each replacement is atomic; the full set of replacements
is not a single filesystem transaction.
The OpenAPI import example includes a small spec, generated GET/PUT tools, and a local API demonstrating JSON, headers, and an environment-supplied example credential.
