feat: add write tools (add_records, update_records, delete_records)

This commit is contained in:
2025-12-03 14:49:32 -05:00
parent 0a6f699d30
commit eb0bf3eaf6
2 changed files with 157 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
"""Write tools - create, update, delete records."""
from grist_mcp.auth import Agent, Authenticator, Permission
from grist_mcp.grist_client import GristClient
async def add_records(
agent: Agent,
auth: Authenticator,
document: str,
table: str,
records: list[dict],
client: GristClient | None = None,
) -> dict:
"""Add records to a table."""
auth.authorize(agent, document, Permission.WRITE)
if client is None:
doc = auth.get_document(document)
client = GristClient(doc)
ids = await client.add_records(table, records)
return {"inserted_ids": ids}
async def update_records(
agent: Agent,
auth: Authenticator,
document: str,
table: str,
records: list[dict],
client: GristClient | None = None,
) -> dict:
"""Update existing records."""
auth.authorize(agent, document, Permission.WRITE)
if client is None:
doc = auth.get_document(document)
client = GristClient(doc)
await client.update_records(table, records)
return {"updated": True}
async def delete_records(
agent: Agent,
auth: Authenticator,
document: str,
table: str,
record_ids: list[int],
client: GristClient | None = None,
) -> dict:
"""Delete records by ID."""
auth.authorize(agent, document, Permission.WRITE)
if client is None:
doc = auth.get_document(document)
client = GristClient(doc)
await client.delete_records(table, record_ids)
return {"deleted": True}