OpenAPI adapter

Checked against FrontMCP 1.12.2 on

OpenapiAdapter, from @frontmcp/adapters, reads an OpenAPI 3 description of a REST API and gives your app one tool per operation. When the model calls getTicket, the adapter builds the HTTP request the spec describes, sends it with the credentials you configure, and hands back the API's answer. Use it to put an API you already have in front of a model without writing a tool for each endpoint; write tools yourself, with this.fetch(), when the model needs a few well-shaped calls rather than the whole API. For an API too large to list as tools, see Skilled OpenAPI. Wrapping an OpenAPI Service teaches the adapter step by step. The Pet Store from OpenAPI example wraps a whole API and makes it fit for a model.

@App({ adapters: [OpenapiAdapter.init({ name, baseUrl, spec | url, ...options })] })

Reference

OpenapiAdapter.init(options)

Install the package with npm install @frontmcp/adapters and list the result of init() in the adapters of an @App. A plugin can bring adapters too, in its own adapters option, and they add their tools to the app the plugin is on. In @FrontMcp({ adapters }), the adapter's tools are served from every app (Registering an adapter); before 1.9, @FrontMcp ignored adapters.

desk.app.ts
import { App } from "@frontmcp/sdk";
import { OpenapiAdapter } from "@frontmcp/adapters";
import spec from "./desk-openapi.json";

@App({
  id: "desk",
  name: "Desk",
  adapters: [
    OpenapiAdapter.init({
      name: "desk",
      baseUrl: "https://api.desk.example/v1",
      spec,
      staticAuth: { jwt: process.env.DESK_API_TOKEN },
    }),
  ],
})
export class DeskApp {}

It's also the default export of @frontmcp/adapters/openapi. See more examples below.

Options

Required:

OptionTypeDescription
namestringNames this adapter. It must be unique among the OpenapiAdapter.init() calls of the whole process, not only of one server: a second call with the same name throws (see Troubleshooting). It's also the prefix a tool gets when its name clashes with another tool's, and the adapter's logger is adapter:<name>.
baseUrlstringWhere the API is, like https://api.desk.example/v1. Each operation's path is appended to it. It wins over the spec's servers. It must be http: or https:; any other value fails every call with Invalid base URL: ….
spec or urlobject or stringThe OpenAPI 3.0 or 3.1 document: spec as an object (an imported JSON file, or a literal), or url, an http: or https: address to download it from when the server starts. Exactly one. See loading the spec from a URL.

Calling the API:

OptionTypeDefaultDescription
additionalHeadersRecord<string, string>Headers sent with every request. They replace headers of the same name that the adapter built, accept included. A security scheme's header set here counts as that scheme's credential (see how credentials are chosen).
headersMapper(ctx, headers) => HeadersCalled for every request with the request's context (ctx.authInfo, ctx.requestId, ctx.traceContext, …) and the headers built so far. Headers in the Headers object it returns are set on the request. Runs after additionalHeaders, so it can override them. A security scheme's header it sets counts as that scheme's credential.
bodyMapper(ctx, body) => objectCalled with the context and the JSON body, for operations that send one; the body is replaced by what it returns. Not called when the request has no body.
requestTimeoutMsnumber30000Milliseconds a request may take. After that it's aborted and the call fails with Request timeout after …ms for tool '…'.
maxRequestSizenumber10485760 (10 MB)Largest JSON body, in bytes, the adapter sends. A larger one fails the call before anything is sent.
maxResponseSizenumber10485760 (10 MB)Largest response, in bytes, the adapter reads. A larger one fails the call.

Credentials, described in how credentials are chosen:

OptionTypeDescription
staticAuthPartial<SecurityContext>Fixed credentials for every call, like { jwt: process.env.DESK_API_TOKEN }, whoever the caller is. With authProviderMapper, they fill in what its functions don't return.
authProviderMapperRecord<string, (ctx) => string | undefined>One function per security scheme in the spec (components.securitySchemes), returning that scheme's credential for this call, or undefined for none. Every scheme the spec uses must have one, or another source: staticAuth, securitySchemesInInput, a header from additionalHeaders or headersMapper, or passthroughCallerToken for an HTTP bearer scheme. Otherwise the server doesn't start.
securityResolver(tool, ctx) => SecurityContext | Promise<SecurityContext>Returns the credentials for one call to one tool. It wins over the other options.
securitySchemesInInputstring[]Schemes whose credential the model provides, as a required tool argument named after the scheme. The adapter sends it where the scheme says, unless the options above give that scheme a credential, which wins. The other schemes still come from the options above. Rated HIGH risk.
passthroughCallerTokenbooleanDefault false. Send the MCP client's own token (ctx.authInfo.token) to the API as a bearer token, when neither authProviderMapper nor staticAuth gave a credential. It fills HTTP bearer schemes only: an operation secured by an API key still needs its key. Only for an API that accepts the tokens your server accepts. Not used with securityResolver.

