Skip to content

add new mcp tools for cloud build#76

Open
aliciatang07 wants to merge 11 commits intomainfrom
addtools
Open

add new mcp tools for cloud build#76
aliciatang07 wants to merge 11 commits intomainfrom
addtools

Conversation

@aliciatang07
Copy link
Contributor

Added tools under cloud build
cloudbuild.list_builds: List builds for the given project and region
cloudbuild.build_info: This should provide a detailed information about a given build along with build logs.
cloudbuild.start: This will allow running a GCB build on a local directory.

@aliciatang07 aliciatang07 requested a review from haroonc February 5, 2026 18:26
@aliciatang07
Copy link
Contributor Author

/gemini help

@gemini-code-assist
Copy link

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.

@aliciatang07
Copy link
Contributor Author

/gemini review

@aliciatang07
Copy link
Contributor Author

/gemini summary

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 adds new MCP tools for interacting with Google Cloud Build, including listing builds, getting build information, and starting new builds. The implementation is mostly solid, but there are a few issues to address. The most critical is a bug in the start_build tool where the specified location is ignored, and the build is always created in the global location. Additionally, there are some inconsistencies in tool naming between the code and the PR description, and a misleading tool description. I've also included some suggestions for improving code style and log message formatting.

RunBuildTrigger(ctx context.Context, projectID, location, triggerID, branch, tag, commitSha string) (*cloudbuild.RunBuildTriggerOperation, error)
ListBuilds(ctx context.Context, projectID, location string) ([]*cloudbuildpb.Build, error)
GetBuildInfo(ctx context.Context, projectID, location, buildID string) (BuildInfo, error)
StartBuild(ctx context.Context, projectID string, source *cloudbuildpb.Source) (*cloudbuild.CreateBuildOperation, error)

Choose a reason for hiding this comment

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

high

The StartBuild function should accept a location parameter. Currently, the implementation hardcodes it to global, but the corresponding tool cloudbuild.start defines a location argument, which is then ignored. This is a bug that needs to be fixed across the interface and implementation.

Suggested change
StartBuild(ctx context.Context, projectID string, source *cloudbuildpb.Source) (*cloudbuild.CreateBuildOperation, error)
StartBuild(ctx context.Context, projectID, location string, source *cloudbuildpb.Source) (*cloudbuild.CreateBuildOperation, error)

Comment on lines +267 to +271
func (c *CloudBuildClientImpl) StartBuild(ctx context.Context, projectID string, source *cloudbuildpb.Source) (*cloudbuild.CreateBuildOperation, error) {
req := &cloudbuildpb.CreateBuildRequest{
Parent: fmt.Sprintf("projects/%s/locations/global", projectID),
Build: &cloudbuildpb.Build{Source: source},
}

Choose a reason for hiding this comment

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

high

This implementation of StartBuild should take location as an argument and use it to construct the Parent field for the request, instead of hardcoding global. This fixes a bug where the user-provided location is ignored.

func (c *CloudBuildClientImpl) StartBuild(ctx context.Context, projectID, location string, source *cloudbuildpb.Source) (*cloudbuild.CreateBuildOperation, error) {
	req := &cloudbuildpb.CreateBuildRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		Build:  &cloudbuildpb.Build{Source: source},
	}

},
},
}
res, err := cbClient.StartBuild(ctx, args.ProjectID, source)

Choose a reason for hiding this comment

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

high

The location argument from StartBuildArgs is being ignored here. You should pass it to the cbClient.StartBuild function. This change depends on updating the StartBuild method signature in the client to accept a location.

Suggested change
res, err := cbClient.StartBuild(ctx, args.ProjectID, source)
res, err := cbClient.StartBuild(ctx, args.ProjectID, args.Location, source)

}
return &mcp.CallToolResult{}, res, nil
}
mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.start_build", Description: "Starts a new Cloud Build with the given source locally."}, startBuildToolFunc)

Choose a reason for hiding this comment

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

high

The tool name cloudbuild.start_build is inconsistent with the PR description (cloudbuild.start). Additionally, the description Starts a new Cloud Build with the given source locally. is misleading, as the source is from Google Cloud Storage, not a local directory. Please update both for clarity and consistency.

Suggested change
mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.start_build", Description: "Starts a new Cloud Build with the given source locally."}, startBuildToolFunc)
mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.start", Description: "Starts a new Cloud Build from a source in Google Cloud Storage."}, startBuildToolFunc)

Comment on lines 22 to 30
cloudbuild "cloud.google.com/go/cloudbuild/apiv1/v2"
cloudbuildpb "cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb"

logging "cloud.google.com/go/logging/apiv2"
build "google.golang.org/api/cloudbuild/v1"
"google.golang.org/api/iterator"
"google.golang.org/protobuf/types/known/timestamppb"

cloudbuildpb "cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb"
loggingpb "cloud.google.com/go/logging/apiv2/loggingpb"
)

