Skip to main content

Model Context Protocol (MCP) To LangChain Tools Conversion Utility

Project description

MCP To LangChain Tools Conversion Utility License: MIT pypi version

This package is intended to simplify the use of Model Context Protocol (MCP) server tools with LangChain / Python.

Model Context Protocol (MCP), an open source technology announced by Anthropic, dramatically expands LLM’s scope by enabling external tool and resource integration, including Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…

Over 800 functional components available as MCP servers:

The goal of this utility is to make these 800+ MCP servers readily accessible from LangChain.

It contains a utility function convert_mcp_to_langchain_tools().
This async function handles parallel initialization of specified multiple MCP servers and converts their available tools into a list of LangChain-compatible tools.

For detailed information on how to use this library, please refer to the following document:

A typescript equivalent of this utility is available here

Prerequisites

  • Python 3.11+

Installation

pip install langchain-mcp-tools

Quick Start

convert_mcp_to_langchain_tools() utility function accepts MCP server configurations that follow the same structure as Claude for Desktop, but only the contents of the mcpServers property, and is expressed as a dict, e.g.:

mcp_configs = {
    'filesystem': {
        'command': 'npx',
        'args': ['-y', '@modelcontextprotocol/server-filesystem', '.']
    },
    'fetch': {
        'command': 'uvx',
        'args': ['mcp-server-fetch']
    }
}

tools, cleanup = await convert_mcp_to_langchain_tools(
    mcp_configs
)

This utility function initializes all specified MCP servers in parallel, and returns LangChain Tools (tools: List[BaseTool]) by gathering available MCP tools from the servers, and by wrapping them into LangChain tools. It also returns an async callback function (cleanup: McpServerCleanupFn) to be invoked to close all MCP server sessions when finished.

The returned tools can be used with LangChain, e.g.:

# from langchain.chat_models import init_chat_model
llm = init_chat_model(
    model='claude-3-5-sonnet-latest',
    model_provider='anthropic'
)

# from langgraph.prebuilt import create_react_agent
agent = create_react_agent(
    llm,
    tools
)

Find complete, minimal working usage examples here

For hands-on experimentation with MCP server integration, try this LangChain application built with the utility

For detailed information on how to use this library, please refer to the following document:
"Supercharging LangChain: Integrating 800+ MCP with ReAct"

Limitations

Currently, only text results of tool calls are supported.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_mcp_tools-0.1.7.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_mcp_tools-0.1.7-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_mcp_tools-0.1.7.tar.gz.

File metadata

  • Download URL: langchain_mcp_tools-0.1.7.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for langchain_mcp_tools-0.1.7.tar.gz
Algorithm Hash digest
SHA256 0876a4aec7a69dd82207cd3e358046b0efa1fdf7c19b6f4fc160dd851eddd89c
MD5 085eb2777c6345753ad7e03e3b823a39
BLAKE2b-256 2d6df65d17b7ca032b6fa6a2003ca147566a4d2b71ef8a946f26bb7b4fc12e15

See more details on using hashes here.

File details

Details for the file langchain_mcp_tools-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_mcp_tools-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 78d33b59ade4a7130a728cdc06251818ea8b47adbf9551dd38fa3e867bb2257f
MD5 948cf8be24fb7d4c4f7e267d7cbc527a
BLAKE2b-256 51772d395a6792484d0e241cc40e3c00b4e9fd1a5105b7270d74ebce248f9d98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page