- Explore MCP Servers
- mcp_langchain_examples
Mcp Langchain Examples
What is Mcp Langchain Examples
mcp_langchain_examples is a project that demonstrates how to integrate Model Control Protocol (MCP) with LangChain to create AI agents. It utilizes DuckDuckGo for web searches, showcasing the configuration and orchestration of tools to enhance the capabilities of AI agents.
Use cases
Use cases include building AI chatbots that can perform web searches, creating intelligent assistants for information retrieval, and developing applications that require real-time data access from the web.
How to use
To use mcp_langchain_examples, install the required dependencies using either ‘uv’ or ‘pip’, configure your Google API key in a .env file, and then run the MCP server using the provided commands.
Key features
Key features include integration of MCP with LangChain, the use of DuckDuckGo for web searches, a modular project structure with clear separation of components, and the ability to extend functionality by integrating additional tools and models.
Where to use
mcp_langchain_examples can be used in fields such as AI development, web search applications, and any domain requiring intelligent agents that can interact with external tools and services.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Mcp Langchain Examples
mcp_langchain_examples is a project that demonstrates how to integrate Model Control Protocol (MCP) with LangChain to create AI agents. It utilizes DuckDuckGo for web searches, showcasing the configuration and orchestration of tools to enhance the capabilities of AI agents.
Use cases
Use cases include building AI chatbots that can perform web searches, creating intelligent assistants for information retrieval, and developing applications that require real-time data access from the web.
How to use
To use mcp_langchain_examples, install the required dependencies using either ‘uv’ or ‘pip’, configure your Google API key in a .env file, and then run the MCP server using the provided commands.
Key features
Key features include integration of MCP with LangChain, the use of DuckDuckGo for web searches, a modular project structure with clear separation of components, and the ability to extend functionality by integrating additional tools and models.
Where to use
mcp_langchain_examples can be used in fields such as AI development, web search applications, and any domain requiring intelligent agents that can interact with external tools and services.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
MCP LangChain Integration Example
This project serves as a tutorial on integrating Model Control Protocol (MCP) with LangChain to build AI agents. By using a web search tool (DuckDuckGo) as an example, it demonstrates how to configure and orchestrate tools to enhance the agent’s capabilities. The concepts and implementation can be extended to integrate other tools and models.
Overview
The application uses:
- MCP (Model Control Protocol): Provides a standardized way for models to interact with external tools
- LangChain: For agent creation and orchestration
- Google’s Gemini 2.0 Flash: As the underlying AI model
- DuckDuckGo Search: As an external tool for web searches
Project Structure
server.py: Implements the MCP server with DuckDuckGo search functionalityprompt.py: Contains the system prompt that instructs the AI how to respondmain.py: Main application that connects the model, tools, and user inputrequirements.txt: Lists all required dependencies
Prerequisites
- Python 3.8+
- Google API key (for Gemini model access)
Installation
There are two methods to install the dependencies:
Method 1: Using uv (recommended)
# Install uv first if you don't have it
# For macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
# For Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Create virtual environment and install dependencies
uv venv
uv sync
Method 2: Using pip
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
Configuration
- Create a
.envfile in the project root directory - Add your Google API key:
GOOGLE_API_KEY=your_api_key_here
Running the Application
Start the MCP Server
First, start the MCP server:
# Using uv
uv run .\src\server.py
# Or using Python directly (after activating virtual environment)
python .\src\server.py
Run the Main Application
In a separate terminal:
# Using uv
uv run .\src\main.py
# Or using Python directly (after activating virtual environment)
python .\src\main.py
How It Works
- The MCP server provides a search tool that connects to DuckDuckGo
- The main application creates a reactive agent using LangChain and Gemini
- User questions are passed to the agent
- The agent follows the system prompt to always use the search tool
- Results are formatted and returned to the user
Example Usage
When you run main.py, you’ll be prompted to enter a question. The agent will:
- Process your question
- Use the DuckDuckGo search tool to find relevant information
- Format and return an answer based on the search results
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










