mcp
Allows developers and AI Agents to query Google Cloud Logging using natural language, translating queries into Google Cloud Logging Query Language (LQL) with Vertex AI Gemini 2.5.
Allows developers and AI Agents to query Google Cloud Logging using natural language, translating queries into Google Cloud Logging Query Language (LQL) with Vertex AI Gemini 2.5.
This project provides a Model Context Protocol (MCP) server that allows developers and AI Agents to query Google Cloud Logging using natural language. The server uses Vertex AI Gemini 2.5 to translate natural language queries into Google Cloud Logging Query Language (LQL), then queries Cloud Logging and returns the results.
POST /logs/nl_query
Request:
{
"query": "Show me all error logs from yesterday for my Cloud Run service 'my-service'",
"max_results": 20
}
Response:
{
"lql": "resource.type = "cloud_run_revision" AND resource.labels.service_name = "my-service" AND severity = ERROR AND timestamp >= "2025-04-17T00:00:00Z" AND timestamp < "2025-04-18T00:00:00Z"",
"entries": [ ... log entries ... ]
}
POST /logs/query
Request:
{
"filter": "resource.type="cloud_run_revision" AND severity=ERROR",
"max_results": 20
}
Response:
{
"lql": "resource.type="cloud_run_revision" AND severity=ERROR",
"entries": [ ... log entries ... ]
}
/docs
and /openapi.json
when running.curl -X POST $MCP_BASE_URL/logs/nl_query -H 'Content-Type: application/json' -d '{"query": "Show error logs for my Cloud Run service", "max_results": 2}'
curl -X POST $MCP_BASE_URL/logs/query -H 'Content-Type: application/json' -d '{"filter": "resource.type="cloud_run_revision" AND severity=ERROR", "max_results": 2}'
test_main.py
(see repo)You can deploy this server to Google Cloud Run for a fully managed, scalable solution.
Steps: 1. Build the Docker image:
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/mcp-logging-server
2. Deploy to Cloud Run:
gcloud run deploy mcp-logging-server
--image gcr.io/YOUR_PROJECT_ID/mcp-logging-server
--platform managed
--region YOUR_REGION
--allow-unauthenticated
--port 8080
Replace YOUR_PROJECT_ID
and YOUR_REGION
with your actual GCP project ID and region (e.g., us-central1
).
--set-env-vars
flag, provide:VERTEX_PROJECT=your-gcp-project-id
VERTEX_LOCATION=us-central1
(or your region)Credentials:
GOOGLE_APPLICATION_CREDENTIALS
on Cloud Run unless using a non-default service account key.IAM Permissions:
Ensure the Cloud Run service account has:
roles/logging.viewer
roles/aiplatform.user
Accessing the Service:
https://mcp-logging-server-xxxxxx.a.run.app
).$MCP_BASE_URL
in API requests.This project requires Google Cloud Application Default Credentials (ADC) to access Logging and Vertex AI APIs.
Steps to Set Up Credentials: 1. Create a Service Account: - Go to the Google Cloud Console → IAM & Admin → Service Accounts. - Select your project. - Create or select a service account with permissions: Logging Viewer and Vertex AI User. 2. Create and Download a Key: - In the Service Account, click "Manage keys" → "Add key" → "Create new key" (choose JSON). - Download the JSON key file to your computer. 3. Set the Environment Variable: - In your terminal, set the environment variable to the path of your downloaded key:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"
- Replace /path/to/your/service-account-key.json
with the actual path.
4. (Optional) Set Project and Location:
- You may also need:
export VERTEX_PROJECT=your-gcp-project-id
export VERTEX_LOCATION=us-central1
5. Verify Authentication:
- Run a simple gcloud
or Python client call to ensure authentication is working.
- If you see DefaultCredentialsError
, check your environment variable and file path.
VERTEX_PROJECT
: Your GCP project IDVERTEX_LOCATION
: Vertex AI region (default: us-central1
)GOOGLE_APPLICATION_CREDENTIALS
: Path to your service account JSON key filepip install -r requirements.txt
export VERTEX_PROJECT=your-project-id
export VERTEX_LOCATION=us-central1
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
python main.py
gcloud builds submit --tag gcr.io/$VERTEX_PROJECT/mcp-logging-server
gcloud run deploy mcp-logging-server
--image gcr.io/$VERTEX_PROJECT/mcp-logging-server
--platform managed
--region $VERTEX_LOCATION
--allow-unauthenticated
For more LQL examples, see the official documentation.
Apache 2.0