This project demonstrates a Python LangChain / LangGraph agent that uses the Model Context Protocol (MCP) to for example browse the web via the Microsoft Playwright MCP server, then answers user queries with retrieved page context.
- Node.js 18+
- Python 3.11+
- npm
- Chrome browser
This project requires API keys to function. Follow these steps to set up your environment:
cp .env.example .envOpen the .env file in VS Code and replace your_api_key_here with your actual API key.
Update the following line in your .env file:
GENAI_API_KEY=your_actual_api_key_here
The .env file should contain:
GENAI_API_KEY: Your API key (required)LLM_PROVIDER: Set to eitheranthropicorazure(default:anthropic)- Other configuration options with sensible defaults
.env file to version control. The .env file is already included in .gitignore to prevent accidental commits.
# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
source .venv/bin/activate
# Upgrade pip and install dependencies
pip install --upgrade pip
pip install -r requirements.txt# Create virtual environment
python -m venv .venv
# Activate virtual environment
.venv\Scripts\activate
# Upgrade pip and install dependencies
python -m pip install --upgrade pip
pip install -r requirements.txtNote: VS Code can automatically detect and activate your virtual environment. Look for the Python interpreter selector in the bottom-left status bar.
When you're done working on the project:
deactivateYou have two ways to run the Playwright MCP server:
This repo now contains a minimal package.json. Install dependencies:
npm installStart the MCP servers (you might require to disable VPN during the initial installation that happens after starting it):
npm run mcpFor windows:
npm run mcp-winor windows powershell:
npm run mcp-psYou should see output like:
Listening on http://localhost:8931
Put this in your client config:
{
"mcpServers": {
"playwright": { "url": "http://localhost:8931/mcp" }
}
}
Ensure the MCP server is listening (one of the options above), then:
python -m research.runThe agent will:
- Connect to the MCP servers
- Use the provided tools
- Produce a concise summary
You can update the research/run.py and change the prompt for the agent to solve.
There is a great UI that you can start that will make use of our agent. To do that:
- Clone the repo: https://github.com/langchain-ai/deep-agents-ui/tree/main
- Follow readme and use the following as config:
NEXT_PUBLIC_DEPLOYMENT_URL="http://127.0.0.1:2024" # Or your server URL
NEXT_PUBLIC_AGENT_ID="research"
- Run our agent using langgraph server:
langgraph dev --config research/langgraph.json - Run UI:
npm install
npm run dev
- Open the UI under http://localhost:3000 and start asking questions.
python test_mcp_integration.pyThis project is provided as-is for demonstration purposes.