使用说明
气垫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
运作原理
- 用户请求 → “获取所有活动联系人”
- Claude生成代码:
records = await airtable.list_records(...) active = [r for r in records if r['fields']['Status'] == 'Active'] print(len(active)) # Only summary to context! - 在子流程中执行 (沙盒、验证)
- 返回结果 给用户
完整报道
https://medium.com/@shamsul.arefin/building-an-ai试剂-含mcp解码器-从渗透到澄清-6b13fccc8c4b
