Skip to content

MagarongCandy/MCP_Tools

Repository files navigation

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


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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages