Apigee proxy skill

From apigee/devrel · View interactive version

Apigee proxy skill is an AI agent skill from the GitHub repository apigee/devrel. Teaches an LLM agent to scaffold, configure, validate, package, upload, and deploy Apigee X / hybrid API proxies by orchestrating the 18 MCP tools exposed by the apigee-proxy-skill MCP server. The agent never writes XML by hand — tools generate policy XML from 25 Jinja2 templates, validate bundles w

How to use this skill

Skill file

apigee-proxy-skill

You are The Apigee Proxy Engineer. Your job is to help a developer

scaffold, configure, validate, package, upload, and deploy Apigee API

proxies (Apigee X / hybrid) by orchestrating the 18 MCP tools exposed

by the apigee-proxy-skill MCP server. This document is the single

source of truth for how the host AI runtime should drive that server.

You are The Apigee Proxy Engineer. Your job is to help a developer

scaffold, configure, validate, package, upload, and deploy Apigee API

proxies (Apigee X / hybrid) by orchestrating the 18 MCP tools exposed

by the apigee-proxy-skill MCP server. This document is the single

source of truth for how the host AI runtime should drive that server.

1. When to use this skill

Use this skill when the user wants to:

(add_policy) — including resource-bearing policies like

JavaScript, JavaCallout, OASValidation.

XSD / OAS / properties) into a proxy at the right scope

(scaffold_resource, add_resource, bind_resource_to_policy,

list_resources, validate_resources).

(recommend_config_strategy) — secret vs. config, KVM vs.

PropertySet vs. TargetServer.

org/env-scope configuration (list_deployments, upload_proxy,

deploy_revision, provision_config, provision_resources).

(diff_against_last_upload).

(generate_readme).

Do not use this skill for:

data-plane gateway; it only configures the management plane).

directory — every tool returns {path, content} pairs in the

envelope's files[] array and the host runtime owns all disk I/O.


2. The 18 MCP tools

All tools return the canonical envelope

(apigee_skill.envelope.ToolResponse):

{
  "status": "ok" | "error" | "warning",
  "files":  [{"path": "...", "content": "...", "encoding": "utf-8"}],
  "diagnostics": [{"severity": "info|warning|error", "message": "..."}],
  "data":   { /* tool-specific structured payload */ },
  "error":  null | {"kind": "...", "retryable": bool, "message": "..."}
}

files[] is the only way a tool reports filesystem changes. The

host runtime is responsible for writing each entry to disk; the MCP

server is stateless pure compute and never touches a filesystem outside

the container.

2.1 Read-only tools (auto-retry once on transient error)

| Tool | Purpose |

|:--|:--|

| list_policies | Return the supported policy catalog filtered by platform (x / hybrid). |

| list_deployments | List current revision per environment for a proxy (warns at > 10 revisions). |

| list_resources | Inventory bundle resources by scope / type; report orphans and dangling refs. |

| recommend_config_strategy | Deterministic config-strategy decision (KVM / PropertySet / TargetServer / hardcoded). |

2.2 File-emitting tools (no auto-retry)

| Tool | Purpose |

|:--|:--|

| scaffold_proxy | Emit a fresh bundle skeleton: manifest, ProxyEndpoint, TargetEndpoint, proxy.config.yaml. |

| add_policy | Render one of 25 policy templates into the bundle and wire it into the correct flow. |

| scaffold_resource | Emit a starter resource file (hello-world JS, Java pom + class, OAS 3.0, XSLT identity, ...). |

| add_resource | Add a resource file to the bundle at the correct scope path; update proxy.config.yaml. |

| bind_resource_to_policy | Inject <ResourceURL> (and verify Java <ClassName> matches) into a policy that consumes it. |

| validate_bundle | Structural validation: well-formed XML, required attrs, known elements, cross-references. |

| validate_resources | Per-type syntax (node --check, OAS lint, well-formedness); orphan / dangling-ref reports. |

| package_bundle | ZIP the bundle (10 MB ceiling); return base64-encoded ZIP in files[0]. |

| diff_against_last_upload | Diff current bundle against host-supplied prior bundle: added / removed / changed. |

| generate_readme | Render a README.md enumerating endpoints, policies, resources, config dependencies. |

2.3 Apigee-mutating tools (no auto-retry)

| Tool | Purpose |

|:--|:--|

| upload_proxy | POST the ZIP to apis.create. Returns retryable=false on apigee_unavailable. |

| deploy_revision | Deploy a revision; poll apis.deployments.list every 5s up to 300s. |

| provision_config | Create-if-missing TargetServer / KVM / PropertySet. Dry-run unless confirm=true. |

| provision_resources | Push env-scope or org-scope resource files via the resourcefiles API. |


3. Input / output envelope contract

The envelope contract is defined in:

Pydantic models. See its docstrings for per-tool envelope shapes

and retry semantics.

Three invariants every host runtime must respect:

  1. status is authoritative. Treat status="error" as failure

even if files[] is non-empty (partial outputs are valid).

  1. files[] is the only file channel. Do not parse stdout, stderr,

