No description available
This project demonstrates an Agent Development Kit (ADK) agent that interacts with a local SQLite database. The interaction is facilitated by a Model Context Protocol (MCP) server that exposes tools to query and modify the database.
adk-mcp/
โโโ local_mcp/
โ โโโ agent.py # The ADK agent for the local SQLite DB
โ โโโ server.py # The MCP server exposing database tools
โ โโโ create_db.py # Script to initialize the SQLite database
โ โโโ database.db # The SQLite database file
โ โโโ __init__.py
โโโ remote_mcp_agent/ # Example agent for connecting to a remote MCP server
โ โโโ agent.py # The ADK agent configured for a remote MCP
โ โโโ __init__.py
โโโ .env # For GOOGLE_API_KEY (ensure it's in .gitignore if repo is public)
โโโ requirements.txt # Python dependencies
โโโ readme.md # This file
It's highly recommended to use a virtual environment to manage project dependencies.
# Create a virtual environment (e.g., named .venv)
python3 -m venv .venv
Activate the virtual environment:
On macOS/Linux:
# Activate virtual environment
source .venv/bin/activate
On Windows:
# Activate virtual environment
.venv\Scripts\activate
Install all required Python packages using pip:
# Install all dependencies from requirements.txt
pip install -r requirements.txt
The ADK agent in this project uses a Gemini model. You'll need a Gemini API key.
Create or use an existing Google AI Studio account.
Get your Gemini API key from the API Keys section.
Set the API key as an environment variable. Create a .env
file in the root of the adk-mcp
project (i.e., next to the local_mcp
folder and readme.md
):
# .env
GOOGLE_API_KEY=your_gemini_api_key_here
The server.py
and agent.py
will load this key.
The project includes a script to create and populate the SQLite database (database.db
) with some initial tables (users
, todos
) and dummy data.
Navigate to the local_mcp
directory and run the script:
cd local_mcp
python3 create_db.py
cd ..
This will create local_mcp/database.db
if it doesn't already exist.
The ADK agent (local_mcp/agent.py
) is configured to automatically start the MCP server (local_mcp/server.py
) when it initializes its MCP toolset.
To run the agent:
Ensure your virtual environment is active and you are in the root directory of the adk-mcp
project.
Execute the agent script:
python3 local_mcp/agent.py
This will:
agent.py
script.MCPToolset
, will execute the python3 local_mcp/server.py
command.server.py
(MCP server) will start and listen for tool calls from the agent via stdio.You should see log output from both the agent (if any) and the MCP server (in local_mcp/mcp_server_activity.log
, and potentially to the console if you uncommented the stream handler in server.py
).
While the local SQLite MCP server in this specific project (local_mcp/server.py
) only requires Python for its own execution, you might want to use this ADK agent to connect to other MCP servers that have different runtime dependencies. Two common dependencies for such external MCP servers are Node.js (which provides npx
for running JavaScript-based servers) and Docker (for servers distributed as Docker images).
If you plan to use MCP servers requiring these, here's how to set them up:
npx
is a package runner tool that comes with npm
(Node Package Manager), which is included with Node.js. It's often used to run MCP servers built with Node.js without needing to install them globally.
npm
and npx
) from the official Node.js website. It is recommended to install the LTS (Long Term Support) version.node -v
npm -v
npx -v
You should see version numbers printed for each command, confirming they are installed and in your system's PATH.Docker allows applications to be packaged and run in isolated environments called containers. Some MCP servers are distributed as Docker images, making them easy to run across different operating systems.
docker --version
# You can also run a test container to ensure Docker is working correctly:
# docker run hello-world
The first command should display your Docker version. Running docker run hello-world
will download and run a small test image, confirming Docker is operational.Setting up these tools will broaden the range of MCP servers your ADK agent can potentially interact with.
The local_mcp/server.py
exposes the following tools for the ADK agent to use:
list_db_tables(dummy_param: str) -> dict
: Lists all tables in the database.
dummy_param
string due to current ADK schema generation behavior; the agent's instructions guide it to provide a default.get_table_schema(table_name: str) -> dict
: Retrieves the schema (column names and types) for a specified table.query_db_table(table_name: str, columns: str, condition: str) -> list[dict]
: Queries a table.
columns
: Comma-separated list of columns (e.g., "id, username") or "*" for all.condition
: SQL WHERE clause (e.g., "email LIKE '%@example.com'"). The agent is instructed to use "1=1" if no condition is implied.insert_data(table_name: str, data: dict) -> dict
: Inserts a new row into a table.
data
: A dictionary where keys are column names and values are the corresponding data for the new row.delete_data(table_name: str, condition: str) -> dict
: Deletes rows from a table based on a condition.
The agent (local_mcp/agent.py
) has specific instructions on how to use these tools effectively, including using smart defaults for parameters if not explicitly provided by the end-user's request.
No such file or directory
for server.py
:
PATH_TO_YOUR_MCP_SERVER_SCRIPT
in local_mcp/agent.py
correctly points to local_mcp/server.py
. The current setup uses (Path(__file__).parent / "server.py").resolve()
, which should be correct after the folder consolidation.McpError: Input must be an instance of Schema, got <class 'NoneType'>
(Client-side Error):
adk_to_mcp_tool_type
in server.py
generates a None
input schema for a tool. The list_db_tables
tool in server.py
includes a dummy_param
as a workaround for this known issue with parameter-less functions. The server also has a patch to provide a default schema if one is None
.python3 local_mcp/create_db.py
to create the database.db
file and its tables.DATABASE_PATH
in local_mcp/server.py
correctly points to local_mcp/database.db
.GOOGLE_API_KEY
is correctly set in the .env
file in the project root and that the file is being loaded.local_mcp/mcp_server_activity.log
for detailed logs from the MCP server, which can help diagnose issues with tool calls or database operations.{ "mcpServers": { "adk-mcp-tutorial": { "command": "python3", "args": [ "local_mcp/server.py" ] } } }
Related projects feature coming soon
Will recommend related projects based on sub-categories