gcp-storage-mcp

gcp-storage-mcp

Enables interaction with Google Cloud Storage buckets and blobs through an MCP server, supporting operations like listing, uploading, searching, batch operations, and generating signed URLs.

Category
访问服务器

README

🚀 Professional GCP Storage API

A comprehensive, enterprise-grade FastAPI server providing REST endpoints for Google Cloud Storage operations. Built with production-ready features including authentication, rate limiting, monitoring, caching, and structured logging.

<img src="imgs/logo.png" alt="Logo" width="300" height="300">

✨ Features

🔧 Core API Features

  • Complete GCS Operations: Full REST API for buckets, blobs, and storage management
  • Batch Operations: Efficient bulk upload/delete operations
  • Storage Analytics: Comprehensive storage usage and performance metrics
  • Search & Filter: Advanced blob search and size-based filtering
  • Signed URLs: Temporary access URL generation with configurable expiration
  • Project Management: Multi-project support and project switching

🔒 Security & Authentication

  • API Key Authentication: Secure API key-based authentication system
  • Rate Limiting: Configurable rate limiting with Redis support
  • CORS Protection: Configurable cross-origin resource sharing
  • Security Headers: Comprehensive security headers (CSP, HSTS, etc.)
  • Input Validation: Extensive request validation and sanitization

Performance & Monitoring

  • Intelligent Caching: In-memory caching with TTL and automatic invalidation
  • Request Tracking: Unique request IDs for complete request tracing
  • Metrics Collection: Built-in performance and usage metrics
  • Structured Logging: JSON-based structured logging with request context
  • Health Checks: Advanced health monitoring with dependency status

🛡️ Production Ready

  • Configuration Management: Environment-based configuration system
  • Error Handling: Comprehensive error responses with detailed context
  • Graceful Shutdown: Proper application lifecycle management
  • Documentation: Auto-generated OpenAPI documentation with examples
  • Monitoring Endpoints: Built-in metrics and health check endpoints

📖 Usage

GCP Storage MCP can be used with Claude Desktop, Cursor, and more.

📦 Claude Desktop

claude_desktop_config.json

"mcpServers": {
    "gcp-storage-mcp": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/uysalserkan/gcp-storage-mcp",
        "gcp-storage-mcp",
        "--credential_path",
        "your-credential-path.json"
      ]
    },
    ...
}

📦 Cursor

.cursor/mcp.json

"mcpServers": {
    "gcp-storage-mcp": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/uysalserkan/gcp-storage-mcp",
        "gcp-storage-mcp",
        "--credential_path",
        "your-credential-path.json"
      ]
    },
    ...
}

📦 Quick Start FastAPI

Prerequisites

  • Python 3.11+
  • Google Cloud SDK installed and configured
  • Active Google Cloud Project with Cloud Storage API enabled
  • Service Account with appropriate permissions

Installation

  1. Clone and Setup
git clone https://github.com/your-username/gcp-storage-mcp.git
cd gcp-storage-mcp

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt
  1. Configure GCP Authentication
# Option 1: Service Account Key
export GOOGLE_APPLICATION_CREDENTIALS="path/to/service-account.json"

# Option 2: Application Default Credentials
gcloud auth application-default login
  1. Start the Server
# Development mode
python gcp-storage-mcp/api.py

# Production mode with configuration
GCP_STORAGE_API_LOG_LEVEL=INFO python gcp-storage-mcp/api.py
  1. Access the API
  • API Documentation: http://localhost:8000/docs
  • Health Check: http://localhost:8000/health
  • Metrics: http://localhost:8000/metrics

📖 API Documentation

Core Endpoints

Health & Monitoring

  • GET /health - Advanced health check with dependencies
  • GET /metrics - System performance metrics
  • GET / - API information and navigation

Project Management

  • GET /projects - List all accessible GCP projects
  • GET /projects/current - Get current project ID

Bucket Operations

  • GET /buckets - List all buckets
  • POST /buckets/{bucket_name} - Create bucket
  • DELETE /buckets/{bucket_name} - Delete bucket
  • GET /buckets/{bucket_name} - Get bucket information
  • GET /buckets/{bucket_name}/exists - Check bucket existence

Blob Operations

  • GET /buckets/{bucket_name}/blobs - List blobs with prefix filtering
  • POST /buckets/{bucket_name}/blobs/{blob_name}/upload - Upload blob
  • POST /buckets/{bucket_name}/blobs/{blob_name}/download - Download blob
  • DELETE /buckets/{bucket_name}/blobs/{blob_name} - Delete blob
  • GET /buckets/{bucket_name}/blobs/{blob_name} - Get blob information
  • GET /buckets/{bucket_name}/blobs/{blob_name}/url - Get public URL
  • POST /buckets/{bucket_name}/blobs/{blob_name}/signed-url - Generate signed URL

Advanced Operations

  • POST /buckets/{bucket_name}/blobs/{blob_name}/copy - Copy blob
  • POST /buckets/{bucket_name}/blobs/{blob_name}/move - Move blob
  • POST /buckets/{bucket_name}/batch/upload - Batch upload
  • POST /buckets/{bucket_name}/batch/delete - Batch delete

