Serve over MCP

Expose your project's tools, prompts and resources to any MCP client with createMCPServer. Here it serves the AI Agent template's calculator tool.

Before you start

You need a project made from the AI Agent template. See Build your first agent.

Serve your tools

  1. Add the server as a route. The validate function decides which tokens are allowed, and any other token gets 401:
    app/api/mcp/route.ts
    import { createMCPServer } from "veryfront/mcp"; const server = createMCPServer({  enabled: true,  auth: { type: "bearer", validate: (token) => token === process.env.MCP_TOKEN },}); export const POST = server.createHTTPHandler();
  2. Let MCP clients post to it. Veryfront refuses a POST that has no CSRF cookie, which a client never has:
    veryfront.config.ts
    export default {  security: { csrf: { excludePaths: ["/api/mcp"] } },};
  3. Start the project with a secret of your own as the token: MCP_TOKEN=<a secret> npm run dev.
  4. Ask for the tool list. You should now see calculator in result.tools:
    Shell
    curl -X POST http://localhost:3000/api/mcp \  -H "Content-Type: application/json" \  -H "Accept: application/json, text/event-stream" \  -H "Authorization: Bearer $MCP_TOKEN" \  -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/list" }'

Try it in a sandbox

  1. Create a project

  2. Add the server as a route

  3. Let MCP clients post to it

  4. Pick a secret as the token

  5. Start it

  6. Check it

Try it out

Dev tools for a coding agent

veryfront dev also serves Veryfront's dev tools (vf_*, such as vf_scaffold) at http://localhost:3002/mcp, for a coding agent working on the project. They never run in production.

Troubleshooting

If curl answers "Forbidden: invalid or missing CSRF token", the route still checks CSRF. Add step 2's veryfront.config.ts and start the project again.

Next steps