Class MibCompilerTool

java.lang.Object
org.snmp4j.mcp.tool.mib.compiler.MibCompilerTool
All Implemented Interfaces:
McpTool

public class MibCompilerTool extends Object implements McpTool
An MCP Tool that compiles SMIv1 or SMIv2 MIB specifications using the underlying SmiManager and returns compilation results as a JSON string.

Three instances of this tool are intended to be registered with the MCP server, one per applicable SmiCompiler.TargetMode:

  • check_mib — dry-run syntax check, no repository changes.
  • check_mib_completely — dry-run without error count limit.
  • compile_mib — compile and persist into the repository (no cache load).

Compilation progress is reported via the server's logging infrastructure using a CompilationMonitor implementation. If the MCP framework supports client-side progress notifications in a future version, the monitor can be extended accordingly.

The MIB specification to compile can be supplied in one of two ways:

  • Inline via the mibContent parameter (the raw SMIv1/v2 text), or
  • By reference via the mibFile parameter, a filename (text or ZIP archive) relative to the server's configured MIB source directory (MIB.mibSourcePath, default "mibs"). ZIP archives (recognized by a .zip extension) are expanded into their individual module entries. A mibFile that resolves to a location outside the configured source directory is rejected. When mibFile is provided it takes precedence over mibContent. The file and ZIP names reported in the returned CompilationResults are kept relative to the configured source directory and never expose the server's absolute file-system paths.
Since:
0.1.0
Version:
0.1.0
Author:
SNMP4J.org
  • Constructor Details

    • MibCompilerTool

      public MibCompilerTool(com.snmp4j.smi.SmiManager smiManager, com.snmp4j.smi.SmiCompiler.TargetMode targetMode, String mibSourcePath)
      Creates a MibCompilerTool for the specified target mode. The tool ID, title, and description are determined by the given targetMode.
      Parameters:
      smiManager - the SmiManager used to compile MIB specifications.
      targetMode - the compilation target mode; must be one of SmiCompiler.TargetMode.dryRun, SmiCompiler.TargetMode.dryRunWithoutErrorLimit, or SmiCompiler.TargetMode.storeIntoRepositoryNoLoad.
      mibSourcePath - the directory (from the MIB.mibSourcePath server configuration setting) against which the mibFile parameter is resolved. A blank or null value falls back to the current working directory.
      Throws:
      IllegalArgumentException - if targetMode is not supported by this tool.
  • Method Details

    • getId

      public String getId()
      Description copied from interface: McpTool
      Gets the unique identifier for this tool.
      Specified by:
      getId in interface McpTool
      Returns:
      the tool ID
    • getName

      public String getName()
      Description copied from interface: McpTool
      Gets the display name for this tool.
      Specified by:
      getName in interface McpTool
      Returns:
      the tool name
    • getTitle

      public String getTitle()
      Description copied from interface: McpTool
      Gets the title associated with this tool.
      Specified by:
      getTitle in interface McpTool
      Returns:
      the tool title
    • getDescription

      public String getDescription()
      Description copied from interface: McpTool
      Gets the description for this tool.
      Specified by:
      getDescription in interface McpTool
      Returns:
      the tool description
    • getVersion

      public String getVersion()
      Description copied from interface: McpTool
      Gets the version of this tool.
      Specified by:
      getVersion in interface McpTool
      Returns:
      the tool version
    • getParameters

      public List<ToolParameter> getParameters()
      Description copied from interface: McpTool
      Gets the supported parameters for this tool.
      Specified by:
      getParameters in interface McpTool
      Returns:
      a list of parameter descriptions
    • execute

      public ToolResult execute(Map<String,Object> params) throws McpToolException
      Description copied from interface: McpTool
      Executes the tool with the provided parameters.
      Specified by:
      execute in interface McpTool
      Parameters:
      params - the parameters to use
      Returns:
      the result of the execution
      Throws:
      McpToolException - if the tool execution fails
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: McpTool
      Checks if the tool is available in the current environment.
      Specified by:
      isAvailable in interface McpTool
      Returns:
      true if the tool is available, false otherwise
    • getRequiredContexts

      public List<String> getRequiredContexts()
      Description copied from interface: McpTool
      Gets the contexts that this tool requires.
      Specified by:
      getRequiredContexts in interface McpTool
      Returns:
      a list of required context IDs
    • getAnnotation

      public io.modelcontextprotocol.spec.McpSchema.ToolAnnotations getAnnotation()
      Description copied from interface: McpTool
      Gets the tool annotations. By default, readOnly, hidden, idempotent, openWorld are true while destructive and returnDirect are false.
      Specified by:
      getAnnotation in interface McpTool
      Returns:
      McpSchema.ToolAnnotations