Analytics & Search

  • GET /buckets/{bucket_name}/analytics/storage - Storage analytics
  • POST /buckets/{bucket_name}/search - Search blobs by pattern
  • POST /buckets/{bucket_name}/filter - Filter blobs by size

🔧 Usage Examples

Basic Operations

Authentication with API Key

curl -H "X-API-Key: your-api-key" \
     -H "Content-Type: application/json" \
     http://localhost:8000/health

List Buckets

curl -H "X-API-Key: your-api-key" \
     http://localhost:8000/buckets

Upload a File

curl -X POST \
     -H "X-API-Key: your-api-key" \
     -H "Content-Type: application/json" \
     -d '{"file_path": "/path/to/local/file.txt"}' \
     http://localhost:8000/buckets/my-bucket/blobs/path/to/file.txt/upload

Generate Signed URL

curl -X POST \
     -H "X-API-Key: your-api-key" \
     -H "Content-Type: application/json" \
     -d '{"expiration_hours": 24, "method": "GET"}' \
     http://localhost:8000/buckets/my-bucket/blobs/file.txt/signed-url

Python Client Example

import httpx
import asyncio

class GCPStorageClient:
    def __init__(self, base_url: str, api_key: str):
        self.base_url = base_url
        self.headers = {"X-API-Key": api_key}

    async def list_buckets(self):
        async with httpx.AsyncClient() as client:
            response = await client.get(
                f"{self.base_url}/buckets",
                headers=self.headers
            )
            return response.json()

    async def upload_file(self, bucket: str, blob_name: str, file_path: str):
        async with httpx.AsyncClient() as client:
            response = await client.post(
                f"{self.base_url}/buckets/{bucket}/blobs/{blob_name}/upload",
                headers=self.headers,
                json={"file_path": file_path}
            )
            return response.json()

# Usage
async def main():
    client = GCPStorageClient("http://localhost:8000", "your-api-key")

    # List buckets
    buckets = await client.list_buckets()
    print(f"Found {buckets['count']} buckets")

    # Upload file
    result = await client.upload_file(
        "my-bucket",
        "documents/file.pdf",
        "/local/path/file.pdf"
    )
    print(f"Upload completed: {result}")

if __name__ == "__main__":
    asyncio.run(main())

📊 Monitoring & Observability

Health Monitoring

The API provides comprehensive health checks:

# Basic health check
curl http://localhost:8000/health

# Response includes:
# - Overall status
# - GCP connection status
# - Dependency health
# - Performance metrics
# - Uptime information

Metrics Collection

Built-in metrics endpoint provides:

curl http://localhost:8000/metrics

# Metrics include:
# - Request counts by endpoint
# - Response times
# - Error rates
# - Active requests
# - Cache hit rates

Structured Logging

All requests are logged with structured JSON:

{
  "timestamp": "2024-01-15T10:30:00Z",
  "level": "INFO",
  "message": "Request completed",
  "request_id": "550e8400-e29b-41d4-a716-446655440000",
  "method": "GET",
  "path": "/buckets",
  "status_code": 200,
  "duration_ms": 45.2,
  "client_ip": "192.168.1.100"
}

🔒 Security Best Practices

Authentication

  • Use strong, randomly generated API keys
  • Rotate API keys regularly
  • Store keys securely (environment variables, secret managers)

CORS Configuration

# Restrict origins in production
GCP_STORAGE_API_ALLOWED_ORIGINS="https://yourdomain.com,https://app.yourdomain.com"

Rate Limiting

# Configure appropriate limits
GCP_STORAGE_API_RATE_LIMIT_DEFAULT="1000/hour"
GCP_STORAGE_API_RATE_LIMIT_STORAGE="redis://secure-redis:6379"

GCP Permissions

Minimum required IAM roles:

  • roles/storage.objectViewer - Read operations
  • roles/storage.objectCreator - Upload operations
  • roles/storage.admin - Full management (production)

📈 Performance Features

Intelligent Caching

  • Bucket Lists: Cached for 5 minutes
  • Bucket Info: Cached for 10 minutes
  • Blob URLs: Cached for 1 hour
  • Storage Analytics: Cached for 30 minutes
  • Automatic Invalidation: Cache cleared on data modifications

Request Optimization

  • Parallel Processing: Concurrent operations where possible
  • Batch Operations: Efficient bulk operations
  • Connection Pooling: Optimized GCP client connections
  • Request Tracking: Complete request lifecycle monitoring

🧪 Testing

# Install test dependencies
pip install pytest pytest-cov httpx

# Run tests
pytest tests/

# Run with coverage
pytest --cov=gcp-storage-mcp tests/

# Integration tests (requires GCP setup)
GCP_STORAGE_API_TEST_BUCKET="test-bucket" pytest tests/integration/

🤝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow the existing code style
  4. Add tests for new features
  5. Update documentation
  6. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Resources

📞 Support


Status: ✅ Production Ready | Version: 1.0.0 | Last Updated: January 2025

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选