Skip to main content
The @frontmcp/react/router entry point bridges React Router v7 with MCP. AI agents can navigate your app, go back in history, and read the current route — all through standard MCP tools and resources.
react-router-dom is an optional peer dependency. Only install it if you use the router integration.

Setup

1. Install React Router

2. Wire the Bridge

Call useRouterBridge() inside your React Router tree:
src/App.tsx

3. Register Router Entries

Add the router tools and resources to your MCP server:
src/server.ts

useRouterBridge

Wires React Router’s navigate and location into a module-scoped bridge singleton.
Must be called inside a React Router tree (<BrowserRouter>, <MemoryRouter>, etc.). It:
  • Captures useNavigate() and syncs it to the bridge on mount
  • Updates the bridge location on every route change
  • Clears the bridge on unmount

MCP tool that navigates to a URL path.

Input Schema

Example

Returns: "Navigated to /dashboard"

GoBackTool

MCP tool that navigates back in browser history. Takes no input parameters.

CurrentRouteResource

MCP resource that reads the current URL/path/params.

Response


createRouterEntries

Factory that returns tool and resource entries for easy spreading into create() config:

Bridge Functions

Low-level bridge functions for advanced use cases:
If the bridge is not connected (e.g., useRouterBridge() not called), NavigateTool and GoBackTool return an error message instead of navigating. CurrentRouteResource returns an error JSON object.