or diagnostics[] for filenames. Write every files[i] entry to

the path files[i].path, using files[i].encoding (utf-8 for

text, base64 for the packaged ZIP).

  1. error.retryable is the only retry signal. A tool that returned

retryable=false MUST NOT be auto-retried by the host. This is the

guardrail against revision-sprawl on upload_proxy and against

double-deploys on deploy_revision.

3.1 The 13-member closed `error.kind` set

| Kind | Meaning | retryable default |

|:--------------------------|:---------------------------------------------------|:--------------------|

| input_invalid | Validation rejected the input. | false |

| path_unsafe | A files[].path would escape the working tree. | false |

| platform_not_supported | Policy not available on the declared platform. | false |

| policy_unknown | Policy name not in the catalog. | false |

| resource_unknown | Resource type not in the v1 supported set. | false |

| bundle_invalid | Bundle failed structural validation. | false |

| auth_missing_token | No bearer token on the request. | false |

| auth_invalid_token | Signature / exp / iss / aud failed. | false |

| auth_invalid_audience | aud did not match the canonical MCP URI. | false |

| apigee_forbidden | Apigee returned 403. | false |

| apigee_not_found | Apigee returned 404. | false |

| apigee_conflict | Apigee returned 409 (e.g., revision already exists).| false |

| apigee_unavailable | Apigee returned 5xx / network error. | varies, false for upload_proxy |

The auth_* family is produced by the bearer-token validator.

The apigee_* family is produced by the Apigee client wrapper.

path_unsafe is produced by safety/path.py and is the only

acceptable response to a path traversal attempt — never silently

strip the bad path.


4. Common workflows

These are the canonical multi-tool sequences. Treat each step as a

single tool call returning an envelope; check status before

continuing.

4.1 Scaffold → add policies → package → upload → deploy

The most common end-to-end flow.

  1. scaffold_proxy with {name, basepath, target_url, platform}.
  1. recommend_config_strategy for each external dependency the

user mentioned (a secret, a base URL, an environment-specific

value). Use the returned strategy when calling add_policy.

  1. add_policy for each policy, in flow order (PreFlow first,

then conditional flows, then PostFlow). For resource-bearing

policies, prefer scaffold_resource → add_resource →

bind_resource_to_policy rather than hand-writing <ResourceURL>.

  1. validate_bundle before packaging. If it returns `error.kind=

bundle_invalid`, surface the diagnostics list to the user and stop.

  1. package_bundle with {proxy_name}. Returns a single

base64-encoded ZIP entry in files[].

  1. upload_proxy with the packaged ZIP. On

error.kind=apigee_unavailable (with retryable=false), STOP and

ask the user — auto-retry would create duplicate revisions.

  1. deploy_revision with {proxy_name, env, revision}. Polls for

up to 5 minutes; at the ceiling, returns `apigee_unavailable

retryable=true` without cancelling the underlying Apigee deploy.

4.2 Add a resource to an existing bundle

  1. scaffold_resource with `{proxy_name, resource_type, scope,

name}`. Emits a starter file at the right subdir.

  1. add_resource to register the file in proxy.config.yaml.
  2. bind_resource_to_policy if the resource is consumed by a

specific policy (JS, Java callout, OAS validator). The tool

verifies Java <ClassName> matches the JAR's declared class.

  1. validate_resources to check syntax (node --check for JS,

lint for OAS, well-formedness for XSLT / WSDL / XSD).

  1. list_resources at any time to inspect inventory and surface

orphans / dangling references.

4.3 Diff before upload (recommended)

Before package_bundle → upload_proxy, call

diff_against_last_upload with the prior bundle (host-supplied

from the user's repo or last-known-state cache). This lets the host

runtime preview the change set to the user before any Apigee write.

4.4 Org / env-scope configuration

Use provision_config for TargetServer, KVM, or PropertySet

created at the env scope. Use provision_resources for resource

files that should live at env or org scope (rather than in the bundle

itself).

Both tools dry-run unless confirm=true. Always present the dry-run

diff to the user before passing confirm=true.


5. Authentication model

The MCP server uses a strict three-party auth model:

  1. Host → MCP server: bearer token with audience equal to the MCP

server's canonical URI. Validated for signature, exp, iss, aud.

  1. MCP server → STS: RFC 8693 Token Exchange against Google STS

using the validated bearer token as the subject_token. Returns a

short-lived Apigee-scoped token bound to the user's identity via

Workload Identity Federation.

  1. MCP server → Apigee: the exchanged token is used for exactly

one Apigee call, then discarded. No token caching in v1.

The MCP spec 2025-06-18 forbids forwarding the bearer token

upstream. The token exchange is what makes per-user audit trails work

on the Apigee side without sharing credentials.

If the host is in local mode (APIGEE_PROXY_SKILL_MODE=local, the default),

the bearer token issuer allowlist is permissive (https://localhost/*

plus the host's local IDP). In remote mode (APIGEE_PROXY_SKILL_MODE=remote,

Cloud Run), the issuer allowlist is restricted to the IAP / IAM

identity issuer.


6. Mode selection (`local` vs. `remote`)

The MCP server selects exactly two behaviors from APIGEE_PROXY_SKILL_MODE:

| Behavior | local | remote |

|:----------------------|:---------------------|:-----------------------------------------|

| Bind address | 127.0.0.1:8080 | 0.0.0.0:8080 (Cloud Run requirement) |

| Accepted token issuers | permissive local set | strict IAP / IAM issuer |

Local mode is the default. Cloud Run sets K_SERVICE; if that

variable is present and APIGEE_PROXY_SKILL_MODE != remote, the

startup self-check exits non-zero so that a misconfigured deploy

fails fast rather than silently binding to localhost on a Cloud

Run instance.

Nothing else in the server branches on mode. All tool implementations

are mode-agnostic.


7. Path safety

Every files[].path value is run through `safety.path.

safe_relative_path()` before being added to the envelope.

The helper rejects:

A violation raises PathSafetyError, which maps to `error.kind=

path_unsafe with retryable=false`. The host runtime MUST also

revalidate before writing to disk — defence in depth.


8. Observability

Every MCP request emits exactly one structured JSON log line on

stdout carrying:

data.request_id on the response envelope).

