@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.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:
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
TheHttpClient interface lets you inject any HTTP library. Implement a single request method:
Axios Example
Custom Client with Token Refresh
Backward Compatibility
Thefetch 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 plainfetch function into the HttpClient interface:
HttpClient interface but still use fetch under the hood.
parseOpenApiSpec
ExtractsApiOperation[] 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 thestyle/explodeit declares, souseApiClientsends query and header parameters as the spec lays them out (cookie parameters are not sent)
Headers Factory
Theheaders option can be a factory function that’s called fresh on every request. This is useful for dynamic auth tokens: