Skip to content

Conversation

@MengqinShen
Copy link
Contributor

@MengqinShen MengqinShen commented Jan 7, 2026

See the summary of changes below from gemini-code-assist.

@github-actions github-actions bot added docs Improvements or additions to documentation python Python config labels Jan 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MengqinShen, 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 introduces a new sample application for the Model Context Protocol (MCP) integrated with the Genkit Python SDK. The sample provides practical, runnable examples that illustrate how to set up and interact with various MCP servers, including those for git operations, filesystem access, and general-purpose tool exposure. It covers both client-side interactions and server-side implementation, aiming to give developers a clear understanding of how to leverage MCP within their Genkit projects for enhanced AI model capabilities.

Highlights

  • New MCP Sample: Introduces a new sample application for the Model Context Protocol (MCP) within the Genkit Python SDK, demonstrating various MCP functionalities.
  • Client/Host Examples: Includes runnable examples for an MCP client/host (main.py and http_server.py) that interact with different MCP servers (git, filesystem, and 'everything' servers).
  • MCP Server Implementation: Provides an example of an MCP server (server.py) that exposes Genkit tools, prompts, and resources, showcasing how to build custom MCP servers.
  • Dynamic Tooling and Resource Handling: Demonstrates advanced MCP features such as dynamic tool selection, enabling/disabling MCP clients, and simulated resource reading.
  • Comprehensive Documentation: Adds a detailed README.md file that guides users through setting up the environment, running the samples, and understanding the requirements and MCP servers involved.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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
Contributor

@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 comprehensive sample for the MCP (Model Context Protocol) plugin in the Genkit Python SDK. The changes include a README, project configuration, and several Python scripts demonstrating client, server, and HTTP server functionalities. The code is well-structured and provides good examples. My review focuses on improving documentation clarity, code robustness, and adherence to Python best practices. I've identified some areas for improvement, such as clarifying the README, removing redundant code, avoiding private API usage, and handling exceptions more safely. Overall, this is a great addition that will be very helpful for users of the MCP plugin.


async def handle_sse(request):
"""Handle incoming SSE connections."""
async with sse.connect_sse(request.scope, request.receive, request._send) as streams:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using the private attribute request._send is not recommended as it relies on internal implementation details of Starlette's Request object. This could break with future updates to the library. It would be better to use a public API if one is available. If not, this reliance on an internal API should be documented with a comment.

Comment on lines +50 to +55
await mcp_host.start()
tools = await mcp_host.register_tools(ai)

result = await ai.generate(prompt=f"summarize last 5 commits in '{repo_root}'", tools=tools)

await mcp_host.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The pattern of manually calling mcp_host.start() at the beginning and mcp_host.close() at the end of each flow is repeated across multiple functions. This is verbose and error-prone, as an exception between these calls would prevent close() from being executed.

Consider refactoring this into a decorator or an async context manager to handle the setup and teardown of the mcp_host automatically. This would make the flow implementations cleaner and more robust.

Example using a decorator:

import functools

def with_mcp_host(flow_func):
    @functools.wraps(flow_func)
    async def wrapper(*args, **kwargs):
        await mcp_host.start()
        try:
            return await flow_func(*args, **kwargs)
        finally:
            await mcp_host.close()
    return wrapper

@ai.flow(name='git_commits')
@with_mcp_host
async def git_commits(query: str = ''):
    tools = await mcp_host.register_tools(ai)
    result = await ai.generate(prompt=f"summarize last 5 commits in '{repo_root}'", tools=tools)
    return result.text


# Filter for specific tool: 'fs/read_file'
# JS: tools: ['test-mcp-manager:tool/fs/read_file']
import fnmatch
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Imports should be at the top of the file, as recommended by PEP 8. Move import fnmatch to the top of the file with the other imports. This improves readability and avoids re-importing the module multiple times within different functions.

# Re-registering might be needed if registry was cleaned, but here we just re-connnect
# Implementation detail: Does register_tools need to be called again?
# Code shows wrappers capture client, client.session is updated on connect.
await mcp_host.clients['fs'].connect()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The mcp_host.enable('fs') call on line 160 should handle re-connecting the client, as demonstrated in the control_mcp flow. This explicit call to connect() is redundant and should be removed.

from pydantic import BaseModel, Field

from genkit.ai import Genkit
from genkit.plugins.google_genai import GoogleAI
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The GoogleAI plugin is imported but not used. Unused imports should be removed to keep the code clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation python Python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants