"""
Keboola MCP Agent - Manages your data platform
This example shows how to use the Agno MCP tools to interact with your Keboola project.
1. Get your Keboola Storage API token from your project settings
2. Create a workspace and get your workspace schema
3. Set environment variables:
export KBC_STORAGE_TOKEN=your_keboola_storage_token
export KBC_WORKSPACE_SCHEMA=your_workspace_schema
export KBC_API_URL=https://connection.YOUR_REGION.keboola.com
Dependencies: pip install agno mcp openai
"""
import asyncio
import os
from textwrap import dedent
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mcp import MCPTools
from mcp import StdioServerParameters
async def run_agent():
storage_token = os.getenv("KBC_STORAGE_TOKEN")
workspace_schema = os.getenv("KBC_WORKSPACE_SCHEMA")
api_url = os.getenv("KBC_API_URL", "https://connection.keboola.com")
if not storage_token:
raise ValueError(
"Missing Keboola Storage API token: set KBC_STORAGE_TOKEN environment variable"
)
if not workspace_schema:
raise ValueError(
"Missing Keboola workspace schema: set KBC_WORKSPACE_SCHEMA environment variable"
)
command = "uvx"
args = ["keboola_mcp_server", "--api-url", api_url]
env = {
"KBC_STORAGE_TOKEN": storage_token,
"KBC_WORKSPACE_SCHEMA": workspace_schema,
}
# Add BigQuery credentials if available
google_creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
if google_creds:
env["GOOGLE_APPLICATION_CREDENTIALS"] = google_creds
server_params = StdioServerParameters(command=command, args=args, env=env)
async with MCPTools(server_params=server_params) as mcp_tools:
agent = Agent(
name="KeboolaDataAgent",
model=OpenAIChat(id="gpt-4o"),
tools=[mcp_tools],
description="Agent to query and manage Keboola data platform via MCP",
instructions=dedent("""\
You have access to Keboola data platform through MCP tools.
- Use tools to query tables, manage transformations, and run jobs.
- Confirm with the user before making modifications or running jobs.
- Always use proper SQL syntax based on the workspace dialect (Snowflake or BigQuery).
- When querying tables, use fully qualified table names from table details.
"""),
markdown=True,
show_tool_calls=True,
)
await agent.acli_app(
message="You are a data platform assistant that can access your Keboola project. I can help you query data, create transformations, manage components, and run jobs.",
stream=True,
markdown=True,
exit_on=["exit", "quit"],
)
if __name__ == "__main__":
asyncio.run(run_agent())