Skip to content

Conversation

@MengqinShen
Copy link
Contributor

Description here... Help the reviewer by:

  • linking to an issue that includes more details
  • if it's a new feature include samples of how to use the new feature
  • (optional if issue link is provided) if you fixed a bug include basic bug details

Checklist (if applicable):

@github-actions github-actions bot added docs Improvements or additions to documentation js python Python ci config labels Jan 9, 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 foundational support for the Model Context Protocol (MCP) within the Python Genkit framework, significantly enhancing its ability to interact with external, dynamically provided tools and resources. The changes span core API modifications to accommodate resource grounding and dynamic action resolution, alongside a robust sample application that showcases practical integrations with various MCP clients and servers. This feature aims to make Genkit more extensible and adaptable to diverse operational environments by allowing seamless discovery and utilization of external capabilities.

Highlights

  • Model Context Protocol (MCP) Integration: Core Genkit Python APIs (genkit.ai.generate, genkit.blocks.prompt, genkit.core.registry) are updated to support the Model Context Protocol (MCP), enabling dynamic discovery and interaction with external tools and resources.
  • Dynamic Action Providers: The Genkit registry now supports DYNAMIC_ACTION_PROVIDER action kinds, allowing for asynchronous lookup and resolution of actions (tools, resources) provided by external MCP servers.
  • Resource Grounding: New resources parameters are introduced across Genkit's generation APIs and prompt definitions, allowing models to be grounded with external data sources managed via MCP.
  • Comprehensive MCP Sample: A new Python sample (py/samples/mcp) is added, demonstrating various MCP features including integration with Git and filesystem MCP clients, dynamic tool selection, resource grounding, and dynamic control (enable/disable/reconnect) of MCP clients.
  • Asynchronous Registry Operations: Many registry lookup and listing operations have been converted to asynchronous methods to better support dynamic and potentially network-bound action resolution.

🧠 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 support for resources in the Python Genkit library, which can be used for grounding in generation requests. This is a significant feature that touches many parts of the core library, including generate, prompt, action, and registry. The changes also include making the action registry lookups asynchronous to support dynamic action providers, which is a major architectural change. A new sample application for MCP (mcp-sample) is also added to demonstrate these new capabilities.

My review found a critical issue in the compat-oai plugin where a method call was changed to a non-existent method, which will cause a runtime error. There are also some medium-severity issues related to code style (local imports) and redundancy in the MCP server setup.

Overall, this is a substantial and important feature addition. The core logic seems well-implemented, but the side-effects on other plugins and some code style issues need to be addressed.

result = []
for tool_definition in tools:
action = self._registry.registry.lookup_action(ActionKind.TOOL, tool_definition.name)
action = self._registry.registry.get_action(ActionKind.TOOL, tool_definition.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This change from lookup_action to get_action is incorrect, as the Registry class does not have a get_action method. This will cause an AttributeError.

The correct method is lookup_action, which has been made async in this PR. This means that this function _get_tools_definition and its callers (_get_openai_request_config and generate) must be converted to async to correctly await the lookup_action call.

Additionally, assuming self._registry is the GenkitRegistry instance, the call should be await self._registry.lookup_action(...), not self._registry.registry.get_action(...).

Note: The suggested code below will only work after you convert _get_tools_definition and its callers to async methods.

Suggested change
action = self._registry.registry.get_action(ActionKind.TOOL, tool_definition.name)
action = await self._registry.lookup_action(ActionKind.TOOL, tool_definition.name)


resources: list[Action] = []
if request.resources:
from genkit.blocks.resource import lookup_resource_by_name
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Local imports are generally discouraged as they can affect readability and hide dependencies. It's better to move this import to the top of the file unless it's needed to avoid a circular dependency. Based on the file structure, a circular dependency doesn't seem to be the case here.

Comment on lines +621 to +629
from genkit.blocks.resource import lookup_resource_by_name

for res_name in options.resources:
res_action = await lookup_resource_by_name(registry, res_name)
if res_action is None:
raise GenkitError(status='NOT_FOUND', message=f'Unable to resolve resource {res_name}')
resources.append(res_action)

from genkit.blocks.generate import to_tool_definition
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There are a couple of local imports within this function (lookup_resource_by_name and to_tool_definition). It's generally better practice to have all imports at the top of the file for readability and to avoid potential issues, unless it's to resolve a circular dependency. Consider moving these imports to the top of the file.

Comment on lines +157 to 162
for kind in [ActionKind.TOOL, ActionKind.PROMPT, ActionKind.RESOURCE]:
actions = self.ai.registry.get_actions_by_kind(kind)
for action in actions.values():
if kind == ActionKind.TOOL and action not in self.tool_actions:
self.tool_actions.append(action)
self.tool_actions_map[action.name] = action
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This loop appears to be redundant and incomplete. The preceding loop (lines 139-154) already iterates over self.ai.registry._entries and populates self.tool_actions, self.prompt_actions, and self.resource_actions.

This new loop iterates over the same actions (since get_actions_by_kind reads from _entries) and re-adds tool actions, which is inefficient due to the action not in self.tool_actions check.

Furthermore, this loop iterates over PROMPT and RESOURCE kinds but has no logic to handle them, making it incomplete. The preceding loop seems to handle all kinds correctly. This block should probably be removed entirely, or updated to correctly handle all action kinds if it's intended to replace the first loop.

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

Labels

ci config docs Improvements or additions to documentation js python Python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants