Skip to content

Conversation

@Vrajesh-Babu
Copy link
Contributor

Add PostgreSQL MCP Agent Sample

This PR adds a new sample agent that demonstrates how to integrate PostgreSQL databases using the Model Context Protocol (MCP).

What's Added

  • PostgreSQL MCP Agent (mcp_postgres_agent/agent.py): A fully functional agent that connects to PostgreSQL databases via the postgres-mcp MCP server
  • Comprehensive README (mcp_postgres_agent/README.md): Documentation with setup instructions, configuration details, and example queries
  • Environment Configuration: Support for secure credential management via .env files

Key Features

  • MCP Integration: Demonstrates proper use of MCPToolset with StdioConnectionParams
  • Zero Installation: Uses uvx to run the MCP server without manual installation
  • Secure Credentials: Database connection strings passed via environment variables
  • Production-Ready: Uses Gemini 2.0 Flash with unrestricted access mode for full database operations

Technical Details

  • Model: Gemini 2.0 Flash
  • MCP Server: postgres-mcp (via uvx)
  • Connection: StdioConnectionParams with 60-second timeout
  • Environment Variable: Maps POSTGRES_CONNECTION_STRING to DATABASE_URI

Testing

The agent has been tested with:

  • PostgreSQL database connections (local and remote)
  • Schema inspection queries
  • Data querying operations
  • Table listing and management

Example Queries

Users can interact with the agent using natural language queries like:

  • "What tables are in the database?"
  • "Show me the schema for the users table"
  • "Query the first 10 rows from the products table"

This sample serves as a reference implementation for developers looking to integrate PostgreSQL databases with ADK agents using MCP.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Vrajesh-Babu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers a new sample agent designed to facilitate the integration of PostgreSQL databases with the Model Context Protocol (MCP). It provides a robust reference implementation for developers, showcasing how to securely manage database credentials, deploy the MCP server with minimal setup using uvx, and interact with PostgreSQL databases using the Gemini 2.0 Flash model for comprehensive data operations. The changes aim to simplify the process of building ADK agents that can effectively communicate with PostgreSQL instances.

Highlights

  • New PostgreSQL MCP Agent Sample: This pull request introduces a new sample agent that demonstrates how to integrate PostgreSQL databases using the Model Context Protocol (MCP).
  • Comprehensive Documentation: A detailed README.md file is included, providing setup instructions, configuration details, and example queries for the PostgreSQL agent.
  • Secure Credential Management: The agent supports secure credential management by loading database connection strings from .env files, mapping POSTGRES_CONNECTION_STRING to DATABASE_URI.
  • Zero-Installation MCP Server: The agent leverages uvx to run the postgres-mcp server, enabling a zero-installation setup without manual server configuration.
  • Production-Ready Configuration: The agent is configured with Gemini 2.0 Flash and uses an unrestricted access mode for the MCP server, allowing full database operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable sample agent for integrating with PostgreSQL databases using the Model Context Protocol (MCP). The code is well-structured and the accompanying README provides clear setup instructions. My review focuses on improving the robustness, security, and reliability of the sample. I've suggested adding an explicit check for the database connection string to prevent runtime errors, lowering the model's temperature for more predictable and accurate SQL generation, and adding a security warning to the README regarding the use of 'unrestricted' access mode. I also pointed out a minor code cleanup by removing an unused import.

@GWeale
Copy link
Collaborator

GWeale commented Oct 16, 2025

Hi, Thank you for the PR! can you fix these failing test

@Vrajesh-Babu Vrajesh-Babu force-pushed the postgres-mcp branch 3 times, most recently from 143ffb2 to c91944e Compare October 17, 2025 04:02
@Vrajesh-Babu
Copy link
Contributor Author

Hi, Thank you for the PR! can you fix these failing test

Hi, I have made the fix for the failing test. Could you please check it out once - Thanks

image

@Vrajesh-Babu Vrajesh-Babu force-pushed the postgres-mcp branch 2 times, most recently from 46db38d to f3b3846 Compare October 21, 2025 07:39
@GWeale GWeale self-requested a review October 22, 2025 22:54
@GWeale GWeale added ready to pull [Status] This PR is ready to be importing back to Google and removed ready to pull [Status] This PR is ready to be importing back to Google labels Oct 22, 2025
@Vrajesh-Babu Vrajesh-Babu requested a review from GWeale October 23, 2025 03:32
copybara-service bot pushed a commit that referenced this pull request Oct 23, 2025
…tgreSQL databases using the Model Context Protocol (MCP)

## What's Added

- **PostgreSQL MCP Agent** ([mcp_postgres_agent/agent.py](cci:7://file:///Users/admin/git%20repos/adk-python/contributing/samples/mcp_postgres_agent/agent.py:0:0-0:0)): A fully functional agent that connects to PostgreSQL databases via the `postgres-mcp` MCP server
- **Comprehensive README** ([mcp_postgres_agent/README.md](cci:7://file:///Users/admin/git%20repos/adk-python/contributing/samples/mcp_postgres_agent/README.md:0:0-0:0)): Documentation with setup instructions, configuration details, and example queries
- **Environment Configuration**: Support for secure credential management via `.env` files

## Key Features

- **MCP Integration**: Demonstrates proper use of `MCPToolset` with `StdioConnectionParams`
- **Zero Installation**: Uses `uvx` to run the MCP server without manual installation
- **Secure Credentials**: Database connection strings passed via environment variables
- **Production-Ready**: Uses Gemini 2.0 Flash with unrestricted access mode for full database operations

## Technical Details

- **Model**: Gemini 2.0 Flash
- **MCP Server**: `postgres-mcp` (via `uvx`)
- **Connection**: StdioConnectionParams with 60-second timeout
- **Environment Variable**: Maps `POSTGRES_CONNECTION_STRING` to `DATABASE_URI`

## Testing

The agent has been tested with:
- PostgreSQL database connections (local and remote)
- Schema inspection queries
- Data querying operations
- Table listing and management

## Example Queries

Users can interact with the agent using natural language queries like:
- "What tables are in the database?"
- "Show me the schema for the users table"
- "Query the first 10 rows from the products table"

This sample serves as a reference implementation for developers looking to integrate PostgreSQL databases with ADK agents using MCP.

COPYBARA_INTEGRATE_REVIEW=#3182 from Vrajesh-Babu:postgres-mcp f3b3846
PiperOrigin-RevId: 822865931
@GWeale
Copy link
Collaborator

GWeale commented Oct 23, 2025

Thank you for your PR just merged this!

@GWeale GWeale closed this Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants