Skip to main content
Glama

NestJS MCP Tool Demo

A minimal NestJS app that lets Claude use MCP-style tools backed by hardcoded JSON.


Setup

npm install

Create a .env file in the project root:

ANTHROPIC_API_KEY=sk-ant-...your key here...
ANTHROPIC_MODEL=claude-2  # optional override; set this to a model your Anthropic key supports

Start the server:

npx nest start --watch
# or: npm run start:dev

Server runs on http://localhost:3000


Related MCP server: Logseq MCP Server

How to test in Postman

Endpoint

POST http://localhost:3000/ai/ask

Headers

Content-Type: application/json

Body (raw JSON)

{ "message": "What projects are currently active?" }

More example questions to try

{ "message": "Give me full details about the Alpha Launch project" }
{ "message": "Search for documents about authentication" }
{ "message": "Who owns the Gamma API project and what's the deadline?" }
{ "message": "List all projects and then show me the detail of the on-hold one" }

Example Postman response

{
  "answer": "There are two active projects:\n1. **Alpha Launch** (p1) — owned by Alice\n2. **Gamma API** (p3) — owned by Carol",
  "toolCallsUsed": ["get_project_list"],
  "timestamp": "2026-05-18T10:32:00.000Z"
}

The toolCallsUsed field shows exactly which MCP tools Claude chose to call. A log of every tool call is also written to tool-call-log.json in the project root.


Project structure

src/
  ai/
    tools.ts          ← JSON data + tool definitions + executor
    ai.service.ts     ← calls Claude API, runs the tool loop, writes logs
    ai.controller.ts  ← POST /ai/ask endpoint
    ai.module.ts
  app.module.ts
  main.ts

What happens inside (the tool loop)

  1. Postman sends { "message": "..." } to POST /ai/ask

  2. NestJS sends message + tool definitions to Claude API

  3. Claude replies with stop_reason: "tool_use" and picks a tool

  4. NestJS runs the tool against the hardcoded JSON → gets result

  5. NestJS writes the call to tool-call-log.json

  6. NestJS sends the result back to Claude

  7. Claude gives a final text answer (stop_reason: "end_turn")

  8. NestJS returns the answer + list of tools used to Postman

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A NestJS-based server that enables AI agents to interact with Logseq graphs through its HTTP API for managing notes, journals, and blocks. It features specialized tools for project development tracking, including progress logs, technical decisions, and workflow prompts.
    20 npm
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    A local Model Context Protocol (MCP) server that exposes custom tools to Claude Desktop, enabling direct interaction with your local environment. It provides a framework for building and integrating custom TypeScript tools into the Claude interface.
    3 npm
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    An MCP server that exposes structured Functional Requirements Documents (FRDs) to enable AI assistants like GitHub Copilot to automatically generate complete NestJS boilerplate architectures. It orchestrates the multi-phase creation of production-ready APIs including core CRUD, database integration, JWT authentication, and unit testing.
    1
    MIT