From 5561b3b5f339542f4082df2f773b75d1591b0699 Mon Sep 17 00:00:00 2001 From: Patrick Donohoe Date: Thu, 26 Nov 2026 03:59:39 -0500 Subject: [PATCH 1/2] feat: load scoped floo tools in LangChain applications --- python/langchain-floo/.gitignore | 3 ++ python/langchain-floo/LICENSE | 21 ++++++++++ python/langchain-floo/README.md | 29 ++++++++++++++ python/langchain-floo/pyproject.toml | 21 ++++++++++ .../src/langchain_floo/__init__.py | 38 +++++++++++++++++++ python/langchain-floo/tests/test_tools.py | 17 +++++++++ 6 files changed, 129 insertions(+) create mode 100644 python/langchain-floo/.gitignore create mode 100644 python/langchain-floo/LICENSE create mode 100644 python/langchain-floo/README.md create mode 100644 python/langchain-floo/pyproject.toml create mode 100644 python/langchain-floo/src/langchain_floo/__init__.py create mode 100644 python/langchain-floo/tests/test_tools.py diff --git a/python/langchain-floo/.gitignore b/python/langchain-floo/.gitignore new file mode 100644 index 0000000..0c5ca2e --- /dev/null +++ b/python/langchain-floo/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +dist/ +.venv/ diff --git a/python/langchain-floo/LICENSE b/python/langchain-floo/LICENSE new file mode 100644 index 0000000..1e47d24 --- /dev/null +++ b/python/langchain-floo/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 floo contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/python/langchain-floo/README.md b/python/langchain-floo/README.md new file mode 100644 index 0000000..631c5ad --- /dev/null +++ b/python/langchain-floo/README.md @@ -0,0 +1,29 @@ +# langchain-floo + +Load floo tools into a Python LangChain agent. The tools use the permissions of the floo API key supplied by the application. + +Install from this repository: + +```bash +python -m pip install 'langchain-floo @ git+https://github.com/getfloo/floo-cli.git#subdirectory=python/langchain-floo' +``` + +Set `FLOO_KEY` in your application environment. To give an inventory assistant access to two read tools: + +```python +import asyncio + +from langchain_floo import load_floo_tools + + +async def main(): + tools = await load_floo_tools(tool_names=["list_orgs", "list_apps"]) + print([tool.name for tool in tools]) + + +asyncio.run(main()) +``` + +Pass the returned tools to LangChain's `create_agent`. Omit `tool_names` to load all tools exposed by floo to that credential. To supply the key from your application's secret store, pass `api_key` to `load_floo_tools`. + +[floo MCP guide](https://getfloo.com/docs/guides/mcp#langchain) diff --git a/python/langchain-floo/pyproject.toml b/python/langchain-floo/pyproject.toml new file mode 100644 index 0000000..31c56a3 --- /dev/null +++ b/python/langchain-floo/pyproject.toml @@ -0,0 +1,21 @@ +[build-system] +requires = ["hatchling>=1.27"] +build-backend = "hatchling.build" + +[project] +name = "langchain-floo" +version = "0.1.0" +description = "Load floo application deployment and hosting tools into a LangChain agent." +requires-python = ">=3.10" +readme = "README.md" +license = "MIT" +license-files = ["LICENSE"] +authors = [{ name = "floo" }] +dependencies = ["langchain-mcp-adapters>=0.3.2,<0.4", "langchain-core>=1,<2"] + +[project.urls] +Documentation = "https://getfloo.com/docs/guides/mcp#langchain" +Repository = "https://github.com/getfloo/floo-cli/tree/main/python/langchain-floo" + +[tool.hatch.build.targets.wheel] +packages = ["src/langchain_floo"] diff --git a/python/langchain-floo/src/langchain_floo/__init__.py b/python/langchain-floo/src/langchain_floo/__init__.py new file mode 100644 index 0000000..8d29994 --- /dev/null +++ b/python/langchain-floo/src/langchain_floo/__init__.py @@ -0,0 +1,38 @@ +"""LangChain tools for the floo cloud.""" + +import os +from collections.abc import Collection + +from langchain_core.tools import BaseTool +from langchain_mcp_adapters.client import MultiServerMCPClient + + +async def load_floo_tools( + *, api_key: str | None = None, tool_names: Collection[str] | None = None +) -> list[BaseTool]: + """Discover floo tools for this credential, optionally selecting by exact name.""" + key = api_key if api_key is not None else os.environ.get("FLOO_KEY") + if not key or not key.strip(): + raise ValueError("Pass api_key or set FLOO_KEY to a floo API key.") + if isinstance(tool_names, str): + raise TypeError("Pass a collection of tool names, such as ['list_apps'].") + + client = MultiServerMCPClient({ + "floo": { + "transport": "http", + "url": "https://api.getfloo.com/mcp", + "headers": {"Authorization": f"Bearer {key.strip()}"}, + } + }) + tools = await client.get_tools() + if tool_names is None: + return tools + + selected = set(tool_names) + missing = selected.difference(tool.name for tool in tools) + if missing: + raise ValueError(f"Unavailable floo tools: {', '.join(sorted(missing))}") + return [tool for tool in tools if tool.name in selected] + + +__all__ = ["load_floo_tools"] diff --git a/python/langchain-floo/tests/test_tools.py b/python/langchain-floo/tests/test_tools.py new file mode 100644 index 0000000..7c279e7 --- /dev/null +++ b/python/langchain-floo/tests/test_tools.py @@ -0,0 +1,17 @@ +import unittest +from types import SimpleNamespace +from unittest.mock import AsyncMock, patch + +from langchain_floo import load_floo_tools + + +class TestToolSelection(unittest.IsolatedAsyncioTestCase): + async def test_explicit_selection_does_not_expose_unrequested_tools(self): + read = SimpleNamespace(name="list_apps") + write = SimpleNamespace(name="create_app") + with patch("langchain_floo.MultiServerMCPClient") as client: + client.return_value.get_tools = AsyncMock(return_value=[read, write]) + tools = await load_floo_tools(api_key="test", tool_names=["list_apps"]) + self.assertEqual(tools, [read]) + with self.assertRaisesRegex(ValueError, "missing_tool"): + await load_floo_tools(api_key="test", tool_names=["missing_tool"]) From 7b330b2727dbe681eb8d60f07a2c02105e1194bd Mon Sep 17 00:00:00 2001 From: Patrick Donohoe Date: Thu, 26 Nov 2026 04:07:12 -0500 Subject: [PATCH 2/2] fix: honor the API base URL for LangChain connections --- python/langchain-floo/README.md | 2 +- .../langchain-floo/src/langchain_floo/__init__.py | 15 +++++++++------ python/langchain-floo/tests/test_tools.py | 8 +++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/python/langchain-floo/README.md b/python/langchain-floo/README.md index 631c5ad..bd563c2 100644 --- a/python/langchain-floo/README.md +++ b/python/langchain-floo/README.md @@ -8,7 +8,7 @@ Install from this repository: python -m pip install 'langchain-floo @ git+https://github.com/getfloo/floo-cli.git#subdirectory=python/langchain-floo' ``` -Set `FLOO_KEY` in your application environment. To give an inventory assistant access to two read tools: +Set `FLOO_KEY` in your application environment. For a different floo environment, set `FLOO_API_URL` to its API base URL and use a key from that environment. To give an inventory assistant access to two read tools: ```python import asyncio diff --git a/python/langchain-floo/src/langchain_floo/__init__.py b/python/langchain-floo/src/langchain_floo/__init__.py index 8d29994..ae54754 100644 --- a/python/langchain-floo/src/langchain_floo/__init__.py +++ b/python/langchain-floo/src/langchain_floo/__init__.py @@ -17,13 +17,16 @@ async def load_floo_tools( if isinstance(tool_names, str): raise TypeError("Pass a collection of tool names, such as ['list_apps'].") - client = MultiServerMCPClient({ - "floo": { - "transport": "http", - "url": "https://api.getfloo.com/mcp", - "headers": {"Authorization": f"Bearer {key.strip()}"}, + base_url = os.environ.get("FLOO_API_URL", "https://api.getfloo.com").rstrip("/") + client = MultiServerMCPClient( + { + "floo": { + "transport": "http", + "url": f"{base_url}/mcp", + "headers": {"Authorization": f"Bearer {key.strip()}"}, + } } - }) + ) tools = await client.get_tools() if tool_names is None: return tools diff --git a/python/langchain-floo/tests/test_tools.py b/python/langchain-floo/tests/test_tools.py index 7c279e7..aeb7034 100644 --- a/python/langchain-floo/tests/test_tools.py +++ b/python/langchain-floo/tests/test_tools.py @@ -9,9 +9,15 @@ class TestToolSelection(unittest.IsolatedAsyncioTestCase): async def test_explicit_selection_does_not_expose_unrequested_tools(self): read = SimpleNamespace(name="list_apps") write = SimpleNamespace(name="create_app") - with patch("langchain_floo.MultiServerMCPClient") as client: + with ( + patch.dict("os.environ", {"FLOO_API_URL": "https://example.test/"}), + patch("langchain_floo.MultiServerMCPClient") as client, + ): client.return_value.get_tools = AsyncMock(return_value=[read, write]) tools = await load_floo_tools(api_key="test", tool_names=["list_apps"]) self.assertEqual(tools, [read]) + self.assertEqual( + client.call_args.args[0]["floo"]["url"], "https://example.test/mcp" + ) with self.assertRaisesRegex(ValueError, "missing_tool"): await load_floo_tools(api_key="test", tool_names=["missing_tool"])