langchain-mcp-tools


Namelangchain-mcp-tools JSON
Version 0.1.4 PyPI version JSON
download
home_pageNone
SummaryModel Context Protocol (MCP) To LangChain Tools Conversion Utility
upload_time2025-01-23 01:40:33
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords modelcontextprotocol mcp mcp-client langchain langchain-python tool-call tool-calling python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MCP To LangChain Tools Conversion Utility [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/hideya/langchain-mcp-tools-py/blob/main/LICENSE) [![pypi version](https://img.shields.io/pypi/v/langchain-mcp-tools.svg)](https://pypi.org/project/langchain-mcp-tools/)

This package is intended to simplify the use of
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
server tools with LangChain / Python.

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/),
introduced by
[Anthropic](https://www.anthropic.com/news/model-context-protocol),
extends the capabilities of LLMs by enabling interaction with external tools and resources,
such as web search and database access.
Thanks to its open-source nature, MCP has gained significant traction in the developer community,
with over 400 MCP servers already developed and shared:

- [Glama’s list of Open-Source MCP servers](https://glama.ai/mcp/servers)
- [Smithery: MCP Server Registry](https://smithery.ai/)
- [awesome-mcp-servers](https://github.com/hideya/awesome-mcp-servers#Server-Implementations)
- [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)

In the MCP framework, external features are encapsulated in an MCP server,
which typically runs in a separate process and communicates
via `stdio` using the open standard protocol.
This clean decoupling makes it easy to adopt and reuse any of
the significant collections of MCP servers listed above.

To make it easy for LangChain users to take advantage of such a vast resource base,
this package offers quick and seamless access from LangChain to MCP servers.

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.

A typescript equivalent of this utility is available
[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)

## Requirements

- Python 3.11+

## Installation

```bash
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](https://modelcontextprotocol.io/quickstart/user),
but only the contents of the `mcpServers` property,
and is expressed as a `dict`, e.g.:

```python
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]`](https://python.langchain.com/api_reference/core/tools/langchain_core.tools.base.BaseTool.html#langchain_core.tools.base.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.:

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

# from langgraph.prebuilt import create_react_agent
agent = create_react_agent(
    llm,
    tools
)
```
A simple and experimentable usage example can be found
[here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)

A more realistic usage example can be found
[here](https://github.com/hideya/mcp-client-langchain-py)


## Limitations

Currently, only text results of tool calls are supported.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "langchain-mcp-tools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "modelcontextprotocol, mcp, mcp-client, langchain, langchain-python, tool-call, tool-calling, python",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/80/4a/2893db35660eee2534f292855c9096e481262e49bb48a6d16bb972764ab9/langchain_mcp_tools-0.1.4.tar.gz",
    "platform": null,
    "description": "# MCP To LangChain Tools Conversion Utility [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/hideya/langchain-mcp-tools-py/blob/main/LICENSE) [![pypi version](https://img.shields.io/pypi/v/langchain-mcp-tools.svg)](https://pypi.org/project/langchain-mcp-tools/)\n\nThis package is intended to simplify the use of\n[Model Context Protocol (MCP)](https://modelcontextprotocol.io/)\nserver tools with LangChain / Python.\n\n[Model Context Protocol (MCP)](https://modelcontextprotocol.io/),\nintroduced by\n[Anthropic](https://www.anthropic.com/news/model-context-protocol),\nextends the capabilities of LLMs by enabling interaction with external tools and resources,\nsuch as web search and database access.\nThanks to its open-source nature, MCP has gained significant traction in the developer community,\nwith over 400 MCP servers already developed and shared:\n\n- [Glama\u2019s list of Open-Source MCP servers](https://glama.ai/mcp/servers)\n- [Smithery: MCP Server Registry](https://smithery.ai/)\n- [awesome-mcp-servers](https://github.com/hideya/awesome-mcp-servers#Server-Implementations)\n- [MCP Get Started/Example Servers](https://modelcontextprotocol.io/examples)\n\nIn the MCP framework, external features are encapsulated in an MCP server,\nwhich typically runs in a separate process and communicates\nvia `stdio` using the open standard protocol.\nThis clean decoupling makes it easy to adopt and reuse any of\nthe significant collections of MCP servers listed above.\n\nTo make it easy for LangChain users to take advantage of such a vast resource base,\nthis package offers quick and seamless access from LangChain to MCP servers.\n\nIt contains a utility function `convert_mcp_to_langchain_tools()`.  \nThis async function handles parallel initialization of specified multiple MCP servers\nand converts their available tools into a list of LangChain-compatible tools.\n\nA typescript equivalent of this utility is available\n[here](https://www.npmjs.com/package/@h1deya/langchain-mcp-tools)\n\n## Requirements\n\n- Python 3.11+\n\n## Installation\n\n```bash\npip install langchain-mcp-tools\n```\n\n## Quick Start\n\n`convert_mcp_to_langchain_tools()` utility function accepts MCP server configurations\nthat follow the same structure as\n[Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),\nbut only the contents of the `mcpServers` property,\nand is expressed as a `dict`, e.g.:\n\n```python\nmcp_configs = {\n    'filesystem': {\n        'command': 'npx',\n        'args': ['-y', '@modelcontextprotocol/server-filesystem', '.']\n    },\n    'fetch': {\n        'command': 'uvx',\n        'args': ['mcp-server-fetch']\n    }\n}\n\ntools, cleanup = await convert_mcp_to_langchain_tools(\n    mcp_configs\n)\n```\n\nThis utility function initializes all specified MCP servers in parallel,\nand returns LangChain Tools\n([`tools: List[BaseTool]`](https://python.langchain.com/api_reference/core/tools/langchain_core.tools.base.BaseTool.html#langchain_core.tools.base.BaseTool))\nby gathering available MCP tools from the servers,\nand by wrapping them into LangChain tools.\nIt also returns an async callback function (`cleanup: McpServerCleanupFn`)\nto be invoked to close all MCP server sessions when finished.\n\nThe returned tools can be used with LangChain, e.g.:\n\n```python\n# from langchain.chat_models import init_chat_model\nllm = init_chat_model(\n    model='claude-3-5-haiku-latest',\n    model_provider='anthropic'\n)\n\n# from langgraph.prebuilt import create_react_agent\nagent = create_react_agent(\n    llm,\n    tools\n)\n```\nA simple and experimentable usage example can be found\n[here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)\n\nA more realistic usage example can be found\n[here](https://github.com/hideya/mcp-client-langchain-py)\n\n\n## Limitations\n\nCurrently, only text results of tool calls are supported.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Model Context Protocol (MCP) To LangChain Tools Conversion Utility",
    "version": "0.1.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/hideya/langchain-mcp-tools-py/issues",
        "Source Code": "https://github.com/hideya/langchain-mcp-tools-py"
    },
    "split_keywords": [
        "modelcontextprotocol",
        " mcp",
        " mcp-client",
        " langchain",
        " langchain-python",
        " tool-call",
        " tool-calling",
        " python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "79237f77051ea340180c0af3b9a33c596625a760ef0e54780ca31fa59373e013",
                "md5": "f272d878e5f76841f309ef28bfd19f54",
                "sha256": "a2df968b99f0c5f01336714878ffe2bd01fe3393de417bfa351db52d84b5a0fe"
            },
            "downloads": -1,
            "filename": "langchain_mcp_tools-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f272d878e5f76841f309ef28bfd19f54",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 7501,
            "upload_time": "2025-01-23T01:40:31",
            "upload_time_iso_8601": "2025-01-23T01:40:31.249474Z",
            "url": "https://files.pythonhosted.org/packages/79/23/7f77051ea340180c0af3b9a33c596625a760ef0e54780ca31fa59373e013/langchain_mcp_tools-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "804a2893db35660eee2534f292855c9096e481262e49bb48a6d16bb972764ab9",
                "md5": "5d08642e390f862d9aac3a9e09e88940",
                "sha256": "2f477918b53538b94bca30e242e3c4c676bbdd74686cd4f6537537242d2ef480"
            },
            "downloads": -1,
            "filename": "langchain_mcp_tools-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "5d08642e390f862d9aac3a9e09e88940",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 8288,
            "upload_time": "2025-01-23T01:40:33",
            "upload_time_iso_8601": "2025-01-23T01:40:33.053490Z",
            "url": "https://files.pythonhosted.org/packages/80/4a/2893db35660eee2534f292855c9096e481262e49bb48a6d16bb972764ab9/langchain_mcp_tools-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-23 01:40:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hideya",
    "github_project": "langchain-mcp-tools-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "langchain-mcp-tools"
}
        
Elapsed time: 0.41098s