bkend-mcp: MCP Tools & AI Integration Expert Skill
1. MCP Overview
The Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and data sources through a unified interface. bkend.ai implements MCP to provide AI-powered development workflows.
Protocol Specification
| Property |
Value |
| Protocol |
MCP 2025-03-26 |
| Transport |
Streamable HTTP |
| Authentication |
OAuth 2.1 + PKCE |
| Server URL |
https://api.bkend.ai/mcp |
| Content Type |
application/json |
| Session Header |
Mcp-Session-Id |
How It Works
- The AI client (Gemini CLI, Claude Code, Cursor, etc.) connects to the MCP server
- The server advertises available tools and resources
- The AI model invokes tools on behalf of the user
- The server executes operations and returns structured results
- OAuth 2.1 + PKCE ensures secure, user-authorized access
2. MCP Tool Catalog (28 Tools)
bkend.ai exposes 28 MCP tools organized into 6 categories. Each tool follows the MCP tool schema with name, description, and inputSchema properties.
2.1 Fixed Tools (3)
These tools are always available regardless of project context.
| Tool Name |
Description |
Parameters |
get_context |
Returns current session context including org, project, environment, and user info |
None |
search_docs |
Searches bkend.ai documentation by topic or keyword |
query (string, required), category (string, optional) |
get_operation_schema |
Returns the OpenAPI schema for a specific REST API operation |
operationId (string, required) |
Usage Notes:
- Always call
get_context first to verify your session is properly authenticated
- Use
search_docs to find REST API documentation for Auth and Storage features (no MCP tools available for these)
- Use
get_operation_schema to get detailed request/response schemas for code generation
2.2 Project Management Tools (6)
Tools for managing organizations, projects, and environments.
| Tool Name |
Description |
Parameters |
backend_org_list |
Lists all organizations the user belongs to |
None |
backend_project_list |
Lists all projects in the current organization |
orgId (string, required) |
backend_project_create |
Creates a new project |
orgId (string, required), name (string, required), description (string, optional) |
backend_project_get |
Gets project details |
projectId (string, required) |
backend_env_list |
Lists environments for a project |
projectId (string, required) |
backend_env_create |
Creates a new environment (dev/staging/prod) |
projectId (string, required), name (string, required), type (enum: dev/staging/prod) |
Usage Notes:
- Start with
backend_org_list to get the orgId
- Then use
backend_project_list or backend_project_create to set up project context
- Each project can have multiple environments with isolated data
2.3 Table Management Tools (9)
Tools for defining and managing database table schemas.
| Tool Name |
Description |
Parameters |
backend_table_list |
Lists all tables in the environment |
envId (string, required) |
backend_table_create |
Creates a new table with fields |
envId (string, required), name (string, required), fields (array, required) |
backend_table_get |
Gets table schema details |
envId (string, required), tableId (string, required) |
backend_table_update |
Updates table settings |
envId (string, required), tableId (string, required), settings (object, required) |
backend_table_delete |
Deletes a table and all its data |
envId (string, required), tableId (string, required) |
backend_field_manage |
Adds, updates, or removes fields on a table |
envId (string, required), tableId (string, required), action (enum: add/update/remove), field (object, required) |
backend_index_manage |
Manages indexes on a table |
envId (string, required), tableId (string, required), action (enum: create/delete), index (object, required) |
backend_schema_version_list |
Lists schema versions (migration history) |
envId (string, required), tableId (string, required) |
backend_schema_version_get |
Gets a specific schema version |
envId (string, required), tableId (string, required), versionId (string, required) |
Field Types:
string, number, boolean, date, datetime
text (long text), richtext (HTML content)
email, url, phone
enum (with options array)
relation (with targetTable and relationType)
file (stored in bkend Storage)
json (arbitrary JSON object)
2.4 Data CRUD Tools (5)
Tools for creating, reading, updating, and deleting records in tables.
| Tool Name |
Description |
Parameters |
backend_data_list |
Lists records with filtering and paging |
envId (string, required), tableId (string, required), filter (object, optional), sort (object, optional), page (number, optional), limit (number, optional) |
backend_data_get |
Gets a single record by ID |
envId (string, required), tableId (string, required), recordId (string, required) |
backend_data_create |
Creates a new record |
envId (string, required), tableId (string, required), data (object, required) |
backend_data_update |
Updates an existing record |
envId (string, required), tableId (string, required), recordId (string, required), data (object, required) |
backend_data_delete |
Deletes a record |
envId (string, required), tableId (string, required), recordId (string, required) |
Filter Syntax:
{
"filter": {
"field": "status",
"operator": "eq",
"value": "active"
}
}
Supported Operators: eq, ne, gt, gte, lt, lte, in, nin, contains, startsWith, endsWith, exists
Sort Syntax:
{
"sort": {
"field": "createdAt",
"order": "desc"
}
}
2.5 Environment Tools (3)
Included in Project Management above: backend_env_list, backend_env_create, plus:
| Tool Name |
Description |
Parameters |
backend_env_get |
Gets environment details and configuration |
envId (string, required) |
2.6 Schema Tools (2)
Included in Table Management above: backend_schema_version_list, backend_schema_version_get.
These tools provide migration history and rollback capabilities for table schemas.
3. MCP Resources (4)
MCP resources provide read-only contextual data that AI models can access without explicit tool calls.
| Resource URI |
Description |
MIME Type |
bkend://context |
Current session context (org, project, env) |
application/json |
bkend://tables |
List of all tables in the current environment |
application/json |
bkend://schema/{table} |
Full schema definition for a specific table |
application/json |
bkend://docs/{topic} |
Documentation content for a specific topic |
text/markdown |
Resource Usage:
- Resources are automatically available to AI models that support MCP resource reading
- Use
bkend://context to understand the current working environment
- Use
bkend://tables to discover available data structures
- Use
bkend://schema/{table} to get detailed field definitions before data operations
- Use
bkend://docs/{topic} to retrieve documentation (topics: auth, storage, rls, api-keys, webhooks)
4. Auth & Storage MCP Limitation
Important: bkend.ai does NOT provide MCP tools for Authentication or Storage operations. These features are accessible only through the REST API.
Why No MCP Tools?
- Authentication operations (signup, login, token management) involve sensitive credentials and security flows that are better handled through direct REST API calls with proper error handling
- Storage operations (file upload, download, signed URLs) require binary data transfer that is not well-suited for the MCP tool protocol
Recommended Workflow
- Use
search_docs to find the relevant REST API documentation:search_docs("authentication signup")
search_docs("storage file upload")
- Use
get_operation_schema to get the detailed OpenAPI schema:get_operation_schema("auth-signup")
get_operation_schema("storage-upload")
- Generate REST API client code based on the retrieved documentation and schemas
- Use the generated code in your application to call the REST API directly
Auth REST API Endpoints (Reference)
| Endpoint |
Method |
Description |
/auth/signup |
POST |
Register a new user |
/auth/login |
POST |
Login with credentials |
/auth/logout |
POST |
Invalidate session |
/auth/refresh |
POST |
Refresh access token |
/auth/me |
GET |
Get current user profile |
/auth/password/reset |
POST |
Request password reset |
/auth/password/change |
POST |
Change password |
Storage REST API Endpoints (Reference)
| Endpoint |
Method |
Description |
/storage/upload |
POST |
Upload a file |
/storage/download/{fileId} |
GET |
Download a file |
/storage/list |
GET |
List files in a bucket |
/storage/delete/{fileId} |
DELETE |
Delete a file |
/storage/signed-url |
POST |
Generate a signed URL |
5. AI Tool Setup
5.1 Gemini CLI
Create or edit .gemini/settings.json in your project root:
{
"mcpServers": {
"bkend": {
"httpUrl": "https://api.bkend.ai/mcp"
}
}
}
Verification:
gemini --mcp-list
The first time you invoke a bkend tool, Gemini CLI will open your browser for OAuth authentication.
5.2 Claude Code
Create or edit .mcp.json in your project root:
{
"mcpServers": {
"bkend": {
"type": "streamable-http",
"url": "https://api.bkend.ai/mcp"
}
}
}
Verification:
claude mcp list
Claude Code will automatically handle OAuth 2.1 + PKCE authentication when tools are first invoked.
5.3 Cursor
- Open Settings (Cmd/Ctrl + ,)
- Navigate to MCP section
- Click Add Server
- Configure:
- Name:
bkend
- Type: HTTP
- URL:
https://api.bkend.ai/mcp
- Click Save
Cursor will prompt for OAuth authentication when MCP tools are first used.
5.4 Windsurf
Create or edit .windsurfrules or use the MCP configuration in settings:
{
"mcpServers": {
"bkend": {
"serverUrl": "https://api.bkend.ai/mcp",
"transport": "streamable-http"
}
}
}
5.5 VS Code (GitHub Copilot)
Add to .vscode/settings.json:
{
"github.copilot.chat.mcpServers": {
"bkend": {
"type": "http",
"url": "https://api.bkend.ai/mcp"
}
}
}
5.6 Other Editors
Any MCP-compatible editor can connect to bkend.ai using:
- Transport: Streamable HTTP
- URL:
https://api.bkend.ai/mcp
- Auth: OAuth 2.1 + PKCE (handled automatically by most clients)
6. OAuth 2.1 + PKCE Authentication Flow
Flow Overview
AI Client bkend.ai Auth Server User Browser
| | |
|-- 1. Generate code_verifier -->| |
|-- 2. Compute code_challenge -->| |
| | |
|-- 3. GET /oauth/authorize ---->| |
| ?client_id=... | |
| &code_challenge=... | |
| &code_challenge_method=S256 |
| &redirect_uri=... | |
| &response_type=code | |
| &scope=mcp | |
| |-- 4. Show login page -------->|
| |<-- 5. User authenticates -----|
| | |
|<-- 6. Redirect with auth code -| |
| ?code=AUTH_CODE | |
| | |
|-- 7. POST /oauth/token ------->| |
| grant_type=authorization_code |
| code=AUTH_CODE | |
| code_verifier=... | |
| | |
|<-- 8. Access + Refresh tokens -| |
| | |
|-- 9. MCP requests with ------->| |
| Authorization: Bearer ... | |
Token Lifecycle
| Token |
Lifetime |
Storage |
Refresh Method |
| Access Token |
1 hour |
In-memory (client) |
Exchange refresh token |
| Refresh Token |
30 days |
Secure storage |
Re-authenticate |
Token Refresh
When the access token expires, the MCP client automatically:
- Sends a
POST /oauth/token request with grant_type=refresh_token
- Includes the refresh token in the request body
- Receives a new access token (and optionally a new refresh token)
- Retries the failed MCP request with the new access token
7. MCP Best Practices
7.1 Session Initialization
Always start by verifying your session context:
1. Call get_context -> verify org, project, and environment
2. Call backend_table_list -> understand available data structures
3. Proceed with specific operations
7.2 Schema-First Development
Create tables and define schemas via MCP before performing data operations:
1. backend_table_create -> define table with fields
2. backend_field_manage -> add/modify fields as needed
3. backend_index_manage -> create indexes for query performance
4. backend_data_create -> insert records
7.3 Documentation-Driven Code Generation
For Auth and Storage features (no MCP tools), use documentation tools:
1. search_docs("authentication login flow") -> get documentation
2. get_operation_schema("auth-login") -> get OpenAPI schema
3. Generate client code based on the schema
7.4 Environment Awareness
- Always confirm which environment (dev/staging/prod) you are working in before making changes
- Use
get_context to verify the active environment
- Create separate environments for development and production workflows
7.5 Batch Operations
- Use filtering and pagination with
backend_data_list for large datasets
- Set appropriate
limit values (default: 20, max: 100) to avoid excessive data transfer
- Use
sort to control the order of returned records
8. Common MCP Errors and Solutions
Connection Errors
| Error |
Cause |
Solution |
401 Unauthorized |
Expired or missing access token |
Re-authenticate via OAuth flow |
403 Forbidden |
Insufficient permissions or RLS |
Check API key type and RLS policies |
404 Not Found |
Invalid endpoint or resource ID |
Verify server URL and resource IDs |
429 Too Many Requests |
Rate limit exceeded |
Wait and retry with exponential backoff |
500 Internal Server Error |
Server-side issue |
Retry after a brief delay |
Tool Invocation Errors
| Error |
Cause |
Solution |
tool_not_found |
Tool name is incorrect |
Check tool catalog for exact names |
invalid_params |
Missing or invalid parameters |
Review tool parameter requirements |
env_not_set |
No environment selected |
Call get_context and set environment |
table_not_found |
Table does not exist |
Use backend_table_list to verify |
field_type_mismatch |
Data type does not match schema |
Check field types with backend_table_get |
Authentication Errors
| Error |
Cause |
Solution |
oauth_pkce_mismatch |
Code verifier does not match |
Regenerate code_verifier and retry |
oauth_code_expired |
Authorization code expired |
Restart OAuth flow from the beginning |
oauth_redirect_mismatch |
Redirect URI does not match |
Verify redirect_uri matches registered value |
refresh_token_expired |
Refresh token (30d) expired |
Full re-authentication required |
Quick Reference Card
Essential Tool Sequence
get_context # 1. Verify session
backend_org_list # 2. List organizations
backend_project_list(orgId) # 3. List projects
backend_table_list(envId) # 4. List tables
backend_data_list(envId, tableId) # 5. Query data
MCP Server Connection
URL: https://api.bkend.ai/mcp
Transport: Streamable HTTP
Auth: OAuth 2.1 + PKCE
Tool Count Summary
| Category |
Count |
Tools |
| Fixed |
3 |
get_context, search_docs, get_operation_schema |
| Project Management |
6 |
org_list, project_list/create/get, env_list/create |
| Table Management |
9 |
table CRUD (5), field_manage, index_manage, schema_version (2) |
| Data CRUD |
5 |
data_list/get/create/update/delete |
| Environment |
3 |
env_list/create/get |
| Schema |
2 |
schema_version_list/get |
| Total |
28 |
|
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: popup-studio-ai-bkit-gemini-bkend-mcp3description: bkend-mcp: MCP Tools & AI Integration Expert Skill4---56# bkend-mcp: MCP Tools & AI Integration Expert Skill78## 1. MCP Overview910The Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and data sources through a unified interface. bkend.ai implements MCP to provide AI-powered development workflows.1112### Protocol Specification1314| Property | Value |15|-----------------|--------------------------------------|16| Protocol | MCP 2025-03-26 |17| Transport | Streamable HTTP |18| Authentication | OAuth 2.1 + PKCE |19| Server URL | `https://api.bkend.ai/mcp` |20| Content Type | `application/json` |21| Session Header | `Mcp-Session-Id` |2223### How It Works24251. The AI client (Gemini CLI, Claude Code, Cursor, etc.) connects to the MCP server262. The server advertises available tools and resources273. The AI model invokes tools on behalf of the user284. The server executes operations and returns structured results295. OAuth 2.1 + PKCE ensures secure, user-authorized access3031---3233## 2. MCP Tool Catalog (28 Tools)3435bkend.ai exposes 28 MCP tools organized into 6 categories. Each tool follows the MCP tool schema with `name`, `description`, and `inputSchema` properties.3637### 2.1 Fixed Tools (3)3839These tools are always available regardless of project context.4041| Tool Name | Description | Parameters |42|------------------------|---------------------------------------------------|--------------------------------|43| `get_context` | Returns current session context including org, project, environment, and user info | None |44| `search_docs` | Searches bkend.ai documentation by topic or keyword | `query` (string, required), `category` (string, optional) |45| `get_operation_schema` | Returns the OpenAPI schema for a specific REST API operation | `operationId` (string, required) |4647**Usage Notes:**48- Always call `get_context` first to verify your session is properly authenticated49- Use `search_docs` to find REST API documentation for Auth and Storage features (no MCP tools available for these)50- Use `get_operation_schema` to get detailed request/response schemas for code generation5152### 2.2 Project Management Tools (6)5354Tools for managing organizations, projects, and environments.5556| Tool Name | Description | Parameters |57|--------------------------|------------------------------------------------|-----------------------------------------------------|58| `backend_org_list` | Lists all organizations the user belongs to | None |59| `backend_project_list` | Lists all projects in the current organization | `orgId` (string, required) |60| `backend_project_create` | Creates a new project | `orgId` (string, required), `name` (string, required), `description` (string, optional) |61| `backend_project_get` | Gets project details | `projectId` (string, required) |62| `backend_env_list` | Lists environments for a project | `projectId` (string, required) |63| `backend_env_create` | Creates a new environment (dev/staging/prod) | `projectId` (string, required), `name` (string, required), `type` (enum: dev/staging/prod) |6465**Usage Notes:**66- Start with `backend_org_list` to get the `orgId`67- Then use `backend_project_list` or `backend_project_create` to set up project context68- Each project can have multiple environments with isolated data6970### 2.3 Table Management Tools (9)7172Tools for defining and managing database table schemas.7374| Tool Name | Description | Parameters |75|--------------------------------|---------------------------------------------|---------------------------------------------------------|76| `backend_table_list` | Lists all tables in the environment | `envId` (string, required) |77| `backend_table_create` | Creates a new table with fields | `envId` (string, required), `name` (string, required), `fields` (array, required) |78| `backend_table_get` | Gets table schema details | `envId` (string, required), `tableId` (string, required) |79| `backend_table_update` | Updates table settings | `envId` (string, required), `tableId` (string, required), `settings` (object, required) |80| `backend_table_delete` | Deletes a table and all its data | `envId` (string, required), `tableId` (string, required) |81| `backend_field_manage` | Adds, updates, or removes fields on a table | `envId` (string, required), `tableId` (string, required), `action` (enum: add/update/remove), `field` (object, required) |82| `backend_index_manage` | Manages indexes on a table | `envId` (string, required), `tableId` (string, required), `action` (enum: create/delete), `index` (object, required) |83| `backend_schema_version_list` | Lists schema versions (migration history) | `envId` (string, required), `tableId` (string, required) |84| `backend_schema_version_get` | Gets a specific schema version | `envId` (string, required), `tableId` (string, required), `versionId` (string, required) |8586**Field Types:**87- `string`, `number`, `boolean`, `date`, `datetime`88- `text` (long text), `richtext` (HTML content)89- `email`, `url`, `phone`90- `enum` (with `options` array)91- `relation` (with `targetTable` and `relationType`)92- `file` (stored in bkend Storage)93- `json` (arbitrary JSON object)9495### 2.4 Data CRUD Tools (5)9697Tools for creating, reading, updating, and deleting records in tables.9899| Tool Name | Description | Parameters |100|------------------------|------------------------------------------|-----------------------------------------------------------|101| `backend_data_list` | Lists records with filtering and paging | `envId` (string, required), `tableId` (string, required), `filter` (object, optional), `sort` (object, optional), `page` (number, optional), `limit` (number, optional) |102| `backend_data_get` | Gets a single record by ID | `envId` (string, required), `tableId` (string, required), `recordId` (string, required) |103| `backend_data_create` | Creates a new record | `envId` (string, required), `tableId` (string, required), `data` (object, required) |104| `backend_data_update` | Updates an existing record | `envId` (string, required), `tableId` (string, required), `recordId` (string, required), `data` (object, required) |105| `backend_data_delete` | Deletes a record | `envId` (string, required), `tableId` (string, required), `recordId` (string, required) |106107**Filter Syntax:**108```json109{110 "filter": {111 "field": "status",112 "operator": "eq",113 "value": "active"114 }115}116```117118**Supported Operators:** `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`, `nin`, `contains`, `startsWith`, `endsWith`, `exists`119120**Sort Syntax:**121```json122{123 "sort": {124 "field": "createdAt",125 "order": "desc"126 }127}128```129130### 2.5 Environment Tools (3)131132Included in Project Management above: `backend_env_list`, `backend_env_create`, plus:133134| Tool Name | Description | Parameters |135|----------------------|------------------------------------------------|-----------------------------------------------------|136| `backend_env_get` | Gets environment details and configuration | `envId` (string, required) |137138### 2.6 Schema Tools (2)139140Included in Table Management above: `backend_schema_version_list`, `backend_schema_version_get`.141142These tools provide migration history and rollback capabilities for table schemas.143144---145146## 3. MCP Resources (4)147148MCP resources provide read-only contextual data that AI models can access without explicit tool calls.149150| Resource URI | Description | MIME Type |151|-------------------------------|------------------------------------------------|--------------------|152| `bkend://context` | Current session context (org, project, env) | `application/json` |153| `bkend://tables` | List of all tables in the current environment | `application/json` |154| `bkend://schema/{table}` | Full schema definition for a specific table | `application/json` |155| `bkend://docs/{topic}` | Documentation content for a specific topic | `text/markdown` |156157**Resource Usage:**158- Resources are automatically available to AI models that support MCP resource reading159- Use `bkend://context` to understand the current working environment160- Use `bkend://tables` to discover available data structures161- Use `bkend://schema/{table}` to get detailed field definitions before data operations162- Use `bkend://docs/{topic}` to retrieve documentation (topics: `auth`, `storage`, `rls`, `api-keys`, `webhooks`)163164---165166## 4. Auth & Storage MCP Limitation167168**Important:** bkend.ai does NOT provide MCP tools for Authentication or Storage operations. These features are accessible only through the REST API.169170### Why No MCP Tools?171172- **Authentication** operations (signup, login, token management) involve sensitive credentials and security flows that are better handled through direct REST API calls with proper error handling173- **Storage** operations (file upload, download, signed URLs) require binary data transfer that is not well-suited for the MCP tool protocol174175### Recommended Workflow1761771. Use `search_docs` to find the relevant REST API documentation:178 ```179 search_docs("authentication signup")180 search_docs("storage file upload")181 ```1822. Use `get_operation_schema` to get the detailed OpenAPI schema:183 ```184 get_operation_schema("auth-signup")185 get_operation_schema("storage-upload")186 ```1873. Generate REST API client code based on the retrieved documentation and schemas1884. Use the generated code in your application to call the REST API directly189190### Auth REST API Endpoints (Reference)191192| Endpoint | Method | Description |193|------------------------------|--------|---------------------------|194| `/auth/signup` | POST | Register a new user |195| `/auth/login` | POST | Login with credentials |196| `/auth/logout` | POST | Invalidate session |197| `/auth/refresh` | POST | Refresh access token |198| `/auth/me` | GET | Get current user profile |199| `/auth/password/reset` | POST | Request password reset |200| `/auth/password/change` | POST | Change password |201202### Storage REST API Endpoints (Reference)203204| Endpoint | Method | Description |205|------------------------------|--------|---------------------------|206| `/storage/upload` | POST | Upload a file |207| `/storage/download/{fileId}` | GET | Download a file |208| `/storage/list` | GET | List files in a bucket |209| `/storage/delete/{fileId}` | DELETE | Delete a file |210| `/storage/signed-url` | POST | Generate a signed URL |211212---213214## 5. AI Tool Setup215216### 5.1 Gemini CLI217218Create or edit `.gemini/settings.json` in your project root:219220```json221{222 "mcpServers": {223 "bkend": {224 "httpUrl": "https://api.bkend.ai/mcp"225 }226 }227}228```229230**Verification:**231```bash232gemini --mcp-list233```234235The first time you invoke a bkend tool, Gemini CLI will open your browser for OAuth authentication.236237### 5.2 Claude Code238239Create or edit `.mcp.json` in your project root:240241```json242{243 "mcpServers": {244 "bkend": {245 "type": "streamable-http",246 "url": "https://api.bkend.ai/mcp"247 }248 }249}250```251252**Verification:**253```bash254claude mcp list255```256257Claude Code will automatically handle OAuth 2.1 + PKCE authentication when tools are first invoked.258259### 5.3 Cursor2602611. Open **Settings** (Cmd/Ctrl + ,)2622. Navigate to **MCP** section2633. Click **Add Server**2644. Configure:265 - **Name:** `bkend`266 - **Type:** HTTP267 - **URL:** `https://api.bkend.ai/mcp`2685. Click **Save**269270Cursor will prompt for OAuth authentication when MCP tools are first used.271272### 5.4 Windsurf273274Create or edit `.windsurfrules` or use the MCP configuration in settings:275276```json277{278 "mcpServers": {279 "bkend": {280 "serverUrl": "https://api.bkend.ai/mcp",281 "transport": "streamable-http"282 }283 }284}285```286287### 5.5 VS Code (GitHub Copilot)288289Add to `.vscode/settings.json`:290291```json292{293 "github.copilot.chat.mcpServers": {294 "bkend": {295 "type": "http",296 "url": "https://api.bkend.ai/mcp"297 }298 }299}300```301302### 5.6 Other Editors303304Any MCP-compatible editor can connect to bkend.ai using:305- **Transport:** Streamable HTTP306- **URL:** `https://api.bkend.ai/mcp`307- **Auth:** OAuth 2.1 + PKCE (handled automatically by most clients)308309---310311## 6. OAuth 2.1 + PKCE Authentication Flow312313### Flow Overview314315```316AI Client bkend.ai Auth Server User Browser317 | | |318 |-- 1. Generate code_verifier -->| |319 |-- 2. Compute code_challenge -->| |320 | | |321 |-- 3. GET /oauth/authorize ---->| |322 | ?client_id=... | |323 | &code_challenge=... | |324 | &code_challenge_method=S256 |325 | &redirect_uri=... | |326 | &response_type=code | |327 | &scope=mcp | |328 | |-- 4. Show login page -------->|329 | |<-- 5. User authenticates -----|330 | | |331 |<-- 6. Redirect with auth code -| |332 | ?code=AUTH_CODE | |333 | | |334 |-- 7. POST /oauth/token ------->| |335 | grant_type=authorization_code |336 | code=AUTH_CODE | |337 | code_verifier=... | |338 | | |339 |<-- 8. Access + Refresh tokens -| |340 | | |341 |-- 9. MCP requests with ------->| |342 | Authorization: Bearer ... | |343```344345### Token Lifecycle346347| Token | Lifetime | Storage | Refresh Method |348|----------------|----------|---------------------|-------------------------|349| Access Token | 1 hour | In-memory (client) | Exchange refresh token |350| Refresh Token | 30 days | Secure storage | Re-authenticate |351352### Token Refresh353354When the access token expires, the MCP client automatically:3551. Sends a `POST /oauth/token` request with `grant_type=refresh_token`3562. Includes the refresh token in the request body3573. Receives a new access token (and optionally a new refresh token)3584. Retries the failed MCP request with the new access token359360---361362## 7. MCP Best Practices363364### 7.1 Session Initialization365366Always start by verifying your session context:367368```3691. Call get_context -> verify org, project, and environment3702. Call backend_table_list -> understand available data structures3713. Proceed with specific operations372```373374### 7.2 Schema-First Development375376Create tables and define schemas via MCP before performing data operations:377378```3791. backend_table_create -> define table with fields3802. backend_field_manage -> add/modify fields as needed3813. backend_index_manage -> create indexes for query performance3824. backend_data_create -> insert records383```384385### 7.3 Documentation-Driven Code Generation386387For Auth and Storage features (no MCP tools), use documentation tools:388389```3901. search_docs("authentication login flow") -> get documentation3912. get_operation_schema("auth-login") -> get OpenAPI schema3923. Generate client code based on the schema393```394395### 7.4 Environment Awareness396397- Always confirm which environment (dev/staging/prod) you are working in before making changes398- Use `get_context` to verify the active environment399- Create separate environments for development and production workflows400401### 7.5 Batch Operations402403- Use filtering and pagination with `backend_data_list` for large datasets404- Set appropriate `limit` values (default: 20, max: 100) to avoid excessive data transfer405- Use `sort` to control the order of returned records406407---408409## 8. Common MCP Errors and Solutions410411### Connection Errors412413| Error | Cause | Solution |414|---------------------------------|------------------------------------|-----------------------------------------|415| `401 Unauthorized` | Expired or missing access token | Re-authenticate via OAuth flow |416| `403 Forbidden` | Insufficient permissions or RLS | Check API key type and RLS policies |417| `404 Not Found` | Invalid endpoint or resource ID | Verify server URL and resource IDs |418| `429 Too Many Requests` | Rate limit exceeded | Wait and retry with exponential backoff |419| `500 Internal Server Error` | Server-side issue | Retry after a brief delay |420421### Tool Invocation Errors422423| Error | Cause | Solution |424|---------------------------------|------------------------------------|-----------------------------------------|425| `tool_not_found` | Tool name is incorrect | Check tool catalog for exact names |426| `invalid_params` | Missing or invalid parameters | Review tool parameter requirements |427| `env_not_set` | No environment selected | Call `get_context` and set environment |428| `table_not_found` | Table does not exist | Use `backend_table_list` to verify |429| `field_type_mismatch` | Data type does not match schema | Check field types with `backend_table_get` |430431### Authentication Errors432433| Error | Cause | Solution |434|---------------------------------|------------------------------------|-----------------------------------------|435| `oauth_pkce_mismatch` | Code verifier does not match | Regenerate code_verifier and retry |436| `oauth_code_expired` | Authorization code expired | Restart OAuth flow from the beginning |437| `oauth_redirect_mismatch` | Redirect URI does not match | Verify redirect_uri matches registered value |438| `refresh_token_expired` | Refresh token (30d) expired | Full re-authentication required |439440---441442## Quick Reference Card443444### Essential Tool Sequence445446```447get_context # 1. Verify session448backend_org_list # 2. List organizations449backend_project_list(orgId) # 3. List projects450backend_table_list(envId) # 4. List tables451backend_data_list(envId, tableId) # 5. Query data452```453454### MCP Server Connection455456```457URL: https://api.bkend.ai/mcp458Transport: Streamable HTTP459Auth: OAuth 2.1 + PKCE460```461462### Tool Count Summary463464| Category | Count | Tools |465|--------------------|-------|-----------------------------------------------|466| Fixed | 3 | get_context, search_docs, get_operation_schema |467| Project Management | 6 | org_list, project_list/create/get, env_list/create |468| Table Management | 9 | table CRUD (5), field_manage, index_manage, schema_version (2) |469| Data CRUD | 5 | data_list/get/create/update/delete |470| Environment | 3 | env_list/create/get |471| Schema | 2 | schema_version_list/get |472| **Total** | **28**| |473474---475> Converted and distributed by [TomeVault](https://tomevault.io/claim/popup-studio-ai) — claim your Tome and manage your conversions.476<!-- tomevault:4.0:skill_md:2026-04-11 -->