-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor(dataconnect): merge dataconnect_execute tools #9046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Merges four dataconnect execute tools (`execute_graphql`, `execute_graphql_read`, `execute_query`, and `execute_mutation`) into a single `dataconnect_execute` tool. The new tool provides a more versatile interface by accepting either a `query` or an `operationName`, and includes a `read_only` flag to control whether the operation can write data. This change simplifies the toolset while preserving all existing functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @fredzqm, 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 significantly refactors the Data Connect toolset by merging four existing execution tools into a single, more versatile dataconnect_execute
tool. The primary goal is to simplify the interface for executing GraphQL operations against Data Connect services, whether they are arbitrary queries/mutations or deployed operations. The consolidated tool now intelligently handles different operation types and read/write permissions through a unified input schema, improving usability and reducing code duplication without sacrificing any existing capabilities.
Highlights
- Tool Consolidation: The pull request consolidates four distinct Data Connect execution tools (
execute_graphql
,execute_graphql_read
,execute_query
,execute_mutation
) into a single, unifieddataconnect_execute
tool. - Enhanced Flexibility: The new
dataconnect_execute
tool offers a more flexible interface, allowing users to specify either a raw GraphQLquery
or anoperationName
for deployed operations. - Read-Only Flag: A new
read_only
flag has been introduced within the unified tool, providing explicit control over whether the operation should use a read-only endpoint, effectively replacing the need for separate read-specific tools. - Simplified Toolset: This refactoring simplifies the overall toolset for Data Connect operations, reducing redundancy and streamlining future maintenance, while ensuring all previous functionalities are preserved.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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
-
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. ↩
There was a problem hiding this 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 successfully refactors four separate dataconnect
execution tools into a single, more versatile dataconnect_execute
tool. This is a great simplification of the toolset. The implementation is solid, using zod
for robust input validation. My review focuses on reducing some code duplication within the new tool to enhance maintainability. I've provided specific suggestions to make the code more concise by dynamically selecting the execution function based on the read_only
flag.
src/mcp/tools/dataconnect/execute.ts
Outdated
if (read_only) { | ||
const response = await dataplane.executeGraphQLRead(apiClient, serviceInfo.serviceName, { | ||
name: "", | ||
query, | ||
variables: parseVariables(unparsedVariables), | ||
}); | ||
return graphqlResponseToToolResponse(response.body); | ||
} else { | ||
const response = await dataplane.executeGraphQL(apiClient, serviceInfo.serviceName, { | ||
name: "", | ||
query, | ||
variables: parseVariables(unparsedVariables), | ||
}); | ||
return graphqlResponseToToolResponse(response.body); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if (read_only)
and else
blocks contain very similar logic, with the only difference being the dataplane
function called. This can be refactored to reduce code duplication and improve maintainability. You can determine the function to call based on the read_only
flag and then call it once.
const executeFn = read_only ? dataplane.executeGraphQLRead : dataplane.executeGraphQL;
const response = await executeFn(apiClient, serviceInfo.serviceName, {
name: "",
query,
variables: parseVariables(unparsedVariables),
});
return graphqlResponseToToolResponse(response.body);
src/mcp/tools/dataconnect/execute.ts
Outdated
if (read_only) { | ||
const response = await dataplane.executeGraphQLQuery(apiClient, connectorPath, { | ||
operationName, | ||
variables: parseVariables(unparsedVariables), | ||
}); | ||
return graphqlResponseToToolResponse(response.body); | ||
} else { | ||
const response = await dataplane.executeGraphQLMutation(apiClient, connectorPath, { | ||
operationName, | ||
variables: parseVariables(unparsedVariables), | ||
}); | ||
return graphqlResponseToToolResponse(response.body); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the query
block, this part has duplicated code for the read_only
and non-read_only
cases. This can be simplified by selecting the appropriate execution function based on the read_only
flag and then making a single call.
const connectorPath = `${serviceInfo.serviceName}/connectors/${connector_id}`;
if (read_only) {
const response = await dataplane.executeGraphQLQuery(apiClient, connectorPath, {
operationName,
variables: parseVariables(unparsedVariables),
});
return graphqlResponseToToolResponse(response.body);
} else {
const response = await dataplane.executeGraphQLMutation(apiClient, connectorPath, {
operationName,
variables: parseVariables(unparsedVariables),
});
return graphqlResponseToToolResponse(response.body);
}
@tammam-g Fun PR generated by Jules~ It did a great job!! Per Michael's feedback, we should prefer fewer more powerful tools. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but could we add scenarios tested?
…ools' into feat/merge-dataconnect-execute-tools
…ect-execute-tools
…ools' into feat/merge-dataconnect-execute-tools
[Not time sensitive] @tammam-g Added a screencast of test scenarios~ |
Description
Merges four dataconnect execute tools (
execute_graphql
,execute_graphql_read
,execute_query
, andexecute_mutation
) into a singledataconnect_execute
tool.Remove the functionality to
execute_operation
on a connector. In practice, it's difficult to get LLM to use it correctly. It's simpler to ask LLM to pass the query from local files.Added
auth_token_json
, so LLM can execute query that requires auth as well.Remove
read_only
flag. We can detect whether it's a query with a simple heurestic.Scenarios Tested
Execute query against emulator and prod, with and without auth token.
https://screencast.googleplex.com/cast/NDg1MzYzNjE0NzQ0NTc2MHw2ZTE2OWNjMy1hNA
Sample Commands