Skip to main content
@frontmcp/react/api turns OpenAPI operations into MCP tools that agents can call. It supports any HTTP client — fetch, axios, ky, or a custom wrapper with token refresh and interceptors.

useApiClient

Registers each API operation as an MCP tool. Tools are registered on mount and cleaned up on unmount.
Query parameters and header parameters are sent from the operation’s parameters: an argument declared in: 'query' goes into the query string and one declared in: 'header' becomes a request header. Arrays and objects follow the parameter’s OpenAPI style and explode: a query argument defaults to form (an array repeats the key, an object sends each property as its own parameter) and may set style to spaceDelimited, pipeDelimited or deepObject (filter[owner]=ada); a header argument is comma-separated (x,y, or a=1,b=2 with explode: true). {param} placeholders in path are filled from the arguments and body is the request body. parseOpenApiSpec fills parameters from the spec; a hand-written operation lists them itself:
The options may be written inline: the tools are registered again only when prefix, server, or what an operation declares (id, description, method, path, input schema, parameters) changes. baseUrl, headers, client and fetch are read when a tool runs.

Options

Tool Naming

Each operation becomes a tool named {prefix}_{operationId}. For example, with prefix 'api' and operationId 'getUser', the tool name is api_getUser.

HttpClient Interface

The HttpClient interface lets you inject any HTTP library. Implement a single request method:

Axios Example

Custom Client with Token Refresh

Backward Compatibility

The fetch option still works but is deprecated. When provided without client, it’s internally wrapped into an HttpClient. If both are provided, client takes precedence.

createFetchClient

A convenience factory that wraps a plain fetch function into the HttpClient interface:
Useful when you want the generic HttpClient interface but still use fetch under the hood.

parseOpenApiSpec

Extracts ApiOperation[] from an OpenAPI 3.x JSON spec. Handles parameters, request bodies, and generates operation IDs when missing.

What Gets Extracted

  • operationId: From spec or auto-generated from {method}_{path}
  • description: From summary, description, or {METHOD} {path}
  • method: HTTP method (uppercase)
  • path: URL path with {param} placeholders
  • inputSchema: JSON Schema built from parameters + requestBody
  • parameters: where each parameter goes (path, query, header, cookie) and the style / explode it declares, so useApiClient sends query and header parameters as the spec lays them out (cookie parameters are not sent)

Headers Factory

The headers option can be a factory function that’s called fresh on every request. This is useful for dynamic auth tokens: