How to create a SQL Agent with Agno and GibsonAI

Step-by-step guide on how to create a SQL Agent with Agno and GibsonAI

This guide will show you how to build a SQL Agent that can create, modify, and manage databases using GibsonAI MCP Server and Agno.

What You’ll Build

  • A SQL Agent powered by Agno that can:
    • Create new databases and tables from natural language prompts.
    • Modify existing schemas (add, remove, or update columns and tables).
    • Deploy schema changes to serverless databases (e.g., MySQL).
    • Inspect and query database schemas with conversational commands.

Key Concepts

  • GibsonAI MCP Server: Turns natural language prompts into fully functional database schemas and exposes REST APIs for data access and CRUD operations.
  • From Prompt to Database: You can go from describing a database in plain English to having a running schema with deployed APIs in minutes.
  • Serverless Data APIs: Once your schema is created, GibsonAI provides instant endpoints (e.g., /query for SQL operations or /{tablename} for CRUD).

The GibsonAI MCP integration in Agno is available in the Agno repo: GibsonAI MCP Toolkit – agno/cookbook/tools/mcp/gibsonai.py

Prerequisites

Before starting, ensure you have:

  1. A GibsonAI account – Sign up at https://app.gibsonai.com.
  2. Python 3.9+ installed.
  3. OpenAI API key (you can get one from OpenAI).
  1. Install UV Package Manager

    UV is needed to run GibsonAI CLI.

    Run:

    curl -LsSf https://astral.sh/uv/install.sh | sh
  2. Install GibsonAI CLI

    The GibsonAI CLI lets you log in and manage projects:

    uvx --from gibson-cli@latest gibson auth login

    Log in with your GibsonAI account.

  3. Install Python Dependencies

    Install Agno, MCP, and OpenAI libraries:

    pip install agno mcp openai
  4. Set Your OpenAI API Key

    Export your API key:

    export OPENAI_API_KEY="your_openai_api_key"

    (Replace your_openai_api_key with your real key.)

  5. Create a Python File

    Create a new Python file (e.g., sql_agent.py) and copy this code:

    import asyncio
    from textwrap import dedent
    
    from agno.agent import Agent
    from agno.models.openai import OpenAIChat
    from agno.tools.mcp import MCPTools
    
    async def run_gibsonai_agent(message: str) -> None:
        """Run the GibsonAI SQL Agent with the given message."""
        async with MCPTools(
            "uvx --from gibson-cli@latest gibson mcp run",
            timeout_seconds=300,  # Longer timeout for database operations
        ) as mcp_tools:
            agent = Agent(
                name="GibsonAIAgent",
                model=OpenAIChat(id="gpt-4o"),
                tools=[mcp_tools],
                description="SQL Agent for managing database projects and schemas",
                instructions=dedent("""\
                    You are a GibsonAI database assistant.
                    Help users manage databases and schemas by creating tables,
                    updating columns, and deploying schema changes.
                """),
                markdown=True,
                show_tool_calls=True,
            )
    
            await agent.aprint_response(message, stream=True)
    
    # Example usage
    if __name__ == "__main__":
        asyncio.run(
            run_gibsonai_agent(
                "Create a database for a blog with users and posts tables."
            )
        )
  6. Run the Agent

    Run the script:

    python sql_agent.py

    The agent will:

    • Start the GibsonAI MCP Server.
    • Take your prompt (e.g., "Create a database for a blog with users and posts tables").
    • Automatically create a database schema.
  7. View Your Database

    Go to your GibsonAI Dashboard:

    https://app.gibsonai.com

    Here, you can:

    • See your database schema.
    • Check generated REST APIs for your data.

Example Prompts to Try

You can experiment with:

  • "Show me the current schema for my project."
  • "Add a 'products' table with name, price, and description."
  • "Deploy schema changes to production."
  • "Create a new database for a task management app."

Need help?

Join our Discord Server to ask questions or see what others are doing with GibsonAI.

Last updated on

Was this page helpful?