- Explore MCP Servers
- mcp-typescript-boilerplate
Mcp Typescript Boilerplate
What is Mcp Typescript Boilerplate
mcp-typescript-boilerplate is a comprehensive boilerplate for creating Model Context Protocol (MCP) servers, supporting multiple transport methods including stdio, Server-Sent Events (SSE), and HTTP.
Use cases
Use cases include developing real-time applications, creating APIs for web services, and building scalable server architectures that require modular and maintainable code.
How to use
To use mcp-typescript-boilerplate, clone the repository, install dependencies, build the project, and run it in your desired mode (stdio, HTTP, or development with hot reload). Configure your MCP client to connect to the server as needed.
Key features
Key features include multiple transport support, full type safety with TypeScript, modular architecture, structured logging, a reusable generic API client, a streamlined tool factory, and development-ready features like hot reload and linting.
Where to use
mcp-typescript-boilerplate can be used in various domains where a robust server architecture is needed, particularly in applications requiring real-time data handling and API interactions.
Overview
What is Mcp Typescript Boilerplate
mcp-typescript-boilerplate is a comprehensive boilerplate for creating Model Context Protocol (MCP) servers, supporting multiple transport methods including stdio, Server-Sent Events (SSE), and HTTP.
Use cases
Use cases include developing real-time applications, creating APIs for web services, and building scalable server architectures that require modular and maintainable code.
How to use
To use mcp-typescript-boilerplate, clone the repository, install dependencies, build the project, and run it in your desired mode (stdio, HTTP, or development with hot reload). Configure your MCP client to connect to the server as needed.
Key features
Key features include multiple transport support, full type safety with TypeScript, modular architecture, structured logging, a reusable generic API client, a streamlined tool factory, and development-ready features like hot reload and linting.
Where to use
mcp-typescript-boilerplate can be used in various domains where a robust server architecture is needed, particularly in applications requiring real-time data handling and API interactions.
Content
MCP TypeScript Boilerplate
A comprehensive TypeScript boilerplate for creating Model Context Protocol (MCP) servers with support for stdio, SSE, and HTTP transports.
🚀 Features
- Multiple Transport Support: stdio, Server-Sent Events (SSE), and HTTP
- TypeScript: Full type safety and modern development experience
- Modular Architecture: Clean separation of tools, utilities, and server logic
- Structured Logging: Built-in logger with configurable levels
- Generic API Client: Reusable HTTP client with interceptors and error handling
- Tool Factory: Streamlined tool creation with validation and error handling
- Development Ready: Hot reload, linting, formatting, and type checking
🛠️ Getting Started
Prerequisites
- Node.js >= v18.0.0
- MCP Client (Cursor, VS Code, Claude Desktop, etc.)
Local Development
-
Clone and install:
git clone https://github.com/andradehenrique/mcp-typescript-boilerplate.git cd mcp-typescript-boilerplate npm install
-
Build the project:
npm run build
-
Run in different modes:
# Stdio mode (default) npm run start:stdio # HTTP server mode npm run start:http # Development with hot reload npm run dev
MCP Client Configuration
For Local Development
Configure your MCP client to use the built server directly:
{
"mcpServers": {
"mcp-typescript-boilerplate": {
"command": "node",
"args": [
"/path/to/mcp-typescript-boilerplate/build/index.js"
],
"env": {
"API_BASE_URL": "https://your-api-server.com/api",
"API_TOKEN": "your-api-token"
}
}
}
}
Using tsx for Development
{
"mcpServers": {
"mcp-typescript-boilerplate": {
"command": "npx",
"args": [
"tsx",
"/path/to/mcp-typescript-boilerplate/src/index.ts"
],
"env": {
"API_BASE_URL": "https://your-api-server.com/api",
"API_TOKEN": "your-api-token"
}
}
}
}
Docker Support
-
Build and run:
docker build -t mcp-typescript-boilerplate . docker-compose up
-
HTTP mode:
docker run -p 3000:3000 -e MCP_TRANSPORT=http mcp-typescript-boilerplate
Environment Variables
API_BASE_URL
: Your API server base URL (optional)API_TOKEN
: Your API authentication token (optional)API_TIMEOUT
: Request timeout in milliseconds (default: 30000)MCP_TRANSPORT
: Transport mode - stdio, http, or sse (default: stdio)HTTP_PORT
: HTTP server port (default: 3000)
📚 Available Tools
This boilerplate includes 3 example tools:
hello-world
- Simple greeting toolcalculate-sum
- Number calculation examplemake-api-call
- External API integration example
For detailed tool information, see TOOLS.md.
🏗️ Architecture
src/ ├── index.ts # Entry point with transport selection ├── server.ts # MCP server setup and tool registration ├── http-server.ts # HTTP/SSE server implementation ├── mcp/ │ └── tools/ │ ├── index.ts # Tool exports │ ├── toolFactory.ts # Tool creation utilities │ └── example/ # Example tools ├── types/ # TypeScript type definitions └── utils/ # Shared utilities ├── apiClient.ts # HTTP client ├── clientConfig.ts # Configuration ├── logger.ts # Logging utilities └── responseFormatter.ts # Response formatting
🔧 Creating Tools
Use the provided toolFactory
for easy tool creation:
import { z } from "zod";
import { createTool } from "../toolFactory.js";
import { ResponseFormatter } from "../../utils/responseFormatter.js";
export const myTool = createTool({
name: "my-tool",
description: "My custom tool",
schema: z.object({
input: z.string().describe("Input parameter"),
}),
handler: async (input) => {
// Your logic here
return ResponseFormatter.success("Success", { result: input });
},
});
Add to src/mcp/tools/index.ts
:
import { myTool } from "./myTool.js";
export const allTools = [
myTool,
// ... other tools
];
📝 Available Scripts
npm run build
- Build the projectnpm run dev
- Development with hot reloadnpm run start:stdio
- Start in stdio modenpm run start:http
- Start HTTP servernpm run lint
- Run ESLintnpm run format
- Format code with Prettiernpm run type-check
- Type checkingnpm run clean
- Clean build directory
🔧 Testing
Test with MCP Inspector:
npx @modelcontextprotocol/inspector node build/index.js
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
See CONTRIBUTING.md for details.
🔗 Resources
📄 License
This project is licensed under the MIT License.