Skip to content

Commit 2b4f3cb

Browse files
authored
Merge branch 'main' into martinmatejka-kids-453-update-telemetry-dashboards-docs
2 parents df34a64 + 7bfee88 commit 2b4f3cb

5 files changed

Lines changed: 204 additions & 1 deletion

File tree

_data/navigation.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ items:
8989
- url: /kai/security-and-privacy/
9090
title: Security & Privacy
9191

92+
- url: /kai/python-client/
93+
title: Python Client
94+
9295
- url: /flows/
9396
title: Flows
9497
items:

ai/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Keboola integrates artificial intelligence throughout the platform to enhance pr
1717
Keboola's embedded AI assistant that serves as a comprehensive data engineering co-pilot within the platform. Kai is context-aware of your specific project and can both explore and modify your Keboola environment through natural conversation.
1818
[Learn more about Kai →](/kai/)
1919

20+
A [Python client library](https://github.com/keboola/kai-client) is also available for programmatic access to the Kai API, enabling scripting, automation, and integration into custom workflows.
21+
[Learn more about the Python Client →](/kai/python-client/)
22+
2023
### MCP Server
2124

2225
Model Context Protocol server integration for seamless communication between AI agents and your data infrastructure on Keboola.

components/extractors/other/telemetry-data/telemetry-data.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Keep in mind that the tables *contact_limit_monthly*, *kbc_organization*, and *u
3434
***Note:** You can find the schema in full resolution and with several export options [here](https://dbdiagram.io/d/602629a380d742080a3a406a).*
3535

3636
## Project Mode Tables
37-
The extracted tables provide you with information about your buckets, configurations, branches, jobs, sandboxes, projects, users, and security events.
37+
The extracted tables provide you with information about your buckets, configurations, branches, jobs, AI agent and MCP interactions, sandboxes, projects, users, and security events.
3838

3939
### kbc_bucket_snapshot
4040
This table shows snapshots of buckets in Storage.
@@ -228,6 +228,37 @@ This table lists Keboola [jobs](/management/jobs/)
228228
| `backend_size` | Backend used for data science transformations (`Small`, `Medium`, `Large`) | `Small` |
229229
| `company_id` | Identifier of the company the event belongs to | `011t00000Gs3BiAAJ` |
230230

231+
### kbc_mcp_event
232+
This table captures [MCP](/ai/mcp-server/) (Model Context Protocol) interaction events — every tool call made against a Keboola project
233+
through an MCP server. This includes calls from external MCP clients (e.g., Claude Desktop, Cursor) as well as
234+
Keboola's internal AI agents such as [Kai](/ai/kai-assistant/) and AI Chat. Each row represents a single tool invocation with its
235+
input arguments, outcome (success or error), duration, and the context of the caller.
236+
237+
The table enables analysis of AI-assisted operations: what tools are used, by whom, how often they fail,
238+
which environments and agent types drive the most activity, and how MCP adoption evolves over time.
239+
240+
| **Column** | **Description** | **Example** |
241+
|---|---|---|
242+
| `kbc_mcp_event_id` (PK) | Unique identifier of the MCP event | `019d032f-b425-7692-bb3c-638fed287c7a_com-keboola-gcp-us-east4` |
243+
| `kbc_project_id` (FK) | Foreign key to the Keboola project where the tool call was executed | `361_com-keboola-gcp-us-east4` |
244+
| `event_created_at` | Timestamp when the MCP event occurred | `2026-03-18 23:02:31.000` |
245+
| `event` | Event source identifier indicating the MCP server component that handled the call. Possible values include: <br> `ext.keboola.mcp-server-tool.` – external MCP server tool call, <br> `ext.keboola.kai-assistant.` – Kai assistant tool call, <br> `ext.keboola.ai-chat.` – AI Chat tool call | `ext.keboola.kai-assistant.` |
246+
| `type` | Outcome of the tool call (`success`, `error`) | `success` |
247+
| `kbc_token_id` (FK) | Composite identifier of the token used for the MCP session (numeric ID + stack) | `1177215_com-keboola-gcp-us-east4` |
248+
| `token_name` | Name of the token used for the MCP session — typically the user's email for interactive sessions or a scheduler token name for automated calls | `some_user@example.com` |
249+
| `api_version` | Version of the Keboola API used by the MCP server | `v2` |
250+
| `http_user_agent` | HTTP user agent string of the MCP server, including server version, environment, and transport protocol | `Keboola MCP Server/1.48.4 app_env=local transport=http-compat/streamable-http` |
251+
| `mcp_user_agent` | User agent of the MCP client connecting to the server (e.g., the IDE or AI tool). Identifies the caller application | `claude-ai/0.1.0` |
252+
| `mcp_version` | Version of the Keboola MCP server that processed the call | `1.48.4` |
253+
| `mcp_environment` | Deployment environment of the MCP server. `DEV` for local/external clients; production hashes for Keboola-hosted agents (Kai, AI Chat) | `DEV` |
254+
| `mcp_conversation_id` | Unique identifier linking tool calls within the same conversation session. Empty for external clients that don't report conversation context | `4a22b77b-5a08-4ec3-8477-3c6f4369c418` |
255+
| `tool` | Name of the MCP tool that was called (e.g., `query_data`, `get_project_info`, `create_sql_transformation`) | `query_data` |
256+
| `tool_arguments` | JSON array of key-value pairs representing the arguments passed to the tool call | `[{"key":"bucket_ids","value":"[]"}]` |
257+
| `duration` | Duration of the tool call execution in seconds | `3` |
258+
| `message` | Result message — a success confirmation or the full error message for failed calls | `MCP tool "query_data" call succeeded.` |
259+
| `agent_type` | Type of agent that made the call. Possible values: <br> `external` – an external MCP client (Claude Desktop, Cursor, etc.), <br> `kai-assistant` – the Keboola Kai assistant, <br> `ai-chat` – the Keboola AI Chat | `kai-assistant` |
260+
| `is_keboola_agent_event` | Flag indicating whether the event originated from a Keboola-managed AI agent (`true` for Kai and AI Chat, `false` for external clients) | `true` |
261+
231262
### kbc_project
232263
This table shows data about Keboola [projects](/management/project/)
233264
belonging to an organization.

kai/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Kai is now in **Public Beta** and available to all users. Look for the **KAI** b
5353
- [Settings (Tool Permissions & System Instructions)](/kai/settings/)
5454
- [Use Cases & Examples](/kai/use-cases/)
5555
- [Best Practices](/kai/best-practices/)
56+
- [Python Client](/kai/python-client/)
5657

5758
## Security & Privacy
5859

kai/python-client.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: Kai Python Client
3+
permalink: /kai/python-client/
4+
---
5+
6+
* TOC
7+
{:toc}
8+
9+
The [Kai Python Client](https://github.com/keboola/kai-client) is an official Python library for interacting with the Kai API programmatically. It provides async support, SSE streaming, a command-line interface, and comprehensive type safety through Pydantic models.
10+
11+
## Features
12+
13+
- **Command-line interface** for quick interactions without writing code
14+
- **Real-time streaming** — see responses as they arrive
15+
- **Conversation management** — maintain context across multiple messages
16+
- **Tool approval flows** — review and approve Kai actions programmatically
17+
- **Full API coverage** — chat, history, and feedback
18+
19+
## Installation
20+
21+
### Using uv (recommended)
22+
23+
```bash
24+
uv add kai-client
25+
```
26+
27+
### Using pip
28+
29+
```bash
30+
pip install kai-client
31+
```
32+
33+
## Prerequisites
34+
35+
The Kai Python Client requires a [Master Token](/management/project/tokens/#master-tokens) to authenticate with the Keboola API. Standard tokens with limited permissions will not work. You can create a Master Token in your project's **Settings → API Tokens**.
36+
37+
## Quick Start
38+
39+
```python
40+
import asyncio
41+
from kai_client import KaiClient
42+
43+
async def main():
44+
# Auto-discover the Kai API URL from your Keboola stack
45+
client = await KaiClient.from_storage_api(
46+
storage_api_token="your-master-token",
47+
storage_api_url="https://connection.keboola.com" # Your stack URL
48+
)
49+
50+
async with client:
51+
# Start a new chat
52+
chat_id = client.new_chat_id()
53+
54+
# Send a message and stream the response
55+
async for event in client.send_message(chat_id, "What tables do I have?"):
56+
if event.type == "text":
57+
print(event.text, end="", flush=True)
58+
elif event.type == "tool-call":
59+
print(f"\n[Calling tool: {event.tool_name}]")
60+
elif event.type == "finish":
61+
print(f"\n[Finished: {event.finish_reason}]")
62+
63+
asyncio.run(main())
64+
```
65+
66+
## Command-Line Interface
67+
68+
The package includes a `kai` CLI for quick interactions without writing code.
69+
70+
### Setup
71+
72+
Set your credentials as environment variables:
73+
74+
```bash
75+
export STORAGE_API_TOKEN="your-master-token"
76+
export STORAGE_API_URL="https://connection.keboola.com"
77+
```
78+
79+
### Commands
80+
81+
```bash
82+
kai ping # Check server health
83+
kai info # Show server version and info
84+
kai chat # Start an interactive chat session
85+
kai chat -m "List my tables" # Send a single message
86+
kai chat --auto-approve -m "..." # Auto-approve tool calls
87+
kai history # View recent chat history
88+
kai get-chat <chat-id> # Get full chat details
89+
kai delete-chat <chat-id> # Delete a chat
90+
```
91+
92+
In interactive mode, type your messages and press Enter. Type `exit`, `quit`, or press Ctrl+C to end.
93+
94+
**Tool approval:** When Kai calls a write tool (e.g., `update_descriptions`, `run_job`, `create_config`), the CLI pauses and asks you to approve or deny. Use `--auto-approve` to skip this prompt.
95+
96+
For more usage examples (non-streaming chat, conversations, tool calls, tool approval, error handling), see the [client README](https://github.com/keboola/kai-client#readme).
97+
98+
## Use Cases
99+
100+
### Integrating Kai into Data Apps
101+
102+
The Kai Python Client can be embedded into Keboola [Data Apps](/data-apps/) to provide AI-powered chat interfaces for your end users.
103+
104+
**Important:** Data Apps are automatically provisioned with a Storage API token, but this built-in token is **not** a master token and is insufficient for the Kai Client. You must pass a [Master Token](/management/project/tokens/#master-tokens) explicitly — for example, via a [secret environment variable](/data-apps/python-js/#secrets) in your Data App configuration.
105+
106+
#### Python/JS Data Apps
107+
108+
You can integrate Kai into [Python/JS Data Apps](/data-apps/python-js/) today using the Kai Python Client directly. A dedicated plugin with ready-made patterns will be available soon to simplify the setup.
109+
110+
#### Streamlit Data Apps
111+
112+
The [kai-streamlit plugin](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) provides patterns and working code for building [Streamlit Data Apps](/data-apps/streamlit/) with an integrated Kai chat interface. It handles the async bridge between Streamlit's synchronous model and the KaiClient's async API, streaming responses into Streamlit containers, tool approval flows with interactive Approve/Deny buttons, and session state management across Streamlit reruns.
113+
114+
To get started, install the dependencies:
115+
116+
```bash
117+
pip install kai-client streamlit
118+
```
119+
120+
Then use the `run_async` bridge pattern to call KaiClient from Streamlit:
121+
122+
```python
123+
import asyncio
124+
from kai_client import KaiClient
125+
126+
def run_async(coro):
127+
"""Run an async coroutine from sync Streamlit code."""
128+
loop = asyncio.new_event_loop()
129+
try:
130+
return loop.run_until_complete(coro)
131+
finally:
132+
loop.close()
133+
```
134+
135+
See the [plugin repository](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) for a complete working example with streaming, tool approval, and suggested action buttons.
136+
137+
### Kai via CLI with Claude Code
138+
139+
The [kai-cli plugin](https://github.com/keboola/kai-client/tree/main/plugins/kai-cli) lets AI coding assistants like [Claude Code](https://claude.com/claude-code) interact with your Keboola project through the Kai CLI. Install the plugin to give Claude the ability to query data, manage configurations, run jobs, and troubleshoot issues — all through natural language in your terminal.
140+
141+
#### Installation
142+
143+
Download the plugin to your Claude Code plugins directory:
144+
145+
```bash
146+
mkdir -p ~/.claude/plugins
147+
148+
curl -L https://github.com/keboola/kai-client/archive/refs/heads/main.tar.gz | \
149+
tar -xz --strip-components=2 -C ~/.claude/plugins kai-client-main/plugins/kai-cli
150+
```
151+
152+
Or clone and link for development:
153+
154+
```bash
155+
git clone https://github.com/keboola/kai-client.git
156+
ln -s "$(pwd)/kai-client/plugins/kai-cli" ~/.claude/plugins/kai-cli
157+
```
158+
159+
Once installed, ask Claude to "use kai" or "help me with kai cli" to activate the skill. Claude can then run `kai chat`, `kai history`, `kai ping`, and other CLI commands on your behalf.
160+
161+
## Resources
162+
163+
- [GitHub Repository](https://github.com/keboola/kai-client)
164+
- [PyPI Package](https://pypi.org/project/kai-client/)
165+
- [Kai Documentation](/kai/)

0 commit comments

Comments
 (0)