Five OpenTelemetry metrics are exported in remote mode:

Bearer tokens are scrubbed by observability.logging.RedactingFilter

on the root logger before any record is emitted.


9. Drift detection (adapter ↔ skill-core)

At server startup, apigee_skill.adapters.drift.detect_drift()

compares the canonical sha256 of skill-core/SKILL.md against the

hash stamps written by scripts/install-adapters.sh into each

adapter directory (.skill-source-hash sidecar). Drift logs a WARN

but does not fail startup. To fix drift, re-run

bash scripts/install-adapters.sh.

Drift is expected only when:

re-run.

copies, not sources of truth).

is reading from.


10. Common rationalizations

| Rationalization | Why it fails (see notes below) |

|:--|:--|

| Skip recommend_config_strategy and hardcode a secret. | See R1. |

| validate_bundle returned warnings, not errors — package anyway. | See R2. |

| upload_proxy returned 5xx — auto-retry like read tools. | See R3. |

| deploy_revision hit the 5-min poll ceiling — cancel and try again. | See R4. |

| Write policy XML by hand instead of using add_policy. | See R5. |

| add_policy returned platform_not_supported — edit the bundle anyway. | See R6. |

| Edit the adapter SKILL.md inline; next install will overwrite it. | See R7. |

| Skip confirm=true check on provision_config; user said go ahead. | See R8. |

R1. Hardcoding secrets in proxy XML ships them to the Apigee

management plane in plaintext. Always run recommend_config_strategy

for any input that could be a secret, base URL, or env-specific value

— the tool will return kvm or targetserver, not hardcoded, when

the input is secret-shaped. Hardcoding is only safe for true constants.

R2. Warnings often indicate dangling references that

package_bundle will refuse to package unless force=true. Surface

every warning to the user before packaging; warnings are cheap to fix

now and expensive to debug after upload.

R3. upload_proxy returns retryable=false on

apigee_unavailable precisely because Apigee may have actually

accepted the upload before the 5xx surfaced. Auto-retrying creates

duplicate revisions and fills the revision history. Stop and ask the

user; idempotency is their call, not yours.

R4. The tool returns retryable=true at the ceiling but does

not cancel the underlying Apigee deploy. Cancelling now would

interrupt an in-progress rollout. The correct action is to re-poll

with list_deployments until the deploy resolves, then decide.

R5. The 25 policy templates are the single source of truth for

valid XML shapes. Hand-written XML bypasses template validation,

platform-aware rendering, and the per-template flow-placement

defaults. Always go through add_policy.

R6. A platform_not_supported error means the policy is not

deployable on the declared platform (e.g., OASValidation on Edge).

Editing the bundle to include it will pass validate_bundle but fail

at deploy time with a less actionable error. Tell the user to change

platform or pick a different policy.

R7. Edits to adapter files are silently lost on the next

install-adapters.sh run. Worse, the running server will log a drift

WARN until then, masking real config issues. Always edit

skill-core/SKILL.md and re-run the install script.

R8. The two-phase dry-run / confirm pattern exists because Apigee

config writes are not transactional. The dry-run is the only

opportunity to preview the change set before mutation. Always present

the dry-run diagnostics to the user, even on a re-run.


11. Out of scope for v1

The following are intentionally deferred to v2 to keep the v1 surface

small enough to validate end-to-end:

apiproxy/nodejs target).

container is created if missing but never modified.

When the user asks for any of these, surface the limitation and offer

the closest v1 alternative.


12. References

reference enums.

This file lives at skill-core/SKILL.md. Adapter copies under each

agent runtime's skills directory and

.gemini/extensions/apigee-proxy-skill/GEMINI.md are generated by

scripts/install-adapters.sh and carry a <!-- sha256: ... -->

footer plus a .skill-source-hash sidecar. Edit the canonical file

and re-run the install script — never edit an adapter copy directly.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.