Skip to main content
Expose a greet tool at /api/mcp in your existing TanStack Start app. TanStack Start serves your application and the MCP endpoint together.

Prerequisites

  • A working TanStack Start app using React, Vite 8, and TypeScript. Upgrade apps on older Vite majors before installing mcp-use, which requires Vite ^8.0.0.
  • Node.js 22.22.2 or later. This recipe configures Nitro for a Node.js server deployment.

Add the integration

Install the canary release of mcp-use, which includes the TanStack Start adapter, and Zod in your project:
If your app does not already use Nitro 3, install the version used by the example for the Node.js server build:
Keep the MCP server and its handler in src/mcp. Add a catch-all server route inside your existing src/routes directory:

Define the server

Create src/mcp/server.ts. Register a tool that accepts a name and returns a greeting:
src/mcp/server.ts
TanStack Start owns the HTTP listener, so do not call server.listen(). Configure CORS on MCPServer to allow browser clients such as the Inspector to connect.

Configure the adapter

Add mcpUseTanStackStart before the Start and React plugins in your existing Vite configuration. Keep your application’s other options and plugins:
vite.config.ts
The plugin’s basePath must match the one on MCPServer.

Mount the endpoint

Create the handler in src/mcp/handler.server.ts. The Vite plugin loads the authored server in its dedicated MCP environment, so this route module does not import server.ts:
src/mcp/handler.server.ts
Create a catch-all server route at src/routes/api.mcp.$.ts. Forward all HTTP methods to the handler so it can serve the MCP endpoint and nested asset paths:
src/routes/api.mcp.$.ts

Try it

Start your TanStack Start app with its usual command:
In a second terminal, open the Inspector connected to your new endpoint:
Select Tools → greet and enter:
Run the tool. It returns Hello, Ada!. Use your app’s port if it differs from 3000. MCP views share the application’s browser environment for React Fast Refresh and CSS HMR. Server edits replace the MCP instance and interrupt active requests; failed edits retain the last working instance. View registrations and skills refresh without restarting Vite. Configure React, CSS and aliases in the main Vite config. See the complete TanStack Start example for a runnable application with a shared UI card, an OAuth discovery route, and production build instructions.