AI agent that generates and executes Python code to interact with Airtable using the MCP code execution pattern from Anthropic's blog.
User Input → Claude Sonnet 4 → Python Code → Subprocess → Airtable MCP → Results
Key benefit: Process data in code, not in context.
# Airtable MCP server running at http://localhost:8000/mcp
# Anthropic API keypip install langchain langchain-anthropic anthropic aiohttpexport ANTHROPIC_API_KEY="your-anthropic-api-key"python cli.pyYou: List all my Airtable bases
🤖 Agent: Thinking...
Generated Code (Attempt 1):
============================================================
from airtable_client import airtable_client
async with airtable_client("http://localhost:8000/mcp") as client:
from servers import airtable
bases = await airtable.list_bases()
print(json.dumps({"bases": bases}))
============================================================
✅ Success!
Output:
------------------------------------------------------------
{"bases": [{"id": "appXXX", "name": "My Base"}]}
------------------------------------------------------------
"List all my Airtable bases"
"Show me tables in base appXXXXXXXXXXXXXX"
"Get all active Orders from my CRM base"
"Find records containing 'john@example.com'"
"Count records in each table of my base"
/help - Show help
/clear - Clear conversation history
/exit - Exit
- User request → "Get all active contacts"
- Claude generates code:
records = await airtable.list_records(...) active = [r for r in records if r['fields']['Status'] == 'Active'] print(len(active)) # Only summary to context!
- Execute in subprocess (sandboxed, validated)
- Return results to user