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.

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

Headers Factory

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