list_tables
Retrieve tables from an Airtable base using either table identifiers or detailed field information to manage and organize data efficiently.
Instructions
List tables in a specific base
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base_id | Yes | The Airtable base ID | |
| detail_level | No | Level of detail to include in response | tableIdentifiersOnly |
Implementation Reference
- src/airtable_mcp/mcp/server.py:141-184 (handler)The main handler function for the 'list_tables' MCP tool. It authenticates via OAuth, retrieves the base schema using AirtableClient, and returns either basic table identifiers or detailed info including fields based on the detail_level parameter. This decorator @self.mcp.tool also serves as the registration.@self.mcp.tool(description="List tables in a specific base") async def list_tables( base_id: Annotated[str, Field(description="The Airtable base ID")], detail_level: Annotated[ Literal["tableIdentifiersOnly", "withFieldInfo"], Field( description="Level of detail to include in response", default="tableIdentifiersOnly", ), ] = "tableIdentifiersOnly", ) -> list[dict[str, Any]]: """List tables in a specific base with optional field information.""" client = await self._get_authenticated_client() schema = await client.get_base_schema(base_id) if detail_level == "tableIdentifiersOnly": return [ { "id": table.id, "name": table.name, } for table in schema.tables ] else: # withFieldInfo return [ { "id": table.id, "name": table.name, "description": table.description, "primaryFieldId": table.primary_field_id, "fields": [ { "id": field.id, "name": field.name, "type": field.type, "description": field.description, "options": field.options, } for field in table.fields ], } for table in schema.tables ]
- Pydantic schema class ListTablesArgs defining the input arguments for the list_tables tool, matching the handler parameters. Used in tests for validation.class ListTablesArgs(BaseArgs): """Arguments for list_tables tool.""" base_id: str = Field(description="The Airtable base ID") detail_level: Literal["tableIdentifiersOnly", "withFieldInfo"] = Field( default="tableIdentifiersOnly", description="Level of detail to include in response", )
- Helper method to create an authenticated AirtableClient using the access token from the AuthContext, called by the list_tables handler.async def _get_authenticated_client(self) -> AirtableClient: """Get an authenticated Airtable client using access token from context. Returns: Authenticated AirtableClient instance Raises: AirtableAuthError: If authentication fails """ # Get access token from authentication context (set by middleware) access_token = AuthContext.require_access_token() try: # Use the OAuth provider provider = self._get_oauth_provider() if not provider: raise AirtableAuthError( "OAuth provider not available - ensure OAuth endpoints are enabled and credentials are configured" ) # Set the access token in the provider provider.access_token = access_token return AirtableClient(provider) except Exception as e: logger.error(f"Failed to create authenticated client: {e}") raise AirtableAuthError(f"Authentication failed: {e}") from e