Protocol Interaction Description Language - A JSON-based DSL for describing protocol choreography that compiles to diagrams.
PIDL models protocols as directed interaction graphs between entities, enabling generation of sequence diagrams, data flow diagrams, and other visualizations. It's designed for protocols where the primary concern is "who talks to whom, in what order" rather than message schemas or transport details.
- 📋 JSON-based DSL for describing protocol flows
- 🎨 Multiple output formats: PlantUML, Mermaid, Graphviz DOT, D2
- 📚 Built-in examples: OAuth 2.0, PKCE, OIDC, MCP, A2A
- ⌨️ CLI tool for validation and diagram generation
- 📦 Go library for programmatic use
- 🔀 Conditional flows with
conditionfield for when clauses - 🔄 Alternative paths with
alternativesfor error handling and branching - 📝 Annotations with typed notes (security, performance, deprecated, etc.)
- 📊 Nested phases with parent hierarchy support
go install github.com/grokify/pidl/cmd/pidl@latestOr clone and build:
git clone https://github.com/grokify/pidl.git
cd pidl
go build -o pidl ./cmd/pidlpidl examples# PlantUML sequence diagram
pidl generate oauth2_authorization_code
# Mermaid sequence diagram
pidl generate -f mermaid oauth2_pkce
# Graphviz DOT data flow diagram
pidl generate -f dot mcp_tool_invocation
# D2 sequence diagram
pidl generate -f d2 oauth2_pkce
# D2 data flow diagram
pidl generate -f d2-flow oauth2_pkce
# D2 architecture diagram
pidl generate -f d2-arch oauth2_pkce# Create from scratch
pidl init my-protocol.json
# Copy from an example
pidl init -from oauth2_authorization_code my-oauth.jsonpidl validate my-protocol.json
pidl validate *.jsonA PIDL document is a JSON file with three main sections:
{
"protocol": {
"id": "my-protocol",
"name": "My Protocol",
"version": "1.0",
"description": "A sample protocol",
"category": "auth"
},
"entities": [
{"id": "client", "name": "Client", "type": "client"},
{"id": "server", "name": "Server", "type": "server"}
],
"phases": [
{"id": "main", "name": "Main Flow"},
{"id": "error_handling", "name": "Error Handling", "parent": "main"}
],
"flows": [
{
"from": "client",
"to": "server",
"action": "request",
"label": "Request",
"mode": "request",
"phase": "main",
"condition": "token_valid",
"note": "Requires valid token",
"annotations": [
{"type": "security", "text": "Validate token signature"}
],
"alternatives": [
{
"condition": "token_expired",
"flows": [
{"from": "server", "to": "client", "action": "refresh_required", "mode": "response"}
]
}
]
},
{"from": "server", "to": "client", "action": "response", "label": "Response", "mode": "response", "phase": "main"}
]
}| Type | Description |
|---|---|
client |
Application or service initiating requests |
authorization_server |
Issues tokens and handles authentication |
resource_server |
Hosts protected resources |
user |
Human actor |
browser |
User agent / web browser |
agent |
AI/LLM agent |
tool_server |
Exposes tools via protocol (MCP) |
delegated_agent |
Agent receiving delegated tasks (A2A) |
| Mode | Description | Arrow Style |
|---|---|---|
request |
Synchronous request | Solid -> |
response |
Synchronous response | Dashed --> |
redirect |
HTTP redirect | Solid with annotation |
callback |
Callback/webhook | Solid with annotation |
interactive |
Human interaction | Solid |
event |
Asynchronous event | Dashed |
tool_call |
Tool invocation (MCP) | Solid with annotation |
tool_result |
Tool result (MCP) | Dashed with annotation |
| Field | Description |
|---|---|
condition |
Conditional execution clause (renders as opt block) |
note |
Visible note displayed on diagram |
annotations |
Array of typed annotations for tooling |
alternatives |
Alternative paths (renders as alt/else blocks) |
| Type | Description |
|---|---|
security |
Security-related notes |
performance |
Performance considerations |
deprecated |
Deprecated functionality |
info |
General information |
warning |
Warning messages |
error |
Error conditions |
Phases support hierarchical nesting via the parent field:
{
"phases": [
{"id": "auth", "name": "Authentication"},
{"id": "mfa", "name": "Multi-Factor Auth", "parent": "auth"},
{"id": "token", "name": "Token Exchange", "parent": "auth"}
]
}pidl <command> [options] [arguments]
Commands:
validate Validate PIDL JSON files
generate Generate diagrams from PIDL files
examples List or show built-in examples
init Create a new PIDL file from template
version Print version information
help Show help message
pidl validate [options] <file> [file...]
Options:
-q Quiet mode (only show errors)pidl generate [options] <file>
Options:
-f string Output format: plantuml, mermaid, dot, d2, d2-flow, d2-arch (default "plantuml")
-o string Output file (default: stdout)D2 formats:
d2- Sequence diagramd2-flow- Data flow diagram with entity shapesd2-arch- Architecture diagram with entities grouped by type
pidl examples [options] [name]
Options:
-json Show example JSON contentpidl init [options] <filename>
Options:
-name string Protocol name
-from string Initialize from exampleimport (
"github.com/grokify/pidl"
"github.com/grokify/pidl/render"
"github.com/grokify/pidl/examples"
)
// Parse a PIDL file
p, err := pidl.ParseFile("protocol.json")
// Validate
if errs := p.Validate(); errs.HasErrors() {
log.Fatal(errs)
}
// Generate PlantUML
diagram, err := render.RenderString(render.FormatPlantUML, p)
// Use built-in examples
names := examples.List()
oauth, err := examples.GetProtocol("oauth2_authorization_code")
// Create a new protocol
p := pidl.NewMinimalProtocol("my-protocol", "My Protocol")
pidl.WriteProtocolFile("output.json", p)| Example | Protocol |
|---|---|
oauth2_authorization_code |
OAuth 2.0 Authorization Code Flow |
oauth2_pkce |
OAuth 2.0 with PKCE |
oidc_authentication |
OpenID Connect Authentication |
mcp_tool_invocation |
MCP Tool Invocation |
a2a_agent_delegation |
A2A Agent Delegation |
PIDL is designed for describing:
- Authentication/Authorization: OAuth 2.0, OpenID Connect, SAML
- Agent Protocols: MCP (Model Context Protocol), A2A (Agent-to-Agent)
- API Flows: Multi-party API choreography
- Specification - Full language specification
- JSON Schema - Schema for validation
MIT License - see LICENSE for details.