Model context protocol connector for LangChain
Project description
Langchain Model Context Protocol Connector
Introduction
This project introduces tools to easily integrate Anthropic Model Context Protocol(MCP) with langchain. It provides a simple way to connect to MCP servers and access tools that can be made available to LangChain.
MCP integrations with langchain expands the capabilities of LLM by providing access to an ecosystem of community build servers and additional resources. This means that we do not need to create custom tools for each LLM, but rather use the same tools across different LLMs.
Installation
pip install langchain-mcp-connect
What is the Model Context Protocol (MCP)?
The Model Context Protocol (MCP) is an open-source standard released by Anthropic. The Model Context Protocol highlights the importance of tooling standardisation through open protocols. Specifically, it standardises how applications interact and provide context to LLMs. Just like how HTTP standardises how we communicate across the internet, MCP provides a standard protocol for LLM to interact with external tools. You can find out more about the MCP at https://github.com/modelcontextprotocol and https://modelcontextprotocol.io/introduction.
Example usage
The langchain_mcp_connect contain key methods to determine available tools
in the model context protocol. Before starting,
please ensure you meet the pre-requisites.
For a detail example on how langchain_mcp_connect can be used, see this demo project.
Pre requisites
- Install uv
Defining a tool
Define your tool within claude_mcp_config.json file in the root directory. For a list
of available tools and how to configure tools see here.
{
"mcpServers": {
"git": {
"command": "uvx",
"args": ["mcp-server-git", "--repository", "./"]
},
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"./"
]
},
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ENV_GITHUB_PERSONAL_ACCESS_TOKEN"
}
}
}
}
Environment Variables
Managing secrets is a key aspect of any project. The langchain_mcp_connect tool is
able to inject secrets from the current environment.
To do so, prefix the name of your environment variable with
ENV_ in claude_mcp_config.json to inject environment variables into the current
context. In the example above, ensure you have defined GITHUB_PERSONAL_ACCESS_TOKEN
in your current environment with:
export GITHUB_PERSONAL_ACCESS_TOKEN="<YOUR_TOKEN_HERE>"
export OPENAI_API_KEY="<YOUR_KEY_HERE>"
Running the example
uv run src/example/agent.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_mcp_connect-2.0.3.tar.gz.
File metadata
- Download URL: langchain_mcp_connect-2.0.3.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d94e2fb1d04366946443d82912813be974aec87e7817fd7ac2f84c5e57b172f7
|
|
| MD5 |
f12b3ded53a5bfadc1f09203d18ea685
|
|
| BLAKE2b-256 |
9f9092dcf2d05b590c7fa6025cfe5ff16851e0c0579f26d8c209a5af8c42b295
|
File details
Details for the file langchain_mcp_connect-2.0.3-py3-none-any.whl.
File metadata
- Download URL: langchain_mcp_connect-2.0.3-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
124e44842729e47d6caaaa87170b14b59504a5ebeb2e6d377c7c52a2b089fa84
|
|
| MD5 |
f5c496bd00dc701fc74d0c0c636d3c63
|
|
| BLAKE2b-256 |
0fbd015302187846eb0a61f608f75320e2d1685d0ce9083997be4bf82ac05041
|