UNPKG

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
# 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