-
Notifications
You must be signed in to change notification settings - Fork 2
add new mcp tools for cloud build #76
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
Open
aliciatang07
wants to merge
14
commits into
main
Choose a base branch
from
addtools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−3
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
72e51b0
add new mcp tools for cloud build
aliciatang07 60edcbe
replace logging with api
aliciatang07 62dd5de
debug
aliciatang07 b49e30e
fix wrong import
aliciatang07 5808353
add new line
aliciatang07 09b6e1e
debug
aliciatang07 4ed3a6a
fix typo
aliciatang07 2ead99b
fix payload error
aliciatang07 e188839
debug
aliciatang07 b8d5e42
debug wrong type
aliciatang07 49e2bf6
debug
aliciatang07 76dbe7b
reslove CRA suggestions
aliciatang07 ba4497a
add protojson import
aliciatang07 71e2c9b
fix wrong parameter
aliciatang07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,8 @@ import ( | |||||
| cloudbuildclient "devops-mcp-server/cloudbuild/client" | ||||||
| iamclient "devops-mcp-server/iam/client" | ||||||
| resourcemanagerclient "devops-mcp-server/resourcemanager/client" | ||||||
|
|
||||||
| cloudbuildpb "cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb" | ||||||
| ) | ||||||
|
|
||||||
| // Handler holds the clients for the cloudbuild service. | ||||||
|
|
@@ -39,6 +41,9 @@ func (h *Handler) Register(server *mcp.Server) { | |||||
| addCreateTriggerTool(server, h.CbClient, h.IClient, h.RClient) | ||||||
| addRunTriggerTool(server, h.CbClient) | ||||||
| addListTriggersTool(server, h.CbClient) | ||||||
| addListBuildsTool(server, h.CbClient) | ||||||
| addGetBuildInfoTool(server, h.CbClient) | ||||||
| addStartBuildTool(server, h.CbClient) | ||||||
| } | ||||||
|
|
||||||
| type RunTriggerArgs struct { | ||||||
|
|
@@ -146,3 +151,62 @@ func IsValidServiceAccount(sa string) bool { | |||||
| var saRegex = regexp.MustCompile(`^serviceAccount:[a-z0-9-]+@[a-z0-9-]+\.iam\.gserviceaccount\.com$`) | ||||||
| return saRegex.MatchString(sa) | ||||||
| } | ||||||
|
|
||||||
| type ListBuildsArgs struct { | ||||||
| ProjectID string `json:"project_id" jsonschema:"The Google Cloud project ID."` | ||||||
| Location string `json:"location" jsonschema:"The Google Cloud location for the builds."` | ||||||
| } | ||||||
|
|
||||||
| type GetBuildInfoArgs struct { | ||||||
| ProjectID string `json:"project_id" jsonschema:"The Google Cloud project ID."` | ||||||
| Location string `json:"location" jsonschema:"The Google Cloud location for the build."` | ||||||
| BuildID string `json:"build_id" jsonschema:"The ID of the build."` | ||||||
| } | ||||||
|
|
||||||
| type StartBuildArgs struct { | ||||||
| ProjectID string `json:"project_id" jsonschema:"The Google Cloud project ID."` | ||||||
| Location string `json:"location" jsonschema:"The Google Cloud location for the build."` | ||||||
| Bucket string `json:"bucket" jsonschema:"The Cloud Storage bucket where the source is located."` | ||||||
| Object string `json:"object" jsonschema:"The Cloud Storage object (file) where the source is located."` | ||||||
| } | ||||||
|
|
||||||
| func addListBuildsTool(server *mcp.Server, cbClient cloudbuildclient.CloudBuildClient) { | ||||||
| listBuildsToolFunc := func(ctx context.Context, req *mcp.CallToolRequest, args ListBuildsArgs) (*mcp.CallToolResult, any, error) { | ||||||
| res, err := cbClient.ListBuilds(ctx, args.ProjectID, args.Location) | ||||||
| if err != nil { | ||||||
| return &mcp.CallToolResult{}, nil, fmt.Errorf("failed to list builds: %w", err) | ||||||
| } | ||||||
| return &mcp.CallToolResult{}, map[string]any{"builds": res}, nil | ||||||
| } | ||||||
| mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.list_builds", Description: "Lists all Cloud Builds in a given location and project."}, listBuildsToolFunc) | ||||||
| } | ||||||
|
|
||||||
| func addGetBuildInfoTool(server *mcp.Server, cbClient cloudbuildclient.CloudBuildClient) { | ||||||
| getBuildInfoToolFunc := func(ctx context.Context, req *mcp.CallToolRequest, args GetBuildInfoArgs) (*mcp.CallToolResult, any, error) { | ||||||
| res, err := cbClient.GetBuildInfo(ctx, args.ProjectID, args.Location, args.BuildID) | ||||||
| if err != nil { | ||||||
| return &mcp.CallToolResult{}, nil, fmt.Errorf("failed to get build info: %w", err) | ||||||
| } | ||||||
| return &mcp.CallToolResult{}, res, nil | ||||||
| } | ||||||
| mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.get_build_info", Description: "Gets information about a specific Cloud Build."}, getBuildInfoToolFunc) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tool name
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| func addStartBuildTool(server *mcp.Server, cbClient cloudbuildclient.CloudBuildClient) { | ||||||
| startBuildToolFunc := func(ctx context.Context, req *mcp.CallToolRequest, args StartBuildArgs) (*mcp.CallToolResult, any, error) { | ||||||
| source:= &cloudbuildpb.Source{ | ||||||
| Source: &cloudbuildpb.Source_StorageSource{ | ||||||
| StorageSource: &cloudbuildpb.StorageSource{ | ||||||
| Bucket: args.Bucket, | ||||||
| Object: args.Object, | ||||||
| }, | ||||||
| }, | ||||||
| } | ||||||
| res, err := cbClient.StartBuild(ctx, args.ProjectID, args.Location, source) | ||||||
| if err != nil { | ||||||
| return &mcp.CallToolResult{}, nil, fmt.Errorf("failed to start build: %w", err) | ||||||
| } | ||||||
| return &mcp.CallToolResult{}, res, nil | ||||||
| } | ||||||
| mcp.AddTool(server, &mcp.Tool{Name: "cloudbuild.start_build", Description: "Starts a new Cloud Build from a source in Google Cloud Storage."}, startBuildToolFunc) | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.