-
Notifications
You must be signed in to change notification settings - Fork 2
add new tool for cloud run #77
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,7 @@ func ContextWithClient(ctx context.Context, client CloudRunClient) context.Conte | |||||||||||||||||||||||||||||||||
| // CloudRunClient is an interface for interacting with the Cloud Run API. | ||||||||||||||||||||||||||||||||||
| type CloudRunClient interface { | ||||||||||||||||||||||||||||||||||
| GetService(ctx context.Context, projectID, location, serviceName string) (*cloudrunpb.Service, error) | ||||||||||||||||||||||||||||||||||
| GetStatus(ctx context.Context, projectID, location, serviceName string) (State, error) | ||||||||||||||||||||||||||||||||||
| ListServices(ctx context.Context, projectID, location string) ([]*cloudrunpb.Service, error) | ||||||||||||||||||||||||||||||||||
| CreateService(ctx context.Context, projectID, location, serviceName, imageURL string, port int32) (*cloudrunpb.Service, error) | ||||||||||||||||||||||||||||||||||
| UpdateService(ctx context.Context, projectID, location, serviceName, imageURL, revisionName string, port int32, service *cloudrunpb.Service) (*cloudrunpb.Service, error) | ||||||||||||||||||||||||||||||||||
|
|
@@ -144,6 +145,15 @@ func (c *CloudRunClientImpl) GetService(ctx context.Context, projectID, location | |||||||||||||||||||||||||||||||||
| return service, nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func (c *CloudRunClientImpl) GetStatus(ctx context.Context, projectID, location, serviceName string) (*cloudrunpb.Condition_State, error) { | ||||||||||||||||||||||||||||||||||
| service, err:= c.GetService(ctx, projectID, location, serviceName) | ||||||||||||||||||||||||||||||||||
| if err!=nil { | ||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("failed to get service: %w", err) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| terminalCondition:= service.GetTerminalCondition() | ||||||||||||||||||||||||||||||||||
| return terminalCondition.State, nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+148
to
+155
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. This function is declared to return a pointer
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func (c *CloudRunClientImpl) GetRevision(ctx context.Context, service *cloudrunpb.Service) (*cloudrunpb.Revision, error) { | ||||||||||||||||||||||||||||||||||
| // Get the latest revision | ||||||||||||||||||||||||||||||||||
| latestRevision, err := c.revisionsClient.GetRevision(ctx, &cloudrunpb.GetRevisionRequest{Name: service.LatestReadyRevision}) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ func (h *Handler) Register(server *mcp.Server) { | |||||||||||||||||||||||||||||||||||||||
| addListServicesTool(server, h.CrClient) | ||||||||||||||||||||||||||||||||||||||||
| addDeployToCloudRunFromImageTool(server, h.CrClient) | ||||||||||||||||||||||||||||||||||||||||
| addDeployToCloudRunFromSourceTool(server, h.CrClient) | ||||||||||||||||||||||||||||||||||||||||
| addGetServiceStatus(server, h.CrClient) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| type ListServicesArgs struct { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -134,3 +135,19 @@ func addDeployToCloudRunFromSourceTool(server *mcp.Server, crClient cloudrunclie | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| mcp.AddTool(server, &mcp.Tool{Name: "cloudrun.deploy_to_cloud_run_from_source", Description: "Creates a new Cloud Run service or updates an existing one from source. This tool may take a couple minutes to finish running."}, deployToCloudRunFromSourceToolFunc) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| type GetServiceStatusArgs struct{ | ||||||||||||||||||||||||||||||||||||||||
| ProjectID string `json:"project_id" jsonschema:"The Google Cloud project ID."` | ||||||||||||||||||||||||||||||||||||||||
| Location string `json:"location" jsonschema:"The Google Cloud location."` | ||||||||||||||||||||||||||||||||||||||||
| ServiceName string `json: service_name jsonschema:"The Cloud Run service name"` | ||||||||||||||||||||||||||||||||||||||||
|
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 JSON tag for
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| func addGetServiceStatusTool(server *mcp.Server, crClient cloudrunclient.CloudRunClient) { | ||||||||||||||||||||||||||||||||||||||||
| getServiceStatusToolFunc = func(ctx context.Context, req* mcp.CallToolRequest, args GetServiceStatusArgs){ | ||||||||||||||||||||||||||||||||||||||||
| state, err := crClient.GetServiceStatus(ctx, args.ProjectID, args.Location, args.ServiceName) | ||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||
| return &mcp.CallToolResult{}, nil, fmt.Errorf("failed to get service state: %w", err) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return &mcp.CallToolResult{}, state, nil | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+145
to
+153
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. This new function to add the service status tool is incomplete and has several issues that will cause compilation and runtime errors:
Here is a corrected version of the function. Please note you will also need to add
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
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 return type
Stateis not defined, which will cause a compilation error. It should be*cloudrunpb.Condition_Stateto match the intended implementation and allow for anilreturn on error.