ARTICLE AD BOX
MCP-Use is an open-source room that lets you link immoderate LLM to immoderate MCP server, giving your agents instrumentality entree for illustration web browsing, record operations, and much — each without relying connected closed-source clients. In this tutorial, we’ll usage langchain-groq and MCP-Use’s built-in speech representation to build a elemental chatbot that tin interact pinch devices via MCP.
Installing uv package manager
We will first group up our situation and commencement pinch installing nan uv package manager. For Mac aliases Linux:
For Windows (PowerShell):
Creating a caller directory and activating a virtual environment
We will past create a caller task directory and initialize it pinch uv
We tin now create and activate a virtual environment. For Mac aliases Linux:
For Windows:
Installing Python dependencies
We will now instal nan required dependencies
Groq API Key
To usage Groq’s LLMs:
- Visit Groq Console and make an API key.
- Create a .env record successful your task directory and adhd nan pursuing line:
Replace <YOUR_API_KEY> pinch nan cardinal you conscionable generated.
Brave Search API Key
This tutorial uses nan Brave Search MCP Server.
- Get your Brave Search API cardinal from: Brave Search API
- Create a record named mcp.json successful nan task guidelines pinch nan pursuing content:
Replace <YOUR_BRAVE_SEARCH_API> pinch your existent Brave API key.
Node JS
Some MCP servers (including Brave Search) require npx, which comes pinch Node.js.
- Download nan latest type of Node.js from nodejs.org
- Run nan installer.
- Leave each settings arsenic default and complete nan installation
Using different servers
If you’d for illustration to usage a different MCP server, simply switch nan contents of mcp.json pinch nan configuration for that server.
Create an app.py record successful nan directory and adhd nan pursuing content:
Importing nan libraries
This conception loads situation variables and imports required modules for LangChain, MCP-Use, and Groq. It besides suppresses ResourceWarning for cleaner output.
Setting up nan chatbot
This conception loads nan Groq API cardinal from nan .env record and initializes nan MCP customer utilizing nan configuration provided successful mcp.json. It past sets up nan LangChain Groq LLM and creates a memory-enabled supplier to grip conversations.
Implementing nan chatbot
This conception enables interactive chatting, allowing nan personification to input queries and person responses from nan assistant. It besides supports clearing nan chat history erstwhile requested. The assistant’s responses are displayed successful real-time, and nan codification ensures that each MCP sessions are closed cleanly erstwhile nan speech ends aliases is interrupted.
Running nan app
This conception runs nan asynchronous chatbot loop, managing continuous relationship pinch nan user. It besides handles keyboard interruptions gracefully, ensuring nan programme exits without errors erstwhile nan personification terminates nan session.
You tin find nan full codification here
To tally nan app, tally nan pursuing command
This will commencement nan app, and you tin interact pinch nan chatbot and usage nan server for nan session
I americium a Civil Engineering Graduate (2022) from Jamia Millia Islamia, New Delhi, and I person a keen liking successful Data Science, particularly Neural Networks and their exertion successful various areas.