Airtable代码生成代理

通过AI代理生成并执行Python代码与Airtable交互,采用MCP代码执行模式实现数据处理自动化。

  • by shams858
  • Python
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 shams858/code-execution-with-mcp

使用说明

气垫MCP代理-MVP

生成并执行Python代码以使用MCP代码执行模式与Airtable交互的AI代理 Anthropic的博客.

建筑

User Input → Claude Sonnet 4 → Python Code → Subprocess → Airtable MCP → Results

主要优势:在代码中处理数据,而不是在上下文中。

快速开始

1.先决条件

# Airtable MCP server running at http://localhost:8000/mcp
# Anthropic API key

2.安装

pip install langchain langchain-anthropic anthropic aiohttp

3.设置API密钥

export ANTHROPIC_API_KEY="your-anthropic-api-key"

4.跑步

python cli.py

用法

You: 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

运作原理

  1. 用户请求 → “获取所有活动联系人”
  2. Claude生成代码:
    records = await airtable.list_records(...)
    active = [r for r in records if r['fields']['Status'] == 'Active']
    print(len(active))  # Only summary to context!
    
  3. 在子流程中执行 (沙盒、验证)
  4. 返回结果 给用户

完整报道

https://medium.com/@shamsul.arefin/building-an-ai试剂-含mcp解码器-从渗透到澄清-6b13fccc8c4b