https://github.com/hideya/langchain-mcp-tools-py-usage
Simple MCP Client Using LangChain / Python
https://github.com/hideya/langchain-mcp-tools-py-usage
langchain langchain-python mcp mcp-client modelcontextprotocol python tool-call tool-calling
Last synced: 7 months ago
JSON representation
Simple MCP Client Using LangChain / Python
- Host: GitHub
- URL: https://github.com/hideya/langchain-mcp-tools-py-usage
- Owner: hideya
- License: mit
- Created: 2025-01-14T05:14:53.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-03-13T11:27:25.000Z (7 months ago)
- Last Synced: 2025-03-13T12:30:41.778Z (7 months ago)
- Topics: langchain, langchain-python, mcp, mcp-client, modelcontextprotocol, python, tool-call, tool-calling
- Language: Python
- Homepage:
- Size: 412 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple MCP Client Using LangChain / Python [](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/LICENSE)
This simple [Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
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`](https://pypi.org/project/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]](https://python.langchain.com/api_reference/core/tools/langchain_core.tools.base.BaseTool.html#langchain_core.tools.base.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](https://github.com/hideya/mcp-client-langchain-py)A typescript equivalent of this MCP client is available
[here](https://github.com/hideya/langchain-mcp-tools-ts-usage)## Prerequisites
- Python 3.11+
- [optional] [`uv` (`uvx`)](https://docs.astral.sh/uv/getting-started/installation/)
installed to run Python package-based MCP servers
- [optional] [npm 7+ (`npx`)](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
to run Node.js package-based MCP servers
- API key from [Anthropic](https://console.anthropic.com/settings/keys)
(or [OpenAI](https://platform.openai.com/api-keys))## Usage
1. Install dependencies:
```bash
make install
```2. Setup API key:
```bash
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:
```bash
make start
```
It takes a while on the first run.