Which operations become tools, and how they look:

OptionTypeDescription
generateOptionsOpenApiGenerateOptionsWhich operations to include, how to name them, and how schemas are built. See generateOptions.
descriptionMode"summaryOnly" | "descriptionOnly" | "combined" | "full"How a tool's description is made from the operation. Default "summaryOnly". See how operations become tools.
toolTransforms{ global?, perTool?, generator? }Rename a tool, change its description, add annotations, tags or examples, or hide it from tools/list. See toolTransforms.
inputTransforms{ global?, perTool?, generator? }Remove arguments from a tool's input and fill them in on the server. See inputTransforms.
schemaTransforms{ input?, output? }Functions that return a new input or output JSON Schema for a tool. See schemaTransforms.
outputSchema{ mode?, descriptionFormat?, descriptionFormatter? }Keep the response schema as the tool's outputSchema, move it into the description, or both. See outputSchema.
dataTransforms{ preToolTransforms?, postToolTransforms? }Change output schemas and descriptions when tools are built, and the API's data before the model gets it. See dataTransforms.

Loading and watching the spec:

OptionTypeDescription
loadOptionsLoadOptionsHow the spec is loaded and checked. See loadOptions.
pollingSpecPollerOptions & { enabled: boolean }Fetch url again every so often and rebuild the tools when the spec changes. Only with url. See polling.
loggerFrontMcpLoggerA logger for the adapter. Inside a server FrontMCP replaces it with its own, adapter:<name>, before the tools are built.

generateOptions

The adapter passes these fields on to the generator (mcp-from-openapi) that turns operations into tools:

