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
- Add the server as a route. The
validatefunction decides which tokens are allowed, and any other token gets401:app/api/mcp/route.tsimport { createMCPServer } from "veryfront/mcp"; const server = createMCPServer({ enabled: true, auth: { type: "bearer", validate: (token) => token === process.env.MCP_TOKEN },}); export const POST = server.createHTTPHandler(); - 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"] } },}; - Start the project with a secret of your own as the token:
MCP_TOKEN=<a secret> npm run dev. - Ask for the tool list. You should now see
calculatorinresult.tools:Shellcurl -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
Create a project
Add the server as a route
Let MCP clients post to it
Pick a secret as the token
Start it
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.