A robust Python client for interacting with Model Context Protocol (MCP) servers. Built with LangChain and LangGraph, it enables you to chat with multiple MCP servers simultaneously using a natural language interface on the CLI or a Web UI.
- Multi-Server Support: Connect to unlimited MCP servers (local processes or remote HTTP/SSE).
- Secure Authentication: Securely inject API keys and OAuth tokens via Environment Variables (
${VAR}). - Streaming Responses: Real-time token-by-token generation in the CLI.
- Customizable Agent: Configure the System Prompt and LLM Provider via
.env. - Web Interface: Optional Flask-based UI for browser interaction.
- Dremio Integration: Native helper script for Dremio OAuth flow.
Clone the repository and install dependencies:
git clone https://github.com/AlexMercedCoder/langchain-mcp-client.git
cd langchain-mcp-client
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate a .env file from the example:
cp .env.example .envEdit .env to add your LLM API Key (e.g., OpenAI):
OPENAI_API_KEY=sk-...
LLM_MODEL=openai:gpt-4o
SYSTEM_PROMPT="You are a helpful assistant."Start the interactive CLI:
python client.pyDefine your servers in mcp_servers.json.
Connect to local processes using the stdio transport. Ideal for secure, local-only tools like filesystem access or SQLite interaction.
{
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/files"],
"transport": "stdio"
},
"sqlite": {
"command": "uvx",
"args": ["mcp-server-sqlite", "--db-path", "./my.db"],
"transport": "stdio"
}
}Connect to public MCP servers via HTTP.
{
"weather": {
"url": "https://weather-mcp.example.com",
"transport": "streamable_http"
}
}Never commit secrets to mcp_servers.json.
Instead, use the ${VAR_NAME} syntax. The client will automatically substitute these with values from your .env file at runtime.
In .env:
MY_OAUTH_TOKEN=secret-123In mcp_servers.json:
{
"secure-api": {
"url": "https://api.example.com/mcp",
"transport": "streamable_http",
"headers": {
"Authorization": "Bearer ${MY_OAUTH_TOKEN}"
}
}
}To query Dremio Data Catalogs, you must authenticate via OAuth.
- Create App: In Dremio, register a "Native" OAuth App with Redirect URI:
http://localhost:8000/callback - Configure
.env:DREMIO_CLIENT_ID=your-client-id
- Get Token: Run the helper script:
Login via the browser link provided.
python auth_dremio.py
- Save Token: Copy the resulting token to
.env:DREMIO_TOKEN=eyJhbGci...
- Configure Server:
"dremio": { "url": "https://mcp.dremio.cloud/mcp/<PROJECT_ID>", "transport": "streamable_http", "headers": { "Authorization": "Bearer ${DREMIO_TOKEN}" } }
Customize the agent's personality or rules by setting SYSTEM_PROMPT in .env.
SYSTEM_PROMPT="You are a SQL expert. Always check schemas before querying."Prefer a browser UI?
python webui.pyOpen http://localhost:5000 to chat.
The client uses LangChain, so it supports OpenAI, Anthropic, Google Vertex, etc.
Change LLM_MODEL in .env:
openai:gpt-4oanthropic:claude-3-sonnet(requiresANTHROPIC_API_KEY)google:gemini-pro(requiresGOOGLE_API_KEY)
Keep the core libraries up to date:
pip install --upgrade -r requirements.txtRun tests to ensure environment substitution and agent creation are working:
python verify_changes.pyMIT