关于 next-devtools-guide
next-devtools-guide 是使用 Next.js DevTools MCP 检查和操作 Next.js 应用的技能,涵盖运行时诊断、浏览器自动化、文档查询及 Next.js 16 迁移指导。
主要功能
- 01发现运行中的 Next.js 开发服务器
- 02调用已发现服务器上的工具
- 03获取 Next.js 官方文档
- 04使用 Playwright 自动化浏览器测试
- 05指导 Next.js 16 升级与缓存配置
适用场景
- 01检查路由和运行时错误
- 02追踪 Server Actions
- 03查询 Next.js API 与文档
- 04迁移到 Next.js 16 Cache Components
MCP 相关
该技能指导客户端初始化 Next.js DevTools MCP 上下文、发现运行中的开发服务器并调用其工具。它还介绍了用于文档和 Cache Components 指引的 MCP 提示词与资源。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ fradser/ dotclaude --skill next-devtools-guide安装后在 Claude Code 中输入/next-devtools-guide确认已加载。
附带文件references/tools-reference.md
详细介绍
Next.js DevTools MCP
要求:Node.js v20.19+、npm 或 pnpm;运行时诊断需要 Next.js 16+。
功能总数:7 个工具 + 2 个提示词 + 17 个资源 = 26 项可用功能。
工具命名:所有工具均遵循 mcp__plugin_next-devtools_next-devtools__<tool-name>。为简洁起见,本文使用缩写名称。
完整工具表和 nextjs_call 工具名称,请参阅 references/tools-reference.md。
工具(7 个)
| 工具 | 用途 |
|---|---|
init | 使用文档优先行为初始化 MCP 上下文 |
nextjs_index | 发现正在运行的 Next.js 开发服务和可用的 MCP 工具 |
nextjs_call | 在正在运行的 Next.js 开发服务上调用指定的 MCP 工具 |
nextjs_docs | 按路径获取 Next.js 官方文档 |
browser_eval | 用于测试的 Playwright 浏览器自动化 |
enable_cache_components | 迁移到 Next.js 16 Cache Components 模式 |
upgrade_nextjs_16 | 指引升级到 Next.js 16 |
提示词(2 个)
| 提示词 | 用途 |
|---|---|
upgrade-nextjs-16 | 完整升级指南,包括执行 codemod 和手动修复 |
enable-cache-components | 完整的 Cache Components 设置流程,包含自动错误修复 |
资源(17 个)
Cache Components(13 个):
cache-components://overview- AI Agent 常犯的关键错误,快速参考cache-components://core-mechanics- 基本范式转变和 cacheComponents 行为cache-components://public-caches- 使用 'use cache' 的公共缓存机制cache-components://private-caches- 使用 'use cache: private' 的私有缓存机制cache-components://runtime-prefetching- 预取配置和过期时间规则cache-components://request-apis- 异步 params、searchParams、cookies()、headers() 模式cache-components://cache-invalidation- updateTag()、revalidateTag() 模式和策略cache-components://advanced-patterns- cacheLife()、cacheTag()、草稿模式cache-components://build-behavior- 预渲染、静态外壳、构建时行为cache-components://error-patterns- 常见错误和解决方案cache-components://test-patterns- 来自 125+ 个 fixture 的真实测试驱动模式cache-components://reference- 思维模型、API 参考、检查清单cache-components://route-handlers- 在 Route Handlers(API Routes)中使用 'use cache'
其他(4 个):
nextjs-fundamentals://use-client- 了解何时以及为何在 Server Components 中使用 'use client'nextjs16://migration/beta-to-stable- 从 Next.js 16 beta 迁移到稳定版的完整指南nextjs16://migration/examples- 迁移到 Next.js 16 的真实示例nextjs-docs://llms-index- 完整的 Next.js 文档索引
会话初始化
每次会话开始时都调用 init,以启用文档优先行为并获取工具使用指南。
快速开始
Next.js 16+(运行时诊断):
- 启动开发服务:
npm run dev(或pnpm dev) - 调用
init初始化 MCP 上下文 - 调用
nextjs_index发现正在运行的服务和可用工具 - 使用所需的
toolName调用nextjs_call,在开发服务上执行工具
所有 Next.js 版本(自动化和文档):
调用 init 后,根据需要使用 upgrade_nextjs_16、enable_cache_components、nextjs_docs 或 browser_eval。
常见工作流
实现更改前:调用 nextjs_index 了解当前应用状态,然后使用相应工具调用 nextjs_call。
错误检测:调用 nextjs_index,然后使用 toolName="get_errors" 调用 nextjs_call。
路由检查:调用 nextjs_index,然后使用 toolName="get_routes" 调用 nextjs_call。
Server Action 跟踪:使用 toolName="get_server_action_by_id" 和相应参数调用 nextjs_call。
文档搜索:读取 nextjs-docs://llms-index MCP 资源以获取正确路径,然后使用该路径调用 nextjs_docs。
重要:nextjs_call 的 args 参数必须是一个对象。如果工具不需要参数,请完全省略 args。
故障排除
MCP 服务无法连接:
- 确认使用的是 Next.js v16+
- 确认已在
.mcp.json中配置next-devtools-mcp - 启动或重启开发服务器(
npm run dev) - 如果
nextjs_index自动发现失败,请询问用户开发服务器运行在哪个端口,并将其作为port参数传入
“未找到服务器信息”:开发服务器必须正在运行。如果使用的是 Next.js 15 或更早版本,请使用 upgrade_nextjs_16 工具。
找不到模块:清除 npx 缓存并重启 MCP 客户端。
最佳实践
- 在会话开始时先调用
init,再使用其他工具 - 使用
nextjs_index或nextjs_call前先启动开发服务器 - 对于错误检测和诊断,优先使用
nextjs_index或nextjs_call,而不是browser_eval - 仅在任务需要实际页面渲染或执行 JavaScript 时使用
browser_eval - 调用
nextjs_docs前,先读取nextjs-docs://llms-index资源