Skip to main content
Glama

mcp-template

A template for building MCP servers in TypeScript that a model uses correctly on the first try — whether it runs in an agent harness that fetches tool schemas on demand or in a small local model that carries every schema on every turn.

It was extracted from a production MCP server and stripped of its domain. What is left is the machinery that made that server reliable, with an in-memory notes store standing in for a real backend so that every pattern has a working, tested example.

What you get

  • One-file tools. A tool is a definition plus a run(args) that returns plain data. Dispatch, timing, the MCP envelope and error mapping live in one base class; the router, tools/list and the contract tests are all derived from the definitions, so a listed tool is always callable and tested.

  • Honest annotations. All four MCP hints on every tool, held there by tests — including on the wire, which is what directories such as OpenAI's check.

  • Profiles. MCP_PROFILE picks which tools are listed and routable, so a small client carries a small menu and readonly genuinely cannot write.

  • A response budget. An over-sized answer is replaced by valid JSON that names the next step, never by a fragment a model will retry.

  • A capability gate. Tools the backend cannot serve are withheld before tools/list answers, and every failure path fails open.

  • Self-documentation. The guides in docs/ and the skills in skills/ are served as MCP resources and through readServerGuide / readSkill, so an agent can look things up by itself.

  • Session recovery. Connect on demand, reconnect and retry once after a dropped session, and never retry a refused credential — retries lock accounts.

  • Two transports. stdio, and Streamable HTTP with one backend session per caller's bearer token, sessions bound to their token, origin and host allow-lists, and a per-session rate limit.

  • Docs that cannot drift. The tool reference is generated and a test compares it; server.json is checked against every environment variable the code reads.

  • A container. A two-stage Dockerfile that ships the docs and skills the server reads at runtime.

Related MCP server: notes-box

Quick start

git clone --recurse-submodules <this repository> my-server
cd my-server
npm install
npm run build
npm test
npm run smoke        # drives the built server over stdio
npm run dev          # the MCP Inspector, against the build

Register it with a client:

{
  "mcpServers": {
    "notes": {
      "command": "node",
      "args": ["C:/path/to/my-server/dist/index.js"]
    }
  }
}

Making it yours

AGENTS.md has the step-by-step list. In short: rename it in package.json and server.json, replace the backend in src/backend/ and the tools in src/handlers/, rewrite the domain parts of the docs, and swap the example skill. Every place that needs a decision is marked TEMPLATE::

grep -rn "TEMPLATE" --exclude-dir=node_modules --exclude-dir=dist .

Asking an agent to do it? Point it at AGENTS.md first — it was written for exactly that.

Configuration

Everything is optional; the example runs with no configuration. See .env.example.

Variable

Default

Effect

MCP_PROFILE

all

core, readonly or all — which tools are listed and callable

MCP_MAX_RESPONSE_BYTES

per profile

Ceiling on one answer; 0 removes it

MCP_GATE

on

off skips asking the backend which features it has

MCP_TRANSPORT

stdio

http for Streamable HTTP at /mcp

MCP_HTTP_PORT, MCP_HTTP_HOST

3000, 0.0.0.0

Where HTTP mode listens

MCP_HTTP_ALLOWED_ORIGINS

none

Browser origins allowed; * for any

MCP_HTTP_ALLOWED_HOSTS

any

Host values answered to

MCP_HTTP_RATE_LIMIT

0 (off)

Requests per minute per session

EXAMPLE_ACCEPTED_TOKENS

none

Example backend: bearer tokens HTTP callers may present

Running it for a team, over HTTP or in Docker: docs/Hosting.md.

Documentation

Document

For

AGENTS.md

Working on this code — conventions, layout, how to test, how to start a new server

docs/MCP-Tools.md

How the server behaves: architecture, profiles, budget, gate, errors, troubleshooting

docs/Tool-Router.md

Which tool does what, in the words people use

docs/Tool-Reference.md

Every tool and argument — generated, never edited by hand

docs/Hosting.md

stdio, Streamable HTTP, Docker

