Google Cloud MCP Server
An MCP server that enables querying and interacting with Google Cloud services including Logging, Spanner, Monitoring, and Cloud Trace through natural language.
Tools
query-logs
logs-time-range
execute-spanner-query
list-spanner-tables
list-spanner-instances
list-spanner-databases
natural-language-spanner-query
spanner-query-count
query-metrics
list-metric-types
natural-language-metrics-query
get-trace
list-traces
find-traces-from-logs
natural-language-trace-query
set-project-id
get-project-id
README
Google Cloud MCP Server
A Model Context Protocol (MCP) server for Google Cloud services including Logging, Spanner, Monitoring, and Cloud Trace.
Features
- Google Cloud Logging: Query logs, list log entries, and search across different log sources
- Google Cloud Spanner: Execute queries, list databases and instances, get schema information
- Google Cloud Monitoring: Query metrics, list metric descriptors, get monitoring data
- Google Cloud Trace: Retrieve trace data and analyze distributed system performance
- Resource Discovery: Automatically discover and list available Google Cloud resources
- Project Management: Tools for managing Google Cloud project settings
Transport Support
This server supports two transport modes:
1. Stdio Transport (Default)
The traditional MCP stdio transport for use with MCP clients like Claude Desktop.
2. HTTP Transport (New!)
A web-based HTTP transport implementing the MCP Streamable HTTP specification.
Installation
# Clone the repository
git clone <repository-url>
cd google-cloud-mcp
# Install dependencies
pnpm install
# Build the project
pnpm build
Configuration
Environment Variables
GOOGLE_APPLICATION_CREDENTIALS: Path to your Google Cloud service account key fileGOOGLE_CLOUD_PROJECT: Your default Google Cloud project IDGOOGLE_CLIENT_EMAIL: Service account email (alternative to credentials file)GOOGLE_PRIVATE_KEY: Service account private key (alternative to credentials file)LAZY_AUTH: Set to 'false' to initialize auth immediately (default: 'true')DEBUG: Set to 'true' for debug loggingMCP_TRANSPORT: Transport type - 'stdio' (default) or 'http'MCP_HTTP_PORT: Port for HTTP transport (default: 3000)
Google Cloud Authentication
You can authenticate in several ways:
-
Service Account Key File (Recommended):
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json -
Environment Variables:
export GOOGLE_CLIENT_EMAIL=your-service-account@project.iam.gserviceaccount.com export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n" -
Application Default Credentials: If running on Google Cloud, ADC will be used automatically.
Usage
Using Stdio Transport (Default)
# Start with stdio transport
pnpm start
# Or explicitly specify stdio
MCP_TRANSPORT=stdio pnpm start
Using HTTP Transport
# Start with HTTP transport
MCP_TRANSPORT=http pnpm start
# Or with custom port
MCP_TRANSPORT=http MCP_HTTP_PORT=8080 pnpm start
When using HTTP transport, the server will be available at:
- MCP Endpoint:
http://127.0.0.1:3000/mcp - Health Check:
http://127.0.0.1:3000/health
HTTP Transport Features
The HTTP transport implements the MCP Streamable HTTP specification with:
- Session Management: Automatic session ID assignment and tracking
- Server-Sent Events (SSE): For real-time communication and server-initiated messages
- Request/Response Handling: Proper JSON-RPC 2.0 message handling
- Security: Origin validation to prevent DNS rebinding attacks
- CORS Support: Cross-origin requests support for web applications
- Connection Management: Automatic cleanup of stale connections
HTTP Transport Usage Examples
Initialize Connection
curl -X POST http://127.0.0.1:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}'
The response will include a Mcp-Session-Id header that should be used in subsequent requests.
Make Requests with Session
curl -X POST http://127.0.0.1:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Mcp-Session-Id: <session-id>" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}'
Server-Sent Events Stream
curl -X GET http://127.0.0.1:3000/mcp \
-H "Accept: text/event-stream" \
-H "Mcp-Session-Id: <session-id>"
Available Tools
Logging Tools
gcp-logging-query: Query Google Cloud Logsgcp-logging-list-entries: List log entries with filters
Spanner Tools
gcp-spanner-execute-query: Execute SQL queries on Spanner databasesgcp-spanner-list-databases: List Spanner databasesgcp-spanner-list-instances: List Spanner instancesgcp-spanner-get-schema: Get database schema informationgcp-spanner-query-count: Get query execution metrics
Monitoring Tools
gcp-monitoring-query: Query monitoring metricsgcp-monitoring-list-metrics: List available metric descriptorsgcp-monitoring-get-resource-metrics: Get metrics for specific resources
Trace Tools
get-trace: Retrieve trace data by trace IDsearch-traces: Search for traces with filtersget-trace-summary: Get summary statistics for traces
Project Tools
gcp-get-project-info: Get current project informationgcp-list-enabled-services: List enabled APIs and services
Available Resources
Logging Resources
gcp://logging/logs/{logName}: Individual log resourcesgcp://logging/entries: Recent log entries
Spanner Resources
gcp://spanner/instances: List of Spanner instancesgcp://spanner/databases/{instanceId}: Databases in an instancegcp://spanner/schema/{instanceId}/{databaseId}: Database schema
Monitoring Resources
gcp://monitoring/metrics: Available monitoring metricsgcp://monitoring/resources: Monitored resource types
Trace Resources
gcp://trace/traces: Recent trace data
Available Prompts
analyze-logs: Analyze log patterns and errorsquery-optimization: Optimize Spanner queriestroubleshoot-performance: Troubleshoot application performance issuessecurity-analysis: Analyze security-related logs and traces
Development
# Install dependencies
pnpm install
# Run in development mode with stdio transport
pnpm dev
# Run in development mode with HTTP transport
MCP_TRANSPORT=http pnpm dev
# Build the project
pnpm build
# Run tests
pnpm test
# Lint the code
pnpm lint
# Format the code
pnpm format
Troubleshooting
Authentication Issues
-
Check your credentials:
gcloud auth application-default login -
Verify service account permissions:
- Logging Viewer
- Spanner Database User
- Monitoring Viewer
- Cloud Trace User
-
Test authentication:
DEBUG=true pnpm start
HTTP Transport Issues
-
Port conflicts: If port 3000 is in use, specify a different port:
MCP_HTTP_PORT=8080 MCP_TRANSPORT=http pnpm start -
CORS issues: The server only accepts requests from localhost, 127.0.0.1, and .local domains for security.
-
Session management: Make sure to include the
Mcp-Session-Idheader in requests after initialization.
Performance Issues
-
Enable lazy authentication:
LAZY_AUTH=true pnpm start -
Reduce logging verbosity: Remove
DEBUG=truefrom production environments.
Security Considerations
HTTP Transport Security
- The server binds only to
127.0.0.1(localhost) by default - Origin header validation prevents DNS rebinding attacks
- Sessions are automatically cleaned up
- Request timeouts prevent resource exhaustion
Google Cloud Security
- Use service accounts with minimal required permissions
- Regularly rotate service account keys
- Monitor access logs for unusual activity
- Use VPC-native clusters when possible
License
MIT License - see LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。