Choose a reason for hiding this comment

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

medium

The import block is not organized according to Go conventions. Running goimports would automatically group standard library, third-party, and internal packages, improving readability and maintainability.

Comment on lines +66 to +67


Choose a reason for hiding this comment

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

medium

These extra blank lines can be removed to improve code conciseness.

Comment on lines +85 to +89
return &CloudBuildClientImpl{
v1client: c,
legacyClient: c2,
loggingClient: loggingClient,
}, nil

Choose a reason for hiding this comment

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

medium

The formatting of this struct literal is inconsistent. Running gofmt or goimports would fix the alignment and spacing, making the code more readable and consistent with Go standards.

Suggested change
return &CloudBuildClientImpl{
v1client: c,
legacyClient: c2,
loggingClient: loggingClient,
}, nil
return &CloudBuildClientImpl{
v1client: c,
legacyClient: c2,
loggingClient: loggingClient,
}, nil

Comment on lines +254 to +255
case *loggingpb.LogEntry_JsonPayload:
logMessage = fmt.Sprintf("%v", payload.JsonPayload)

Choose a reason for hiding this comment

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

medium

Using fmt.Sprintf("%v", ...) for a JSON payload will produce the Go struct's string representation, not a valid JSON string. This can be hard to parse or read. Consider marshaling the payload to a JSON string using protojson.Marshal. You will need to add "google.golang.org/protobuf/encoding/protojson" to your imports.

case *loggingpb.LogEntry_JsonPayload:
				jsonBytes, err := protojson.Marshal(payload.JsonPayload)
				if err != nil {
					logMessage = fmt.Sprintf("failed to marshal json payload to string: %v", err)
				} else {
					logMessage = string(jsonBytes)
				}

}
return &mcp.CallToolResult{}, res, nil
}
mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.get_build_info", Description: "Gets information about a specific Cloud Build."}, getBuildInfoToolFunc)

Choose a reason for hiding this comment

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

medium

The tool name cloudbuild.get_build_info is inconsistent with the PR description, which specifies cloudbuild.build_info. Please align the tool name for consistency.

Suggested change
mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.get_build_info", Description: "Gets information about a specific Cloud Build."}, getBuildInfoToolFunc)
mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.build_info", Description: "Gets information about a specific Cloud Build."}, getBuildInfoToolFunc)

@gemini-code-assist
Copy link

Summary of Changes

This pull request significantly expands the capabilities of the Cloud Build integration by adding three new tools. These tools enable users to list all builds for a given project and region, retrieve detailed information about a specific build including its logs, and initiate new builds directly from Google Cloud Storage. The changes involve updating the Cloud Build client interface and implementation to support these new operations, as well as registering the corresponding tools within the system.

Highlights

  • New Cloud Build Tools: Introduced cloudbuild.list_builds, cloudbuild.build_info, and cloudbuild.start for enhanced Cloud Build management.
  • Detailed Build Information: The cloudbuild.build_info tool now provides comprehensive build details along with their associated logs.
  • Cloud Build Initiation: Users can now start new Cloud Builds by specifying a source from Google Cloud Storage.

🧠 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.

Changelog
  • devops-mcp-server/cloudbuild/client/cloudbuildclient.go
    • Added imports for cloud.google.com/go/logging/apiv2 and cloud.google.com/go/logging/apiv2/loggingpb.
    • Extended the CloudBuildClient interface with ListBuilds, GetBuildInfo, and StartBuild methods.
    • Defined a new BuildInfo struct to hold build details and aggregated logs.
    • Modified CloudBuildClientImpl to embed a logging.Client for log retrieval.
    • Implemented ListBuilds to fetch a list of Cloud Builds.
    • Implemented GetBuildInfo to retrieve a specific build's details and its logs by parsing different payload types.
    • Implemented StartBuild to create and initiate a new Cloud Build.
  • devops-mcp-server/cloudbuild/cloudbuild.go
    • Added import for cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb.
    • Registered the new tools: cloudbuild.list_builds, cloudbuild.get_build_info, and cloudbuild.start_build.
    • Introduced ListBuildsArgs, GetBuildInfoArgs, and StartBuildArgs structs for tool arguments.
    • Added addListBuildsTool, addGetBuildInfoTool, and addStartBuildTool functions to integrate the new client functionalities as MCP tools.
Activity
  • The author, aliciatang07, initiated the PR by requesting /gemini help.
  • gemini-code-assist[bot] provided help documentation.
  • aliciatang07 requested /gemini review.
  • aliciatang07 requested /gemini summary.
  • gemini-code-assist[bot] provided high priority feedback on the StartBuild function and tool, noting that the location parameter was being ignored and hardcoded to global, and that the tool name and description were inconsistent with the PR body.
  • gemini-code-assist[bot] provided medium priority feedback on Go code style, including import organization, unnecessary blank lines, inconsistent struct literal formatting, and incorrect JSON payload handling for logs.

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.

1 participant