Prompts using Gemini CLI
Before you begin
This guide assumes you have already done the following:
- Installed PostgreSQL 16+ and the
psqlclient.
Step 1: Set up your database
In this section, we will create a database, insert some data that needs to be accessed by our agent, and create a database user for Toolbox to connect with.
Connect to postgres using the
psqlcommand:psql -h 127.0.0.1 -U postgresHere,
postgresdenotes the default postgres superuser.Info
Having trouble connecting?
- Password Prompt: If you are prompted for a password for the
postgresuser and do not know it (or a blank password doesn’t work), your PostgreSQL installation might require a password or a different authentication method. FATAL: role "postgres" does not exist: This error means the defaultpostgressuperuser role isn’t available under that name on your system.Connection refused: Ensure your PostgreSQL server is actually running. You can typically check withsudo systemctl status postgresqland start it withsudo systemctl start postgresqlon Linux systems.
Common Solution
For password issues or if the
postgresrole seems inaccessible directly, try switching to thepostgresoperating system user first. This user often has permission to connect without a password for local connections (this is called peer authentication).sudo -i -u postgres psql -h 127.0.0.1Once you are in the
psqlshell using this method, you can proceed with the database creation steps below. Afterwards, type\qto exitpsql, and thenexitto return to your normal user shell.If desired, once connected to
psqlas thepostgresOS user, you can set a password for thepostgresdatabase user using:ALTER USER postgres WITH PASSWORD 'your_chosen_password';. This would allow direct connection with-U postgresand a password next time.- Password Prompt: If you are prompted for a password for the
Create a new database and a new user:
Tip
For a real application, it’s best to follow the principle of least permission and only grant the privileges your application needs.
CREATE USER toolbox_user WITH PASSWORD 'my-password'; CREATE DATABASE toolbox_db; GRANT ALL PRIVILEGES ON DATABASE toolbox_db TO toolbox_user; ALTER DATABASE toolbox_db OWNER TO toolbox_user;End the database session:
\q(If you used
sudo -i -u postgresand thenpsql, remember you might also need to typeexitafter\qto leave thepostgresuser’s shell session.)Connect to your database with your new user:
psql -h 127.0.0.1 -U toolbox_user -d toolbox_dbCreate the required tables using the following commands:
CREATE TABLE users ( id SERIAL PRIMARY KEY, username VARCHAR(50) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW() ); CREATE TABLE restaurants ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, location VARCHAR(100) ); CREATE TABLE reviews ( id SERIAL PRIMARY KEY, user_id INT REFERENCES users(id), restaurant_id INT REFERENCES restaurants(id), rating INT CHECK (rating >= 1 AND rating <= 5), review_text TEXT, is_published BOOLEAN DEFAULT false, moderation_status VARCHAR(50) DEFAULT 'pending_manual_review', created_at TIMESTAMPTZ DEFAULT NOW() );Insert dummy data into the tables.
INSERT INTO users (id, username, email) VALUES (123, 'jane_d', 'jane.d@example.com'), (124, 'john_s', 'john.s@example.com'), (125, 'sam_b', 'sam.b@example.com'); INSERT INTO restaurants (id, name, location) VALUES (455, 'Pizza Palace', '123 Main St'), (456, 'The Corner Bistro', '456 Oak Ave'), (457, 'Sushi Spot', '789 Pine Ln'); INSERT INTO reviews (user_id, restaurant_id, rating, review_text, is_published, moderation_status) VALUES (124, 455, 5, 'Best pizza in town! The crust was perfect.', true, 'approved'), (125, 457, 4, 'Great sushi, very fresh. A bit pricey but worth it.', true, 'approved'), (123, 457, 5, 'Absolutely loved the dragon roll. Will be back!', true, 'approved'), (123, 456, 4, 'The atmosphere was lovely and the food was great. My photo upload might have been weird though.', false, 'pending_manual_review'), (125, 456, 1, 'This review contains inappropriate language.', false, 'rejected');End the database session:
\q
Step 2: Configure Toolbox
Create a file named tools.yaml. This file defines the database connection, the
SQL tools available, and the prompts the agents will use.
sources:
my-foodiefind-db:
kind: postgres
host: 127.0.0.1
port: 5432
database: toolbox_db
user: toolbox_user
password: my-password
tools:
find_user_by_email:
kind: postgres-sql
source: my-foodiefind-db
description: Find a user's ID by their email address.
parameters:
- name: email
type: string
description: The email address of the user to find.
statement: SELECT id FROM users WHERE email = $1;
find_restaurant_by_name:
kind: postgres-sql
source: my-foodiefind-db
description: Find a restaurant's ID by its exact name.
parameters:
- name: name
type: string
description: The name of the restaurant to find.
statement: SELECT id FROM restaurants WHERE name = $1;
find_review_by_user_and_restaurant:
kind: postgres-sql
source: my-foodiefind-db
description: Find the full record for a specific review using the user's ID and the restaurant's ID.
parameters:
- name: user_id
type: integer
description: The numerical ID of the user.
- name: restaurant_id
type: integer
description: The numerical ID of the restaurant.
statement: SELECT * FROM reviews WHERE user_id = $1 AND restaurant_id = $2;
prompts:
investigate_missing_review:
description: "Investigates a user's missing review by finding the user, restaurant, and the review itself, then analyzing its status."
arguments:
- name: "user_email"
description: "The email of the user who wrote the review."
- name: "restaurant_name"
description: "The name of the restaurant being reviewed."
messages:
- content: >-
**Goal:** Find the review written by the user with email '{{.user_email}}' for the restaurant named '{{.restaurant_name}}' and understand its status.
**Workflow:**
1. Use the `find_user_by_email` tool with the email '{{.user_email}}' to get the `user_id`.
2. Use the `find_restaurant_by_name` tool with the name '{{.restaurant_name}}' to get the `restaurant_id`.
3. Use the `find_review_by_user_and_restaurant` tool with the `user_id` and `restaurant_id` you just found.
4. Analyze the results from the final tool call. Examine the `is_published` and `moderation_status` fields and explain the review's status to the user in a clear, human-readable sentence.
Step 3: Connect to Gemini CLI
Configure the Gemini CLI to talk to your local Toolbox MCP server.
Open or create your Gemini settings file:
~/.gemini/settings.json.Add the following configuration to the file:
{ "mcpServers": { "MCPToolbox": { "httpUrl": "http://localhost:5000/mcp" } }, "mcp": { "allowed": ["MCPToolbox"] } }Start Gemini CLI using
geminiIn case Gemini CLI is already running, use
/mcp refreshto refresh the MCP server.Use gemini slash commands to run your prompt:
/investigate_missing_review --user_email="jane.d@example.com" --restaurant_name="The Corner Bistro"