feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The mcp command group for the Cloud API Registry API."""
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Mcp(base.Group):
"""Manage MCP Command Group.
Commands for managing MCP enablement and disablement for a given service
in the current project.
"""
category = base.API_PLATFORM_AND_ECOSYSTEMS_CATEGORY
def Filter(self, context, args):
base.RequireProjectID(args)
del context, args

View File

@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""api registry mcp server disable command."""
from googlecloudsdk.api_lib.api_registry import resources
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.api_lib.services import serviceusage
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
# TODO(b/321801975) make command public after preview.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DisableAlpha(base.SilentCommand):
"""Disables MCP server for a given service in the current project."""
@staticmethod
def Args(parser):
parser.add_argument(
'service',
help='The MCP server to disable.',
)
def Run(self, args):
"""Disables MCP server for a given service in the current project."""
op = serviceusage.RemoveMcpEnableRule(
resources.GetProjectId(),
args.service,
)
if op is None:
return None
services_util.WaitOperation(op.name, serviceusage.GetOperationV2Beta)
# services_util.PrintOperation(op)
log.status.Print('MCP Server disabled for service:', args.service)
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class DisableBeta(base.SilentCommand):
"""Disables MCP server for a given service in the current project."""
@staticmethod
def Args(parser):
parser.add_argument(
'service',
help='The MCP server to disable.',
)
def Run(self, args):
"""Disables MCP server for a given service in the current project."""
op = serviceusage.RemoveMcpEnableRule(
resources.GetProjectId(),
args.service,
)
if op is None:
return None
services_util.WaitOperation(op.name, serviceusage.GetOperationV2Beta)
# services_util.PrintOperation(op)
log.status.Print('MCP Server disabled for service:', args.service)

View File

@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""api registry mcp server enable command."""
from googlecloudsdk.api_lib.api_registry import resources
from googlecloudsdk.api_lib.services import exceptions
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.api_lib.services import serviceusage
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
# TODO(b/321801975) make command public after preview.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class EnableAlpha(base.SilentCommand):
"""Enables MCP server for a given service in the current project."""
@staticmethod
def Args(parser):
parser.add_argument(
'service',
help='The MCP server to enable.',
)
def Run(self, args):
"""Enables MCP server for a given service in the current project."""
project_resource = resources.GetProjectResource()
# check if service has Mcp Config
try:
service_metadata = serviceusage.GetServiceV2Beta(
f'{project_resource}/services/{args.service}')
except exceptions.GetServiceException:
log.error(
'Service %s not found or permission_denied.', args.service)
return
if not service_metadata.state.enableRules:
track_prefix = 'alpha '
enable_command = f'gcloud {track_prefix}services enable {args.service}'
log.warning(
'To enable the MCP endpoint, the service must'
' be enabled first. Please run the following command to enable the'
' service: %s.', enable_command)
op = serviceusage.AddMcpEnableRule(
args.service,
resources.GetProjectId(),
)
if op is None:
return None
services_util.WaitOperation(op.name, serviceusage.GetOperationV2Beta)
# services_util.PrintOperation(op)
log.status.Print('MCP Server enabled for service:', args.service)
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class EnableBeta(base.SilentCommand):
"""Enables MCP server for a given service in the current project."""
@staticmethod
def Args(parser):
parser.add_argument(
'service',
help='The MCP server to enable.',
)
def Run(self, args):
"""Enables MCP server for a given service in the current project."""
project_resource = resources.GetProjectResource()
# check if service has Mcp Config
try:
service_metadata = serviceusage.GetServiceV2Beta(
f'{project_resource}/services/{args.service}')
except exceptions.GetServiceException:
log.error(
'Service %s not found or permission_denied.', args.service)
return
if not service_metadata.state.enableRules:
track_prefix = 'beta '
enable_command = f'gcloud {track_prefix}services enable {args.service}'
log.warning(
'To enable the MCP endpoint, the service must'
' be enabled first. Please run the following command to enable the'
' service: %s.', enable_command)
op = serviceusage.AddMcpEnableRule(
args.service,
resources.GetProjectId(),
)
if op is None:
return None
services_util.WaitOperation(op.name, serviceusage.GetOperationV2Beta)
# services_util.PrintOperation(op)
log.status.Print('MCP Server enabled for service:', args.service)

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The servers command group for the cloudapiregistry API."""
from googlecloudsdk.calliope import base
# NOTE: Release track decorators can be used here as well, and would propagate
# to this group's children.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Servers(base.Group):
"""Manage Cloud API Registry MCP servers."""

