Setting Up Environment
Setting Up Your MCP Development Environment
To build MCP servers, you need Node.js 18+ and a package manager (npm or pnpm). You'll also want Claude Desktop installed to test your servers. Let's set everything up.
Step 1: Create a New Project
bash
# Create a new directory for your MCP server
mkdir my-mcp-server
cd my-mcp-server
# Initialize a Node.js project
npm init -y
# Install the MCP SDK and dependencies
npm install @modelcontextprotocol/sdk zod
# Install TypeScript (recommended)
npm install -D typescript @types/node tsx
# Initialize TypeScript
npx tsc --initStep 2: Configure TypeScript
Update your
tsconfig.json to support ES modules and modern features:typescript
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src/**/*"]
}Step 3: Update package.json
typescript
// Add these to your package.json:
{
"type": "module",
"scripts": {
"build": "tsc",
"dev": "tsx src/index.ts",
"start": "node dist/index.js"
},
"bin": {
"my-mcp-server": "./dist/index.js"
}
}Tip:The "type": "module" is important — MCP SDK uses ES modules. Make sure your package.json includes this.
Step 4: Configure Claude Desktop
To test your server with Claude Desktop, you'll need to add it to your Claude configuration. We'll cover this in the next lesson after building the server.
PreviewTypeScriptRead Only
Copy this code and run it locally with
npx tsx server.ts