MCP ExplorerExplorer

Langchain Mcp Tools Py Usage

@hideyaon a year ago
6 MIT
FreeCommunity
AI Systems
#langchain#langchain-python#mcp#mcp-client#modelcontextprotocol#python#tool-call#tool-calling
Simple MCP Client Using LangChain / Python

Overview

What is Langchain Mcp Tools Py Usage

langchain-mcp-tools-py-usage is a simple Model Context Protocol (MCP) client built using LangChain and Python. It demonstrates the use of MCP server tools through the LangChain ReAct Agent.

Use cases

Use cases include building conversational agents, integrating multiple AI tools, and enhancing applications with advanced language models.

How to use

To use langchain-mcp-tools-py-usage, first install the dependencies using ‘make install’. Then, set up your API key by copying the .env.template to .env and updating it as needed. Finally, run the application with ‘make start’.

Key features

Key features include the ability to initialize multiple MCP servers in parallel and convert their tools into a list of LangChain-compatible tools. It utilizes Anthropic’s ‘claude-3-7-sonnet-latest’ as the LLM.

Where to use

langchain-mcp-tools-py-usage can be used in various fields such as AI development, natural language processing, and any application requiring integration with MCP servers.

Content

MCP Tools Usage From LangChain / Example in Python License: MIT

This simple Model Context Protocol (MCP)
client demonstrates the use of MCP server tools by 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]).

Anthropic’s claude-3-7-sonnet-latest is used as the LLM.
For convenience, code for OpenAI’s o3-mini is also included and commented out.

A bit more realistic (conversational) MCP Client is available
here

A typescript equivalent 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 key from Anthropic
    (or OpenAI)

Usage

  1. Install dependencies:

    make install
    
  2. Setup API key:

    cp .env.template .env
    
    • Update .env as needed.
    • .gitignore is configured to ignore .env
      to prevent accidental commits of the credentials.
  3. Run the app:

make start

It takes a while on the first run.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers