A Simple chat application that uses the Model Context Protocol (MCP) to interact with AI models and tools.
This application provides a simple and intuitive chat interface for interacting with AI models that support the Model Context Protocol (MCP). It enables calling external tools through the MCP server and displays the results in a user-friendly chat interface.

The application is structured as follows:
- server.js: Express server that handles HTTP requests and manages the chat sessions.
- mcpClient.js: Contains the client implementation for the Model Context Protocol.
- mcpServer.js: Server script that implements the tools accessible via MCP.
- public/index.html: Frontend chat interface.
- MCPClient: Handles communication with the MCP server, processes user queries, and manages tool calls.
- MCPManager: Manages multiple MCP client instances for different user sessions.
- Express Server: Provides REST API endpoints for the chat functionality.
- Frontend: A responsive chat UI built with HTML, CSS, and JavaScript.
- Node.js (v14 or higher)
- npm (Node Package Manager)
-
Clone the repository:
git clone <repository-url> cd mcp-node
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following content:ANTHROPIC_API_KEY=your_anthropic_api_key
-
Start the server:
node server.js
-
Open your browser and navigate to:
http://localhost:3000
-
Start chatting! You can ask questions that might require external tools.
-
POST /api/chat: Send a message to the chat
- Request body:
{ "message": "Your message here" }
- Response: JSON with chat response and history
- Request body:
-
POST /api/chat/clear: Clear the current chat session
-
GET /api/chat/history: Get the chat history for the current session
To add new tools to the MCP server, modify the mcpServer.js
file:
- Define a new tool function
- Register the tool with the MCP server
- Implement the tool's functionality
- Anthropic for the Claude AI model API
- Model Context Protocol (MCP) for enabling tool use with AI models