platform-mcp 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- platform_mcp-0.2.0/LICENSE +21 -0
- platform_mcp-0.2.0/PKG-INFO +341 -0
- platform_mcp-0.2.0/README.md +306 -0
- platform_mcp-0.2.0/pyproject.toml +52 -0
- platform_mcp-0.2.0/setup.cfg +4 -0
- platform_mcp-0.2.0/src/platform_mcp/__init__.py +3 -0
- platform_mcp-0.2.0/src/platform_mcp/__main__.py +4 -0
- platform_mcp-0.2.0/src/platform_mcp/clients.py +116 -0
- platform_mcp-0.2.0/src/platform_mcp/config.py +329 -0
- platform_mcp-0.2.0/src/platform_mcp/diagnostics.py +173 -0
- platform_mcp-0.2.0/src/platform_mcp/errors.py +101 -0
- platform_mcp-0.2.0/src/platform_mcp/formatting.py +55 -0
- platform_mcp-0.2.0/src/platform_mcp/observability.py +152 -0
- platform_mcp-0.2.0/src/platform_mcp/registration.py +34 -0
- platform_mcp-0.2.0/src/platform_mcp/server.py +94 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/__init__.py +1 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/cost_tools.py +152 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/environment_tools.py +41 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/error_reporting_tools.py +89 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/inventory_tools.py +128 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/logging_tools.py +115 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/monitoring_tools.py +210 -0
- platform_mcp-0.2.0/src/platform_mcp/tools/recommender_tools.py +210 -0
- platform_mcp-0.2.0/src/platform_mcp.egg-info/PKG-INFO +341 -0
- platform_mcp-0.2.0/src/platform_mcp.egg-info/SOURCES.txt +32 -0
- platform_mcp-0.2.0/src/platform_mcp.egg-info/dependency_links.txt +1 -0
- platform_mcp-0.2.0/src/platform_mcp.egg-info/entry_points.txt +2 -0
- platform_mcp-0.2.0/src/platform_mcp.egg-info/requires.txt +13 -0
- platform_mcp-0.2.0/src/platform_mcp.egg-info/top_level.txt +1 -0
- platform_mcp-0.2.0/tests/test_config.py +137 -0
- platform_mcp-0.2.0/tests/test_errors.py +60 -0
- platform_mcp-0.2.0/tests/test_formatting.py +79 -0
- platform_mcp-0.2.0/tests/test_observability.py +108 -0
- platform_mcp-0.2.0/tests/test_protocol.py +110 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dimuthu Wickramanayake
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: platform-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Read-only GCP platform-engineer MCP server for debugging and cost optimization
|
|
5
|
+
Author: Dimuthu Bhathiya
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/deBilla/platform-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/deBilla/platform-mcp
|
|
9
|
+
Project-URL: Issues, https://github.com/deBilla/platform-mcp/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,gcp,google-cloud,sre,finops,observability
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: System :: Monitoring
|
|
18
|
+
Classifier: Topic :: System :: Systems Administration
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: mcp<2,>=1.2.0
|
|
23
|
+
Requires-Dist: google-auth>=2.28.0
|
|
24
|
+
Requires-Dist: google-cloud-logging>=3.9.0
|
|
25
|
+
Requires-Dist: google-cloud-monitoring>=2.19.0
|
|
26
|
+
Requires-Dist: google-cloud-error-reporting>=1.11.0
|
|
27
|
+
Requires-Dist: google-cloud-recommender>=2.15.0
|
|
28
|
+
Requires-Dist: google-cloud-asset>=3.25.0
|
|
29
|
+
Requires-Dist: google-cloud-billing>=1.13.0
|
|
30
|
+
Requires-Dist: google-cloud-bigquery>=3.19.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
33
|
+
Requires-Dist: anyio>=4.0; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# platform-mcp
|
|
37
|
+
|
|
38
|
+
<!-- Identifier for the official MCP registry; must match server.json. -->
|
|
39
|
+
mcp-name: io.github.deBilla/platform-mcp
|
|
40
|
+
|
|
41
|
+
A **read-only** [Model Context Protocol](https://modelcontextprotocol.io) server that turns an AI agent (Claude Code, Claude Desktop, or any MCP client) into a GCP platform engineer. Point it at your Google Cloud projects and ask it to investigate incidents, take inventory, and surface cost-optimization opportunities — all without any ability to change your infrastructure.
|
|
42
|
+
|
|
43
|
+
> **Observation only.** No tool in this server mutates state. Combined with a viewer-only identity (below), that gives you a hard, defense-in-depth guarantee that an agent can look but never touch.
|
|
44
|
+
|
|
45
|
+
## What it can do
|
|
46
|
+
|
|
47
|
+
| Area | Tools |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| **Environments** | `list_environments` |
|
|
50
|
+
| **Logs & errors** | `query_logs`, `get_recent_errors`, `list_error_groups` |
|
|
51
|
+
| **Metrics & alerting** | `query_metric`, `list_alert_policies`, `list_uptime_checks` |
|
|
52
|
+
| **Cost & recommendations** | `get_cost_breakdown`, `get_billing_info`, `list_cost_recommendations`, `list_recommendations` |
|
|
53
|
+
| **Resource inventory** | `search_assets`, `list_compute_instances`, `list_cloud_run_services`, `list_gke_clusters`, `list_sql_instances` |
|
|
54
|
+
|
|
55
|
+
Typical prompts once it's connected:
|
|
56
|
+
|
|
57
|
+
- *"What are the top error groups in the last 24 hours, and which one is newest?"*
|
|
58
|
+
- *"Which GKE node pools are over-provisioned? Show mean CPU against machine type."*
|
|
59
|
+
- *"Where can I reduce spend in this project?"*
|
|
60
|
+
|
|
61
|
+
## Multiple environments
|
|
62
|
+
|
|
63
|
+
One server can reach several projects. Define them under
|
|
64
|
+
`PLATFORM_MCP_ENVIRONMENTS` (see [Configuration](#configuration)) and the agent
|
|
65
|
+
picks one from the wording of your prompt:
|
|
66
|
+
|
|
67
|
+
- *"Any errors in **staging** in the last hour?"*
|
|
68
|
+
- *"Compare Cloud Run services between **staging** and **prod**."*
|
|
69
|
+
|
|
70
|
+
Every tool takes an optional `environment` argument. Omit it and the default
|
|
71
|
+
environment is used; pass `environment="production"` to target another. Names,
|
|
72
|
+
any aliases you define, common shorthands (`prod`, `stg`, `qa`, …) and bare
|
|
73
|
+
project ids all resolve. An unrecognized name is an error listing the valid
|
|
74
|
+
options — a typo can never silently retarget the wrong project.
|
|
75
|
+
|
|
76
|
+
Each environment carries its own service account, so staging and production are
|
|
77
|
+
reached through separate identities from the same process, and every result
|
|
78
|
+
echoes back the `environment` and `project` it came from.
|
|
79
|
+
|
|
80
|
+
## Requirements
|
|
81
|
+
|
|
82
|
+
- Python 3.11+
|
|
83
|
+
- A Google Cloud project and credentials (your own login, or a service account)
|
|
84
|
+
- The [`gcloud` CLI](https://cloud.google.com/sdk/docs/install) for the one-time setup
|
|
85
|
+
|
|
86
|
+
## Install
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
uvx platform-mcp # no install step; uv fetches it on demand
|
|
90
|
+
pipx install platform-mcp # or keep it on PATH
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
From a checkout, for development:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/deBilla/platform-mcp.git
|
|
97
|
+
cd platform-mcp
|
|
98
|
+
python3 -m venv .venv
|
|
99
|
+
./.venv/bin/pip install -e ".[dev]"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Check your setup
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
platform-mcp doctor
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
This checks, for every configured environment, that Application Default
|
|
109
|
+
Credentials exist, that the read-only service account can be impersonated, that
|
|
110
|
+
a real API read succeeds, and that the billing export is readable — printing the
|
|
111
|
+
exact command to fix whatever fails. Run it before reporting a problem.
|
|
112
|
+
|
|
113
|
+
## One-time GCP setup
|
|
114
|
+
|
|
115
|
+
Run these once **per project** you want to reach — staging and production each
|
|
116
|
+
need their own APIs enabled and their own read-only service account.
|
|
117
|
+
|
|
118
|
+
**1. Enable the APIs the tools depend on:**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
gcloud services enable \
|
|
122
|
+
logging.googleapis.com monitoring.googleapis.com clouderrorreporting.googleapis.com \
|
|
123
|
+
recommender.googleapis.com cloudasset.googleapis.com cloudbilling.googleapis.com \
|
|
124
|
+
bigquery.googleapis.com \
|
|
125
|
+
--project YOUR_PROJECT_ID
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**2. Grant read-only access to the identity the server runs as.**
|
|
129
|
+
|
|
130
|
+
For local development with your own login (Application Default Credentials):
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
gcloud auth application-default login
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The identity needs these viewer roles on the project, plus `roles/billing.viewer`
|
|
137
|
+
on the billing account:
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
roles/viewer # broad read (compute, run, gke, sql via Asset Inventory)
|
|
141
|
+
roles/logging.viewer
|
|
142
|
+
roles/monitoring.viewer
|
|
143
|
+
roles/errorreporting.viewer
|
|
144
|
+
roles/recommender.viewer
|
|
145
|
+
roles/cloudasset.viewer
|
|
146
|
+
roles/bigquery.dataViewer # only for get_cost_breakdown
|
|
147
|
+
roles/bigquery.jobUser # only for get_cost_breakdown
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**3. (Recommended) Use a dedicated read-only service account** instead of your login:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
PROJECT=YOUR_PROJECT_ID
|
|
154
|
+
gcloud iam service-accounts create platform-mcp-ro \
|
|
155
|
+
--display-name "platform-mcp read-only" --project $PROJECT
|
|
156
|
+
|
|
157
|
+
SA=platform-mcp-ro@$PROJECT.iam.gserviceaccount.com
|
|
158
|
+
for ROLE in roles/viewer roles/logging.viewer roles/monitoring.viewer \
|
|
159
|
+
roles/errorreporting.viewer roles/recommender.viewer roles/cloudasset.viewer; do
|
|
160
|
+
gcloud projects add-iam-policy-binding $PROJECT \
|
|
161
|
+
--member="serviceAccount:$SA" --role="$ROLE"
|
|
162
|
+
done
|
|
163
|
+
|
|
164
|
+
# Let your own login impersonate it (no key file to manage):
|
|
165
|
+
gcloud iam service-accounts add-iam-policy-binding $SA \
|
|
166
|
+
--member="user:you@example.com" \
|
|
167
|
+
--role="roles/iam.serviceAccountTokenCreator" --project $PROJECT
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Then reference it as that environment's `impersonate` value in
|
|
171
|
+
`PLATFORM_MCP_ENVIRONMENTS` (preferred — no key file), or point at a downloaded
|
|
172
|
+
key via `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
173
|
+
|
|
174
|
+
> Impersonation is performed by whatever identity your ADC resolves to. If your
|
|
175
|
+
> ADC is itself an impersonated service account, that SA — not your user — needs
|
|
176
|
+
> `roles/iam.serviceAccountTokenCreator` on each `platform-mcp-ro`.
|
|
177
|
+
|
|
178
|
+
## Security model
|
|
179
|
+
|
|
180
|
+
Read-only is enforced by **IAM, not by OAuth scope.** The server requests the
|
|
181
|
+
broad `cloud-platform` scope and stays read-only purely because it never calls a
|
|
182
|
+
mutating API. **Do not rely on the code alone** — run it under a viewer-only
|
|
183
|
+
identity (step 3 above) so the credential itself is incapable of writing,
|
|
184
|
+
regardless of what code executes. This gives you two independent layers: the
|
|
185
|
+
server doesn't try to write, and the identity couldn't if it did.
|
|
186
|
+
|
|
187
|
+
With multiple environments this stays per-project: each environment
|
|
188
|
+
authenticates as its own service account, so a staging identity is never used
|
|
189
|
+
to reach production. Grant each one viewer-only access to its project alone.
|
|
190
|
+
|
|
191
|
+
## Configuration
|
|
192
|
+
|
|
193
|
+
The friendliest option is a config file, which keeps project ids and service
|
|
194
|
+
account emails out of every client config you own:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
mkdir -p ~/.config/platform-mcp
|
|
198
|
+
cp config.toml.example ~/.config/platform-mcp/config.toml
|
|
199
|
+
$EDITOR ~/.config/platform-mcp/config.toml
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
With that in place, registering the server takes no environment variables at
|
|
203
|
+
all. Point `PLATFORM_MCP_CONFIG` elsewhere to use a different file — a copy
|
|
204
|
+
committed to your infrastructure repo, for instance.
|
|
205
|
+
|
|
206
|
+
Environment variables still work and always win over the file, so an existing
|
|
207
|
+
setup keeps running unchanged and a one-off override needs no edit:
|
|
208
|
+
|
|
209
|
+
| Variable | Purpose |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| `PLATFORM_MCP_ENVIRONMENTS` | JSON map of environment name → settings. The recommended way to configure the server. |
|
|
212
|
+
| `PLATFORM_MCP_DEFAULT_ENVIRONMENT` | Environment used when a tool call omits `environment`. Defaults to `staging` if configured, else the first entry. |
|
|
213
|
+
| `GOOGLE_APPLICATION_CREDENTIALS` | Path to a read-only SA key file (alternative to impersonation). |
|
|
214
|
+
| `PLATFORM_MCP_DEFAULT_LIMIT` | Default max rows for list-style tools (default 50). |
|
|
215
|
+
|
|
216
|
+
`PLATFORM_MCP_ENVIRONMENTS` holds a JSON object; each entry accepts:
|
|
217
|
+
|
|
218
|
+
| Key | Purpose |
|
|
219
|
+
| --- | --- |
|
|
220
|
+
| `project` | **Required.** GCP project id. |
|
|
221
|
+
| `impersonate` | Read-only SA to impersonate for this environment (no key file needed). |
|
|
222
|
+
| `billing_export_table` | Fully-qualified BigQuery billing export table, required only for `get_cost_breakdown` (e.g. `YOUR_PROJECT_ID.billing.gcp_billing_export_v1_XXXXXX`). |
|
|
223
|
+
| `aliases` | Extra names the agent may use for this environment. |
|
|
224
|
+
|
|
225
|
+
A bare string value is shorthand for `{"project": "..."}`. As JSON inside
|
|
226
|
+
`.mcp.json` the quotes must be escaped; unescaped it reads:
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"staging": {
|
|
231
|
+
"project": "my-app-staging",
|
|
232
|
+
"impersonate": "platform-mcp-ro@my-app-staging.iam.gserviceaccount.com"
|
|
233
|
+
},
|
|
234
|
+
"production": {
|
|
235
|
+
"project": "my-app",
|
|
236
|
+
"impersonate": "platform-mcp-ro@my-app.iam.gserviceaccount.com",
|
|
237
|
+
"billing_export_table": "my-app.billing.gcp_billing_export_v1_XXXXXX"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Single-environment mode.** If `PLATFORM_MCP_ENVIRONMENTS` is unset the server
|
|
243
|
+
behaves as before, exposing one environment named `default`:
|
|
244
|
+
|
|
245
|
+
| Variable | Purpose |
|
|
246
|
+
| --- | --- |
|
|
247
|
+
| `GCP_PROJECT` | Target project. Falls back to your ADC default project if unset. |
|
|
248
|
+
| `IMPERSONATE_SERVICE_ACCOUNT` | Read-only SA to impersonate. Also the fallback for registry entries with no `impersonate`. |
|
|
249
|
+
| `BILLING_EXPORT_TABLE` | Billing export table. Also the fallback for registry entries with no `billing_export_table`. |
|
|
250
|
+
|
|
251
|
+
## Register with a client
|
|
252
|
+
|
|
253
|
+
**Claude Code** — with a config file in place, this is the whole thing:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
claude mcp add platform-mcp --scope user -- uvx platform-mcp
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Claude Desktop** — the same command and args in `claude_desktop_config.json`:
|
|
260
|
+
|
|
261
|
+
```json
|
|
262
|
+
{
|
|
263
|
+
"mcpServers": {
|
|
264
|
+
"platform-mcp": {
|
|
265
|
+
"command": "uvx",
|
|
266
|
+
"args": ["platform-mcp"]
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Without a config file, add the environment variables from
|
|
273
|
+
`.mcp.json.example` to either form.
|
|
274
|
+
|
|
275
|
+
### Skip the approval prompt
|
|
276
|
+
|
|
277
|
+
Every tool here is read-only, so approving each call individually adds nothing.
|
|
278
|
+
Allow the whole server once, in Claude Code settings:
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{ "permissions": { "allow": ["mcp__platform-mcp__*"] } }
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The glob must sit after a literal `mcp__<server>__` prefix — an unanchored
|
|
285
|
+
pattern like `mcp__*` is ignored with a warning and approves nothing.
|
|
286
|
+
|
|
287
|
+
**MCP Inspector** — for interactive testing:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
uvx --with 'mcp[cli]' mcp dev src/platform_mcp/server.py
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Observability
|
|
294
|
+
|
|
295
|
+
Every tool call appends one JSON line to `~/.local/state/platform-mcp/audit.jsonl`:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{"ts":"2026-08-30T18:20:11+0800","tool":"query_logs","environment":"production",
|
|
299
|
+
"project":"my-app","duration_ms":412,"count":50,"bytes":18422,"error":null}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Free-text arguments are recorded by name only — a Cloud Logging filter can carry
|
|
303
|
+
user ids from the logs being searched, and the audit file must not become a
|
|
304
|
+
second copy of that. Set `PLATFORM_MCP_AUDIT_LOG` to another path, or to `off`.
|
|
305
|
+
|
|
306
|
+
Diagnostic logs go to **stderr** (`PLATFORM_MCP_LOG_LEVEL` to adjust); in stdio
|
|
307
|
+
transport stdout carries the protocol, so nothing else may be written there. In
|
|
308
|
+
Claude Code, read them with `claude --debug=mcp`.
|
|
309
|
+
|
|
310
|
+
For a record that does not depend on this server at all, enable **Data Access
|
|
311
|
+
audit logs** in GCP for the read-only service accounts. Token minting already
|
|
312
|
+
appears in Admin Activity logs without any configuration.
|
|
313
|
+
|
|
314
|
+
## Development
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
./.venv/bin/python -m pytest
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
The suite runs entirely in-process against an in-memory MCP client — no
|
|
321
|
+
subprocess, no network, no GCP credentials — and covers environment resolution,
|
|
322
|
+
the tool contract, annotations, error translation and the audit log.
|
|
323
|
+
|
|
324
|
+
## Notes
|
|
325
|
+
|
|
326
|
+
- All tools cap result counts and truncate long payloads to stay token-friendly.
|
|
327
|
+
- GCP clients are built lazily and cached per environment, so switching between
|
|
328
|
+
staging and production mid-conversation costs one client construction each.
|
|
329
|
+
- Cost recommenders are zonal/regional; `list_cost_recommendations` auto-discovers
|
|
330
|
+
the locations where you have resources (via Asset Inventory) and fans out,
|
|
331
|
+
skipping locations and recommenders that are empty or unavailable. It reports
|
|
332
|
+
`skipped_calls` and fails loudly if it cannot discover any location, because
|
|
333
|
+
"I could not look" and "there is nothing to save" must not look alike.
|
|
334
|
+
- `get_cost_breakdown` uses parameterized BigQuery queries with a whitelisted set
|
|
335
|
+
of group-by columns, and filters to the selected environment's project. A
|
|
336
|
+
billing export covers the whole billing account, so pass `all_projects=true`
|
|
337
|
+
when you want account-wide totals.
|
|
338
|
+
|
|
339
|
+
## License
|
|
340
|
+
|
|
341
|
+
[MIT](LICENSE) © 2026 Dimuthu Wickramanayake
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# platform-mcp
|
|
2
|
+
|
|
3
|
+
<!-- Identifier for the official MCP registry; must match server.json. -->
|
|
4
|
+
mcp-name: io.github.deBilla/platform-mcp
|
|
5
|
+
|
|
6
|
+
A **read-only** [Model Context Protocol](https://modelcontextprotocol.io) server that turns an AI agent (Claude Code, Claude Desktop, or any MCP client) into a GCP platform engineer. Point it at your Google Cloud projects and ask it to investigate incidents, take inventory, and surface cost-optimization opportunities — all without any ability to change your infrastructure.
|
|
7
|
+
|
|
8
|
+
> **Observation only.** No tool in this server mutates state. Combined with a viewer-only identity (below), that gives you a hard, defense-in-depth guarantee that an agent can look but never touch.
|
|
9
|
+
|
|
10
|
+
## What it can do
|
|
11
|
+
|
|
12
|
+
| Area | Tools |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| **Environments** | `list_environments` |
|
|
15
|
+
| **Logs & errors** | `query_logs`, `get_recent_errors`, `list_error_groups` |
|
|
16
|
+
| **Metrics & alerting** | `query_metric`, `list_alert_policies`, `list_uptime_checks` |
|
|
17
|
+
| **Cost & recommendations** | `get_cost_breakdown`, `get_billing_info`, `list_cost_recommendations`, `list_recommendations` |
|
|
18
|
+
| **Resource inventory** | `search_assets`, `list_compute_instances`, `list_cloud_run_services`, `list_gke_clusters`, `list_sql_instances` |
|
|
19
|
+
|
|
20
|
+
Typical prompts once it's connected:
|
|
21
|
+
|
|
22
|
+
- *"What are the top error groups in the last 24 hours, and which one is newest?"*
|
|
23
|
+
- *"Which GKE node pools are over-provisioned? Show mean CPU against machine type."*
|
|
24
|
+
- *"Where can I reduce spend in this project?"*
|
|
25
|
+
|
|
26
|
+
## Multiple environments
|
|
27
|
+
|
|
28
|
+
One server can reach several projects. Define them under
|
|
29
|
+
`PLATFORM_MCP_ENVIRONMENTS` (see [Configuration](#configuration)) and the agent
|
|
30
|
+
picks one from the wording of your prompt:
|
|
31
|
+
|
|
32
|
+
- *"Any errors in **staging** in the last hour?"*
|
|
33
|
+
- *"Compare Cloud Run services between **staging** and **prod**."*
|
|
34
|
+
|
|
35
|
+
Every tool takes an optional `environment` argument. Omit it and the default
|
|
36
|
+
environment is used; pass `environment="production"` to target another. Names,
|
|
37
|
+
any aliases you define, common shorthands (`prod`, `stg`, `qa`, …) and bare
|
|
38
|
+
project ids all resolve. An unrecognized name is an error listing the valid
|
|
39
|
+
options — a typo can never silently retarget the wrong project.
|
|
40
|
+
|
|
41
|
+
Each environment carries its own service account, so staging and production are
|
|
42
|
+
reached through separate identities from the same process, and every result
|
|
43
|
+
echoes back the `environment` and `project` it came from.
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
- Python 3.11+
|
|
48
|
+
- A Google Cloud project and credentials (your own login, or a service account)
|
|
49
|
+
- The [`gcloud` CLI](https://cloud.google.com/sdk/docs/install) for the one-time setup
|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uvx platform-mcp # no install step; uv fetches it on demand
|
|
55
|
+
pipx install platform-mcp # or keep it on PATH
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
From a checkout, for development:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://github.com/deBilla/platform-mcp.git
|
|
62
|
+
cd platform-mcp
|
|
63
|
+
python3 -m venv .venv
|
|
64
|
+
./.venv/bin/pip install -e ".[dev]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Check your setup
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
platform-mcp doctor
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
This checks, for every configured environment, that Application Default
|
|
74
|
+
Credentials exist, that the read-only service account can be impersonated, that
|
|
75
|
+
a real API read succeeds, and that the billing export is readable — printing the
|
|
76
|
+
exact command to fix whatever fails. Run it before reporting a problem.
|
|
77
|
+
|
|
78
|
+
## One-time GCP setup
|
|
79
|
+
|
|
80
|
+
Run these once **per project** you want to reach — staging and production each
|
|
81
|
+
need their own APIs enabled and their own read-only service account.
|
|
82
|
+
|
|
83
|
+
**1. Enable the APIs the tools depend on:**
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
gcloud services enable \
|
|
87
|
+
logging.googleapis.com monitoring.googleapis.com clouderrorreporting.googleapis.com \
|
|
88
|
+
recommender.googleapis.com cloudasset.googleapis.com cloudbilling.googleapis.com \
|
|
89
|
+
bigquery.googleapis.com \
|
|
90
|
+
--project YOUR_PROJECT_ID
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**2. Grant read-only access to the identity the server runs as.**
|
|
94
|
+
|
|
95
|
+
For local development with your own login (Application Default Credentials):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
gcloud auth application-default login
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The identity needs these viewer roles on the project, plus `roles/billing.viewer`
|
|
102
|
+
on the billing account:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
roles/viewer # broad read (compute, run, gke, sql via Asset Inventory)
|
|
106
|
+
roles/logging.viewer
|
|
107
|
+
roles/monitoring.viewer
|
|
108
|
+
roles/errorreporting.viewer
|
|
109
|
+
roles/recommender.viewer
|
|
110
|
+
roles/cloudasset.viewer
|
|
111
|
+
roles/bigquery.dataViewer # only for get_cost_breakdown
|
|
112
|
+
roles/bigquery.jobUser # only for get_cost_breakdown
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**3. (Recommended) Use a dedicated read-only service account** instead of your login:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
PROJECT=YOUR_PROJECT_ID
|
|
119
|
+
gcloud iam service-accounts create platform-mcp-ro \
|
|
120
|
+
--display-name "platform-mcp read-only" --project $PROJECT
|
|
121
|
+
|
|
122
|
+
SA=platform-mcp-ro@$PROJECT.iam.gserviceaccount.com
|
|
123
|
+
for ROLE in roles/viewer roles/logging.viewer roles/monitoring.viewer \
|
|
124
|
+
roles/errorreporting.viewer roles/recommender.viewer roles/cloudasset.viewer; do
|
|
125
|
+
gcloud projects add-iam-policy-binding $PROJECT \
|
|
126
|
+
--member="serviceAccount:$SA" --role="$ROLE"
|
|
127
|
+
done
|
|
128
|
+
|
|
129
|
+
# Let your own login impersonate it (no key file to manage):
|
|
130
|
+
gcloud iam service-accounts add-iam-policy-binding $SA \
|
|
131
|
+
--member="user:you@example.com" \
|
|
132
|
+
--role="roles/iam.serviceAccountTokenCreator" --project $PROJECT
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Then reference it as that environment's `impersonate` value in
|
|
136
|
+
`PLATFORM_MCP_ENVIRONMENTS` (preferred — no key file), or point at a downloaded
|
|
137
|
+
key via `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
138
|
+
|
|
139
|
+
> Impersonation is performed by whatever identity your ADC resolves to. If your
|
|
140
|
+
> ADC is itself an impersonated service account, that SA — not your user — needs
|
|
141
|
+
> `roles/iam.serviceAccountTokenCreator` on each `platform-mcp-ro`.
|
|
142
|
+
|
|
143
|
+
## Security model
|
|
144
|
+
|
|
145
|
+
Read-only is enforced by **IAM, not by OAuth scope.** The server requests the
|
|
146
|
+
broad `cloud-platform` scope and stays read-only purely because it never calls a
|
|
147
|
+
mutating API. **Do not rely on the code alone** — run it under a viewer-only
|
|
148
|
+
identity (step 3 above) so the credential itself is incapable of writing,
|
|
149
|
+
regardless of what code executes. This gives you two independent layers: the
|
|
150
|
+
server doesn't try to write, and the identity couldn't if it did.
|
|
151
|
+
|
|
152
|
+
With multiple environments this stays per-project: each environment
|
|
153
|
+
authenticates as its own service account, so a staging identity is never used
|
|
154
|
+
to reach production. Grant each one viewer-only access to its project alone.
|
|
155
|
+
|
|
156
|
+
## Configuration
|
|
157
|
+
|
|
158
|
+
The friendliest option is a config file, which keeps project ids and service
|
|
159
|
+
account emails out of every client config you own:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
mkdir -p ~/.config/platform-mcp
|
|
163
|
+
cp config.toml.example ~/.config/platform-mcp/config.toml
|
|
164
|
+
$EDITOR ~/.config/platform-mcp/config.toml
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
With that in place, registering the server takes no environment variables at
|
|
168
|
+
all. Point `PLATFORM_MCP_CONFIG` elsewhere to use a different file — a copy
|
|
169
|
+
committed to your infrastructure repo, for instance.
|
|
170
|
+
|
|
171
|
+
Environment variables still work and always win over the file, so an existing
|
|
172
|
+
setup keeps running unchanged and a one-off override needs no edit:
|
|
173
|
+
|
|
174
|
+
| Variable | Purpose |
|
|
175
|
+
| --- | --- |
|
|
176
|
+
| `PLATFORM_MCP_ENVIRONMENTS` | JSON map of environment name → settings. The recommended way to configure the server. |
|
|
177
|
+
| `PLATFORM_MCP_DEFAULT_ENVIRONMENT` | Environment used when a tool call omits `environment`. Defaults to `staging` if configured, else the first entry. |
|
|
178
|
+
| `GOOGLE_APPLICATION_CREDENTIALS` | Path to a read-only SA key file (alternative to impersonation). |
|
|
179
|
+
| `PLATFORM_MCP_DEFAULT_LIMIT` | Default max rows for list-style tools (default 50). |
|
|
180
|
+
|
|
181
|
+
`PLATFORM_MCP_ENVIRONMENTS` holds a JSON object; each entry accepts:
|
|
182
|
+
|
|
183
|
+
| Key | Purpose |
|
|
184
|
+
| --- | --- |
|
|
185
|
+
| `project` | **Required.** GCP project id. |
|
|
186
|
+
| `impersonate` | Read-only SA to impersonate for this environment (no key file needed). |
|
|
187
|
+
| `billing_export_table` | Fully-qualified BigQuery billing export table, required only for `get_cost_breakdown` (e.g. `YOUR_PROJECT_ID.billing.gcp_billing_export_v1_XXXXXX`). |
|
|
188
|
+
| `aliases` | Extra names the agent may use for this environment. |
|
|
189
|
+
|
|
190
|
+
A bare string value is shorthand for `{"project": "..."}`. As JSON inside
|
|
191
|
+
`.mcp.json` the quotes must be escaped; unescaped it reads:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"staging": {
|
|
196
|
+
"project": "my-app-staging",
|
|
197
|
+
"impersonate": "platform-mcp-ro@my-app-staging.iam.gserviceaccount.com"
|
|
198
|
+
},
|
|
199
|
+
"production": {
|
|
200
|
+
"project": "my-app",
|
|
201
|
+
"impersonate": "platform-mcp-ro@my-app.iam.gserviceaccount.com",
|
|
202
|
+
"billing_export_table": "my-app.billing.gcp_billing_export_v1_XXXXXX"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Single-environment mode.** If `PLATFORM_MCP_ENVIRONMENTS` is unset the server
|
|
208
|
+
behaves as before, exposing one environment named `default`:
|
|
209
|
+
|
|
210
|
+
| Variable | Purpose |
|
|
211
|
+
| --- | --- |
|
|
212
|
+
| `GCP_PROJECT` | Target project. Falls back to your ADC default project if unset. |
|
|
213
|
+
| `IMPERSONATE_SERVICE_ACCOUNT` | Read-only SA to impersonate. Also the fallback for registry entries with no `impersonate`. |
|
|
214
|
+
| `BILLING_EXPORT_TABLE` | Billing export table. Also the fallback for registry entries with no `billing_export_table`. |
|
|
215
|
+
|
|
216
|
+
## Register with a client
|
|
217
|
+
|
|
218
|
+
**Claude Code** — with a config file in place, this is the whole thing:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
claude mcp add platform-mcp --scope user -- uvx platform-mcp
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Claude Desktop** — the same command and args in `claude_desktop_config.json`:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"mcpServers": {
|
|
229
|
+
"platform-mcp": {
|
|
230
|
+
"command": "uvx",
|
|
231
|
+
"args": ["platform-mcp"]
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Without a config file, add the environment variables from
|
|
238
|
+
`.mcp.json.example` to either form.
|
|
239
|
+
|
|
240
|
+
### Skip the approval prompt
|
|
241
|
+
|
|
242
|
+
Every tool here is read-only, so approving each call individually adds nothing.
|
|
243
|
+
Allow the whole server once, in Claude Code settings:
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{ "permissions": { "allow": ["mcp__platform-mcp__*"] } }
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
The glob must sit after a literal `mcp__<server>__` prefix — an unanchored
|
|
250
|
+
pattern like `mcp__*` is ignored with a warning and approves nothing.
|
|
251
|
+
|
|
252
|
+
**MCP Inspector** — for interactive testing:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
uvx --with 'mcp[cli]' mcp dev src/platform_mcp/server.py
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Observability
|
|
259
|
+
|
|
260
|
+
Every tool call appends one JSON line to `~/.local/state/platform-mcp/audit.jsonl`:
|
|
261
|
+
|
|
262
|
+
```json
|
|
263
|
+
{"ts":"2026-08-30T18:20:11+0800","tool":"query_logs","environment":"production",
|
|
264
|
+
"project":"my-app","duration_ms":412,"count":50,"bytes":18422,"error":null}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Free-text arguments are recorded by name only — a Cloud Logging filter can carry
|
|
268
|
+
user ids from the logs being searched, and the audit file must not become a
|
|
269
|
+
second copy of that. Set `PLATFORM_MCP_AUDIT_LOG` to another path, or to `off`.
|
|
270
|
+
|
|
271
|
+
Diagnostic logs go to **stderr** (`PLATFORM_MCP_LOG_LEVEL` to adjust); in stdio
|
|
272
|
+
transport stdout carries the protocol, so nothing else may be written there. In
|
|
273
|
+
Claude Code, read them with `claude --debug=mcp`.
|
|
274
|
+
|
|
275
|
+
For a record that does not depend on this server at all, enable **Data Access
|
|
276
|
+
audit logs** in GCP for the read-only service accounts. Token minting already
|
|
277
|
+
appears in Admin Activity logs without any configuration.
|
|
278
|
+
|
|
279
|
+
## Development
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
./.venv/bin/python -m pytest
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The suite runs entirely in-process against an in-memory MCP client — no
|
|
286
|
+
subprocess, no network, no GCP credentials — and covers environment resolution,
|
|
287
|
+
the tool contract, annotations, error translation and the audit log.
|
|
288
|
+
|
|
289
|
+
## Notes
|
|
290
|
+
|
|
291
|
+
- All tools cap result counts and truncate long payloads to stay token-friendly.
|
|
292
|
+
- GCP clients are built lazily and cached per environment, so switching between
|
|
293
|
+
staging and production mid-conversation costs one client construction each.
|
|
294
|
+
- Cost recommenders are zonal/regional; `list_cost_recommendations` auto-discovers
|
|
295
|
+
the locations where you have resources (via Asset Inventory) and fans out,
|
|
296
|
+
skipping locations and recommenders that are empty or unavailable. It reports
|
|
297
|
+
`skipped_calls` and fails loudly if it cannot discover any location, because
|
|
298
|
+
"I could not look" and "there is nothing to save" must not look alike.
|
|
299
|
+
- `get_cost_breakdown` uses parameterized BigQuery queries with a whitelisted set
|
|
300
|
+
of group-by columns, and filters to the selected environment's project. A
|
|
301
|
+
billing export covers the whole billing account, so pass `all_projects=true`
|
|
302
|
+
when you want account-wide totals.
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
[MIT](LICENSE) © 2026 Dimuthu Wickramanayake
|