@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.Options
| Option | Type | Default | Description |
|---|---|---|---|
baseUrl | string | — | Required. Base URL for all requests |
operations | ApiOperation[] | — | Required. Operations to register as tools |
headers | Record<string, string> | () => Record<string, string> | — | Static headers or header factory |
prefix | string | 'api' | Tool name prefix |
client | HttpClient | — | Custom HTTP client (takes precedence over fetch) |
fetch | typeof globalThis.fetch | — | Deprecated. Use client instead |
server | string | — | Target a named server |
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
Headers Factory
Theheaders option can be a factory function that’s called fresh on every request. This is useful for dynamic auth tokens: