This is a clean architecture pattern for building MCP servers in Next.js that keeps your route handlers thin and your logic reusable. The core idea is smart: define your tools once with Zod schemas in lib files, then share that exact code between your MCP endpoints and Next.js server actions. That means your web UI for testing and your actual MCP tools stay in sync automatically. It uses mcp-handler for HTTP transport, works with mcp-remote for Claude Desktop, and the folder structure is straightforward App Router stuff. If you're shipping MCP tools on Vercel or want a proper web interface alongside your AI integrations, this gives you a solid starting point without the usual duplication headaches.

skills.sh installs
387
GitHub stars
23
last updated
Aug 21, 2026

Install

$ npx -y skills add gocallum/nextjs16-agent-skills --skill mcp-server-skills --agent claude-code

Installs into .claude/skills of the current project.

Files

Links

Folder Structure (Next.js App Router)

app/
  api/[transport]/route.ts   # One handler for all transports (e.g., /api/mcp)
  actions/mcp-actions.ts     # Server actions reusing the same logic/schemas
lib/
  dice.ts | tools.ts         # Zod schemas, tool definitions, pure logic
components/                  # UI that calls server actions for web testing

Goal: Keep route.ts minimal. Put logic + Zod schemas in lib/* so both the MCP handler and server actions share a single source of truth.

Shared Zod Schema + Tool Definition

// lib/dice.ts
import { z } from "zod";

export const diceSchema = z.number().int().min(2);

export function rollDice(sides: number) {
  const validated = diceSchema.parse(sides);
  const value = 1 + Math.floor(Math.random() * validated);
  return { type: "text" as const, text: `🎲 You rolled a ${value}!` };
}

Sponsors

Details

Repository
github.com/gocallum/nextjs16-agent-skills
Categories
Frontend Development, Backend & APIs, AI & Agent Building
First seen
Jun 3, 2026

More from gocallum/nextjs16-agent-skills

All 9
1levnikolaevich avatarln-742-precommit-setuplevnikolaevich/claude-code-skillsConfigures Husky, lint-staged, commitlint, and Python pre-commit hooks. Use when adding Git hook automation to a project.385skills.sh installs
2davila7 avatartheme-factorydavila7/claude-code-templatesToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fo384skills.sh installs
3secondsky avatarwoocommerce-backend-devsecondsky/claude-skillsAdd or modify WooCommerce backend PHP code following project conventions. Use when creating new classes, methods, hooks, or modifying existing backend code in W379skills.sh installs
4levnikolaevich avatarln-646-project-structure-auditorlevnikolaevich/claude-code-skillsAudits physical architecture structure: modules, domains, layer layout, junk drawers, and framework placement. Use for structure drift.376skills.sh installs
5grasmash avatardrupal-at-your-fingertipsgrasmash/drupal-claude-skillsComprehensive Drupal patterns from "Drupal at Your Fingertips" by Selwyn Polit. Covers 50+ topics including services, hooks, forms, entities, caching, testing, 375skills.sh installs
6umbraco avatarumbraco-unit-testingumbraco/umbraco-cms-backoffice-skillsUnit and component testing for Umbraco backoffice extensions using @open-wc/testing374skills.sh installs