Loading repository data…
Loading repository data…
onamfc / repository
TypeScript starter template for building Model Context Protocol (MCP) servers, designed to help developers create secure and robust AI-agent-compatible services.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A comprehensive starter template for building Model Context Protocol (MCP) servers with TypeScript. This template provides a solid foundation for developers of all skill levels to quickly bootstrap production-ready MCP projects.
Choose your preferred package manager:
Using npm:
git clone https://github.com/onamfc/mcp-starter-template-ts.git
cd mcp-starter-template-ts
npm install
npm run build
npm start
Using yarn:
git clone https://github.com/onamfc/mcp-starter-template-ts.git
cd mcp-starter-template-ts
yarn install
yarn build
yarn start
Using pnpm:
git clone https://github.com/onamfc/mcp-starter-template-ts.git
cd mcp-starter-template-ts
pnpm install
pnpm build
pnpm start
For development with hot reloading:
npm run dev
This will start the server with automatic restarts when you modify source files.
src/
├── server.ts # Main MCP server implementation
├── types/ # TypeScript type definitions
│ └── index.ts
├── tools/ # MCP tools implementation
│ ├── setup.ts # Tool registration and management
│ ├── calculator.ts # Mathematical calculations
│ ├── filesystem.ts # File system operations
│ ├── text-processing.ts # Text manipulation and analysis
│ └── weather.ts # Weather information (mock)
├── resources/ # MCP resources implementation
│ ├── setup.ts # Resource registration and management
│ ├── config.ts # Configuration access
│ ├── docs.ts # Documentation resource
│ └── logs.ts # Logs access
├── utils/ # Utility functions
│ ├── config.ts # Configuration management
│ ├── logger.ts # Structured logging
│ ├── validation.ts # Input validation
│ ├── errors.ts # Error handling
│ └── health.ts # Health check utilities
└── __tests__/ # Test files
├── server.test.ts
├── tools/
└── utils/
The server can be configured through environment variables. Create a .env file in the project root:
# Server Configuration
PORT=3000
HOST=localhost
LOG_LEVEL=info
NODE_ENV=development
# Feature Flags
ENABLE_HEALTH_CHECK=true
# Security
MAX_REQUEST_SIZE=10mb
CORS_ORIGINS=*
# External Services (if needed)
# WEATHER_API_KEY=your_api_key_here
# DATABASE_URL=your_database_url_here
| Variable | Description | Default | Required |
|---|---|---|---|
PORT | Server port number | 3000 | No |
HOST | Server host address | localhost | No |
LOG_LEVEL | Logging level (error, warn, info, debug) | info | No |
NODE_ENV | Environment (development, production, test) | development | No |
ENABLE_HEALTH_CHECK | Enable health check endpoint | true | No |
MAX_REQUEST_SIZE | Maximum request body size | 10mb | No |
CORS_ORIGINS | Allowed CORS origins (comma-separated) | * | No |
calculate)Perform mathematical calculations with support for basic arithmetic operations.
Parameters:
expression (string, required): Mathematical expression to evaluateprecision (number, optional): Number of decimal places (default: 2)Example:
{
"name": "calculate",
"arguments": {
"expression": "2 + 3 * 4",
"precision": 2
}
}
filesystem)Read and write files within the project directory with security restrictions.
Parameters:
operation (string, required): Operation type (read, write, list, exists)path (string, required): File or directory path (relative to project root)content (string, optional): Content to write (required for write operation)encoding (string, optional): File encoding (utf8, base64, default: utf8)Example:
{
"name": "filesystem",
"arguments": {
"operation": "read",
"path": "package.json"
}
}
text-processing)Process and analyze text with various operations.
Parameters:
operation (string, required): Operation type (count, uppercase, lowercase, reverse, wordcount, sentiment)text (string, required): Text content to processoptions (object, optional): Additional options for the operationExample:
{
"name": "text-processing",
"arguments": {
"operation": "sentiment",
"text": "I love this amazing weather today!"
}
}
weather)Get current weather information and forecasts (mock implementation).
Parameters:
location (string, required): Location name or coordinatesunits (string, optional): Temperature units (metric, imperial, kelvin, default: metric)forecast (boolean, optional): Include 5-day forecast (default: false)Example:
{
"name": "weather",
"arguments": {
"location": "New York, NY",
"units": "metric",
"forecast": true
}
}
resource://config/current)Access current application configuration and settings.
resource://docs/api)Complete API documentation and usage examples.
resource://logs/recent)Recent application logs and events.
npm run dev - Start development server with hot reloadingnpm run build - Build the project for productionnpm start - Start the production servernpm test - Run test suitenpm run test:watch - Run tests in watch modenpm run test:coverage - Run tests with coverage reportnpm run lint - Run ESLintnpm run lint:fix - Run ESLint with auto-fixnpm run format - Format code with Prettiernpm run format:check - Check code formattingnpm run type-check - Run TypeScript type checkingnpm run clean - Clean build artifactsnpm run health - Check server healthnpm run validate-config - Validate configurationsrc/tools/your-tool.tsToolDefinition interfacesrc/tools/setup.tssrc/__tests__/tools/your-tool.test.tsExample tool structure:
export const yourTool: ToolDefinition = {
name: 'your-tool',
description: 'Description of what your tool does',
inputSchema: {
type: 'object',
properties: {
// Define your parameters here
},
required: ['requiredParam'],
},
handler: async (args, context) => {
// Implement your tool logic here
// Always include proper error handling and logging
},
};
src/resources/your-resource.tsResourceDefinition interfacesrc/resources/setup.tsRun the complete test suite:
npm test
Run tests in watch mode during development:
npm run test:watch
Generate coverage report:
npm run test:coverage
This project includes comprehensive code quality tools:
Run all quality checks:
npm run lint && npm run format:check && npm run type-check
docker build -t mcp-server .
docker run -p 3000:3000 mcp-server
For development with additional services:
docker-compose up --build
npm run build
NODE_ENV=productionThe server includes built-in health check endpoints:
GET http://localhost:3001/healthGET http://localhost:3001/metricsServer won't start:
npm run validate-config to check configurationTools not working:
Build failures:
npm run clean to remove old build artifactsnpm run type-checkTest failures:
npm test -- --testNamePattern="specific test"Enable debug logging:
LOG_LEVEL=debug npm run dev
resource://docs/apiresource://logs/recentWe welcome contributions! Please follow these guidelines:
git checkout -b feature/your-feature-namenpm testnpm run lint && npm run format:check && npm run type-checkUse conventional commit format:
feat: add new weather toolfix: resolve validation error in calculatordocs: update installation instructionstest: add tests for file system toolchore: update dependenciesMIT License - see LICENSE file for details.
See CHANGELOG.md for version history and updates.
/docs directory for detailed guides