Class McpSnmpCommandGenerator

java.lang.Object
org.snmp4j.mcp.tool.snmp.McpSnmpCommandGenerator
All Implemented Interfaces:
McpTool

public class McpSnmpCommandGenerator extends Object implements McpTool
MCP Tool that sends an SNMP PDU to a named SnmpMcpServer.ServerConfiguration.SnmpTargetConfig and returns the ResponseEvent serialised as JSON.

Supported PDU types: GET, GETNEXT, GETBULK, SET, INFORM.

Variable binding values follow the SNMP4J string syntax, e.g. "string:hello", "integer:42", "oid:1.3.6.1", "timeticks:100".

The JSON schema for the response object is registered as an MCP resource at RESPONSE_SCHEMA_RESOURCE_URI.

Since:
0.1.0
  • Field Details

    • TOOL_ID

      public static final String TOOL_ID
      Tool ID registered with the MCP server ("snmp_command_generator").
      See Also:
    • RESPONSE_SCHEMA_RESOURCE_URI

      public static final String RESPONSE_SCHEMA_RESOURCE_URI
      MCP resource URI for the SNMP response event JSON schema.
      See Also:
    • PDU_REQUEST_SCHEMA_RESOURCE_URI

      public static final String PDU_REQUEST_SCHEMA_RESOURCE_URI
      MCP resource URI for the PDU request JSON schema.
      See Also:
    • SNMP_TARGET_ADDR_ENTRY_CREATE_ROW_SAMPLE_URI

      public static final String SNMP_TARGET_ADDR_ENTRY_CREATE_ROW_SAMPLE_URI
      MCP resource URI for the sample snmpTargetAddrEntry create-row PDU.
      See Also:
  • Constructor Details

    • McpSnmpCommandGenerator

      public McpSnmpCommandGenerator(Supplier<List<SnmpMcpServer.ServerConfiguration.SnmpTargetConfig>> snmpTargetsSupplier, com.snmp4j.smi.SmiManager smiManager)
      Creates a new SNMP command generator tool.
      Parameters:
      snmpTargetsSupplier - provides the current list of configured SNMP targets; resolved lazily on every tool invocation
      smiManager - used to resolve OID syntax when no type prefix is given in a variable binding value; may be null
  • 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
    • 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
    • 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
    • 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
    • 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
    • getPduRequestSchemaJson

      public static String getPduRequestSchemaJson()
      Returns the JSON Schema (Draft 2020-12) for the pdu input parameter of this tool.
      Returns:
      JSON Schema string
    • getSnmpTargetAddrEntryCreateRowSampleJson

      public static String getSnmpTargetAddrEntryCreateRowSampleJson()
      Returns a sample SET PDU JSON that creates a new row in the SNMP-TARGET-MIB snmpTargetAddrTable (1.3.6.1.6.3.12.1.2.1) using createAndGo(4).

      The sample uses the row name "test" (ASCII: 116.101.115.116). Because the INDEX is IMPLIED snmpTargetAddrName, the OID instance suffix is the raw ASCII values of the name characters without a length prefix: <column>.116.101.115.116.

      The TAddress value C0A8016400A1 encodes UDP target 192.168.1.100:161 as six hex bytes (4 bytes IP + 2 bytes port in network byte order).

      Returns:
      JSON string conforming to PDU_REQUEST_SCHEMA_RESOURCE_URI
    • getResponseEventSchemaJson

      public static String getResponseEventSchemaJson()
      Returns the JSON Schema (Draft 2020-12) for the JSON object returned by this tool.
      Returns:
      JSON Schema string