A Model Context Protocol server that connects to Google Cloud services (Logging, Spanner, Monitoring, and Trace) to provide context and tools for interacting with your Google Cloud resources.
- Query Google Cloud Logging for log entries
- Execute SQL queries against Google Cloud Spanner databases
- Retrieve metrics from Google Cloud Monitoring
- Analyse distributed traces from Google Cloud Trace
- Correlate traces with logs for better debugging
- Natural language support for all services
- Authentication via environment variables or service accounts
# Clone the repository
git clone https://github.com/krzko/google-cloud-mcp.git
cd google-cloud-mcp
# Install dependencies
pnpm install
# Build
pnpm build
# Copy and configure environment variables
cp .env.example .env
# Edit .env with your Google Cloud settings
Authenticate to Google Cloud:
gcloud auth application-default login
Configure the mcpServers
in your client:
{
"mcpServers": {
"google-cloud-mcp": {
"command": "node",
"args": [
"/Users/foo/Downloads/google-cloud-mcp/dist/index.js"
],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/Users/foo/.config/gcloud/application_default_credentials.json",
}
}
}
}
# Build the project
pnpm build
# Start the server
pnpm start
# Build the project
pnpm build
# Start the server and inspector
npx -y @modelcontextprotocol/inspector node dist/index.js
This server can be deployed and used with Smithery. The server implements lazy loading of authentication, which means it will start immediately and defer authentication until it's actually needed. Authentication is still required for operation, but this approach prevents timeouts during server initialization.
You can configure the server in your Smithery configuration with the following options:
{
"projectId": "your-google-cloud-project-id", // Optional
"debug": true, // Enable debug logging
"lazyAuth": true, // Enable lazy loading of authentication (recommended for Smithery)
"credentials": {
"keyFilePath": "/path/to/your/credentials.json" // Method 1: Path to credentials file
}
}
Alternatively, you can provide credentials as environment variables:
{
"projectId": "your-google-cloud-project-id",
"credentials": {
"clientEmail": "your-service-account@project.iam.gserviceaccount.com",
"privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
}
}
To use this server with Claude Desktop, add the following to your Claude Desktop configuration:
{
"mcpServers": {
"@krzko-google-cloud-mcp": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@krzko/google-cloud-mcp",
"--config",
"{\"projectId\":\"your-project-id\",\"debug\":true,\"lazyAuth\":true,\"credentials\":\"/path/to/credentials.json\"}"
]
}
}
}
Note: For Claude Desktop, you can pass the credentials path directly as a string.
If you encounter timeout issues when running the server with Smithery, try the following:
- Enable debug logging by setting
debug: true
in your configuration - Ensure
lazyAuth: true
is set to defer authentication until it's actually needed - Ensure your credentials file is accessible and valid
- Check the logs for any error messages
Important: Authentication is still required for operation, but with lazy loading enabled, the server will start immediately and authenticate when needed rather than during initialization.
The server supports two methods of authentication:
-
Service Account Key File: Set
GOOGLE_APPLICATION_CREDENTIALS
environment variable to the path of your service account key file -
Environment Variables: Set
GOOGLE_CLIENT_EMAIL
andGOOGLE_PRIVATE_KEY
environment variables
If you're having authentication issues, make sure:
- Your service account has the necessary permissions
- The key file is properly formatted and accessible
- Environment variables are correctly set
Query and filter log entries from Google Cloud Logging:
- Query logs with custom filters
- Search logs within specific time ranges
- Format and display log entries in a readable format
Interact with Google Cloud Spanner databases:
- Execute SQL queries against Spanner databases
- List available databases and tables
- Explore database schema
Retrieve and analyse metrics from Google Cloud Monitoring:
- Query metrics with custom filters
- Visualise metric data over time
- List available metric types
Analyse distributed traces from Google Cloud Trace:
- Retrieve traces by ID
- List recent traces with filtering options
- Find traces associated with logs
- Identify failed traces
- Use natural language to query traces (e.g., "Show me failed traces from the last hour")
This server supports two methods of authentication with Google Cloud:
-
Service Account Key File (Recommended): Set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to the path of your service account key file. This is the standard Google Cloud authentication method. -
Environment Variables: Set
GOOGLE_CLIENT_EMAIL
andGOOGLE_PRIVATE_KEY
environment variables directly. This is useful for environments where storing a key file is not practical.
The server will also use the GOOGLE_CLOUD_PROJECT
environment variable if set, otherwise it will attempt to determine the project ID from the authentication credentials.
The server implements lazy loading for authentication, which means:
- The server will start successfully even if Google Cloud credentials are not available
- Authentication will only be attempted when a tool or resource requiring Google Cloud access is used
- Clear error messages will be provided if authentication fails when a Google Cloud operation is attempted
This makes the server more flexible for deployment in environments where credentials might not be immediately available.
This server includes configuration for deployment with Smithery. The included smithery.yaml
file supports both authentication methods:
# Example Smithery configuration
startCommand:
type: stdio
configSchema:
# Configuration options
properties:
projectId:
type: string
description: "Google Cloud Project ID (optional)"
credentials:
# Two authentication options
oneOf:
# Option 1: Using environment variables
- properties:
clientEmail:
type: string
privateKey:
type: string
# Option 2: Using a key file (standard approach)
- properties:
keyFilePath:
type: string
To deploy with Smithery:
- Build the Docker image using the included Dockerfile
- Configure authentication in your Smithery configuration
- Deploy the server using Smithery's deployment tools