Skip to content

Commit 82ea7e2

Browse files
committed
new features
1 parent c90337b commit 82ea7e2

5 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SupabaseTool
2+
3+
The `SupabaseTool` allows CrewAI agents to interact with Supabase databases.
4+
5+
## Supported Actions
6+
- `select`
7+
- `insert`
8+
- `update`
9+
- `delete`
10+
11+
## Environment Variables
12+
- SUPABASE_URL
13+
- SUPABASE_KEY
14+
15+
## Example Usage
16+
17+
```python
18+
from crewai.tools import SupabaseTool
19+
20+
tool = SupabaseTool()
21+
22+
result = tool.run({
23+
"action": "select",
24+
"table": "messages",
25+
"filters": {"id": "eq.1"}
26+
})

lib/crewai/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies = [
4545
"pyyaml~=6.0",
4646
"aiofiles~=24.1.0",
4747
"lancedb>=0.29.2,<0.30.1",
48+
"supabase>=2.0.0",
4849
]
4950

5051
[project.urls]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import os
2+
from typing import TYPE_CHECKING, Any, Dict
3+
4+
from crewai.tools import BaseTool
5+
6+
if TYPE_CHECKING:
7+
from supabase import Client
8+
9+
class SupabaseTool(BaseTool):
10+
name: str = "SupabaseTool"
11+
description: str = (
12+
"A tool for performing Supabase database operations such as "
13+
"select, insert, update, and delete."
14+
)
15+
16+
def __init__(self):
17+
super().__init__()
18+
url = os.getenv("SUPABASE_URL")
19+
key = os.getenv("SUPABASE_KEY")
20+
21+
if not url or not key:
22+
raise ValueError("SUPABASE_URL and SUPABASE_KEY must be set in environment variables")
23+
24+
from supabase import create_client
25+
26+
self.client: Client = create_client(url, key)
27+
28+
def _run(self, params: Dict[str, Any]) -> Any:
29+
"""
30+
params example:
31+
{
32+
"action": "select",
33+
"table": "messages",
34+
"filters": {"id": "eq.1"}
35+
}
36+
"""
37+
action = params.get("action")
38+
table = params.get("table")
39+
40+
if not action or not table:
41+
return {"error": "Missing required fields: action, table"}
42+
43+
query = self.client.table(table)
44+
45+
if action == "select":
46+
filters = params.get("filters", {})
47+
for key, condition in filters.items():
48+
query = query.eq(key, condition)
49+
return query.select("*").execute()
50+
51+
elif action == "insert":
52+
data = params.get("data")
53+
if not data:
54+
return {"error": "Missing data for insert"}
55+
return query.insert(data).execute()
56+
57+
elif action == "update":
58+
filters = params.get("filters", {})
59+
data = params.get("data")
60+
if not filters or not data:
61+
return {"error": "Missing filters or data for update"}
62+
for key, condition in filters.items():
63+
query = query.eq(key, condition)
64+
return query.update(data).execute()
65+
66+
elif action == "delete":
67+
filters = params.get("filters", {})
68+
if not filters:
69+
return {"error": "Missing filters for delete"}
70+
for key, condition in filters.items():
71+
query = query.eq(key, condition)
72+
return query.delete().execute()
73+
74+
else:
75+
return {"error": f"Unknown action: {action}"}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import pytest
3+
4+
from crewai.tools.supabase_tool import SupabaseTool
5+
6+
def test_missing_env_vars():
7+
# Temporarily remove env vars
8+
os.environ.pop("SUPABASE_URL", None)
9+
os.environ.pop("SUPABASE_KEY", None)
10+
11+
with pytest.raises(ValueError):
12+
SupabaseTool()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ exclude-newer-package = { msgpack = "2026-06-20T00:00:00Z", pydantic-settings =
245245
# Keep OpenAI on the SDK range required by CrewAI when transitive dependencies
246246
# loosen or pin their own lower versions.
247247
override-dependencies = [
248+
"supabase>=2.0.0",
248249
"openai>=2.30.0,<3",
249250
"rich>=13.7.1",
250251
"onnxruntime<1.24; python_version < '3.11'",

0 commit comments

Comments
 (0)