create-mcp-craft
Version:
Create MCP TypeScript servers with Bun and Hono - the fastest way to scaffold Model Context Protocol servers
179 lines (134 loc) โข 5.89 kB
Markdown
# create-mcp-craft
> Create MCP TypeScript servers with Bun and Hono - the fastest way to scaffold Model Context Protocol servers
## โก Quick Start
The easiest way to create a new MCP server is using the create command:
```bash
# Using bunx (recommended)
bunx create-mcp-craft@latest my-mcp-server
# Using npm
npm create mcp-craft@latest my-mcp-server
# Using yarn
yarn create mcp-craft my-mcp-server
# Using pnpm
pnpm create mcp-craft my-mcp-server
# Using bun create
bun create mcp-craft my-mcp-server
```
Then navigate to your new project and start developing:
```bash
cd my-mcp-server
bun install
bun run dev:stdio
```
Your project comes with git already initialized and an initial commit made! Ready to push to your repository.
## ๐ What You Get
This template creates a production-ready MCP TypeScript server with:
### ๐ง **Modern Tooling**
- **Bun** - Lightning-fast package manager and runtime (20-30x faster than npm)
- **Hono** - Ultra-lightweight web framework (14kB, zero dependencies)
- **TypeScript** - Full type safety with native Bun support
- **ESLint + Prettier** - Code linting and formatting configured
- **Git** - Repository initialized with initial commit
### ๐ก **Complete MCP Implementation**
- **Dual Transport Support**: Both stdio (process communication) and HTTP+SSE (web-based)
- **All MCP Request Types**: Complete implementation of the MCP specification
- **Example Tools**: Calculator and weather API demonstrations
- **Example Resources**: Static config and dynamic greeting resources
- **Example Prompts**: Code review prompt with configurable focus areas
- **Transport-aware Logging**: Proper stderr logging for stdio, console for HTTP
### ๐ ๏ธ **Built-in Examples**
- **Tools**: `add`, `subtract`, `multiply`, `divide`, `fetch-weather`, `get-forecast`
- **Resources**: `config://app`, `greeting://{name}`
- **Prompts**: `review-code` with focus options (security, performance, readability)
- **Zod Validation**: Runtime type checking for all parameters
## ๐ฏ Development Workflow
After creating your project, you'll have these commands available:
```bash
# Development
bun run dev:stdio # Run with stdio transport (for Claude Desktop)
bun run dev:http # Run with HTTP+SSE transport (for web clients)
bun run dev # Run with file watching
# Quality Assurance
bun run typecheck # TypeScript type checking
bun run lint # ESLint code linting
bun run lint:fix # Auto-fix linting issues
bun run format # Prettier code formatting
# Production
bun run build # Build the project
bun run start # Start production server
```
## ๐ Integration Examples
### Claude Desktop Configuration
Add your server to Claude Desktop by updating your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"my-mcp-server": {
"command": "bun",
"args": ["/path/to/my-mcp-server/src/index.ts"]
}
}
}
```
### Web Client (HTTP+SSE)
```typescript
// Connect to your MCP server via HTTP
const response = await fetch('http://localhost:3000/mcp/sse')
const eventSource = new EventSource('http://localhost:3000/mcp/sse')
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data)
console.log('MCP message:', data)
}
```
## ๐ Performance Benefits
| Metric | npm/Express | Bun/Hono | Improvement |
|--------|-------------|-----------|-------------|
| Install Speed | ~15s | ~2s | **7.5x faster** |
| Framework Size | ~200kB | ~14kB | **93% smaller** |
| Runtime Overhead | High | Minimal | **Native TypeScript** |
| Cold Start | ~500ms | ~50ms | **10x faster** |
## ๐๏ธ Template Structure
Your generated project will have this structure:
```
my-mcp-server/
โโโ src/
โ โโโ index.ts # Main server (stdio transport)
โ โโโ http.ts # HTTP server with SSE
โ โโโ config/
โ โ โโโ server.ts # Server configuration
โ โโโ handlers/ # MCP request handlers
โ โโโ services/ # Business logic
โ โโโ types/ # TypeScript definitions
โ โโโ utils/ # Utility functions
โโโ docs/ # Documentation
โโโ package.json # Project configuration
โโโ tsconfig.json # TypeScript configuration
โโโ .eslintrc.json # ESLint configuration
โโโ .prettierrc # Prettier configuration
โโโ README.md # Project documentation
```
## ๐งช Advanced Features
The template includes advanced MCP features out of the box:
- **Resource Subscriptions**: Real-time updates for dynamic resources
- **Prompt Templates**: Parameterized prompts for various use cases
- **Sampling Integration**: Ready for LLM model integration
- **Session Management**: Stateful client sessions
- **Logging Levels**: Configurable logging with proper transport handling
- **Error Handling**: Comprehensive error responses with proper codes
## ๐ Customization
The template automatically replaces placeholders with your project details:
- Project name and description
- Author information (from git config)
- Repository URL
- Current year for copyright
## ๐ค Contributing
Found a bug or have a feature request? Please visit:
- ๐ [Issues](https://github.com/kiliczsh/create-mcp-craft/issues)
- ๐ [Pull Requests](https://github.com/kiliczsh/create-mcp-craft/pulls)
## ๐ License
MIT License ยฉ 2025 Muhammed Kฤฑlฤฑรง
## ๐ Acknowledgments
- [Model Context Protocol](https://modelcontextprotocol.io/) - The open standard this template implements
- [Bun](https://bun.sh/) - The incredibly fast JavaScript runtime and toolkit
- [Hono](https://hono.dev/) - The ultrafast web framework for the Edges
- [Claude](https://claude.ai/) - AI assistant that helps developers build amazing MCP servers