Skip to content

Conversation

@gaojude
Copy link
Contributor

@gaojude gaojude commented Nov 4, 2025

Add initialization tool for Next.js MCP

The problem

Calling the initialization tool significantly improves MCP usage throughout the session.

It's unfortunate that we have to explicitly initialize Next.js MCP, but this is the most reliable workaround we've found. We tried automatic context injection using strong descriptions in the tool metadata, but that turned out to be very unreliable.

What this does

Adds an inittool that sets proper context at the start of a session. The main thing it does is establish that nextjs_docs must be used for ALL Next.js-related queries. It also documents the available tools and provides some best practices.

Why it matters

Without initialization:

User: "What's a Server Component?"
AI: *Answers from memory, potentially outdated or incorrect*

With initialization:

User: "What's a Server Component?"
AI: *Calls nextjs_docs search → retrieves official docs → accurate answer*

Same with questions like "What's a Client Component?", "How does caching work?", etc. The AI will actually use the tools instead of guessing.

@gaojude gaojude requested a review from huozhi November 4, 2025 19:18
@gaojude gaojude force-pushed the jude/init branch 3 times, most recently from 3f886ac to f2e7845 Compare November 4, 2025 22:04

export default async function init(args: InferSchema<typeof schema>): Promise<string> {
try {
const projectPath = args.project_path || process.cwd()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer not give fallback which could cause confusion in the future, like which case is this for

Suggested change
const projectPath = args.project_path || process.cwd()
const projectPath = args.project_path

}

export default function getInitPrompt(args: InferSchema<typeof schema>): string {
const projectPath = args.project_path || process.cwd()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer not give fallback which could cause confusion in the future, like which case is this for

Suggested change
const projectPath = args.project_path || process.cwd()
const projectPath = args.project_path

@gaojude gaojude changed the title Add initialization prompt/tool for Next.js MCP Add initialization tool for Next.js MCP Nov 4, 2025
@gaojude gaojude merged commit ee8edda into main Nov 4, 2025
3 checks passed
@gaojude gaojude deleted the jude/init branch November 4, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants