mcp-task-api
Transforms a NestJS REST API into an MCP server for AI agents to manage tasks securely via standardized tools.
README
NestJS MCP/REST API
<p align="center"> <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> </p> <p align="center"> <a href="README.pt-br.md">π§π· Leia em PortuguΓͺs</a> </p>
A demonstration of integrating enterprise REST APIs with AI Agents using the Model Context Protocol (MCP ).
This project illustrates how to transform a conventional NestJS API into an MCP server, enabling AI agents (such as Claude and ChatGPT) to interact directly with business logic in a secure, standardized way with high code reusability.
π‘ Problem & Solution
The Challenge
Integrating AI agents with internal systems usually requires building custom connectors or insecurely exposing API keys within prompts. Furthermore, keeping API documentation (like Swagger) in sync with AI "skills" creates significant maintenance overhead.
The MCP Approach
By leveraging the Model Context Protocol, this API exposes a single standardized endpoint that describes its capabilities to the AI.
-
Security: Maintains authentication via API Key.
-
Engineering: Reuses 100% of existing NestJS Services and Controllers.
-
Scalability: Enables the AI to perform complex operations (CRUD) without requiring specific integration code on the client side.
π οΈ Tech Stack
-
Framework: NestJS (Node.js)
-
Language: TypeScript
-
ORM: Prisma with SQLite
-
Protocol: @modelcontextprotocol/sdk
-
Package Manager: PNPM
πΏ Branch Structure
To facilitate learning, the repository is organized into:
-
master: Initial REST API boilerplate (starting point for the tutorial). -
final: Complete implementation with the MCP server configured and integrated.
π Setup & Installation
1. Environment Configuration
cp .env.example .env
Generate a secure key for API_KEY:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
2. Installation & Database
pnpm install
pnpm prisma migrate dev
pnpm prisma generate
3. Execution
# Development mode
pnpm run start:dev
π MCP Interface (Model Context Protocol)
The core advantage of this project is the MCP layer. You can inspect how the AI "sees" your API using the official Inspector:
npx @modelcontextprotocol/inspector --cli http://localhost:3000/mcp --transport http --method tools/list --header "X-API-Key: YOUR_KEY_HERE"
Why is this relevant for Engineering?
Unlike a simple webhook, MCP provides a typed schema of tools. When the AI asks "which tasks are pending?", the MCP server maps this intent directly to TasksService.findAll( ), ensuring that business rules are strictly followed.
π Security & Production
-
SSL/TLS: Essential for production. AI agents require HTTPS for secure communication.
-
Ports: Using the standard port
443is recommended to avoid connectivity issues on platforms like ChatGPT. -
Authentication: Implemented via
X-API-Keyin the header, ensuring only authorized agents can invoke the tools.
π¨βπ» About the Author
David FernandesFull Stack Developer specialized in React, Next.js, and TypeScript.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.