NocoDB
STDIONocodb数据库CRUD操作MCP服务器
Nocodb数据库CRUD操作MCP服务器
This MCP server provides tools to interact with a Nocodb database through the Model Context Protocol, offering CRUD operations (Create, Read, Update, Delete) for Nocodb tables.
pip install -r requirements.txt
pip install "mcp[cli]"
This MCP server requires three environment variables:
NOCODB_URL: The base URL of your Nocodb instance (e.g., https://example.com/ncdb)NOCODB_API_TOKEN: The API token for authentication with NocodbNOCODB_BASE_ID: The base ID of your Nocodb databaseYou can obtain an API token from your Nocodb instance by:
The base ID can be found in the URL of your Nocodb dashboard: https://your-nocodb.com/dashboard/#/nc/base/YOUR_BASE_ID/table/...
To integrate with Claude Desktop, add this configuration to claude_desktop_config.json:
{ "mcpServers": { "nocodb": { "command": "python", "args": [ "path/to/nocodb_mcp_server.py" ], "env": { "NOCODB_URL": "https://your-nocodb-instance.com", "NOCODB_API_TOKEN": "your_api_token_here", "NOCODB_BASE_ID": "your_base_id_here" } } } }
Or use the MCP CLI to install (recommended):
# Basic installation mcp install nocodb_mcp_server.py # With environment variables mcp install nocodb_mcp_server.py -v NOCODB_URL=https://your-nocodb-instance.com -v NOCODB_API_TOKEN=your_token -v NOCODB_BASE_ID=your_base_id # OR using an .env file mcp install nocodb_mcp_server.py -f .env
# Install dependencies pip install -r requirements.txt # Run the server directly python nocodb_mcp_server.py # Or using the MCP CLI mcp run nocodb_mcp_server.py
For testing and debugging with the MCP Inspector:
# Run in development mode mcp dev nocodb_mcp_server.py
For Cursor on Windows, use the following syntax in your mcp.json configuration file:
{ "mcpServers": { "nocodb": { "command": "C:\\Path\\To\\Your\\Python\\Executable", "args": [ "C:\\Path\\To\\Your\\nocodb_mcp_server.py" ], "env": { "NOCODB_URL": "http://localhost:8080", "NOCODB_API_TOKEN": "your_api_token_here", "NOCODB_BASE_ID": "your_base_id_here" } } } }
The server provides the following tools:
Retrieve one or multiple records from a Nocodb table.
Parameters:
table_name: Name of the table to queryrow_id (Optional): Specific row ID to retrieve a single recordfilters (Optional): Filter conditions in Nocodb formatlimit (Optional): Maximum number of records to return (default: 10)offset (Optional): Number of records to skip for pagination (default: 0)sort (Optional): Column to sort byfields (Optional): Comma-separated list of fields to includeExamples:
# Get all records from a table (limited to 10) retrieve_records(table_name="customers") # Get a specific record by ID retrieve_records(table_name="customers", row_id="123") # Filter records with conditions retrieve_records( table_name="customers", filters="(age,gt,30)~and(status,eq,active)" )
Create one or multiple records in a Nocodb table.
Parameters:
table_name: Name of the table to insert intodata: Dict with column:value pairs or a list of such dicts for bulk creationbulk (Optional): Set to True for bulk creationExamples:
# Create a single record create_records( table_name="customers", data={"name": "John Doe", "email": "[email protected]", "age": 35} ) # Create multiple records in bulk create_records( table_name="customers", data=[ {"name": "John Doe", "email": "[email protected]", "age": 35}, {"name": "Jane Smith", "email": "[email protected]", "age": 28} ], bulk=True )
Update one or multiple records in a Nocodb table.
Parameters:
table_name: Name of the table to updaterow_id: ID of the record to update (required for single record update)data: Dictionary with column:value pairs to updatebulk (Optional): Set to True for bulk updatesbulk_ids (Optional): List of record IDs to update when bulk=TrueExamples:
# Update a single record by ID update_records( table_name="customers", row_id="123", data={"name": "John Smith", "status": "inactive"} ) # Update multiple records in bulk by IDs update_records( table_name="customers", data={"status": "inactive"}, # Same update applied to all records bulk=True, bulk_ids=["123", "456", "789"] )
Delete one or multiple records from a Nocodb table.
Parameters:
table_name: Name of the table to delete fromrow_id: ID of the record to delete (required for single record deletion)bulk (Optional): Set to True for bulk deletionbulk_ids (Optional): List of record IDs to delete when bulk=TrueExamples:
# Delete a single record by ID delete_records( table_name="customers", row_id="123" ) # Delete multiple records in bulk by IDs delete_records( table_name="customers", bulk=True, bulk_ids=["123", "456", "789"] )
Retrieve the schema (columns) of a Nocodb table.
Parameters:
table_name: Name of the table to get the schema forReturns:
Example:
# Get the schema for the "products" table get_schema(table_name="products")
This MCP server interacts with the Nocodb v2 REST API as described in the Nocodb API documentation.
Key Implementation Details:
xc-token header (Nocodb v2 API requirement)REST API References:
/api/v2/tables/{tableId}/records/... and /api/v2/meta/tables/{tableId}Authentication is handled via the xc-token header, which is automatically populated using the NOCODB_API_TOKEN environment variable. This is the authentication mechanism required by the Nocodb v2 API.
The server includes logging for debugging purposes. By default, the MCP server's log level is set to ERROR in nocodb_mcp_server.py ( mcp = FastMCP("Nocodb MCP Server", log_level="ERROR") ) to avoid excessive output during standard operations like mcp list. If more detailed logs are needed for troubleshooting, you can uncomment the logging.basicConfig section and adjust the level (e.g., level=logging.INFO or level=logging.DEBUG).
All tools return structured responses that include error information if the operation fails. This makes it easy to determine if an operation was successful and to troubleshoot any issues.
For a secure setup:
⚠️ IMPORTANT: Always follow the Principle of Least Privilege when configuring API tokens and database access.