Skip to main content
Glama
JeonJunYeong

sample-mcp

by JeonJunYeong

sample-mcp

NestJS + TypeScript MCP (Model Context Protocol) server boilerplate.

This project is intentionally small. Use it as a starting point when you want to add your own MCP tools and serve them through either stdio or Streamable HTTP.

Features

  • NestJS dependency injection for MCP tools

  • MCP SDK Server integration

  • stdio transport for MCP clients such as Claude Desktop and Cursor

  • Streamable HTTP transport for local HTTP testing

  • Zod-based input validation

  • ESLint + Prettier setup for TypeScript

Related MCP server: NestJS MCP Server

Project Structure

src/
  main.ts                         # Transport bootstrap: stdio or HTTP
  app.module.ts                   # Root Nest module
  config/
    app.config.ts                 # Environment config
  mcp/
    mcp.module.ts                 # MCP Nest module
    mcp.service.ts                # MCP server and request handlers
    http/
      mcp-http.controller.ts      # POST /mcp Streamable HTTP endpoint
    tools/
      base.tool.ts                # Base class for tools
      tool.registry.ts            # Tool list and execution registry
      tools.module.ts             # Nest providers for tools
      ping/
        ping.dto.ts               # Zod schema and output type
        ping.tool.ts              # Example tool implementation

Setup

pnpm install

Copy .env.example to .env if you want local overrides.

MCP_SERVER_NAME=sample-mcp
MCP_SERVER_VERSION=1.0.0
LOG_LEVEL=log
NODE_ENV=development
TRANSPORT=stdio
PORT=3000

Run

stdio mode

pnpm start

Use stdio mode when another MCP client launches this server process.

HTTP mode

pnpm run start:http

The MCP endpoint is:

POST http://localhost:3000/mcp

HTTP requests must include:

Accept: application/json, text/event-stream
Content-Type: application/json

Test With HTTP

List tools:

$body = @{
  jsonrpc = "2.0"
  id = 1
  method = "tools/list"
  params = @{}
} | ConvertTo-Json -Depth 10

Invoke-RestMethod `
  -Method Post `
  -Uri "http://localhost:3000/mcp" `
  -ContentType "application/json" `
  -Headers @{ Accept = "application/json, text/event-stream" } `
  -Body $body

Call the sample ping tool:

$body = @{
  jsonrpc = "2.0"
  id = 2
  method = "tools/call"
  params = @{
    name = "ping"
    arguments = @{
      message = "hello"
    }
  }
} | ConvertTo-Json -Depth 10

Invoke-RestMethod `
  -Method Post `
  -Uri "http://localhost:3000/mcp" `
  -ContentType "application/json" `
  -Headers @{ Accept = "application/json, text/event-stream" } `
  -Body $body

Add A New MCP Tool

  1. Create a folder under src/mcp/tools/<tool-name>/.

  2. Create a Zod schema file, for example <tool-name>.dto.ts.

  3. Create a tool class that extends BaseTool.

  4. Add the tool class to ToolsModule.providers.

  5. Inject it into ToolRegistry and add it to registerTools([...]).

Minimal tool shape:

import { Injectable } from '@nestjs/common';
import type { CallToolResult, Tool } from '@modelcontextprotocol/sdk/types.js';
import { BaseTool } from '../base.tool';

@Injectable()
export class MyTool extends BaseTool {
  get definition(): Tool {
    return {
      name: 'my-tool',
      description: 'Describe what this tool does.',
      inputSchema: {
        type: 'object',
        properties: {
          input: { type: 'string' },
        },
        required: ['input'],
      },
    };
  }

  execute(args: Record<string, unknown>): Promise<CallToolResult> {
    return Promise.resolve(this.success({ args }));
  }
}

Quality Checks

This boilerplate uses ESLint 8 with .eslintrc.cjs for broad editor and CLI compatibility.

pnpm lint
pnpm run lint:fix
pnpm exec tsc --noEmit
pnpm run build
F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JeonJunYeong/sample-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server