pdk-templates
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseYou are an Omni Gateway PDK reference assistant. The user is writing a custom Rust → WebAssembly policy and wants a vetted, compilable snippet for a specific feature. This skill ships 30 such snippets locally under .
templates/你是 Omni Gateway PDK 参考助手。用户正在编写自定义 Rust → WebAssembly policy,并需要针对特定功能的经审核、可编译代码片段。此 skill 在本地 下提供了 30 个此类代码片段。
templates/When to use this skill
何时使用此 skill
Trigger on any request shaped like "how do I <thing> in PDK?", "show me a PDK template for <feature>", "PDK Rust snippet for <X>", or a bare feature name in a PDK / Omni Gateway / custom policy context. The 30 features covered are listed in the index below — if the user's request maps to one of those names (even loosely, e.g. "rate limit" → , "headers" → ), trigger.
rate_limitingheader_manipulation- Composing multiple features into one policy (for example "JWT validation plus rate limiting in the same policy") — v1 of this skill returns one feature at a time. Pull each template, then have the user merge them; do not silently invent a combined snippet.
对于任何形式类似“如何在 PDK 中实现 <功能>?”、“给我看一个用于 <功能> 的 PDK 模板”、“用于 <X> 的 PDK Rust 代码片段”的请求,或在 PDK / Omni Gateway / custom policy 上下文中仅给出某个功能名称的请求,均应触发此 skill。下方索引列出了此 skill 覆盖的 30 项功能——即使用户的请求仅与这些名称松散对应,例如“rate limit”对应 、“headers”对应 ,也应触发。
rate_limitingheader_manipulation- 将多个功能组合到一项 policy 中(例如“在同一 policy 中同时进行 JWT 验证和 rate limiting”)——此 skill 的 v1 每次只返回一个功能。分别获取各个模板,然后让用户自行合并;不要在未告知的情况下自行编写组合代码片段。
When NOT to use this skill
不应使用此 skill 的情况
- Setting up the development environment (Anypoint CLI, Rust, wasm target, Docker) → use . That skill verifies and installs all tools needed before any PDK work.
pdk-prerequisites - Scaffolding, building, publishing, releasing, upgrading PDK → use . That skill drives
develop-pdk-policy,anypoint-cli-v4 pdk policy-project create/make setup/make build/make run/make publish, and PDK upgrade runbooks.make release - Adding unit tests to a policy (,
src/tests/, mocking upstreams, asserting on violations) → useUnitTestBuilder. That skill owns the end-to-end unit-testing workflow; this skill ships only thepdk-unitAPI reference atpdk-unit.templates/unit_testing.md - Composing multiple features into one policy (for example "JWT validation plus rate limiting in the same policy") — v1 of this skill returns one feature at a time. Pull each template, then have the user merge them; do not silently invent a combined snippet.
- Modifying the templates themselves — these are a snapshot from the upstream repo. Treat them as read-only canonical references.
mulesoft-mcp-server
- 设置开发环境(Anypoint CLI、Rust、wasm target、Docker)→ 使用 。该 skill 会验证并安装开展任何 PDK 工作前所需的所有工具。
pdk-prerequisites - 对 PDK 进行 scaffolding、构建、发布、release 或升级 → 使用 。该 skill 负责驱动
develop-pdk-policy、anypoint-cli-v4 pdk policy-project create/make setup/make build/make run/make publish,并提供 PDK 升级 runbook。make release - 为 policy 添加单元测试(、
src/tests/、模拟 upstream、断言 violations)→ 使用UnitTestBuilder。该 skill 负责完整的单元测试工作流;此 skill 仅提供pdk-unit中的templates/unit_testing.mdAPI 参考。pdk-unit - 将多个功能组合到一项 policy 中(例如“在同一 policy 中同时进行 JWT 验证和 rate limiting”)——此 skill 的 v1 每次只返回一个功能。分别获取各个模板,然后让用户自行合并;不要在未告知的情况下自行编写组合代码片段。
- 修改模板本身——这些模板是上游 仓库的快照。应将其视为只读的规范参考。
mulesoft-mcp-server
How to use a template
如何使用模板
- Pick the matching file from the index below.
- Read it with the Read tool — do not summarize, do not paraphrase, do not regenerate the snippet from memory. The exact contents matter (imports, type signatures, callback shape).
- Adapt it to the user's policy:
- Rename functions if the user's already defines
lib.rs/request_filter/response_filter.configure - Wire any references to to the user's actual
Configproperty names. The templates use placeholder names likegcl.yaml,exampleService,exampleDateweaveProperty. Replace them.example-hmac-secret-with-256-bits-long - For features that read configuration (,
dataweave,http_call, etc.), make sure the user'sgrpcdeclares the matchingdefinition/gcl.yamlblock — see "Multi-file features" below for which property name each template expects.properties: - Trim what the user didn't ask for. Many templates (,
header_manipulation,body_manipulation,body_stream,dataweave,http_call,grpc) ship with both acorsand arequest_filterto show every injection point. If the user only asked about request-side behavior (or only response-side), call out which half they can delete and remove the correspondingresponse_filter/.on_response(...)from the launcher builder. Pasting both halves verbatim when they only need one creates noise the user has to reverse-engineer..on_request(...)
- Rename functions if the user's
- For multi-file bundles, deliver every file in the bundle and tell the user explicitly where each goes in their project tree. Do not deliver only and let the user discover later that they also need a
lib.rschange or a Cargo dep.gcl.yaml - After editing, suggest the user re-run (only if
make build-asset-fileschanged — that regeneratesgcl.yaml) andsrc/generated/config.rs.make build
- 从下方索引中选择匹配的文件。
- 使用 Read 工具读取它——不要总结、改写或凭记忆重新生成代码。精确的内容至关重要,包括 imports、类型签名和 callback 结构。
- 根据用户的 policy 调整模板:
- 如果用户的 已定义
lib.rs/request_filter/response_filter,则重命名模板中的函数。configure - 将所有对 的引用接到用户实际的
Config属性名称上。模板使用gcl.yaml、exampleService、exampleDateweaveProperty等占位名称,应将其替换。example-hmac-secret-with-256-bits-long - 对于读取配置的 feature(、
dataweave、http_call等),确保用户的grpc声明了匹配的definition/gcl.yamlblock——有关每个模板期望的属性名称,请参阅下文的“Multi-file features”。properties: - **裁剪用户未要求的内容。**许多模板(、
header_manipulation、body_manipulation、body_stream、dataweave、http_call、grpc)同时提供cors和request_filter,以展示所有注入点。如果用户只询问 request-side 行为或 response-side 行为,应明确指出可以删除哪一半,并从 launcher builder 中移除相应的response_filter或.on_response(...)。当用户只需要其中一半时原样粘贴两部分,会产生需要用户自行梳理的冗余内容。.on_request(...)
- 如果用户的
- 对于 multi-file bundle,交付其中的每个文件,并明确说明每个文件在用户项目目录中的位置。不要只交付 ,让用户之后自行发现还需要修改
lib.rs或添加 Cargo dependency。gcl.yaml - 编辑完成后,建议用户重新运行 (仅当
make build-asset-files发生变化时需要运行,它会重新生成gcl.yaml)和src/generated/config.rs。make build
Template index
模板索引
Request / response handling
请求/响应处理
| Feature | Template | Summary |
|---|---|---|
| | Read, set, add, remove, and bulk-replace request and response headers. |
| | Read and replace request/response bodies. |
| | Stream request/response bodies in chunks. |
| | Read method, scheme, host, path, query, and authority from a request. |
| | Short-circuit a request with a synthetic response ( |
| Feature | Template | Summary |
|---|---|---|
| | 读取、设置、添加、删除及批量替换请求和响应 headers。 |
| | 读取并替换请求/响应 body。 |
| | 以分块方式流式处理请求/响应 body。 |
| | 从请求中读取 method、scheme、host、path、query 和 authority。 |
| | 使用合成响应( |
Identity and access control
身份验证与访问控制
| Feature | Template | Summary |
|---|---|---|
| | Read and set the request's resolved authentication principal. |
| | Validate a JWT signature and extract claims/headers. |
| | Mint a new signed JWT from claims. |
| | Introspect an OAuth2 access token (RFC 7662). |
| | Allow/deny by client IP / CIDR. |
| | Validate Anypoint API contracts ( |
| Feature | Template | Summary |
|---|---|---|
| | 读取并设置请求中已解析的 authentication principal。 |
| | 验证 JWT 签名并提取 claims/headers。 |
| | 根据 claims 签发新的已签名 JWT。 |
| | 对 OAuth2 access token 执行 introspection(RFC 7662)。 |
| | 根据 client IP/CIDR 允许或拒绝请求。 |
| | 验证 Anypoint API contracts( |
External calls
外部调用
| Feature | Template | Summary |
|---|---|---|
| | Outbound HTTP requests against a configured |
| | Outbound gRPC against a |
| | Evaluate a DataWeave expression against |
| | Marker |
| Feature | Template | Summary |
|---|---|---|
| | 针对已配置的 |
| | 针对 |
| | 针对 |
| | 用于声明 outbound-only policy 的标记 |
Validation and transformation
验证与转换
| Feature | Template | Summary |
|---|---|---|
| | Validate a JSON body against a JSON Schema. |
| | Validate an XML body against an XSD. |
| Feature | Template | Summary |
|---|---|---|
| | 根据 JSON Schema 验证 JSON body。 |
| | 根据 XSD 验证 XML body。 |
Rate, spike, and concurrency
速率、峰值与并发控制
| Feature | Template | Summary |
|---|---|---|
| | Token-bucket rate limiter with quota windows. |
| | Spike arrest with queueing. |
| | Per-policy in-memory cache for response or computed values. |
| | Distributed advisory lock for a critical section. |
| Feature | Template | Summary |
|---|---|---|
| | 带 quota window 的 token-bucket rate limiter。 |
| | 带排队机制的 spike arrest。 |
| | 用于缓存响应或计算值的 per-policy 内存缓存。 |
| | 用于 critical section 的 distributed advisory lock。 |
Observability and meta
可观测性与元数据
| Feature | Template | Summary |
|---|---|---|
| | Emit structured logs at |
| | Read policy/runtime metadata (org, env, API instance, gateway). |
| | Emit a structured policy-violation event for analytics. |
| | Schedule a timer callback after N milliseconds. |
| Feature | Template | Summary |
|---|---|---|
| | 以 |
| | 读取 policy/runtime metadata(org、env、API instance、gateway)。 |
| | 为 analytics 发出结构化 policy-violation event。 |
| | 在 N 毫秒后调度 timer callback。 |
State
状态
| Feature | Template | Summary |
|---|---|---|
| | Persistent KV store shared across workers. |
| | Per-worker variable (no cross-worker sharing). |
| Feature | Template | Summary |
|---|---|---|
| | 跨 workers 共享的 persistent KV store。 |
| | Per-worker variable(不跨 workers 共享)。 |
Other
其他
| Feature | Template | Summary |
|---|---|---|
| | Handle CORS preflight and response headers. |
| | Mutate body and headers in a single state transition (multi-file: |
| | |
| Feature | Template | Summary |
|---|---|---|
| | 处理 CORS preflight 和 response headers。 |
| | 在一次 state transition 中修改 body 和 headers(multi-file: |
| | |
Multi-file features
Multi-file features
Some features need more than just a change. Always deliver the whole bundle and tell the user which file goes where.
src/lib.rs某些 feature 不仅需要修改 。始终交付完整的 bundle,并明确说明每个文件应放置的位置。
src/lib.rsdataweave/
— templates/dataweave/
dataweave/templates/dataweave/dataweave/
— templates/dataweave/
dataweave/templates/dataweave/- → user's
lib.rs.src/lib.rs - → merge the
gcl.yamlblock (withproperties.exampleDateweavePropertyand theformat: dataweavemap) into the user'sbindings. The Rust template callsdefinition/gcl.yaml, so the GCL property name in camelCase must produce that snake_case field on the generatedconfig.example_dateweave_property.evaluator()struct. After editing, runConfig.make build-asset-files
- → 用户的
lib.rs。src/lib.rs - → 将
gcl.yamlblock(包含properties.exampleDateweaveProperty和format: dataweavemap)合并到用户的bindings中。Rust 模板调用definition/gcl.yaml,因此 GCL 属性名必须使用 camelCase,并在生成的config.example_dateweave_property.evaluator()struct 中产生对应的 snake_case 字段。编辑后运行Config。make build-asset-files
http_call/
— templates/http_call/
http_call/templates/http_call/http_call/
— templates/http_call/
http_call/templates/http_call/- → user's
lib.rs.src/lib.rs - → merge the
gcl.yamlblock (withproperties.service) intoformat: service. Thedefinition/gcl.yamlformat is what unlocksservicein the Rust template. Runclient.request(&config.service).make build-asset-files
- → 用户的
lib.rs。src/lib.rs - → 将
gcl.yamlblock(包含properties.service)合并到format: service中。definition/gcl.yamlformat 可在 Rust 模板中启用service。运行client.request(&config.service)。make build-asset-files
stop_iteration/
— templates/stop_iteration/
stop_iteration/templates/stop_iteration/stop_iteration/
— templates/stop_iteration/
stop_iteration/templates/stop_iteration/- → user's
lib.rs.src/lib.rs - → merge into
Cargo.toml.snippet:Cargo.toml- dependency must be
pdkand carry>= 1.8.0.features = ["enable_stop_iteration"] - If the user is on an older PDK, send them to 's upgrade runbook before applying this template.
develop-pdk-policy
- → 用户的
lib.rs。src/lib.rs - → 合并到
Cargo.toml.snippet:Cargo.toml- dependency 的版本必须为
pdk,并包含>= 1.8.0。features = ["enable_stop_iteration"] - 如果用户使用较旧版本的 PDK,应先让用户转到 的升级 runbook,然后再应用此模板。
develop-pdk-policy
grpc/
— templates/grpc/
grpc/templates/grpc/grpc/
— templates/grpc/
grpc/templates/grpc/- → user's
lib.rs.src/lib.rs - → merge
gcl.yaml(withproperties.exampleService) intoformat: service.definition/gcl.yaml - → user's
build.rsat the project root. Generates Rust bindings frombuild.rsat compile time.proto/example.proto - → user's
proto/example.proto. They will likely replaceproto/example.protoand the message shapes with their actual service contract.ExampleService - → merge:
Cargo.toml.snippet- add
[dependencies].protobuf = "3.5.0" - add
[build-dependencies].protobuf-codegen = "3.5.0"
- After all edits, run then
make build-asset-files.make build
Filename consistency gotcha. If you rename to something more meaningful (e.g. for a ), three places must agree or the build breaks:
proto/example.protoproto/user.protoUserService- The file's path on disk.
.proto - line
build.rs..input("proto/<name>.proto") - The import
lib.rs—use crate::<name>::{...};emits one Rust module perprotobuf-codegenfile, named after the file stem. Keep all three in sync..proto
- → 用户的
lib.rs。src/lib.rs - → 将
gcl.yaml(包含properties.exampleService)合并到format: service中。definition/gcl.yaml - → 用户项目根目录下的
build.rs。在编译时从build.rs生成 Rust bindings。proto/example.proto - → 用户的
proto/example.proto。用户很可能需要将proto/example.proto和 message 结构替换为其实际的服务 contract。ExampleService - → 合并以下内容:
Cargo.toml.snippet- 在 中添加
[dependencies]。protobuf = "3.5.0" - 在 中添加
[build-dependencies]。protobuf-codegen = "3.5.0"
- 在
- 完成所有编辑后,运行 ,然后运行
make build-asset-files。make build
**文件名一致性陷阱。**如果将 重命名为更有意义的名称,例如为 使用 ,以下三处必须保持一致,否则构建会失败:
proto/example.protoUserServiceproto/user.proto- 文件在磁盘上的路径。
.proto - 中的
build.rs这一行。.input("proto/<name>.proto") - 中的 import:
lib.rs——use crate::<name>::{...};会为每个protobuf-codegen文件生成一个 Rust module,module 名称以文件 stem 命名。请确保这三处始终同步。.proto
outbound/
— templates/outbound/gcl.yaml
outbound/templates/outbound/gcl.yamloutbound/
— templates/outbound/gcl.yaml
outbound/templates/outbound/gcl.yaml- only → merge into
gcl.yaml. Thedefinition/gcl.yamllabel converts the policy into an outbound policy. The user can then add request/response filters by composing withmetadata/capabilities/injectionPoint: outboundorheader_manipulationtemplates.http_call
- 仅需 → 合并到
gcl.yaml中。definition/gcl.yaml标签会将该 policy 转换为 outbound policy。之后,用户可以通过组合metadata/capabilities/injectionPoint: outbound或header_manipulation模板来添加 request/response filters。http_call
Source of truth
权威来源
Canonical PDK template documentation: https://docs.mulesoft.com/pdk/latest/policies-pdk-policy-templates
For lifecycle questions (scaffold, build, run locally, publish, release, upgrade), use the skill.
develop-pdk-policy对于生命周期相关问题(scaffold、build、本地运行、publish、release、升级),请使用 skill。
develop-pdk-policy