Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@aashari/boilerplate-mcp-server

aashari2kISC1.10.5TypeScript support: included

TypeScript Model Context Protocol (MCP) server boilerplate providing IP lookup tools/resources. Includes CLI support and extensible structure for connecting AI systems (LLMs) to external data sources like ip-api.com. Ideal template for creating new MCP in

mcp, typescript, claude, anthropic, ai, boilerplate, server, model-context-protocol, tools, resources, tooling, ai-integration, mcp-server, llm, ai-connector, external-tools, cli, mcp-inspector

readme

Boilerplate MCP Server

A foundation for developing custom Model Context Protocol (MCP) servers in TypeScript. Provides a complete layered architecture pattern, working example tools, and developer infrastructure to connect AI assistants with external APIs and data sources.

NPM Version Build Status TypeScript License: ISC

Why Use This Boilerplate?

  • Production-Ready Architecture: Follows the same pattern used in published MCP servers, with clean separation between CLI, tools, controllers, and services
  • Type Safety: Built with TypeScript for improved developer experience, code quality, and maintainability
  • Working Example: Includes fully implemented tools demonstrating the complete pattern from CLI to API integration
  • Testing Framework: Ready-to-use testing infrastructure for unit and CLI integration tests, with coverage reporting
  • Complete Developer Tooling: Pre-configured ESLint, Prettier, TypeScript, and CI/CD workflows

What is MCP?

Model Context Protocol (MCP) is an open standard for securely connecting AI systems to external tools and data sources. This boilerplate implements the MCP specification with a clean, layered architecture that can be extended to build custom MCP servers for any API or data source.

Prerequisites

  • Node.js (>=18.x): Download
  • Git: For version control

Quick Start

# Clone the repository
git clone https://github.com/aashari/boilerplate-mcp-server.git
cd boilerplate-mcp-server

# Install dependencies
npm install

# Start development server
npm run dev:server

# Try the example tool
npm run dev:cli -- get-ip-details 8.8.8.8

Architecture Overview

<summary>Project Structure (Click to expand)</summary>
src/
├── cli/              # Command-line interfaces
│   ├── index.ts      # CLI entry point
│   └── *.cli.ts      # Feature-specific CLI modules
├── controllers/      # Business logic
│   └── *.controller.ts  # Feature controllers
├── services/         # External API interactions
│   └── *.service.ts  # Service modules
├── tools/            # MCP tool definitions
│   ├── *.tool.ts     # Tool implementations
│   └── *.types.ts    # Tool argument schemas
├── types/            # Type definitions
│   └── common.types.ts # Shared type definitions
├── utils/            # Shared utilities
│   ├── logger.util.ts  # Structured logging
│   ├── error.util.ts   # Error handling
│   └── ...           # Other utility modules
└── index.ts          # Server entry point

Layered Architecture

The boilerplate follows a clean, layered architecture that promotes maintainability and clear separation of concerns:

