NocoDB MCP服务器
一个模型上下文协议(MCP)服务器,为开源Airtable替代品NocoDB提供全面的接口。该服务器使AI代理能够与NocoDB数据库交互,使其非常适合存储和管理多个AI团队的操作数据。
特性
- 数据库操作:列出并管理NocoDB基地/项目
- 表格管理:使用自定义架构创建、列出和删除表
- 栏目管理:向具有完全类型支持的现有表中添加列
- 记录CRUD:对记录进行完整的创建、读取、更新、删除操作
- 高级查询:筛选、排序、搜索和聚合数据
- 视图管理:创建和使用不同的视图(网格、图库、表格等)
- 批量操作:一次插入多条记录
- 文件附件:在本地或从URL上传文件,附加到记录
安装
通过NPM(全球)
npm install -g @andrewlwn77/nocodb-mcp通过NPX(无需安装)
npx @andrewlwn77/nocodb-mcp配置
环境变量
创建一个 .env 项目根目录中的文件:
# Required
NOCODB_BASE_URL=http://localhost:8080
NOCODB_API_TOKEN=your_api_token_here
# Optional
NOCODB_DEFAULT_BASE=your_default_base_id获取您的API代币
- 登录您的NocoDB实例
- 点击您的个人资料图标
- 选择“API令牌”
- 创建具有适当权限的新令牌
MCP配置
添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"nocodb": {
"command": "npx",
"args": ["@andrewlwn77/nocodb-mcp"],
"env": {
"NOCODB_BASE_URL": "http://localhost:8080",
"NOCODB_API_TOKEN": "your_api_token_here"
}
}
}
}或者,如果全局安装:
{
"mcpServers": {
"nocodb": {
"command": "nocodb-mcp",
"env": {
"NOCODB_BASE_URL": "http://localhost:8080",
"NOCODB_API_TOKEN": "your_api_token_here"
}
}
}
}可用工具
数据库操作
list_bases-列出所有可用的数据库/项目get_base_info-获取特定基地的详细信息
表格管理
list_tables-列出基中的所有表get_table_info-获取表架构和列信息create_table-使用自定义架构创建新表delete_table-删除表格add_column-向现有表添加新列delete_column-从表中删除列
记录操作
insert_record-插入一条记录bulk_insert-一次插入多条记录get_record-按ID检索特定记录list_records-列出具有过滤和分页功能的记录update_record-更新现有记录delete_record-删除记录search_records-跨记录的全文搜索
查询操作
query-具有多种条件的高级过滤aggregate-执行SUM、COUNT、AVG、MIN、MAX操作group_by-按列对记录进行分组
视图管理
list_views-列出表的所有视图create_view-创建新视图get_view_data-从特定视图获取记录
文件附件
upload_attachment-将本地文件上传到NocoDB存储upload_attachment_by_url-从URL上传文件attach_file_to_record-上传文件并将其附加到记录中get_attachment_info-从记录中获取附件信息
使用示例
创建表格
{
"tool": "create_table",
"arguments": {
"base_id": "p_abc123",
"table_name": "customers",
"columns": [
{
"title": "Name",
"uidt": "SingleLineText",
"rqd": true
},
{
"title": "Email",
"uidt": "Email",
"unique": true
},
{
"title": "Revenue",
"uidt": "Number",
"dt": "decimal"
},
{
"title": "Status",
"uidt": "SingleSelect",
"dtxp": "'active','inactive','pending'"
}
]
}
}向现有表添加列
这 add_column 该工具允许您向现有表动态添加列。以下是一些示例:
基本列类型
{
"tool": "add_column",
"arguments": {
"table_id": "table_id_here",
"title": "Description",
"uidt": "LongText"
}
}带约束的列
{
"tool": "add_column",
"arguments": {
"table_id": "table_id_here",
"title": "Product Code",
"uidt": "SingleLineText",
"unique": true,
"rqd": true
}
}使用选项选择列
{
"tool": "add_column",
"arguments": {
"table_id": "table_id_here",
"title": "Priority",
"uidt": "SingleSelect",
"meta": {
"options": [
{"title": "Low", "color": "#059669"},
{"title": "Medium", "color": "#d97706"},
{"title": "High", "color": "#dc2626"},
{"title": "Critical", "color": "#7c3aed"}
]
}
}
}货币栏
{
"tool": "add_column",
"arguments": {
"table_id": "table_id_here",
"title": "Price",
"uidt": "Currency",
"meta": {
"currency_code": "USD"
}
}
}有关更多列类型示例,请参见 列类型示例.
删除列
这 delete_column 该工具允许您从现有表中删除列。您可以通过列的ID或名称来标识要删除的列。
按列ID删除
{
"tool": "delete_column",
"arguments": {
"table_id": "table_id_here",
"column_id": "column_id_to_delete"
}
}按列名删除
{
"tool": "delete_column",
"arguments": {
"table_id": "table_id_here",
"column_name": "ColumnToDelete"
}
}注意:该工具将搜索与以下任一项匹配的列 column_name 或 title 字段,使其能够灵活地适应不同的命名约定。
插入记录
{
"tool": "insert_record",
"arguments": {
"base_id": "p_abc123",
"table_name": "customers",
"data": {
"Name": "Acme Corp",
"Email": "contact@acme.com",
"Revenue": 50000,
"Status": "active"
}
}
}使用筛选器进行查询
{
"tool": "query",
"arguments": {
"base_id": "p_abc123",
"table_name": "customers",
"where": "(Status,eq,active)~and(Revenue,gt,10000)",
"sort": ["-Revenue", "Name"],
"fields": ["Name", "Email", "Revenue"],
"limit": 10
}
}数据聚合
{
"tool": "aggregate",
"arguments": {
"base_id": "p_abc123",
"table_name": "customers",
"column_name": "Revenue",
"function": "sum",
"where": "(Status,eq,active)"
}
}文件上传示例
上传本地文件
{
"tool": "upload_attachment",
"arguments": {
"file_path": "/path/to/document.pdf",
"storage_path": "documents/2024"
}
}从URL上传
{
"tool": "upload_attachment_by_url",
"arguments": {
"urls": [
"https://example.com/image1.png",
"https://example.com/image2.jpg"
],
"storage_path": "images"
}
}将文件附加到记录
{
"tool": "attach_file_to_record",
"arguments": {
"base_id": "p_abc123",
"table_name": "products",
"record_id": "42",
"attachment_field": "ProductImages",
"file_path": "/path/to/product-photo.jpg"
}
}获取附件信息
{
"tool": "get_attachment_info",
"arguments": {
"base_id": "p_abc123",
"table_name": "products",
"record_id": "42",
"attachment_field": "ProductImages"
}
}NocoDB字段类型
列支持的UI数据类型(uidt):
基本类型
SingleLineText-短文本字段LongText-多行文本Number-整数数值Decimal-精确的十进制数Checkbox-布尔值真/假
日期与时间
Date-日期无时间DateTime-日期与时间Time-仅限时间Duration-持续时间
专业文本
Email-带有验证的电子邮件地址URL-Web链接PhoneNumber-电话号码(注意:使用“电话号码”而不是“电话”)
数值类型
Currency-货币价值(要求meta.currency_code)Percent-百分比值Rating-星级评定
选择类型
SingleSelect-单选下拉菜单(需要meta.options)MultiSelect-多选(需要meta.options)
高级类型
Attachment-文件上传JSON-JSON数据存储
虚拟/计算列
Formula-计算字段Rollup-汇总相关记录Lookup-从相关记录中查找值QrCode-生成二维码(需要meta.fk_qr_value_column_id)Barcode-生成条形码(需要meta.fk_barcode_value_column_id)
关系的
LinkToAnotherRecord-表之间的关系Links-多对多关系
柱类型的特殊参数
某些列类型需要在 meta 字段:
- 单选/多选:
meta.options阵列与{title, color}物体 - 货币:
meta.currency_code(例如,“美元”、“欧元”) - 二维码:
meta.fk_qr_value_column_id-要编码的列的ID - 条形码:
meta.fk_barcode_value_column_id-要编码的列的ID,可选meta.barcode_format
筛选器语法
NocoDB使用特定的语法进行过滤:
(field,operator,value)-基本情况~and-AND操作员~or-OR操作员~not-非操作员
运算符
eq-等于neq-不等于gt-大于ge-大于或等于lt-小于le-小于或等于like-包含(通配符使用%)nlike-不包含null-为空notnull-不为空
例子
(Status,eq,active)-状态等于“活动”(Revenue,gt,1000)~and(Status,eq,active)-收入>1000,状态=“活跃”(Name,like,%Corp%)-名称包含“Corp”
发展
从源头构建
# Clone the repository
git clone https://github.com/your-org/nocodb-mcp.git
cd nocodb-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev运行测试
npm test错误处理
服务器为常见问题提供详细的错误消息:
- API令牌无效
- 未找到基/表
- 列类型无效
- 网络连接问题
- 速率限制
最佳实践
- 使用视图:为常用访问的数据子集创建视图
- 批量操作:使用
bulk_insert多条记录 - 字段选择:仅指定所需字段以减小有效载荷大小
- 分页:对大型数据集使用限制/偏移
- 缓存:考虑在客户端缓存频繁访问的数据
局限性
- 一些高级NocoDB功能可能无法通过此接口公开
- 速率限制取决于您的NocoDB实例配置
贡献
欢迎投稿!请随时提交拉取请求。
许可证
麻省理工学院
支持
对于问题和功能请求,请在GitHub存储库中创建问题。
