P4 — 132 Operations for AI Agents
P4 programs the network data plane itself — switches, parsers, match-action pipelines. act101 surfaces tables, actions, and headers as structure, so agents follow a packet's path through the pipeline definition.
This page is the canonical reference an AI coding agent uses to refactor, query, and analyze P4 code through the act MCP server. 132 operations available: 58 refactor, 18 query, 42 analysis, 14 verification. Each operation is callable from Claude Code, Cursor, Codex, OpenCode, or any MCP-compatible agent host. Click any operation for a stable anchor link suitable for citation.
Premium language. Operations on P4 require an Elite license or above. See pricing.
Query
18 query tools, the same on every supported language. Descriptions live in the shared reference: /docs/query-tools.
callers control_flow data_flow definition diagnostics effect_closure effect_summary fix_auto get_type graph import_organize interface mutations references repo_outline skeleton symbols symbols_batch
Refactor
| Operation | Description |
|---|---|
add-action |
Add an action reference to a P4 table's action list |
add-counter |
Add a counter instantiation inside a control and attach it to a table via the counters property |
add-default-action |
Add a default_action property to a P4 table |
add-extern-declaration |
Append a P4 extern_declaration with method_prototype(s) |
add-field |
Add a field to a P4 header or struct declaration |
add-meter |
Add a meter instantiation inside a control and attach it to a table via the meters property |
add-register |
Add a register array instantiation inside a control |
add-table-entry |
Insert a static entry into a P4 table's entries block |
add-table-key |
Add a match key to a P4 table's key list |
change-default-action |
Modify a P4 table's existing default_action property |
change-field-type |
Change a P4 header/struct field's type or bit width |
convert-header-union-to-headers |
Expand a P4 header_union back into separate header types |
convert-if-to-switch |
Convert a P4 if/else chain over a table-apply equality test into a switch_statement |
convert-switch-to-if |
Convert a P4 switch_statement on a table-apply expression back into an if/else chain |
convert-to-header-stack |
Convert a header-typed P4 struct field into a header stack array |
convert-to-header-union |
Convert a set of mutually-exclusive P4 header types into a header_union |
convert-to-match-kind-enum |
Convert a set of match-kind constants into a match_kind_declaration |
extract-apply-block |
Extract table-apply logic from a P4 control's apply block into a named sub-block |
extract-control-block |
Extract table-apply logic from a P4 control's apply block into a new control |
extract-header |
Extract a set of fields from a P4 header/struct into a new header type |
extract-parser-state |
Extract parsing logic from a P4 parser state into a new parser state with a transition |
extract_function |
Extract a code selection into a new function — automatically infers parameters, return types, and inserts the call site. Use instead of manually cutting/pasting code. Works without LSP; LSP improves type inference. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool), receipt (bool)] |
extract_variable |
Extract an expression into a named variable — inserts the declaration and replaces the expression with the variable name. Works without LSP. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool)] |
fix-action-parameter-count |
Correct an action's parameter count to match its invocation usages |
fix-missing-header-validity |
Wrap an unguarded header field access in an isValid() guard |
fix-missing-return |
Insert an exit;/return; after a statement where a path needs a terminator |
fix-parser-transition |
Correct an invalid parser transition_statement target to a real state |
fix-table-key-type |
Correct a table key element's match kind to a standard P4 match kind |
fix-undefined-header |
Add a header instantiation to a metadata struct where the header is referenced but not declared |
gen-action-definition |
Generate a P4 action with parameters and a body |
gen-checksum-verification |
Generate a P4 checksum verify/update control scaffold |
gen-clone-entry |
Generate a P4 clone/mirror session scaffold (session-id constant + control invoking the generic clone intrinsic) |
gen-control-block |
Generate a P4 control with an apply block that applies a table |
gen-counter-declaration |
Generate a P4 counter instantiation (direct or indirect) |
gen-deparser-scaffold |
Generate a P4 deparser control with a pkt.emit chain over the named headers |
gen-header-definition |
Generate a P4 header type with standard ethernet/IPv4/TCP-style fields |
gen-parser-state-machine |
Generate a P4 parser with a start state and a select_expression |
gen-struct-definition |
Generate a P4 metadata struct with typed fields |
gen-table-definition |
Generate a P4 table with keys, actions, and size |
inline |
Inline a variable, function, or method — replace every usage with its definition body, then remove the original. The inverse of extract. Works without LSP (single-file); LSP enables cross-file inlining. Params: file (string), symbol (string) [, line (u32), preview (bool), receipt (bool)] |
inline-header |
Inline a P4 header type into the single parent that references it |
insert_body |
Replace a function's implementation body with new code. AST-validated — rejects if the result has parse errors, so you can't accidentally break syntax. Use instead of manual text editing for function rewrites. Params: file (string), symbol (string), code (string) [, commit (bool)] |
merge-control-blocks |
Merge two P4 control blocks into one |
merge-parser-states |
Merge two sequential P4 parser states into one |
move_symbol |
Move a function, class, or type to a different file and automatically update all imports across the codebase. Use instead of manually cut/paste + fixing imports. Works without LSP (single-file); LSP enables cross-file import updates. Params: file (string), symbol (string), destination (string) [, preview (bool), receipt (bool)] |
recipe_run |
Run a codemod recipe: declarative match → transform → optional verify across modeled grammars. Preview lists matches; apply writes with optional E7 receipts and all-or-nothing rollback. Returns a per-site report. |
remove-action |
Remove an action reference from a P4 table's action list |
remove-extern |
Remove an unused P4 extern_declaration |
remove-field |
Remove an unused field from a P4 header or struct declaration |
remove-table-key |
Remove a match key from a P4 table's key list |
rename |
Rename a symbol and automatically update ALL references across the codebase. Safer and faster than find-and-replace — AST-aware, won't rename strings or comments. Works without LSP (single-file); LSP enables cross-file renames. Params: file (string), old_name (string), new_name (string) [, line (u32), column (u32), preview (bool), receipt (bool)] |
rename-action |
Rename a P4 action declaration and its table action-list references and invocations |
rename-field |
Rename a P4 header/struct field and all hdr.field access sites |
rename-header |
Rename a P4 header type and all type references / instantiations |
rename-parser-state |
Rename a P4 parser state and all transition / select targets |
rename-table |
Rename a P4 table declaration and all tbl.apply() call sites |
reorder-fields |
Reorder the fields of a P4 header or struct declaration |
reorder-table-keys |
Reorder the match keys of a P4 table's key list |
Analysis
42 analysis tools, the same on every supported language. Descriptions live in the shared reference: /docs/analysis-tools.
analyze_api_diff analyze_chokepoints analyze_clones analyze_clusters analyze_cohesion analyze_conformance analyze_coupling analyze_cycle_risk analyze_cycles analyze_dead_code analyze_depth analyze_entry_points analyze_export analyze_extraction analyze_fan_balance analyze_features analyze_hotspots analyze_impact analyze_inconsistencies analyze_inheritance analyze_interface_bloat analyze_interfaces analyze_layers analyze_orphan_types analyze_patterns analyze_platform_deps analyze_readiness analyze_roles analyze_seams analyze_stability analyze_surface analyze_test_gaps analyze_thickness analyze_type_completeness churn_hotspots co_change_clusters coverage_overlay ownership_map profile_overlay simulate split_module trace_overlay
Verify
14 verify tools, the same on every supported language. Descriptions live in the shared reference: /docs/verification.
bisect_regression gate generate_test_harness scan secret_surface summarize_pr taint_flow unsafe_surface verify_behavioral_equivalence verify_contract_preserved verify_diff_semantics verify_port_parity verify_side_effects verify_test_impact