FieldTypeDefaultDescription
includeOperationsstring[]Only these operationIds. Operations without an operationId are left out too.
excludeOperationsstring[]Leave these operationIds out.
filterFn(op) => booleanCalled for each operation, with the operation object plus its path and method (lowercase). Return false to leave it out.
namingStrategy.toolNameGenerator(path, method, operationId?, operation?) => stringoperationId, else <method>_<path>Names each tool.
namingStrategy.conflictResolver(name, location, index) => stringthe location in front: pathId, queryId, bodyIdRenames an input whose name is used in two places, like a path id and a query id.
includeDeprecatedbooleanfalseAlso turn operations marked deprecated: true into tools.
preferredStatusCodesnumber[][200, 201, 202, 204]Which response's schema describes success, in order of preference.
includeAllResponsesbooleantrueDescribe every documented response in the output schema (an anyOf), not only the preferred one.
includeSecurityInInputboolean | string[]falseAdd each security scheme (or the ones listed) to the tool's input, as a required string argument named after the scheme, so the model supplies credentials. They're sent like securitySchemesInInput's, and a list means the same as securitySchemesInInput: every scheme it leaves out needs another credential source, or the server doesn't start. (Before 1.8.5, a list's values were never sent.) The adapter logs a SECURITY WARNING and rates the setup HIGH risk.
maxSchemaDepthnumber10Nesting kept in input and output schemas; deeper levels are cut, with a note in the description.
includeExamplesbooleanfalseCopy parameter and media-type example/examples into the schemas.
resolveFormatsbooleanfalseTurn formats into constraints: format: "uuid" gets a pattern and the description UUID string (RFC 4122), int32 a minimum and maximum, email the description Email address (RFC 5322), and so on.
formatResolversRecord<string, (schema) => schema>Your own formats, like phone, or replacements for the built-in ones. Without resolveFormats, only these apply.

OpenApiGenerateOptions, exported by @frontmcp/adapters, is mcp-from-openapi's GenerateOptions, which has more fields, with method filters that take any case. The adapter passes every field on. These select operations, as Choosing which operations become tools shows:

FieldTypeKeeps
includeTags, excludeTagsstring[]Operations with at least one of these tags; or leaves out those with any of them.
includeMethods, excludeMethodsOpenApiHttpMethod[]Operations with these methods, or without them, in any case: "delete", "DELETE" or "Delete". A name that isn't an HTTP method makes init() throw. Before 1.9.3 the type took lower case only, so ["DELETE"] was a type error (TS2820), though it matched at run time.
includePaths, excludePathsstring[]Operations whose path matches one of these globs, or none of them. * matches within one segment and ** across segments: "/tickets" is that path only, "/tickets/*" is /tickets/{id}, and "/admin/**" is everything under /admin.
readOnlyOnlybooleanOnly operations that only read, as the generator judges from the method, like GET, unless the spec's x-frontmcp annotations say otherwise.

Three add to what tools/list shows, as how operations become tools describes:

FieldTypeDefaultDescription
inferAnnotationsbooleantrueGive each tool annotations guessed from its HTTP method. false leaves annotations to x-frontmcp and toolTransforms.
emitMetabooleanfalseAdd _meta["dev.agentfront.openapi/operation"], the operation's path, method, operationId, specTitle and specVersion, to each tool.
inheritDocumentIconsbooleanfalseGive tools without icons of their own the spec's info["x-logo"] as their icon.

The others, descriptionStrategy, appendResponseSummary, maxProperties, maxDescriptionLength, stripExamples, target, maxToolNameLength and emitTypeSignatures, change how tools are built: see mcp-from-openapi's documentation.

Changed in 1.9: the adapter passed on only the fields in the first table, so the others were accepted and had no effect. Changed in 1.9.2: the annotations, title, icons and _meta the generator makes reach the tool, so every tool now lists inferred annotations and its summary as its title.

loadOptions

FieldTypeDefaultDescription
validatebooleantrueCheck the document before building tools. An invalid one stops the server: Invalid OpenAPI document.
dereferencebooleantrueResolve $refs.
refResolution{ allowedProtocols?, allowedHosts?, blockedHosts?, allowInternalIPs? }{ allowedProtocols: [] }Which $refs outside the document may be fetched, and which hosts a url may be loaded from. See below.
headersRecord<string, string>Headers for fetching url, like a token for a private spec. With redirects enabled, they are dropped for every remaining hop once a redirect leaves the original origin (scheme, host or port). Only with url.
timeoutnumber30000Milliseconds to fetch url. Only with url.
followRedirectsbooleanfalseFollow redirects when fetching url, checking each hop like the first. Only with url.

References inside the document (#/components/...) are always resolved. A $ref to another file or URL isn't fetched by default: FrontMCP sets allowedProtocols to [], and the $ref stays in the tool's schema unresolved. Set refResolution to allow some: allowedProtocols: ["https"] with allowedHosts: ["schemas.desk.example"], say. Addresses on private networks, loopback and cloud metadata endpoints are refused unless allowInternalIPs: true, for $refs and for url alike.

allowedHosts and blockedHosts compare host names without regard to case or trailing dots, in both the URL and the list entries.

Changed in 1.10.7: before, spec-URL headers followed redirects to other origins, and host lists compared case and trailing dots literally.

LoadOptions has two more fields, and the adapter passes on every field. overlays takes one OpenAPI Overlay document or a list of them, applied in order before the spec is checked: a way to rewrite summaries, or add x-frontmcp, in a file of your own that survives the next version of the spec (see Naming and describing the tools). secureDefaults: true turns off redirects and external $refs, which the adapter already does by default.

toolTransforms

global applies to every tool, perTool to the tool with that name (the name before any rename), and generator is called with each tool and returns a transform or undefined. For one tool, perTool and generator override global's name, description, hideFromDiscovery and ui; annotations are merged, and tags and examples are added together.

FieldTypeDescription
namestring | (name, tool) => stringThe tool's new name.
descriptionstring | (description, tool) => stringThe tool's new description. The function gets the current one.
annotationsToolAnnotationsreadOnlyHint, destructiveHint, idempotentHint, openWorldHint, title: merged over the annotations inferred from the method and those the spec's x-frontmcp set.
hideFromDiscoverybooleanLeave the tool out of tools/list. It can still be called by name.
tags, examples, uiAs the @Tool options of the same names.

A transform's tool argument is the generated tool: tool.name, tool.description, tool.inputSchema, and tool.metadata, with method (lowercase), path, operationId, operationSummary, operationDescription and tags.

inputTransforms

global is a list for every tool, perTool maps a tool name to a list, and generator returns a list for a tool. Each entry is { inputKey, inject }:

  • inputKey is removed from the tool's input schema (and from required), so the model never sees it.
  • inject({ ctx, env, tool }) runs on every call, with the request's context, process.env and the tool, and its result becomes that argument. A value the model sends for the argument anyway is dropped before the argument check, and the injected one is sent. (In 1.9.2 such a call was refused with Unrecognized key.) Returning undefined leaves the argument out, which fails the call for a parameter the spec requires (see Troubleshooting). It may be async, and must answer within 5 seconds or the call fails with Input transform for '…' failed: Transform timeout after 5000ms.
  • __proto__, constructor and prototype aren't allowed as inputKey: the server doesn't start.

schemaTransforms

input and output each take global, perTool and generator: functions (schema, { tool, adapterOptions }) => schema that return the tool's new input or output JSON Schema. For one tool only one applies: generator's, else perTool's, else global's. An output function may return undefined to drop the output schema. The schema you return is what clients see; arguments are still sent as the spec describes.

outputSchema

FieldTypeDefaultDescription
mode"definition" | "description" | "both""definition"Where the response schema goes: the tool's outputSchema, the end of its description (and no outputSchema), or both.
descriptionFormat"summary" | "jsonSchema""summary"In the description: a ## Returns list of fields with their types, or an ## Output Schema block with the JSON Schema.
descriptionFormatter(schema, { tool, adapterOptions, originalDescription }) => string | Promise<string>Your own text, appended to the description instead.

The schema in the description is the API's response body; the tool's outputSchema, when there is one, is the result envelope around it.

dataTransforms

  • preToolTransforms (global, perTool, generator) runs when tools are built: transformSchema(outputSchema, ctx) returns a new output schema, or undefined to drop it, and transformDescription(description, outputSchema, ctx) returns a new description.
  • postToolTransforms (global, perTool, generator) runs on every call: transform(data, ctx) returns what the model gets as data, and an optional filter(ctx) returning false skips it. ctx has status, ok, tool, ctx (the request context) and adapterOptions. For one tool only one transform runs: generator's, else perTool's, else global's. If transform throws, the error is logged and the model gets the data unchanged.

polling

Only with url: polling with spec throws Polling requires URL-based options (use 'url' instead of 'spec'). The fields are those of OpenApiSpecPoller plus enabled: true. See picking up spec changes.

Returns

A record for adapters, not the adapter: { ...options, provide: Symbol.for("adapter:OpenapiAdapter:<name>"), useValue: <the OpenapiAdapter> }. init() constructs the adapter at once, when your module is imported. The spec is read, and the tools built, when the server starts. To call the adapter's own methods, like stopPolling(), use record.useValue.

How operations become tools

From the spec
NameThe operationId. Without one: the method and path, like get_stats for GET /stats or post_tickets_By_id_comments for POST /tickets/{id}/comments.
TitleThe operation's summary. An operation without one has no title.
DescriptiondescriptionMode: summaryOnly (the default) uses summary, else description, else METHOD path; descriptionOnly prefers description; combined is summary, a blank line, then description; full adds Operation: <operationId> and METHOD path.
Input schemaOne object, with a property for each path, query, header and cookie parameter and each property of the JSON request body. Each property keeps its schema, with an x-parameter-location saying where it goes. Header parameters also get x-mcp-header (see header parameters). required lists the required parameters and body properties, and additionalProperties is false.
Output schema{ status, ok, data, error }, with status and ok required and data being the success response's schema, or an anyOf of every documented response, since an answer can fit more than one. A 2xx response the spec describes with a description only, or a media type with no schema, accepts any answer: its data has no type. A 204, a 205 and a HEAD operation are described as data: { type: "null" }. Changed in 1.11.1: before, a description-only response was listed as data: { type: "null" }, which the API's answer didn't match, and the union was a oneOf.
AnnotationsAll four hints, guessed from the method (inferAnnotations): GET is readOnlyHint and idempotentHint; PUT and DELETE are destructiveHint and idempotentHint; POST and PATCH are destructiveHint. openWorldHint is false. The spec's x-frontmcp, then toolTransforms, are merged over them.
IconsThe operation's x-frontmcp.icons, a list of { src, mimeType?, sizes? }. With inheritDocumentIcons, the spec's info["x-logo"] for the others.
_metaThe operation's x-frontmcp.meta. With emitMeta, also "dev.agentfront.openapi/operation": { path, method, operationId, specTitle, specVersion }.
Left outOperations marked deprecated (see includeDeprecated) and those your generateOptions filter out.

Two operations that end up with the same name stop the server: Tool name collision: "…" produced by 2 operations: …. When an adapter's tool has the same name as a tool from another adapter or app, FrontMCP lists both with their owner's name in front: desk:getStatus and billing:getStatus, or <app id>:getStatus for the app's own tool.

The x-frontmcp extension

An operation in the spec can carry an x-frontmcp object, which the adapter copies onto the tool:

FieldBecomes
annotationsThe tool's annotations: title,