Context7 扩展
Watch the demo
本教程介绍如何将 Context7 MCP 服务器 添加为 goose 扩展,以拉取最新的、针对特定版本的代码和文档,让 goose 能基于真实上下文来写代码,而不是幻觉或过时的答案。
- goose Desktop
- goose CLI
命令
npx -y @upstash/context7-mcp
配置
运行此命令需要在系统上安装 Node.js,因为它使用 npx。
- goose Desktop
- goose CLI
- Launch the installer
- Click
Yesto confirm the installation - Click the button in the top-left to open the sidebar
- Navigate to the chat
- Run the
configurecommand:
goose configure
- Choose to add a
Command-line Extension.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◆ What type of extension would you like to add?
│ ○ Built-in Extension
│ ● Command-line Extension (Run a local command or script)
│ ○ Remote Extension (Streamable HTTP)
└
- Give your extension a name.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◆ What would you like to call this extension?
│ Context7
└
- Enter the command to run when this extension is used.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Context7
│
◆ What command should be run?
│ npx -y @upstash/context7-mcp
└
- Enter the number of seconds goose should wait for actions to complete before timing out. Default is
300seconds.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Context7
│
◇ What command should be run?
│ npx -y @upstash/context7-mcp
│
◆ Please set the timeout for this tool (in secs):
│ 300
└
- Enter a description for this extension.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Context7
│
◇ What command should be run?
│ npx -y @upstash/context7-mcp
│
◇ Please set the timeout for this tool (in secs):
│ 300
│
◆ Enter a description for this extension:
│ 提供最新代码和文档的 Context7 MCP 服务器
└
- Choose
Nowhen asked to add environment variables.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Context7
│
◇ What command should be run?
│ npx -y @upstash/context7-mcp
│
◇ Please set the timeout for this tool (in secs):
│ 300
│
◇ Enter a description for this extension:
│ 提供最新代码和文档的 Context7 MCP 服务器
│
◆ Would you like to add environment variables?
│ No
│
└ Added Context7 extension
使用示例
在这个示例中,goose 使用 Context7 拉取实时文档、比较工具,并仅用最新的官方实现模式搭建一个现代应用。
- goose Desktop
- goose CLI
- 在 goose Desktop 中打开一个新会话
- 打开终端并启动一个新的 goose 会话:
goose session
goose 提示词
我需要帮助搭建一个现代 Web 应用。你能:
- 使用 Context7 分析并比较:
- Next.js App Router 与 Pages Router
- Prisma 与其他 ORM
- 不同的身份验证方案
- 状态管理方案
- 对每项选定的技术:
- 展示最新的官方实现模式
- 提供类型定义和接口
- 分享文档中的相关代码片段
- 解释最佳实践和常见陷阱
- 帮助实现:
- 遵循官方指南的项目结构
- 数据库 schema 与类型安全
- 具备适当安全性的身份验证流程
- 带错误处理的 API 路由
- 性能优化
请引用具体的文档章节,并解释为什么某些做法比其他做法更值得推荐。
goose 输出
- 技术分析 Next.js App Router 与 Pages Router 首先,获取最新的 Next.js 文档:
-------- Resolve-library-id -------
让我们获取关于 Next.js 的详细文档,重点是路由:
------ Get-library-docs ---------
我来分析 Next.js 文档,并拆解 App Router 与 Pages Router 的关键差异:
------ code structure comparison -----
让我们获取 Prisma 和其他 ORM 的信息:
------- Resolve-library-id ----------
让我们获取 Prisma 的文档:
------ Get-library-docs ----------
关键决策与最佳实践:
- App Router 与 Pages Router:
选择 App Router,因为: 默认使用 Server Components(性能更好) 内置带流式传输的数据获取 用 Route Handlers 让 API 路由更简单 TypeScript 集成更好
- 以 Prisma 作为 ORM:
优势: 类型安全的数据库查询 自动生成的客户端 Schema 迁移 丰富的查询 API 使用 Prisma Accelerate 以获得更好的性能
- 身份验证:
选择 NextAuth.js,因为: 内置安全功能 多种身份验证提供商 会话管理 JWT 处理
- 性能优化:
用 Server Components 减少 JavaScript 用 Route Handlers 做 API 端点 用 Prisma Accelerate 提升数据库性能 全栈类型安全
需要我更详细地解释某一部分,或帮你实现具体功能吗?