mcp-server-skills by gocallum/nextjs16-agent-skills
npx skills add https://github.com/gocallum/nextjs16-agent-skills --skill mcp-server-skillsapp/
api/[transport]/route.ts # 所有传输协议的统一处理器 (例如 /api/mcp)
actions/mcp-actions.ts # 复用相同逻辑/模式的服务器操作
lib/
dice.ts | tools.ts # Zod 模式、工具定义、纯逻辑
components/ # 用于 Web 测试、调用服务器操作的 UI
目标: 保持 route.ts 简洁。将逻辑和 Zod 模式放在 lib/* 中,这样 MCP 处理器和服务器操作就能共享单一数据源。
// 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}!` };
}
export const rollDiceTool = {
name: "roll_dice",
description: "Rolls an N-sided die",
schema: { sides: diceSchema },
} as const;
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// app/actions/mcp-actions.ts
"use server";
import { rollDice as rollDiceCore, rollDiceTool } from "@/lib/dice";
export async function rollDice(sides: number) {
try {
const result = rollDiceCore(sides);
return { success: true, result: { content: [result] } };
} catch {
return {
success: false,
error: { code: -32602, message: "Invalid parameters: sides must be >= 2" },
};
}
}
export async function listTools() {
return {
success: true,
result: {
tools: [
{
name: rollDiceTool.name,
description: rollDiceTool.description,
inputSchema: {
type: "object",
properties: { sides: { type: "number", minimum: 2 } },
required: ["sides"],
},
},
],
},
};
}
服务器操作调用与 MCP 处理器相同的逻辑,并为 Web UI 提供支持,确保响应格式一致。
// app/api/[transport]/route.ts
import { createMcpHandler } from "mcp-handler";
import { rollDice, rollDiceTool } from "@/lib/dice";
const handler = createMcpHandler(
(server) => {
server.tool(
rollDiceTool.name,
rollDiceTool.description,
rollDiceTool.schema,
async ({ sides }) => ({ content: [rollDice(sides)] }),
);
},
{}, // 服务器选项
{
basePath: "/api", // 必须与文件夹路径匹配
maxDuration: 60,
verboseLogs: true,
},
);
export { handler as GET, handler as POST };
模式亮点
createMcpHandler;不内联业务逻辑。server.tool 使用共享的工具模式/描述并调用共享逻辑。basePath 应与文件夹路径对齐 (例如 /api/[transport])。{
"mcpServers": {
"rolldice": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://localhost:3000/api/mcp"]
}
}
}
lib/* 中;MCP 工具和服务器操作都导入它们。{ success, result | error } 结构。maxDuration 和 runtime。/api/[transport];需要时添加 stdio 入口点。每周安装数
171
代码仓库
GitHub 星标数
18
首次出现
2026年1月20日
安全审计
安装于
gemini-cli129
codex128
opencode127
github-copilot120
cursor112
claude-code93
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.
// 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}!` };
}
export const rollDiceTool = {
name: "roll_dice",
description: "Rolls an N-sided die",
schema: { sides: diceSchema },
} as const;
// app/actions/mcp-actions.ts
"use server";
import { rollDice as rollDiceCore, rollDiceTool } from "@/lib/dice";
export async function rollDice(sides: number) {
try {
const result = rollDiceCore(sides);
return { success: true, result: { content: [result] } };
} catch {
return {
success: false,
error: { code: -32602, message: "Invalid parameters: sides must be >= 2" },
};
}
}
export async function listTools() {
return {
success: true,
result: {
tools: [
{
name: rollDiceTool.name,
description: rollDiceTool.description,
inputSchema: {
type: "object",
properties: { sides: { type: "number", minimum: 2 } },
required: ["sides"],
},
},
],
},
};
}
Server actions call the same logic as the MCP handler and power the web UI, keeping responses aligned.
// app/api/[transport]/route.ts
import { createMcpHandler } from "mcp-handler";
import { rollDice, rollDiceTool } from "@/lib/dice";
const handler = createMcpHandler(
(server) => {
server.tool(
rollDiceTool.name,
rollDiceTool.description,
rollDiceTool.schema,
async ({ sides }) => ({ content: [rollDice(sides)] }),
);
},
{}, // server options
{
basePath: "/api", // must match folder path
maxDuration: 60,
verboseLogs: true,
},
);
export { handler as GET, handler as POST };
Pattern highlights
createMcpHandler; no business logic inline.server.tool consumes the shared tool schema/description and calls shared logic.basePath should align with the folder (e.g., /api/[transport]).{
"mcpServers": {
"rolldice": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://localhost:3000/api/mcp"]
}
}
}
lib/*; both MCP tools and server actions import them.{ success, result | error } shapes for tools and UI.maxDuration and runtime if needed./api/[transport] for HTTP/SSE; add stdio entrypoint when required.Weekly Installs
171
Repository
GitHub Stars
18
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli129
codex128
opencode127
github-copilot120
cursor112
claude-code93
AI 代码实施计划编写技能 | 自动化开发任务分解与 TDD 流程规划工具
50,900 周安装
Solidity智能合约审计员 | 专业安全漏洞检测与Gas优化审计工具
111 周安装
高级 DevOps 工程师工具包 | 生产级 CI/CD、Kubernetes、Terraform、云架构与可观测性
111 周安装
Star Office UI:开源像素办公室看板,AI助手状态可视化与团队协作仪表盘
110 周安装
规范驱动开发 (Spec-Driven Development) - n8n 开发流程与代码规范一致性指南
71 周安装
DBOS TypeScript 最佳实践:构建可靠、容错的持久化工作流应用指南
112 周安装
功能优先创意改编指南:从DNA提取到正交合成,避免表面翻译陷阱
116 周安装