NestJS MCP Server logo

NestJS MCP Server

by LiusDev

This repository demonstrates a NestJS implementation of the Model Context Protocol (MCP) with a microservice architecture. It includes an MCP server and a client that integrates with LangChain.js.

View on GitHub

Last updated: N/A

What is NestJS MCP Server?

This is a NestJS-based implementation of the Model Context Protocol (MCP) showcasing a microservice architecture. It provides an MCP server that exposes tools, such as a function to get the current time, and an MCP backend that connects to the server using LangChain.js to process user queries.

How to use NestJS MCP Server?

  1. Clone the repository. 2. Install dependencies using npm install. 3. Rename .env.example to .env and add your OpenAI API key. 4. Start the MCP server using npm run start:dev mcp-server. 5. Start the MCP backend using npm run start:dev mcp-backend. 6. Send POST requests to the backend (e.g., http://localhost:3001) with a JSON payload like {"message": "What time is it in Viet Nam?"}.

Key features of NestJS MCP Server

  • Model Context Protocol (MCP) implementation

  • Microservice architecture with NestJS

  • Integration with LangChain.js

  • Ability to connect to multiple MCP servers

  • Example tool for retrieving current time

Use cases of NestJS MCP Server

  • Providing contextual information to LLMs

  • Building AI applications that require real-time data

  • Demonstrating the use of MCP with LangChain.js

  • Creating modular and scalable AI services

FAQ from NestJS MCP Server

What is the Model Context Protocol (MCP)?

MCP is a protocol for providing contextual information to large language models (LLMs).

What is NestJS?

NestJS is a framework for building efficient, scalable Node.js server-side applications.

What is LangChain.js?

LangChain.js is a framework for developing applications powered by language models.

How do I add more tools to the MCP server?

You can add more tools by implementing them in the mcp-server application and exposing them via the MCP protocol.

How do I connect to multiple MCP servers?

You can configure multiple MCP servers in the McpClientModule.register configuration in apps/mcp-backend/src/mcp-backend.module.ts.