import type { Tool } from '@modelcontextprotocol/sdk/types.js';
import { GCPAdapter } from '../adapters/gcp-adapter.js';
export const gcpTools: Tool[] = [
{
name: 'gcp_list_compute_instances',
description: 'List all Compute Engine instances in GCP',
inputSchema: {
type: 'object',
properties: {
projectId: {
type: 'string',
description: 'GCP project ID',
},
region: {
type: 'string',
description: 'GCP region',
default: 'us-central1',
},
},
},
},
{
name: 'gcp_list_storage_buckets',
description: 'List all Cloud Storage buckets in GCP',
inputSchema: {
type: 'object',
properties: {
projectId: {
type: 'string',
description: 'GCP project ID',
},
region: {
type: 'string',
description: 'GCP region',
default: 'us-central1',
},
},
},
},
{
name: 'gcp_list_cloud_functions',
description: 'List all Cloud Functions in GCP',
inputSchema: {
type: 'object',
properties: {
projectId: {
type: 'string',
description: 'GCP project ID',
},
region: {
type: 'string',
description: 'GCP region',
default: 'us-central1',
},
},
},
},
];
export async function handleGCPTool(name: string, args: unknown): Promise<unknown> {
const params = args as Record<string, unknown>;
const projectId = params.projectId as string | undefined;
const region = (params.region as string) || 'us-central1';
const adapter = new GCPAdapter(projectId, region);
switch (name) {
case 'gcp_list_compute_instances': {
const instances = await adapter.listComputeInstances();
return {
total: instances.length,
instances: instances.map((inst) => ({
id: inst.id,
name: inst.name,
machineType: inst.machineType,
zone: inst.zone,
region: inst.region,
status: inst.status,
privateIp: inst.privateIp,
publicIp: inst.publicIp,
})),
};
}
case 'gcp_list_storage_buckets': {
const buckets = await adapter.listStorageBuckets();
return {
total: buckets.length,
buckets: buckets.map((bucket) => ({
id: bucket.id,
name: bucket.bucketName,
location: bucket.location,
storageClass: bucket.storageClass,
})),
};
}
case 'gcp_list_cloud_functions': {
const functions = await adapter.listCloudFunctions();
return {
total: functions.length,
functions: functions.map((func) => ({
id: func.id,
name: func.functionName,
runtime: func.runtime,
region: func.region,
status: func.status,
availableMemoryMb: func.availableMemoryMb,
timeout: func.timeout,
})),
};
}
default:
throw new Error(`Unknown GCP tool: ${name}`);
}
}