|
| 1 | +# Node.js MCP Server Template |
| 2 | + |
| 3 | +A Model Context Protocol (MCP) server template for Node.js applications. This template provides a foundation for building MCP-compatible servers with support for multiple transport protocols. |
| 4 | + |
| 5 | +## Features |
| 6 | +- Multiple Transport Protocols : |
| 7 | + |
| 8 | + - Standard I/O (stdio) for command-line interfaces |
| 9 | + - HTTP Streamable transport for web applications |
| 10 | + - Server-Sent Events (SSE) for real-time updates |
| 11 | +- TypeScript Support : Built with TypeScript for type safety and better developer experience |
| 12 | +- Development Tools : |
| 13 | + |
| 14 | + - Hot reloading during development |
| 15 | + - Integration with MCP Inspector for debugging |
| 16 | + - ESLint and Prettier for code quality |
| 17 | + - Husky and lint-staged for Git hooks |
| 18 | +- Extensible Tool System : Easy registration of custom MCP tools |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | +- Node.js (latest LTS version recommended) |
| 22 | +- npm or yarn |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +```bash |
| 27 | +npm install |
| 28 | +``` |
| 29 | + |
| 30 | +## Development |
| 31 | +```bash |
| 32 | +# Start development server with stdio transport |
| 33 | +npm run dev |
| 34 | + |
| 35 | +# Start development server with web transport |
| 36 | +npm run dev:web |
| 37 | +``` |
| 38 | + |
| 39 | +When using dev:web , the server will be available at: |
| 40 | + |
| 41 | +- Streamable HTTP endpoint: http://localhost:8401/mcp |
| 42 | +- SSE endpoint: http://localhost:8401/sse |
| 43 | + |
| 44 | +## Building |
| 45 | +```bash |
| 46 | +npm run build |
| 47 | +``` |
| 48 | +The build output will be in the build directory. |
| 49 | + |
| 50 | +## Usage |
| 51 | +### Command Line |
| 52 | +```bash |
| 53 | +# Start with stdio transport (default) |
| 54 | +node build/index.js |
| 55 | + |
| 56 | +# Start with web transport |
| 57 | +node build/index.js web --port 8401 |
| 58 | +``` |
| 59 | +### Adding Custom Tools |
| 60 | +Custom tools can be added in the src/tools/index.ts file: |
| 61 | + |
| 62 | +```ts |
| 63 | +server.registerTool( |
| 64 | + 'YourToolName', |
| 65 | + { |
| 66 | + title: 'Your Tool Name', |
| 67 | + description: 'Tool description', |
| 68 | + inputSchema: { |
| 69 | + param1: z.string().describe('Parameter description'), |
| 70 | + }, |
| 71 | + }, |
| 72 | + ({ param1 }) => { |
| 73 | + // Implement tool logic |
| 74 | + return { |
| 75 | + content: [ |
| 76 | + { |
| 77 | + type: 'text', |
| 78 | + text: `Your tool response: ${param1}`, |
| 79 | + }, |
| 80 | + ], |
| 81 | + } |
| 82 | + }, |
| 83 | +) |
| 84 | +``` |
| 85 | + |
| 86 | +## Environment Variables |
| 87 | +- PORT : Specify the port for web transport (default: 8401) |
| 88 | +- NODE_ENV : Set to production for production builds or local for development |
| 89 | + |
| 90 | +## License |
| 91 | +[MIT](LICENSE) |
0 commit comments