Skip to main content
Glama
vespo92

OPNSense MCP Server

macro_play

Execute a saved macro on the OPNSense MCP Server to automate network tasks, configure firewall rules, or manage VLANs. Supports parameter substitution and dry-run mode for testing.

Instructions

Play a saved macro

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dryRunNoExecute in dry-run mode without making actual API calls
idYesMacro ID
parametersNoParameters to substitute in the macro

Implementation Reference

  • Core handler function that loads a macro by ID, substitutes parameters in its API calls, executes them sequentially via the OPNSense API client, supports dry-run mode, error handling options, and pre/post call hooks.
    async playMacro(id: string, options?: MacroPlaybackOptions): Promise<any[]> {
      const macro = await this.loadMacro(id);
      if (!macro) {
        throw new Error(`Macro ${id} not found`);
      }
      
      const results: any[] = [];
      const params = options?.parameters || {};
      
      for (const call of macro.calls) {
        try {
          // Apply parameter substitution
          const processedCall = this.substituteParameters(call, macro.parameters, params);
          
          // Allow pre-processing
          const finalCall = options?.beforeCall 
            ? await options.beforeCall(processedCall) 
            : processedCall;
          
          if (!finalCall) continue; // Skip if beforeCall returns null
          
          // Execute if not dry run
          if (!options?.dryRun) {
            const startTime = Date.now();
            let response;
            
            switch (finalCall.method) {
              case 'GET':
                response = await this.client.get(finalCall.path);
                break;
              case 'POST':
                response = await this.client.post(finalCall.path, finalCall.payload);
                break;
              case 'PUT':
                response = await this.client.put(finalCall.path, finalCall.payload);
                break;
              case 'DELETE':
                response = await this.client.delete(finalCall.path);
                break;
            }
            
            const duration = Date.now() - startTime;
            
            // Record the result
            const result = {
              call: finalCall,
              response,
              duration
            };
            
            results.push(result);
            
            // Allow post-processing
            if (options?.afterCall) {
              await options.afterCall(finalCall, response);
            }
          } else {
            // Dry run - just collect the calls
            results.push({
              call: finalCall,
              response: null,
              duration: 0,
              dryRun: true
            });
          }
        } catch (error) {
          if (options?.stopOnError) {
            throw error;
          }
          results.push({
            call,
            error,
            duration: 0
          });
        }
      }
      
      return results;
    }
  • Type definition for options passed to the macro_play tool, defining parameters for substitution, execution modes, and callback hooks.
    export interface MacroPlaybackOptions {
      parameters?: Record<string, any>;
      dryRun?: boolean;
      stopOnError?: boolean;
      beforeCall?: (call: APICall) => Promise<APICall | null>;
      afterCall?: (call: APICall, response: any) => Promise<void>;
    }
  • Method signature in IMacroRecorder interface declaring the playMacro functionality, serving as the contract for macro playback tool implementation.
    playMacro(id: string, options?: MacroPlaybackOptions): Promise<any[]>;
  • Helper method that substitutes template parameters ({{param}} or JSONPath) in API calls using provided values, enabling dynamic macro execution.
    private substituteParameters(
      call: APICall, 
      parameters: MacroParameter[], 
      values: Record<string, any>
    ): APICall {
      // Deep clone the call object
      const substitutedCall = JSON.parse(JSON.stringify(call));
      
      // Create a context object that includes all values plus any response data
      const context = {
        ...values,
        $: values  // Allow $ as root context for JSONPath expressions
      };
      
      // Convert call to string for pattern matching
      const callStr = JSON.stringify(substitutedCall);
      
      // Find all template expressions in the call
      const templateRegex = /\{\{([^}]+)\}\}/g;
      let modifiedStr = callStr;
      let match;
      
      while ((match = templateRegex.exec(callStr)) !== null) {
        const expression = match[1].trim();
        let value;
        
        if (expression.startsWith('$')) {
          // JSONPath expression
          try {
            const results = jsonpath.query(context, expression);
            value = results.length > 0 ? results[0] : match[0]; // Keep original if no match
          } catch (error) {
            console.warn(`Invalid JSONPath expression: ${expression}`, error);
            value = match[0]; // Keep original on error
          }
        } else {
          // Simple variable substitution
          const param = parameters.find(p => p.name === expression);
          value = values[expression] ?? param?.defaultValue;
        }
        
        if (value !== undefined && value !== match[0]) {
          // Replace the template with the value
          modifiedStr = modifiedStr.replace(match[0], JSON.stringify(value));
        }
      }
      
      return JSON.parse(modifiedStr);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Play a saved macro' implies execution of recorded actions, but it doesn't disclose whether this is destructive, requires specific permissions, has rate limits, or what happens during execution. The description lacks essential behavioral context for a tool that likely performs operations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a tool with clear purpose and good schema documentation, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema that likely executes complex operations (given the 'parameters' object and 'dryRun' option), the description is insufficient. It doesn't explain what 'playing' entails, what types of operations might be executed, or what the expected outcome is, leaving significant gaps in understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so parameters are well-documented in the schema itself. The description adds no additional parameter semantics beyond what's already in the schema, which meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Play a saved macro' clearly states the action (play) and resource (saved macro), making the tool's purpose immediately understandable. However, it doesn't differentiate this from sibling tools like 'macro_analyze' or 'macro_list', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'macro_analyze' or 'macro_list', nor does it mention prerequisites such as needing a recorded macro first. It simply states what the tool does without contextual usage information.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vespo92/OPNSenseMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server