Installing mcp_use
Prerequisites :
For Python: Install Python (version 3.11 or higher)
For TypeScript: Install Node.js (version 18 or higher)
Install the library
Install mcp_use using your preferred package manager: Python (pip)
TypeScript (npm)
Python (Poetry)
TypeScript (yarn)
Python (Conda)
TypeScript (pnpm)
Install LLM provider
Choose and install your preferred LangChain provider: Python (OpenAI)
TypeScript (OpenAI)
Python (Anthropic)
TypeScript (Anthropic)
Python (Google)
TypeScript (Google)
Python (Groq)
TypeScript (Groq)
pip install langchain-openai
Set up environment
Create a .env file for your API keys: OPENAI_API_KEY = your_openai_key_here
ANTHROPIC_API_KEY = your_anthropic_key_here
GROQ_API_KEY = your_groq_key_here
GOOGLE_API_KEY = your_google_key_here
Verify installation
Test your installation with a simple script: from mcp_use import MCPAgent, MCPClient
print ( "mcp_use installed successfully!" )
Development Installation
If you want to contribute or use the latest features, install from source:
Python (Git Clone)
Python (Dev Mode)
git clone https://github.com/mcp-use/mcp-use.git
cd mcp-use/libraries/python
pip install -e .
Installing MCP Servers
mcp_use connects to MCP servers that provide the actual tools. Here are some popular ones:
Playwright (Web Scraping)
npx @playwright/mcp@latest
Filesystem Server
pip install mcp-server-filesystem
SQLite Server
pip install mcp-server-sqlite
Environment Setup
Using Virtual Environments
It’s recommended to use virtual environments to avoid dependency conflicts:
python -m venv mcp_env
source mcp_env/bin/activate # On Windows: mcp_env\Scripts\activate
pip install mcp-use langchain-openai
Environment Variables
Create a .env file in your project root:
# LLM Provider Keys
OPENAI_API_KEY = sk-...
ANTHROPIC_API_KEY = sk-ant-...
GROQ_API_KEY = gsk_...
GOOGLE_API_KEY = AI...
# Optional: Logging level
LOG_LEVEL = INFO
# Optional: MCP server paths
MCP_SERVER_PATH = /path/to/mcp/servers
Load environment variables in your scripts:
from dotenv import load_dotenv
import os
load_dotenv()
# Your API keys are now available as environment variables
openai_key = os.getenv( "OPENAI_API_KEY" )
Verification
Verify your installation works correctly:
import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient
async def verify_installation ():
load_dotenv()
# Simple configuration for testing
config = {
"mcpServers" : {
"test" : {
"command" : "echo" ,
"args" : [ "Hello from MCP!" ]
}
}
}
try :
client = MCPClient(config)
print ( "✅ MCPClient created successfully" )
llm = ChatOpenAI( model = "gpt-3.5-turbo" )
print ( "✅ LLM initialized successfully" )
agent = MCPAgent( llm = llm, client = client)
print ( "✅ MCPAgent created successfully" )
print ( " \n 🎉 Installation verified! You're ready to use mcp_use." )
except Exception as e:
print ( f "❌ Verification failed: { e } " )
print ( "Please check your installation and API keys." )
if __name__ == "__main__" :
asyncio.run(verify_installation())
Next Steps
Troubleshooting
Import errors or module not found
Make sure you’re in the correct virtual environment and that mcp_use is installed:
Verify your .env file is in the correct location and your API keys are valid: cat .env # Check file contents
python -c "import os; from dotenv import load_dotenv; load_dotenv(); print(os.getenv('OPENAI_API_KEY'))"
Ensure your MCP servers are properly installed and accessible: which npx # For Node.js-based servers
pip list | grep mcp-server # For Python-based servers
Tool Calling Required : Only models with tool calling capabilities can be used with mcp_use. Make sure your chosen model supports function calling or tool use.