Metadata-Version: 2.4
Name: langchain_mcp_client
Version: 0.3.0
Project-URL: Home, https://github.com/datalayer/langchain-mcp-client
Author-email: Datalayer <info@datalayer.io>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Datalayer
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
        ---
        
        This library reuse part of Jupyter Server code licensed under BSD 3-Clause License
        Source: https://github.com/jupyter-server/jupyter_server/blame/v2.12.0/jupyter_server/services/kernels/connection/base.py
        
        This library reuse part of traitlets code licensed under BSD 3-Clause License
        Source: https://github.com/ipython/traitlets/blob/v5.14.3/traitlets/log.py
License-File: LICENSE
Keywords: Jupyter
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Requires-Dist: jsonschema-pydantic>=0.6
Requires-Dist: langchain-anthropic>=0.3.1
Requires-Dist: langchain-aws
Requires-Dist: langchain-github-copilot
Requires-Dist: langchain-groq>=0.2.3
Requires-Dist: langchain-openai>=0.3.0
Requires-Dist: langchain>=0.3.14
Requires-Dist: langgraph>=0.2.62
Requires-Dist: mcp>=1.2.0
Requires-Dist: pyjson5>=1.6.8
Requires-Dist: pympler>=1.1
Requires-Dist: python-dotenv>=1.0.1
Provides-Extra: lint
Requires-Dist: mdformat-gfm>=0.3.5; extra == 'lint'
Requires-Dist: mdformat>0.7; extra == 'lint'
Requires-Dist: ruff; extra == 'lint'
Provides-Extra: test
Requires-Dist: ipykernel; extra == 'test'
Requires-Dist: jupyter-server<3,>=1.6; extra == 'test'
Requires-Dist: pytest>=7.0; extra == 'test'
Provides-Extra: typing
Requires-Dist: mypy>=0.990; extra == 'typing'
Description-Content-Type: text/markdown

<!--
  ~ Copyright (c) 2023-2024 Datalayer, Inc.
  ~
  ~ BSD 3-Clause License
-->

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

[![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)

# 🦜 🔗 LangChain MCP Client

[![Github Actions Status](https://github.com/datalayer/langchain-mcp-client/workflows/Build/badge.svg)](https://github.com/datalayer/langchain-mcp-client/actions/workflows/build.yml)
[![PyPI - Version](https://img.shields.io/pypi/v/langchain-mcp-client)](https://pypi.org/project/langchain-mcp-client)

This simple [Model Context Protocol (MCP)](https://modelcontextprotocol.io) client demonstrates the use of MCP server tools by LangChain ReAct Agent.

- 🌐 Seamlessly connect to any MCP servers.
- 🤖 Use any LangChain-compatible LLM for flexible model selection.
- 💬 Interact via CLI, enabling dynamic conversations.

## Conversion to LangChain Tools

It leverages a utility function `convert_mcp_to_langchain_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)).

## Installation

The python version should be 3.11 or higher.

```bash
pip install langchain_mcp_client
```

## Configuration

Create a `.env` file containing all the necessary `API_KEYS` to access your LLM.

Configure the LLM, MCP servers, and prompt example in the `llm_mcp_config.json5` file:

1. **LLM Configuration**: Set up your LLM parameters.
2. **MCP Servers**: Specify the MCP servers to connect to.
3. **Example Queries**: Define example queries that invoke MCP server tools. Press Enter to use these example queries when prompted.

## Usage

Below an example with a [Jupyter MCP Server](https://github.com/datalayer/jupyter-mcp-server):

Check the `llm_mcp_config.json5` configuration (commands depends if you are running on Linux or macOS/Windows).

```bash
# Start jupyterlab.
make jupyterlab
```

```bash
# Launch the CLI.
make cli
```

This is a prompt example.

```
create matplolib examples with many variants in jupyter
```

![](https://assets.datalayer.tech/jupyter-mcp/jupyter-mcp-server-cli.gif)

## Credits

This initial code of this repo is taken from [hideya/mcp-client-langchain-py](https://github.com/hideya/mcp-client-langchain-py) (MIT License) and from [`langchain_mcp_tools`](https://github.com/hideya/langchain-mcp-tools-py) (MIT License).
