Files
grist-mcp-server/src/grist_mcp/tools/write.py
Bill a7c87128ef
All checks were successful
Build and Push Docker Image / build (push) Successful in 8s
feat: replace MCP attachment tool with proxy endpoint
The MCP tool approach was impractical because it required the LLM to
generate large base64 strings token-by-token, causing timeouts.

Changes:
- Remove upload_attachment MCP tool
- Add POST /api/v1/attachments endpoint for multipart/form-data uploads
- Update proxy documentation to show both endpoints
- Uses existing GristClient.upload_attachment() method
- Requires write permission in session token
2026-01-03 20:26:36 -05:00

62 lines
1.5 KiB
Python

"""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}