Sponsored by Deepsite.site

Simple CLI MCP Client Using LangChain / Python

Created By
hideyaa year ago
Simple CLI MCP Client Implementation Using LangChain ReAct Agent / Python
Content

Simple CLI MCP Client Using LangChain / Python License: MIT

This simple Model Context Protocol (MCP) client with command line interface demonstrates the use of MCP server tools by the LangChain ReAct Agent.

It leverages a utility function convert_mcp_to_langchain_tools() from langchain_mcp_tools.
This function handles parallel initialization of specified multiple MCP servers and converts their available tools into a list of LangChain-compatible tools (list[BaseTool]).

LLMs from Anthropic, OpenAI and Groq are currently supported.

A typescript version of this MCP client is available here

Prerequisites

  • Python 3.11+
  • [optional] uv (uvx) installed to run Python package-based MCP servers
  • [optional] npm 7+ (npx) to run Node.js package-based MCP servers
  • API keys from Anthropic, OpenAI, and/or Groq as needed

Setup

  1. Install dependencies:

    make install
    
  2. Setup API keys:

    cp .env.template .env
    
    • Update .env as needed.
    • .gitignore is configured to ignore .env to prevent accidental commits of the credentials.
  3. Configure LLM and MCP Servers settings llm_mcp_config.json5 as needed.

    • The configuration file format for MCP servers follows the same structure as Claude for Desktop, with one difference: the key name mcpServers has been changed to mcp_servers to follow the snake_case convention commonly used in JSON configuration files.
    • The file format is JSON5, where comments and trailing commas are allowed.
    • The format is further extended to replace ${...} notations with the values of corresponding environment variables.
    • Keep all the credentials and private info in the .env file and refer to them with ${...} notation as needed.

Usage

Run the app:

make start

It takes a while on the first run.

Run in verbose mode:

make start-v

See commandline options:

make start-h

At the prompt, you can simply press Enter to use example queries that perform MCP server tool invocations.

Example queries can be configured in llm_mcp_config.json5

Recommend Clients
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
HyperChatHyperChat is a Chat client that strives for openness, utilizing APIs from various LLMs to achieve the best Chat experience, as well as implementing productivity tools through the MCP protocol.
LINKAGOGO-MCP---BOOKMARK-MANAGERManage your LinkaGoGo bookmarks through any AI assistant that supports the Model Context Protocol (MCP). Search, add, organize, tag, move, and export bookmarks conversationally โ€” 16 tools for full bookmark and folder management. Connect via Claude.ai, Claude Desktop, or any MCP-compatible client.
y-cli ๐Ÿš€A Tiny Terminal Chat App for AI Models with MCP Client Support
ChatWiseThe second fastest AI chatbotโ„ข
LutraLutra is the first MCP compatible client built for everyone
ZedCode at the speed of thought โ€“ Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
MCP ConnectEnables cloud-based AI services to access local Stdio based MCP servers via HTTP requests
CursorThe AI Code Editor
Roo Code (prev. Roo Cline)Roo Code (prev. Roo Cline) gives you a whole dev team of AI agents in your code editor.
MCP PlaygroundCall MCP Server Tools Online
Cherry Studio๐Ÿ’ Cherry Studio is a desktop client that supports for multiple LLM providers.
chatmcpChatMCP is an AI chat client implementing the Model Context Protocol (MCP).
DeepChatYour AI Partner on Desktop
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
Cline โ€“ #1 on OpenRouterAutonomous coding agent right in your IDE, capable of creating/editing files, executing commands, using the browser, and more with your permission every step of the way.
Refact.aiOpen-source AI Agent for VS Code and JetBrains that autonomously solves coding tasks end-to-end.
Continueโฉ Create, share, and use custom AI code assistants with our open-source IDE extensions and hub of models, rules, prompts, docs, and other building blocks
A Sleek AI Assistant & MCP Client5ire is a cross-platform desktop AI assistant, MCP client. It compatible with major service providers, supports local knowledge base and tools via model context protocol servers .