git clone https://github.com/mulesoft/pdk-custom-policy-examples.git
Custom Policy Examples
Flex Gateway Policy Development Kit (PDK) provides example policy projects to help you start configuring your Rust source code.
You can find all example policies and their documentation in the PDK Custom Policy GitHub Repository.
API Policy Examples
PDK includes the following API example policies:
-
Block Policy Example: Use the Block Policy as an example of how to block IP ranges by implementing periodic functions and HTTP calls.
-
Certification Policy Example: Use the Certification Policy as an example of how to obtain data concerning connection certificates.
-
CORS Validation Policy Example: Use the CORS Validation Policy as an example of how to use functions of the CORS Library in your custom policy.
-
Crypto Policy Example: Use the Crypto Policy as an example of how to use third-party libraries that provide cryptography capabilities in your custom policy.
-
Data Caching Policy Example: Use the Data Caching Policy as an example of how to implement data caching in your custom policy.
-
Data Storage Stats Policy Example: Use the Data Storage Stats Policy as an example of how to implement data storage with both local (in-memory) and shared (Redis) data storage.
-
DataWeave Policy Example: Use the DataWeave Policy as an example of how to handle custom DataWeave expressions in your custom policy.
-
IP Filter Policy Example: Use the IP Filter Policy as an example of how to extract client IPs from request headers and implement IP-based access control using PDK’s IP Filter feature.
-
JSON Validation Policy Example: Use the JSON Validation Policy as an example of how to enforce JSON payload limits with the JSON Validator library.
-
JWT Generation Policy Example: Use the JWT Generation Policy as an example of how to generate JWT tokens using the JWT generation function.
-
JWT Validation Policy Example: Use the JWT Validation Policy as an example of how to use functions of the JWT Library in your custom policy.
-
Metrics Policy Example: Use the Metrics Policy as an example of how to periodically send data to a metric ingestion service by implementing periodic functions and HTTP calls.
-
OAuth 2.0 Token Introspection Policy Example: Use the OAuth 2.0 Token Introspection Policy as an example of how to use Token Introspection in your custom policy.
-
Query Policy Example: Use the Query Policy as an example of how to handle query parameters in your custom policy.
-
Simple OAuth 2.0 Validation Policy Example: Use the Simple OAuth 2.0 Validation Policy as an example of how to implement HTTP calls in your custom policy.
-
Spike Policy Example: Use the Spike Policy as an example of how to implement spike arrest with the Spike Control library and periodic ticking with Timer functions.
-
Stream Payload Policy Example: Use the Stream Payload Policy as an example of how to read payload bodies larger than 1MB.
-
TLS Calls Policy Example: Use the TLS Calls Policy as an example of how to make HTTPS calls in your policy without installing certificates on the operating system running Flex Gateway.
-
XML Validation Policy Example: Use the XML Validation Policy as an example of how to enforce XML payload limits with the XML Validator library.
A2A and MCP Server Policy Examples
PDK includes the following A2A and MCP example policies:
-
A2A PII Detector Policy Example: Demonstrates how to log or block sensitive information in A2A agent interactions.
-
A2A Prompt Decorator Policy Example: Shows how to modify prompts sent to an A2A agent.
-
A2A Support Policy Example: Demonstrates how to add A2A support.
-
MCP Support Policy Example: Shows how to add MCP support.
Set Up an Example Policy Project
To use an example policy project:
-
Make sure you have installed all PDK prerequisites.
-
Clone the PDK Custom Policy GitHub Repository using the following command or your preferred GitHub interface:
-
Navigate to the newly cloned directory, then copy and paste the directory of your desired policy into a new location.
-
In the
cargo.tomlfile of the copied policy example, replace thegroup-idwith your group ID, for example:group_id = "<your-group-id>" -
Run the
make setupcommand:make setup -
Navigate to the
README.mdfile in the example policy to read more about the policy and how to test it.



