A minimal, production-ready TypeScript starter template for building Model Context Protocol (MCP) servers.
The Model Context Protocol (MCP) is an open protocol that standardizes how AI applications connect to data sources and tools. Think of it as "USB-C for AI" - a universal standard that allows any AI model to connect with any data source or tool through a consistent interface.
graph LR
A[AI] <-->|MCP| B[Server]
B <--> C[Tools]
B <--> D[Resources]
This starter template provides:
- ✅ Minimal boilerplate to get you started quickly
- ✅ Auto-loading architecture for tools, resources, and prompts
- ✅ TypeScript best practices with strict typing
- ✅ Production-ready structure that scales with your project
- ✅ Working example (echo tool) to demonstrate the pattern
Whether you're building integrations for databases, APIs, file systems, or custom business tools, this template helps you create MCP servers that can be used by any MCP-compatible client (like Claude Desktop, IDEs, or custom applications).
- Features
- Prerequisites
- Installation
- Quick Start
- Transport Modes
- Docker Support
- Project Structure
- Development Guide
- Testing with MCP Inspector
- Configuration
- Commands
- Integration
- Contributing
- License
- 🚀 Auto-loading Module System - Drop new tools, resources, or prompts into their directories and they're automatically registered
- 🛠️ TypeScript First - Full type safety with strict TypeScript configuration
- 📦 Minimal Dependencies - Only essential packages included
- 🧪 Built-in Testing - Uses Node.js native test runner
- 🔍 MCP Inspector Support - Test your server with the official MCP Inspector
- 📝 Extensible Architecture - Clear patterns for adding new capabilities
- 🎯 Example Implementation - Working echo tool demonstrates the pattern
- ⚡ Code Generators - Hygen scaffolding for rapid module creation
- 🌐 Dual Transport Support - Both stdio and HTTP (SSE + JSON-RPC) transports
- 🐳 Docker Ready - Containerized deployment with multi-stage builds
Important
Ensure you have Node.js version 20.11.0 or higher installed before proceeding.
- Node.js >= 20.11.0
- npm or yarn
- Basic understanding of TypeScript
- Familiarity with the Model Context Protocol concepts
# Clone the repository
git clone https://github.com/alexanderop/mcp-server-starter-ts.git
cd mcp-server-starter-ts
# Install dependencies
npm install
# Build the project
npm run build
You can also use this as a GitHub template:
- Click "Use this template" on GitHub
- Create your new repository
- Clone and start building your MCP server
Tip
Use the MCP Inspector to test your server interactively during development!
-
Build the server:
npm run build
-
Test with MCP Inspector:
npm run inspect
This opens the MCP Inspector where you can interact with your server's tools, resources, and prompts.
-
Run tests:
npm test
This server supports two transport modes: stdio (default) and HTTP (Streamable SSE + JSON-RPC).
Traditional stdio transport for local development and desktop clients:
# Run with stdio transport
npm run serve:stdio
# Or simply (defaults to stdio)
npm run build && node build/index.js
Streamable HTTP transport for web deployments and remote access:
# Run with HTTP transport on port 3000
npm run serve:http
# Test with MCP Inspector
npm run inspect:http
The HTTP transport exposes:
- SSE endpoint (GET):
http://localhost:3000/mcp
- For server-sent events - JSON-RPC endpoint (POST):
http://localhost:3000/mcp
- For requests
Configure the server behavior using environment variables:
Variable | Description | Default |
---|---|---|
STARTER_TRANSPORT |
Transport mode: stdio or http |
stdio |
PORT |
HTTP server port (HTTP mode only) | 3000 |
CORS_ORIGIN |
CORS allowed origins (HTTP mode only) | * |
{
"servers": {
"starter-stdio": {
"type": "stdio",
"command": "node",
"args": ["./build/index.js"]
},
"starter-http": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}
Add to your Claude Desktop configuration:
{
"mcpServers": {
"mcp-server-starter": {
"command": "node",
"args": ["/path/to/mcp-server-starter/build/index.js"]
}
}
}
The server includes Docker support for easy deployment:
# Build and run with Docker Compose
docker compose up --build
# Or run the pre-built image
docker run -p 3000:3000 ghcr.io/alexanderopalic/mcp-server-starter-ts:latest
The Docker container runs in HTTP mode by default. Override settings with environment variables:
docker run -p 3000:3000 \
-e CORS_ORIGIN="https://example.com" \
-e PORT=3000 \
ghcr.io/alexanderopalic/mcp-server-starter-ts:latest
Use the development profile for hot reload:
docker compose --profile dev up mcp-server-starter-dev
This mounts your source code and enables live reloading on port 3001.
mcp-server-starter-ts/
├── src/
│ ├── index.ts # Main entry point
│ ├── registry/ # Auto-loading system
│ │ ├── auto-loader.ts # Module auto-discovery
│ │ └── types.ts # TypeScript interfaces
│ ├── tools/ # Tool implementations
│ │ └── echo.ts # Example echo tool
│ ├── resources/ # Resource implementations (empty by default)
│ └── prompts/ # Prompt implementations (empty by default)
├── tests/ # Test files
├── _templates/ # Hygen generator templates
│ ├── tool/new/ # Tool generator
│ ├── prompt/new/ # Prompt generator
│ └── resource/new/ # Resource generator
├── build/ # Compiled JavaScript (generated)
├── mcp.json # MCP server configuration
├── package.json # Node.js dependencies
├── tsconfig.json # TypeScript configuration
├── eslint.config.js # ESLint configuration
└── README.md
flowchart TB
A[Start] --> B[Scan]
B --> C[Register]
C --> D[Ready]
Tip
Simply drop your module files into the appropriate directory (tools/
, resources/
, or prompts/
) and they'll be automatically loaded when the server starts!
Tip
The fastest way to create new modules is using the built-in Hygen generators!
This project includes Hygen scaffolding for rapid module creation. Each generator creates both the implementation file and a corresponding test file.
npm run gen:tool
You'll be prompted for:
- Name: Enter in kebab-case (e.g.,
text-transform
) - Description: Brief description of what the tool does
npm run gen:prompt
You'll be prompted for:
- Name: Enter in kebab-case (e.g.,
code-review
) - Description: Brief description of the prompt template
npm run gen:resource
You'll be prompted for:
- Name: Enter in kebab-case (e.g.,
app-status
) - Description: Brief description of the resource
You can also provide parameters directly:
npx hygen tool new --name my-tool --description "Does something useful"
npx hygen prompt new --name my-prompt --description "Generates helpful text"
npx hygen resource new --name my-resource --description "Provides data"
Generated files:
- Implementation:
src/{tools|prompts|resources}/[name].ts
- Test:
tests/[name].test.ts
The auto-loader automatically discovers and registers all generated modules - no additional configuration needed!
graph TD
A[MCP] --> B[Tools]
A --> C[Resources]
A --> D[Prompts]
Note
Tools are functions that can be called by the AI to perform specific actions or computations.
Tools allow your MCP server to perform actions. Create a new file in src/tools/
:
// src/tools/calculate.ts
import { z } from "zod";
import type { RegisterableModule } from "../registry/types.js";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
const calculateModule: RegisterableModule = {
type: "tool",
name: "calculate",
description: "Perform basic arithmetic calculations",
register(server: McpServer) {
server.tool(
"calculate",
"Perform basic arithmetic calculations",
{
operation: z.enum(["add", "subtract", "multiply", "divide"])
.describe("The arithmetic operation to perform"),
a: z.number().describe("First number"),
b: z.number().describe("Second number"),
},
(args) => {
let result: number;
switch (args.operation) {
case "add": result = args.a + args.b; break;
case "subtract": result = args.a - args.b; break;
case "multiply": result = args.a * args.b; break;
case "divide":
if (args.b === 0) throw new Error("Division by zero");
result = args.a / args.b;
break;
}
return {
content: [
{
type: "text",
text: `Result: ${result}`,
},
],
};
}
);
}
};
export default calculateModule;
Note
Resources provide read-only access to data that can be consumed by AI clients.
Resources provide data that can be read by clients. Create a new file in src/resources/
:
// src/resources/config.ts
import type { RegisterableModule } from "../registry/types.js";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
const configResource: RegisterableModule = {
type: "resource",
name: "config",
description: "Application configuration",
register(server: McpServer) {
server.resource(
"config://app/settings",
"Application settings",
"application/json",
async () => {
const settings = {
version: "1.0.0",
environment: process.env.NODE_ENV || "development",
features: {
autoSave: true,
darkMode: false,
}
};
return {
contents: [
{
uri: "config://app/settings",
mimeType: "application/json",
text: JSON.stringify(settings, null, 2),
}
]
};
}
);
}
};
export default configResource;
Note
Prompts are reusable templates that help structure interactions with the AI model.
Prompts are reusable prompt templates. Create a new file in src/prompts/
:
// src/prompts/code-review.ts
import { z } from "zod";
import type { RegisterableModule } from "../registry/types.js";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
const codeReviewPrompt: RegisterableModule = {
type: "prompt",
name: "code-review",
description: "Generate a code review prompt",
register(server: McpServer) {
server.prompt(
"code-review",
"Generate a comprehensive code review",
{
language: z.string().describe("Programming language"),
code: z.string().describe("Code to review"),
focus: z.string().optional().describe("Specific areas to focus on"),
},
(args) => {
return {
messages: [
{
role: "user",
content: {
type: "text",
text: `Please review the following ${args.language} code:
\`\`\`${args.language}
${args.code}
\`\`\`
${args.focus ? `Focus areas: ${args.focus}` : ""}
Please provide:
1. Code quality assessment
2. Potential bugs or issues
3. Performance considerations
4. Security concerns
5. Suggestions for improvement`,
},
},
],
};
}
);
}
};
export default codeReviewPrompt;
The MCP Inspector is a powerful tool for testing your server:
npm run inspect
This command:
- Builds your TypeScript code
- Launches the MCP Inspector
- Connects to your server
- Provides an interactive UI to test tools, resources, and prompts
For rapid testing and development, use the interactive dev mode:
npm run dev
This starts an interactive REPL where you can paste JSON-RPC messages directly and see responses in real-time. Perfect for testing your MCP server during development!
Once you run npm run dev
, you can paste these JSON-RPC messages directly.
Important
MCP Protocol Handshake Required
The MCP protocol requires a specific initialization sequence before you can use tools, resources, or prompts:
- Initialize Request - Client sends capabilities and receives server capabilities
- Initialized Notification - Client confirms it's ready (no response expected)
Why is the initialized notification needed?
- It confirms the client has processed the initialization response and is ready
- It enables bidirectional communication - after this, the server can send requests to the client
- Without it, the server won't send notifications (like
tools/list_changed
) or make requests (likesampling/createMessage
) - This follows a pattern similar to TCP's handshake, ensuring both parties are ready before actual communication begins
The dev server does NOT automatically perform this handshake. You must send these messages manually first.
Step 1 - Send initialize request:
{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"1.0.0","capabilities":{},"clientInfo":{"name":"dev-client","version":"1.0.0"}},"id":1}
Step 2 - After receiving the response, send initialized notification:
{"jsonrpc":"2.0","method":"notifications/initialized"}
Now the server is ready to handle requests!
{"jsonrpc":"2.0","method":"tools/list","params":{},"id":2}
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"echo","arguments":{"text":"Hello, MCP!"}},"id":3}
{"jsonrpc":"2.0","method":"resources/list","params":{},"id":4}
{"jsonrpc":"2.0","method":"resources/read","params":{"uri":"timestamp://current/iso"},"id":5}
{"jsonrpc":"2.0","method":"prompts/list","params":{},"id":6}
{"jsonrpc":"2.0","method":"prompts/get","params":{"name":"generate-readme","arguments":{"projectName":"My Project","description":"A cool project"}},"id":7}
Tip
Using Dev Mode:
- Run
npm run dev
to start the interactive server - Copy any JSON-RPC message above and paste it into the terminal
- The server will show the response with syntax highlighting
- Type
help
for available commands orexit
to quit
Important: Always send the initialize message first to establish the connection!
The project uses strict TypeScript settings for maximum type safety. Key configurations in tsconfig.json
:
- Target: ES2022
- Module: ES2022 with Node module resolution
- Strict mode enabled
- Source maps for debugging
Command | Description |
---|---|
npm run build |
Compile TypeScript to JavaScript |
npm run lint |
Run ESLint checks |
npm run lint:fix |
Auto-fix ESLint issues |
npm run typecheck |
Type-check without building |
npm test |
Run tests |
npm run test:watch |
Run tests in watch mode |
npm run inspect |
Launch MCP Inspector |
npm run dev |
Interactive development mode |
npm run gen:tool |
Generate a new tool with test |
npm run gen:prompt |
Generate a new prompt with test |
npm run gen:resource |
Generate a new resource with test |
sequenceDiagram
IDE->>MCP: Connect
MCP-->>IDE: Ready
IDE->>MCP: Call
MCP-->>IDE: Response
Tip
The easiest way to use your MCP server is through VS Code with MCP support extensions.
-
Build your server:
npm run build
-
Open the project in VS Code:
code .
-
Use the included
mcp.json
configuration:The project includes an
mcp.json
file that VS Code MCP extensions can use to automatically start your server:{ "servers": { "starter": { "type": "stdio", "command": "node", "args": [ "./build/index.js" ] } } }
-
Install a VS Code MCP extension:
- Open VS Code Extensions (⇧⌘X on macOS, Ctrl+Shift+X on Windows/Linux)
- Search for "MCP" or "Model Context Protocol"
- Install an MCP-compatible extension
- The extension will automatically detect and use your
mcp.json
configuration
Note
The mcp.json
file tells VS Code how to start your MCP server. When you open a project with this file, compatible extensions will automatically recognize it as an MCP server project.
Important
Make sure to build your server before configuring Claude Desktop. The server must be compiled to JavaScript.
-
Build your server:
npm run build
-
Add to Claude Desktop configuration:
[!WARNING] Configuration file location varies by operating system:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- Linux:
~/.config/Claude/claude_desktop_config.json
{ "mcpServers": { "my-server": { "command": "node", "args": ["/path/to/your/server/build/index.js"] } } }
- macOS:
-
Restart Claude Desktop
Caution
Always use absolute paths in your configuration. Relative paths may not work correctly.
Use the MCP SDK to connect to your server:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const transport = new StdioClientTransport({
command: "node",
args: ["/path/to/your/server/build/index.js"],
});
const client = new Client({
name: "my-client",
version: "1.0.0",
}, { capabilities: {} });
await client.connect(transport);
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Warning
Common issues and their solutions:
Issue | Solution |
---|---|
Cannot find module errors |
Ensure you've run npm run build before starting the server |
Server not connecting | Check that you're using absolute paths in configuration |
Tools not loading | Verify your module exports match the RegisterableModule interface |
TypeScript errors | Run npm run typecheck to identify type issues |
Auto-loading fails | Check file names and ensure modules are in correct directories |
- ✅ Type Safety: Use TypeScript's strict mode for catching errors early
- ✅ Modular Design: Keep tools, resources, and prompts focused on single responsibilities
- ✅ Error Handling: Always handle errors gracefully and provide meaningful messages
- ✅ Validation: Use Zod schemas to validate all inputs
- ✅ Testing: Write tests for critical functionality
Built with ❤️ for the MCP community