View File

@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to List MCP servers."""
from googlecloudsdk.api_lib.api_registry import utils
from googlecloudsdk.api_lib.api_registry.mcp import servers
from googlecloudsdk.calliope import base
_DETAILED_HELP = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
""" \
To list all MCP servers in a project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class ListAlpha(base.ListCommand):
"""List MCP servers."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
parser.display_info.AddFormat('json')
parser.add_argument(
'--all',
action='store_true',
help='If provided, list all the available (both enabled and'
' non-enabled) MCP servers for the project.',
)
def Run(self, args):
"""Run the list command."""
client = servers.McpServersClient(version='v1alpha')
project = utils.GetProject()
location = utils.GetLocation()
parent = (
f'projects/{project}/locations/{location}'
)
return client.ListAlpha(parent, args)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class ListBeta(base.ListCommand):
"""List MCP servers."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
parser.display_info.AddFormat('json')
parser.add_argument(
'--all',
action='store_true',
help='If provided, list all the available (both enabled and'
' non-enabled) MCP servers for the project.',
)
def Run(self, args):
"""Run the list command."""
client = servers.McpServersClient(version='v1beta')
project = utils.GetProject()
location = utils.GetLocation()
parent = (
f'projects/{project}/locations/{location}'
)
return client.ListBeta(parent, args)

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The tools command group for the cloudapiregistry API."""
from googlecloudsdk.calliope import base
# NOTE: Release track decorators can be used here as well, and would propagate
# to this group's children.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Tools(base.Group):
"""Manage Cloud API Registry MCP tools."""

View File

@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to List MCP tools."""
from googlecloudsdk.api_lib.api_registry import utils
from googlecloudsdk.api_lib.api_registry.mcp import tools
from googlecloudsdk.calliope import base
_DETAILED_HELP = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
""" \
To list MCP tools, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class ListAlpha(base.ListCommand):
"""List MCP tools."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
parser.display_info.AddFormat('json')
parser.add_argument(
'--all',
action='store_true',
help='If provided, list all the available MCP tools for all (both'
' enabled and non-enabled) the MCP Servers for the project.',
)
def Run(self, args):
"""Run the list command."""
client = tools.McpToolsClient('v1alpha')
project = utils.GetProject()
location = utils.GetLocation()
# As per AIP-159, the wildcard '-' matches all MCP Servers.
mcp_server = '-'
parent = f'projects/{project}/locations/{location}/mcpServers/{mcp_server}'
return client.ListAlpha(parent, args)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class ListBeta(base.ListCommand):
"""List MCP tools."""
detailed_help = _DETAILED_HELP
@staticmethod
def Args(parser):
parser.display_info.AddFormat('json')
parser.add_argument(
'--all',
action='store_true',
help='If provided, list all the available MCP tools for all (both'
' enabled and non-enabled) the MCP Servers for the project.',
)
def Run(self, args):
"""Run the list command."""
client = tools.McpToolsClient('v1beta')
project = utils.GetProject()
location = utils.GetLocation()
# As per AIP-159, the wildcard '-' matches all MCP Servers.
mcp_server = '-'
parent = f'projects/{project}/locations/{location}/mcpServers/{mcp_server}'
return client.ListBeta(parent, args)