Skip to content

Commit 763ec6f

Browse files
quuuclaude
andauthored
Migrate to using official MCP TS SDK (#80)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent ee8edda commit 763ec6f

38 files changed

+607
-2364
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.DS_Store
22
node_modules/
33
dist/
4-
.xmcp/
5-
xmcp-env.d.ts
64
.next/
75
*.tsbuildinfo
86
.turbo

CLAUDE.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
This is an MCP (Model Context Protocol) server that provides Next.js development tools for AI coding assistants. The server exposes tools, prompts, and resources to help with Next.js upgrades, Cache Components setup, documentation search, browser testing, and runtime diagnostics.
88

9+
The server is built using the standard `@modelcontextprotocol/sdk` package with TypeScript and ES modules.
10+
911
## Build and Development Commands
1012

1113
```bash
@@ -46,15 +48,18 @@ Test files are located in `test/e2e/` and use test fixtures from `test/fixtures/
4648

4749
### MCP Server Structure
4850

49-
The main server is generated by `xmcp` (configured in `xmcp.config.ts`) and uses stdio transport. The server automatically registers:
50-
- **Tools** (`src/tools/`): Callable functions for automation
51-
- **Prompts** (`src/prompts/`): Pre-configured prompts for common tasks
52-
- **Resources** (`src/resources/`): Knowledge base articles and documentation
51+
The main server entry point is `src/index.ts` which uses the standard MCP SDK with stdio transport. The server manually registers:
52+
- **Tools** (`src/tools/`): Callable functions for automation - each exports `inputSchema`, `metadata`, and `handler`
53+
- **Prompts** (`src/prompts/`): Pre-configured prompts for common tasks - each exports `inputSchema`, `metadata`, and `handler`
54+
- **Resources** (`src/resources/`): Knowledge base articles and documentation - each exports `metadata` and `handler`
55+
56+
All tools, prompts, and resources are explicitly imported and registered in `src/index.ts`.
5357

5458
### Key Components
5559

5660
**MCP Tools** (`src/tools/`):
57-
- Tools are automatically discovered and registered by xmcp from `src/tools/`
61+
- Each tool exports: `inputSchema` (Zod schemas), `metadata` (name, description), `handler` (async function)
62+
- Tools are manually imported and registered in `src/index.ts`
5863
- `nextjs_docs`: Search Next.js documentation and knowledge base
5964
- `browser_eval`: Playwright browser automation (via `playwright-mcp` server)
6065
- `nextjs_runtime`: Connect to Next.js dev server MCP endpoint for runtime diagnostics
@@ -71,34 +76,37 @@ The main server is generated by `xmcp` (configured in `xmcp.config.ts`) and uses
7176
- `nextjs-runtime-manager.ts`: Discovers and connects to Next.js dev servers with MCP enabled
7277

7378
**Resources Architecture**:
74-
- Knowledge base split into focused sections (12 sections for Next.js 16)
75-
- Resources are loaded on-demand to avoid overwhelming context
79+
- Knowledge base split into focused sections (12 sections for Cache Components, 2 for Next.js 16, 1 for fundamentals)
80+
- Each resource exports: `metadata` (uri, name, description, mimeType) and `handler` (function returning content)
81+
- Resources use URI-based addressing (e.g., `cache-components://overview`)
7682
- Markdown files in `src/resources/` are copied to `dist/resources/` during build via `scripts/copy-resources.js`
7783

7884
### TypeScript Configuration
7985

80-
- Target: ES2022, CommonJS modules
86+
- Target: ES2022, ES modules (Node16 module resolution)
8187
- Strict mode enabled
8288
- Output directory: `dist/`
8389
- Declaration files generated
90+
- Package marked as `"type": "module"` for native ES module support
8491

8592
## Build Process
8693

87-
1. Server generation: `xmcp build` generates the MCP server from `xmcp.config.ts` configuration
94+
1. TypeScript compilation: `tsc` compiles all TypeScript files from `src/` to `dist/`
8895
2. Resource copying: `scripts/copy-resources.js` copies markdown files from `src/resources/` and `src/prompts/` to `dist/resources/`
8996

90-
The `dist/stdio.js` file is the entry point for the MCP server and includes a shebang for CLI execution.
97+
The `dist/index.js` file is the entry point for the MCP server and includes a shebang for CLI execution.
9198

9299
## MCP Protocol Integration
93100

94101
This server can:
95-
1. Act as a standalone MCP server (stdio transport)
102+
1. Act as a standalone MCP server (stdio transport using `@modelcontextprotocol/sdk`)
96103
2. Connect to other MCP servers as a client (e.g., playwright-mcp, Next.js runtime MCP)
97104

98105
**Key MCP Patterns**:
99-
- Tools use Zod schemas for input validation
100-
- Tool handlers receive validated arguments via `tool.execute()`
101-
- Resources use URI-based addressing (e.g., `nextjs16://knowledge/overview`)
106+
- Server uses standard MCP SDK `Server` class with `StdioServerTransport`
107+
- Tools use Zod schemas for input validation, converted to JSON Schema for MCP
108+
- Tool handlers are called with validated arguments
109+
- Resources use URI-based addressing (e.g., `cache-components://overview`)
102110
- Prompts return structured messages with markdown content
103111

104112
## External MCP Server Dependencies
@@ -118,16 +126,29 @@ This server can:
118126
## Common Development Patterns
119127

120128
**Adding a new MCP tool**:
121-
1. Create tool file in `src/tools/` with Zod schema and `tool()` function
122-
2. xmcp automatically discovers and registers tools from `src/tools/`
129+
1. Create tool file in `src/tools/` with:
130+
- `export const inputSchema = { ... }` - Zod schemas for each parameter
131+
- `export const metadata = { name, description }`
132+
- `export async function handler(args) { ... }` - Tool implementation
133+
2. Import and add to the `tools` array in `src/index.ts`
123134
3. Build and test
124135

125136
**Adding a new MCP resource**:
126137
1. Create markdown file(s) in `src/resources/`
127-
2. Create resource handler TypeScript file in `src/resources/` with URI scheme
128-
3. xmcp automatically discovers and registers resources from `src/resources/`
138+
2. Create resource handler TypeScript file in `src/resources/` with:
139+
- `export const metadata = { uri, name, description, mimeType }`
140+
- `export function handler() { return readResourceFile(...) }` - Returns content
141+
3. Import and add to the `resources` array in `src/index.ts`
129142
4. The `scripts/copy-resources.js` script automatically copies `.md` files to `dist/resources/`
130143

144+
**Adding a new MCP prompt**:
145+
1. Create prompt file in `src/prompts/` with:
146+
- `export const inputSchema = { ... }` - Optional Zod schemas for parameters
147+
- `export const metadata = { name, description, role }`
148+
- `export function handler(args) { ... }` - Returns prompt text
149+
2. Import and add to the `prompts` array in `src/index.ts`
150+
3. Build and test
151+
131152
**Working with external MCP servers**:
132153
- Use `src/_internal/mcp-client.ts` for stdio-based communication
133154
- Create manager module in `src/_internal/` for lifecycle management
@@ -136,6 +157,7 @@ This server can:
136157
## Package Publishing
137158

138159
- Package name: `next-devtools-mcp`
139-
- Binary: `next-devtools-mcp` points to `dist/stdio.js`
160+
- Package type: ES module (`"type": "module"`)
161+
- Binary: `next-devtools-mcp` points to `dist/index.js`
140162
- prepublishOnly hook: cleans and rebuilds before publishing
141163
- Use `pnpm@9.15.9` as package manager

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
{
22
"name": "next-devtools-mcp",
33
"version": "0.2.6",
4+
"type": "module",
45
"description": "Next.js development tools MCP server with stdio transport",
56
"license": "MIT",
67
"repository": {
78
"type": "git",
89
"url": "https://github.com/vercel/next-devtools-mcp.git"
910
},
1011
"bin": {
11-
"next-devtools-mcp": "./dist/stdio.js"
12+
"next-devtools-mcp": "./dist/index.js"
1213
},
13-
"main": "dist/stdio.js",
14+
"main": "dist/index.js",
1415
"exports": {
1516
"./package.json": "./package.json",
16-
".": "./dist/stdio.js"
17+
".": "./dist/index.js"
1718
},
1819
"files": [
1920
"dist"
2021
],
2122
"mcpName": "io.github.vercel/next-devtools-mcp",
2223
"scripts": {
23-
"dev": "xmcp dev",
24+
"dev": "tsc --watch",
2425
"copy-resources": "node scripts/copy-resources.js",
25-
"build": "xmcp build && npm run copy-resources",
26+
"build": "tsc && npm run copy-resources",
2627
"prepublishOnly": "pnpm run clean && pnpm run build",
2728
"clean": "rm -rf dist",
28-
"start": "node dist/stdio.js",
29+
"start": "node dist/index.js",
2930
"test": "vitest run --exclude 'test/e2e/**'",
3031
"test:e2e": "vitest run test/e2e",
3132
"eval": "vitest run test/e2e/upgrade.test.ts",
@@ -35,7 +36,6 @@
3536
"@modelcontextprotocol/sdk": "1.21.0",
3637
"find-process": "2.0.0",
3738
"pid-port": "2.0.0",
38-
"xmcp": "0.4.0",
3939
"zod": "3.25.76"
4040
},
4141
"devDependencies": {

0 commit comments

Comments
 (0)