NestJS MCP Server module enables AI tools resources prompts with secure transport for enterprise applications
MCP-Nest Server, built on NestJS and the Model Context Protocol (MCP), provides a powerful framework for integrating AI applications with various data sources and tools through a standardized protocol. This server module enables developers to effortlessly expose tools, resources, and prompts, making it an invaluable tool in the development of AI-driven solutions.
The MCP-Nest Server supports multiple transport mechanisms including Streamable HTTP, HTTP+SSE (Server-Sent Events), and STDIO. Each transport type offers unique advantages for different use cases, ensuring flexibility in deployment scenarios and seamless integration with various environments.
A key feature of MCP-Nest Server is its ability to automatically discover, validate, and register tools, resources, and prompts. This automation simplifies the development process by reducing manual configuration requirements, allowing developers to focus on building complex applications without getting bogged down in setup details.
MCP-Nest Server leverages Zod for tool call validation, ensuring that requests adhere to predefined schemas before processing. This not only enhances the security of the server but also provides real-time feedback to clients when invalid data is submitted, improving overall user experience.
The MCP-Nest Server supports sending progress notifications during long-running operations. This feature enables clients, such as AI applications, to provide real-time updates and status information to users, enhancing the efficiency of complex workflows.
To ensure that only authorized endpoints can be accessed, the server integrates with NestJS Guards. Developers can implement custom guards to validate requests based on specific criteria (e.g., JWT tokens or API keys), adding an extra layer of security and authentication.
To utilize MCP-Nest Server, developers need to import the McpModule into their NestJS application. This module facilitates defining tools, resources, and prompts within a familiar NestJS environment while leveraging dependency injection for seamless integration with existing codebases.
The provided tool definition example demonstrates how to use Zod to define parameters and handle asynchronous operations with progress updates:
@Tool({
name: 'hello-world',
description:
'Returns a greeting and simulates a long operation with progress updates',
parameters: z.object({
name: z.string().default('World'),
}),
})
async sayHello({ name }, context: Context) {
const greeting = `Hello, ${name}!`;
const totalSteps = 5;
for (let i = 0; i < totalSteps; i++) {
await new Promise((resolve) => setTimeout(resolve, 500));
// Send a progress update.
await context.reportProgress({
progress: (i + 1) * 20,
total: 100,
} as Progress);
}
return {
content: [{ type: 'text', text: greeting }],
};
}
The MCP-Nest Server supports both stateless and stateful modes, allowing developers to choose the operating mode based on their use case requirements. For instance, the Standard HTTP + SSE transport typically operates in a stateful manner where sessions are maintained between client and server.
For an example of using STDIO with MCP-Nest, refer to the quick start guide for standalone NestJS applications:
async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule, { logger: false });
return app.close();
}
void bootstrap();
To kickstart your project, install @rekog/mcp-nest, @modelcontextprotocol/sdk, and zod via npm:
npm install @rekog/mcp-nest @modelcontextprotocol/sdk zod
Imagine building a chatbot that interacts with users over an extended conversation, updating the user on the progress of each response generation. By leveraging MCP-Nest Server's ability to handle long operations and provide real-time updates, developers can ensure smooth, interactive experiences for end-users.
In this scenario, a data analyst uses an AI application that interfaces with various data sources via MCP-Nest Server. The server exposes tools and resources for data cleaning, transformation, and analysis, enabling the application to perform tasks on-the-fly without needing direct access to raw databases or APIs.
MCP-Nest Server supports multiple MCP clients out of the box, including well-known applications like Claude Desktop, Continue, and Cursor. These clients can seamlessly connect to the server using various transport protocols (Streamable HTTP, HTTP+SSE, STDIO), providing a versatile communication layer between AI applications and their underlying data sources.
The following table outlines the compatibility status of different MCP clients with MCP-Nest Server:
| MCP Client | Resources | Tools | Prompts | Status |
|---|---|---|---|---|
| Claude Desktop | ✅ | ✅ | ✅ | Full Support |
| Continue | ✅ | ✅ | ✅ | Full Support |
| Cursor | ❌ | ✅ | ❌ | Tools Only |
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
Here is an example of how to configure the MCP server in a client configuration file:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
To ensure secure access to your APIs, MCP-Nest Server allows the implementation of custom guards. Here's a basic example:
@Injectable()
export class ApiKeyGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean |ookie<any, any> {
const request = context.switchToHttp().getRequest();
if (request.headers['x-api-key'] === 'your-api-key') {
return true;
}
throw new UnauthorizedException('Invalid API key.');
}
}
Why should I use MCP-Nest Server for my AI application?
How does the STDIO transport mode work in MCP-Nest Server?
What are the key differences between the stateless and stateful modes of operation in MCP-Nest Server?
How do I set up custom verification logic for API access?
What tools are compatible with MCP-Nest Server, and where can I find more information about them?
To contribute to or develop with MCP-Nest Server:
Clone the Repository:
git clone https://github.com/rekog-mc/mcp-nest-server.git
cd mcp-nest-server
Install Dependencies:
npm install
Run Local Development Server:
npm run start
Contributions are welcome! To contribute code or improve documentation, follow these steps:
git checkout -b feature-branch.git push origin feature-branch
Join the growing community of developers using MSP technologies by signing up for forums, attending workshops, and participating in hackathons. Stay updated with the latest news, tutorials, and best practices through official documentation, blogs, and webinars provided by the project maintainers.
For a deeper dive into the Model Context Protocol (MCP), refer to the comprehensive documentation available on the official website. This resource covers every aspect of the protocol, from basic concepts to advanced configurations.
Explore real-world use cases and step-by-step tutorials to understand how MCP-Nest Server can be leveraged in various scenarios. These guides are invaluable for both new users and experienced developers looking to harness the full potential of MCP-Nest Server.
If you encounter any issues with MCP-Nest Server or have suggestions for new features, don't hesitate to submit an issue on GitHub or reach out to the support team. Your feedback is crucial for continuous improvement and enhancement of the product.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration