Building a Context-Aware Chatbot Using MCP and Node.js

Most chatbots today are limited. They can answer questions or guide users, but often fail to understand where the user is in an application or what task they are trying to complete. This issue was addressed by building a smarter chatbot using the Model Context Protocol (MCP) and Node.js.
This blog covers how MCP was used to create a context-aware chatbot that improves admin operations in an educational platform.
What is MCP?
Model Context Protocol (MCP) is a standard that allows AI models to interact with real-world applications in a structured and intelligent way. Instead of guessing or giving static responses, the AI can perform actions inside the app based on the current user context.
MCP acts as a bridge between the AI model and backend systems. It consists of four core components:
Server: The engine that connects tools and user sessions to the AI model
Tools: Defined operations the AI can invoke, such as create user or search boards
Resources: Application data the AI can use to understand the current state
Transport Layer: Manages communication between the AI and backend
Chatbot Implementation Overview
The chatbot was integrated into the admin panel of an educational platform. Unlike traditional chatbots, it performs real tasks such as creating users, updating boards, or searching records based on the current page the user is on.
For example, when the user is on the board listing page, the chatbot only offers context-relevant actions like create board or search board.
Key Features
1. Context Tracking
The chatbot tracks the user’s current module, page, and role. This allows it to suggest the most appropriate actions. Each user session stores details like active page, permitted operations, and recent activities.
2. Modular Tools
Custom tools were developed for specific operations such as creating a board or updating a user. Each tool is clearly defined, specifying required inputs and intended behavior, so the AI understands how to use them effectively.
3. Real-Time UI Updates
WebSocket integration ensures the UI reflects changes immediately. For instance, a command like search boards with keyword AKUEB results in a live update on the interface without requiring a page refresh.
4. Secure API Handling
All operations initiated by the AI are routed through authenticated API endpoints in the Node.js backend. Each session is tied to a verified user, and role-based access control restricts unauthorized operations.
5. Conversation Memory
The chatbot maintains short-term memory to enable smooth and continuous interactions. Older messages are trimmed to keep the session light and responsive.
Why MCP Adds Value
MCP makes the chatbot context-aware and action-oriented. Instead of providing generic replies, the assistant can:
Recognize the user’s current position within the app
Offer only valid actions based on user role and page
Use real backend tools to complete operations
Support administrators in completing tasks quickly and efficiently
This results in a smoother user experience, making complex tasks simple, especially for non-technical users managing educational content.
Subscribe to my newsletter
Read articles from Muhammad Hamdan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Muhammad Hamdan
Muhammad Hamdan
I am a MEAN Stack Developer with expertise in SQL, AWS, and Docker, and over 2 years of professional experience as a Software Engineer, building scalable and efficient solutions.