1. CLI Layer (src/cli/*.cli.ts)

  • Purpose: Command-line interfaces that parse arguments and call controllers
  • Pattern: Use commander for argument parsing, call controllers, handle errors with handleCliError
  • Naming: <feature>.cli.ts

2. Tools Layer (src/tools/*.tool.ts)

  • Purpose: MCP tool definitions exposed to AI assistants
  • Pattern: Use zod for schema validation, call controllers, format responses for MCP
  • Naming: <feature>.tool.ts with types in <feature>.types.ts

3. Controllers Layer (src/controllers/*.controller.ts)

  • Purpose: Business logic orchestration, error handling, response formatting
  • Pattern: Return standardized ControllerResponse objects, throw errors with context
  • Naming: <feature>.controller.ts with optional <feature>.formatter.ts

4. Services Layer (src/services/*.service.ts)

  • Purpose: External API interactions and data handling
  • Pattern: Pure API calls with minimal logic, return raw data
  • Naming: <feature>.service.ts or vendor.<vendor>.<feature>.service.ts

5. Utils Layer (src/utils/*.util.ts)

  • Purpose: Shared functionality across the application
  • Key Utils: Logging, error handling, formatting, configuration

Developer Guide

Development Scripts

# Start server in dev mode with hot-reload & inspector
npm run dev:server

# Run CLI commands in development
npm run dev:cli -- [command] [args]

# Build the project
npm run build

# Production server
npm start
npm run start:server

# Production CLI
npm run start:cli -- [command] [args]

# Testing
npm test                    # Run all tests
npm test -- src/path/to/test.ts  # Run specific tests
npm run test:coverage       # Generate coverage report

# Code Quality
npm run lint                # Run ESLint
npm run format              # Format with Prettier
npm run typecheck           # Check TypeScript types

Debugging Tools

  • MCP Inspector: Visual tool for testing your MCP tools

  • Server Logs: Enable with DEBUG=true npm run dev:server or in config

<summary>Configuration (Click to expand)</summary>

Create ~/.mcp/configs.json:

{
  "boilerplate": {
    "environments": {
      "DEBUG": "true",
      "ANY_OTHER_CONFIG": "value"
    }
  }
}

Building Custom Tools

<summary>Step-by-Step Tool Implementation Guide (Click to expand)</summary>

1. Define Service Layer

Create a new service in src/services/ to interact with your external API:

// src/services/example.service.ts
import { Logger } from '../utils/logger.util.js';

const logger = Logger.forContext('services/example.service.ts');

export async function getData(param: string): Promise<any> {
    logger.debug('Getting data', { param });
    // API interaction code here
    return { result: 'example data' };
}

2. Create Controller

Add a controller in src/controllers/ to handle business logic:

// src/controllers/example.controller.ts
import { Logger } from '../utils/logger.util.js';
import * as exampleService from '../services/example.service.js';
import { formatMarkdown } from '../utils/formatter.util.js';
import { handleControllerError } from '../utils/error-handler.util.js';
import { ControllerResponse } from '../types/common.types.js';

const logger = Logger.forContext('controllers/example.controller.ts');

export interface GetDataOptions {
    param?: string;
}

export async function getData(
    options: GetDataOptions = {},
): Promise<ControllerResponse> {
    try {
        logger.debug('Getting data with options', options);

        const data = await exampleService.getData(options.param || 'default');

        const content = formatMarkdown(data);

        return { content };
    } catch (error) {
        throw handleControllerError(error, {
            entityType: 'ExampleData',
            operation: 'getData',
            source: 'controllers/example.controller.ts',
        });
    }
}

3. Implement MCP Tool

Create a tool definition in src/tools/:

// src/tools/example.tool.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import { Logger } from '../utils/logger.util.js';
import { formatErrorForMcpTool } from '../utils/error.util.js';
import * as exampleController from '../controllers/example.controller.js';

const logger = Logger.forContext('tools/example.tool.ts');

const GetDataArgs = z.object({
    param: z.string().optional().describe('Optional parameter'),
});

type GetDataArgsType = z.infer<typeof GetDataArgs>;

async function handleGetData(args: GetDataArgsType) {
    try {
        logger.debug('Tool get_data called', args);

        const result = await exampleController.getData({
            param: args.param,
        });

        return {
            content: [{ type: 'text' as const, text: result.content }],
        };
    } catch (error) {
        logger.error('Tool get_data failed', error);
        return formatErrorForMcpTool(error);
    }
}

export function register(server: McpServer) {
    server.tool(
        'get_data',
        `Gets data from the example API, optionally using \`param\`.
Use this to fetch example data. Returns formatted data as Markdown.`,
        GetDataArgs.shape,
        handleGetData,
    );
}

4. Add CLI Support

Create a CLI command in src/cli/:

// src/cli/example.cli.ts
import { program } from 'commander';
import { Logger } from '../utils/logger.util.js';
import * as exampleController from '../controllers/example.controller.js';
import { handleCliError } from '../utils/error-handler.util.js';

const logger = Logger.forContext('cli/example.cli.ts');

program
    .command('get-data')
    .description('Get example data')
    .option('--param <value>', 'Optional parameter')
    .action(async (options) => {
        try {
            logger.debug('CLI get-data called', options);

            const result = await exampleController.getData({
                param: options.param,
            });

            console.log(result.content);
        } catch (error) {
            handleCliError(error);
        }
    });

5. Register Components

Update the entry points to register your new components:

// In src/cli/index.ts
import '../cli/example.cli.js';

// In src/index.ts (for the tool)
import exampleTool from './tools/example.tool.js';
// Then in registerTools function:
exampleTool.register(server);

Publishing Your MCP Server

  1. Update package.json with your details:

    {
      "name": "your-mcp-server-name",
      "version": "1.0.0",
      "description": "Your custom MCP server",
      "author": "Your Name",
      // Other fields...
    }
  2. Update README.md with your tool documentation

  3. Build: npm run build
  4. Test: npm run start:server
  5. Publish: npm publish

Testing Best Practices

  • Unit Tests: Test utils and pure functions in isolation
  • Controller Tests: Test business logic with mocked service calls
  • Integration Tests: Test CLI with real dependencies
  • Coverage Goal: Aim for >80% test coverage

License

ISC License

Resources

changelog

1.10.5 (2025-06-02)

Bug Fixes

  • replace Unix-specific chmod with cross-platform ensure-executable script (6733798)

1.10.4 (2025-06-02)

Bug Fixes

1.10.3 (2025-05-21)

Bug Fixes

  • Refactor IP address controller to accept args as a single object (acb7ea2)
  • update dependencies (02c42fa)

1.10.2 (2025-05-21)

Bug Fixes

1.10.1 (2025-05-20)

Bug Fixes

1.10.0 (2025-05-19)

Features

1.9.0 (2025-05-18)

Features

  • refactor services to use live API tests and remove timeout parameter (3c483b4)

1.8.0 (2025-05-18)

Features

  • refactor ControllerResponse to only include content field (68118c7)

1.7.0 (2025-05-17)

Features

  • improve ip_get_details tool description and CLI usability with short options (895feeb)

1.6.0 (2025-05-15)

Features

  • enhanced error handling across the application (75aa905)

1.5.10 (2025-05-14)

Bug Fixes

  • remove Dockerfile and smithery.yaml (582e9f9)

1.5.9 (2025-05-13)

Bug Fixes

1.5.8 (2025-05-07)

Performance Improvements

1.5.7 (2025-05-06)

Performance Improvements

1.5.6 (2025-05-06)

Performance Improvements

1.5.5 (2025-05-06)

Bug Fixes

  • Revert back the index.ts and package.json (74c6e08)

1.5.4 (2025-05-05)

Bug Fixes

  • improve signal handling for npx support (72634a8)

1.5.3 (2025-05-05)

Bug Fixes

  • standardize index.ts entrypoint logic and package bin (7f9aaf0)

Reverts

  • Revert "fix(test): Skip invalid IP test assertion on CI due to rate limits" (be8c766)

1.5.2 (2025-05-05)

Bug Fixes

  • Manually set version to 1.6.1 to resolve release conflict (a96c37b)
  • test: Skip invalid IP test assertion on CI due to rate limits (258d2e7)

Reverts

  • Revert "Revert "chore: Manually set version to 1.6.0 to resolve release conflict"" (e4d071e)

1.5.1 (2025-05-05)

Bug Fixes

  • Add comment to force version bump (0a24ecd)
  • Improve cross-platform compatibility for npx execution (d840c51)
  • Log package name and version on startup (b4534db)

Performance Improvements

1.5.1 (2025-05-05)

Bug Fixes

  • Add comment to force version bump (0a24ecd)
  • Improve cross-platform compatibility for npx execution (d840c51)
  • Log package name and version on startup (b4534db)

Performance Improvements

1.5.1 (2025-05-05)

Bug Fixes

  • Add comment to force version bump (0a24ecd)
  • Improve cross-platform compatibility for npx execution (d840c51)
  • Log package name and version on startup (b4534db)

Performance Improvements

1.5.1 (2025-05-05)

Bug Fixes

  • Improve cross-platform compatibility for npx execution (d840c51)
  • Log package name and version on startup (b4534db)

Performance Improvements

1.5.0 (2025-05-05)

Features

  • boilerplate: add standard pagination utils and formatPagination (cb1e004)

1.4.9 (2025-05-04)

Performance Improvements

1.4.8 (2025-05-04)

Bug Fixes

  • Refactor types using Zod and restore resources (4965bd2)

1.4.7 (2025-05-04)

Bug Fixes

  • Remove unused exports identified by ts-prune (c9fdc7d)

1.4.6 (2025-05-02)

Bug Fixes

1.4.5 (2025-05-02)

Bug Fixes

  • Remove re-exports from index.ts (5175dcf)

1.4.4 (2025-05-02)

Performance Improvements

1.4.3 (2025-05-01)

Bug Fixes

  • Align CLI options and descriptions with style guide (0f5f490)
  • align README tool example with concise description style (b8126a4)

1.4.2 (2025-05-01)

Bug Fixes

  • align ipaddress CLI descriptions with tool/schema (1eeaeeb)

1.4.1 (2025-04-30)

Performance Improvements

1.4.0 (2025-04-30)

Features

  • Support multiple keys for global config lookup (49c26f1)

1.3.5 (2025-04-25)

Bug Fixes

  • rename IP tool to 'ip_get_details' for naming consistency (fb2a5c6)
  • unify tool description for clarity and consistency (006460b)

1.3.4 (2025-04-22)

Performance Improvements

1.3.3 (2025-04-20)

Bug Fixes

  • Update dependencies and fix related type errors (dfdec0a)

1.3.2 (2025-04-09)

Bug Fixes

  • deps: update dependencies to latest versions (97baabe)

1.3.1 (2025-04-04)

Bug Fixes

  • update function references from register to registerTools and registerResources (393cff2)

1.3.0 (2025-04-03)

Features

  • logging: add file logging with session ID to ~/.mcp/data/ (0448918)

1.2.2 (2025-04-03)

Bug Fixes

  • logging: ensure consistent logger implementation across projects (253323e)

1.2.1 (2025-04-03)

Bug Fixes

  • logger: ensure consistent logger implementation across all projects (ec37c74)

1.2.0 (2025-04-03)

Features

  • boilerplate: improve version handling and module exports (faa1713)

1.1.3 (2025-03-28)

Bug Fixes

  • correct TypeScript errors in transport utility (573a7e6)

1.1.2 (2025-03-28)

Performance Improvements

  • ipaddress: enhance formatter output and optimize service implementation (f1ccdbf)

1.1.1 (2025-03-27)

Performance Improvements

  • core: refactor code structure to align with Atlassian MCP patterns (090fd56)
  • standards: align codebase with Atlassian MCP server patterns (8b8eb13)
  • tests: add CLI test infrastructure and ipaddress tests (ccee308)
  • utils: implement standardized core utilities and error handling (6c14a2f)

1.1.0 (2025-03-23)

Features

  • improve development workflow and update documentation (4458957)

1.0.3 (2025-03-23)

Bug Fixes

  • handle empty strings properly in greet function (546d3a8)

1.0.2 (2025-03-23)

Bug Fixes

  • improve error logging with IP address details (121f516)

1.0.1 (2025-03-23)

Bug Fixes

  • ensure executable permissions for bin script (395f1dc)

1.0.0 (2025-03-22)

Bug Fixes

  • add workflows permission to semantic-release workflow (de3a335)
  • improve GitHub Packages publishing with a more robust approach (fd2aec9)
  • improve GitHub Packages publishing with better error handling and debugging (db25f04)
  • improve GITHUB_OUTPUT syntax in semantic-release workflow (6f154bc)
  • improve version detection for global installations (97a95dc)
  • make publish workflow more resilient against version conflicts (ffd3705)
  • remove invalid workflows permission (c012e46)
  • remove type module to fix CommonJS compatibility (8b1f00c)
  • resolve linter errors in version detection code (5f1f33e)
  • update examples to use correct API (greet instead of sayHello) (7c062ca)
  • update release workflow to ensure correct versioning in compiled files (a365394)
  • update version display in CLI (2b7846c)

Features

  • add automated dependency management (efa1b62)
  • add CLI usage examples for both JavaScript and TypeScript (d5743b0)
  • add support for custom name in greet command (be48a05)
  • add version update script and fix version display (ec831d3)
  • implement review recommendations (a23cbc0)
  • implement testing, linting, and semantic versioning (1d7710d)
  • improve CI workflows with standardized Node.js version, caching, and dual publishing (0dc9470)
  • improve package structure and add better examples (bd66891)

Reverts

  • restore simple version handling (bd0fadf)

1.8.0 (2025-03-22)

Features

  • add CLI usage examples for both JavaScript and TypeScript (d5743b0)

1.7.2 (2025-03-22)

Bug Fixes

  • update release workflow to ensure correct versioning in compiled files (a365394)

1.7.1 (2025-03-22)

Bug Fixes

  • update examples to use correct API (greet instead of sayHello) (7c062ca)

1.7.0 (2025-03-22)

Features

  • improve package structure and add better examples (bd66891)

1.6.1 (2025-03-22)

Bug Fixes

  • improve GitHub Packages publishing with better error handling and debugging (db25f04)

1.6.0 (2025-03-22)

Features

  • add support for custom name in greet command (be48a05)

1.5.2 (2025-03-22)

Bug Fixes

  • add workflows permission to semantic-release workflow (de3a335)
  • improve GITHUB_OUTPUT syntax in semantic-release workflow (6f154bc)
  • make publish workflow more resilient against version conflicts (ffd3705)
  • remove invalid workflows permission (c012e46)

1.5.2 (2025-03-22)

Bug Fixes

  • make publish workflow more resilient against version conflicts (ffd3705)

1.5.1 (2025-03-22)

Bug Fixes

  • improve GitHub Packages publishing with a more robust approach (fd2aec9)

1.5.0 (2025-03-22)

Features

  • improve CI workflows with standardized Node.js version, caching, and dual publishing (0dc9470)