docs/Development-Skills.md

The bundled engineering skills

CONTEXT.md, docs/adr

Vocabulary and design decisions

The guides are served to clients too: ask the running server with readServerGuide.

Development

npm run build          # tsc -> dist/
npm test               # vitest, fully offline
npx tsc --noEmit       # type check only
npm run docs:tools     # regenerate docs/Tool-Reference.md after changing a tool (needs a build)
npm run smoke          # the built server over real stdio

License

MIT — see LICENSE.

Available Tools

9 tools
createNoteA

Create a note and return it with its new id. Calling it twice creates two notes — search first if the note might already exist.

Inputs: title (required), body, tags.

deleteNoteA
DestructiveIdempotent

Delete a note permanently. Answers deleted:false rather than failing when the note does not exist, so a repeated call is harmless.

Inputs: id (required).

healthcheckA
Read-onlyIdempotent

What this server is bound to, whether the backend answers, and per-handler call metrics. Call it to find out whether this is the right server for a request that names a target — a server cannot switch target at runtime — or when calls start failing. It never connects to the backend, so it answers when everything else fails. Also reports the active tool profile, the response budget, and anything withheld because the backend does not support it.

Inputs: no named parameters.

listTagsA
Read-onlyIdempotent

Every tag in use and how many notes carry it, most used first. Use it to find the tag to pass to searchNotes.

Inputs: no named parameters.

readNoteA
Read-onlyIdempotent

One note in full — title, body, tags and when it last changed — by its id.

Inputs: id (required).

readServerGuideA
Read-onlyIdempotent

This server's own documentation. Call with no arguments for an index of the available guides and their sections, then request one section by number or title. Use it when you are unsure which tool to use, what an argument means, how a workflow fits together, or why a call is failing.

Inputs: guide, section.

readSkillA
Read-onlyIdempotent

Bundled agent skills — reusable procedures for working with this server and for general engineering (TDD, code review, diagnosing bugs, domain modelling…). Call with no arguments to see which exist, then pass collection for their descriptions and skill to read one. Consult a skill's SKILL.md before starting a task it covers: they carry the conventions and checklists the tool descriptions alone do not.

Inputs: file, skill, collection.

searchNotesA
Read-onlyIdempotent

Find notes by text and/or tag, newest first. Returns summaries with a short preview — not the full body; read one with readNote. total is the number of matches before the limit, so a smaller notes list means there is more to page through.

Inputs: tag, text, limit, offset.

updateNoteA
DestructiveIdempotent

Replace the title, body and/or tags of an existing note. Fields you omit are kept; tags replaces the whole list. Returns the note as it now is, and changed:false when the note already had these values.

Inputs: id (required), body, tags, title.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 9 tools

    Disambiguation4/5

    The note tools are cleanly separated by action and resource: readNote, searchNotes, createNote, updateNote, deleteNote, and listTags have clear boundaries. The meta tools readServerGuide, readSkill, and healthcheck all serve help/troubleshooting purposes and could be mildly confused, though their descriptions distinguish them.

    Naming Consistency4/5

    Most tools follow a consistent camelCase verb_noun pattern: readNote, searchNotes, createNote, updateNote, deleteNote, listTags, readServerGuide, readSkill. healthcheck is the lone noun-style outlier, but it remains readable and understandable.

    Tool Count5/5

    Nine tools is well-scoped for a notes server with built-in documentation: six core note/tag operations plus three meta/help tools. Each tool has a clear reason to exist, and the set does not feel padded or thin.

    Completeness4/5

    The server covers full note CRUD plus search and tag listing, which handles the main lifecycle. Minor gaps remain—no tag rename/delete, no batch operations, and no explicit list-all-notes tool—but agents can work around these using searchNotes and updateNote.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Provides a TypeScript MCP server scaffold that exposes tested, one-file tools to models with profile-scoped listings, honest annotations, response budgets, capability gating, and self-served guides and skills. Ships an in-memory notes backend as a working example and runs over stdio or Streamable HTTP.
      3
      GPL 3.0