Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions devops-mcp-server/cloudrun/client/cloudrunclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

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

critical

The return type State is not defined, which will cause a compilation error. It should be *cloudrunpb.Condition_State to match the intended implementation and allow for a nil return on error.

Suggested change
GetStatus(ctx context.Context, projectID, location, serviceName string) (State, error)
GetStatus(ctx context.Context, projectID, location, serviceName string) (*cloudrunpb.Condition_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)
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

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

critical

This function is declared to return a pointer *cloudrunpb.Condition_State, but on success it returns terminalCondition.State, which is a value of type cloudrunpb.Condition_State. This will cause a compilation error. You should return a pointer to the state. Additionally, there are minor formatting issues that should be addressed for consistency (:=, !=).

Suggested change
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
}
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
}


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})
Expand Down
17 changes: 17 additions & 0 deletions devops-mcp-server/cloudrun/cloudrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`

Choose a reason for hiding this comment

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

high

The JSON tag for ServiceName is malformed. It is missing quotes around service_name, which will prevent it from being correctly parsed from JSON arguments.

Suggested change
ServiceName string `json: service_name jsonschema:"The Cloud Run service name"`
ServiceName string `json:"service_name" jsonschema:"The Cloud Run service name"`

}

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

Choose a reason for hiding this comment

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

critical

This new function to add the service status tool is incomplete and has several issues that will cause compilation and runtime errors:

  1. Function Name Mismatch: The function is named addGetServiceStatusTool, but it's called as addGetServiceStatus in the Register method. This will cause an "undefined" compile error.
  2. Missing Tool Registration: The function defines a tool handler (getServiceStatusToolFunc) but never registers it with the MCP server using mcp.AddTool. The tool will not be available.
  3. Incorrect Handler Signature: The function literal for the handler is missing its return types (*mcp.CallToolResult, any, error). This is a compile error.
  4. Undeclared Variable: The variable getServiceStatusToolFunc is used without being declared at the package level. You need to add a var declaration for it, similar to listServicesToolFunc.
  5. Formatting Issues: There are several formatting problems, including incorrect indentation and a missing space in req* mcp.CallToolRequest.

Here is a corrected version of the function. Please note you will also need to add var getServiceStatusToolFunc func(ctx context.Context, req *mcp.CallToolRequest, args GetServiceStatusArgs) (*mcp.CallToolResult, any, error) at the package level.

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
}
}
func addGetServiceStatus(server *mcp.Server, crClient cloudrunclient.CloudRunClient) {
getServiceStatusToolFunc = func(ctx context.Context, req *mcp.CallToolRequest, args GetServiceStatusArgs) (*mcp.CallToolResult, any, error) {
state, err := crClient.GetStatus(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
}
mcp.AddTool(server, &mcp.Tool{Name: "cloudrun.service_status", Description: "Provide detailed status of a Cloud Run service."}, getServiceStatusToolFunc)
}

Loading