Class McpSnmpCommandGenerator
java.lang.Object
org.snmp4j.mcp.tool.snmp.McpSnmpCommandGenerator
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordJSON representation of an SNMP ScopedPDU sent to the tool as thepduparameter.static final recordJSON representation of a singleVariableBindingwithin aMcpSnmpCommandGenerator.PduRequest. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMCP resource URI for the PDU request JSON schema.static final StringMCP resource URI for the SNMP response event JSON schema.static final StringMCP resource URI for the samplesnmpTargetAddrEntrycreate-row PDU.static final StringTool ID registered with the MCP server ("snmp_command_generator"). -
Constructor Summary
ConstructorsConstructorDescriptionMcpSnmpCommandGenerator(Supplier<List<SnmpMcpServer.ServerConfiguration.SnmpTargetConfig>> snmpTargetsSupplier, com.snmp4j.smi.SmiManager smiManager) Creates a new SNMP command generator tool. -
Method Summary
Modifier and TypeMethodDescriptionExecutes the tool with the provided parameters.Gets the description for this tool.getId()Gets the unique identifier for this tool.getName()Gets the display name for this tool.Gets the supported parameters for this tool.static StringReturns the JSON Schema (Draft 2020-12) for thepduinput parameter of this tool.Gets the contexts that this tool requires.static StringReturns the JSON Schema (Draft 2020-12) for the JSON object returned by this tool.static StringReturns a sample SET PDU JSON that creates a new row in the SNMP-TARGET-MIBsnmpTargetAddrTable(1.3.6.1.6.3.12.1.2.1) usingcreateAndGo(4).getTitle()Gets the title associated with this tool.Gets the version of this tool.booleanChecks if the tool is available in the current environment.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface McpTool
getAnnotation
-
Field Details
-
TOOL_ID
Tool ID registered with the MCP server ("snmp_command_generator").- See Also:
-
RESPONSE_SCHEMA_RESOURCE_URI
MCP resource URI for the SNMP response event JSON schema.- See Also:
-
PDU_REQUEST_SCHEMA_RESOURCE_URI
MCP resource URI for the PDU request JSON schema.- See Also:
-
SNMP_TARGET_ADDR_ENTRY_CREATE_ROW_SAMPLE_URI
MCP resource URI for the samplesnmpTargetAddrEntrycreate-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 invocationsmiManager- used to resolve OID syntax when no type prefix is given in a variable binding value; may benull
-
-
Method Details
-
getId
-
getName
-
getVersion
Description copied from interface:McpToolGets the version of this tool.- Specified by:
getVersionin interfaceMcpTool- Returns:
- the tool version
-
getTitle
-
getDescription
Description copied from interface:McpToolGets the description for this tool.- Specified by:
getDescriptionin interfaceMcpTool- Returns:
- the tool description
-
isAvailable
public boolean isAvailable()Description copied from interface:McpToolChecks if the tool is available in the current environment.- Specified by:
isAvailablein interfaceMcpTool- Returns:
- true if the tool is available, false otherwise
-
getRequiredContexts
Description copied from interface:McpToolGets the contexts that this tool requires.- Specified by:
getRequiredContextsin interfaceMcpTool- Returns:
- a list of required context IDs
-
getParameters
Description copied from interface:McpToolGets the supported parameters for this tool.- Specified by:
getParametersin interfaceMcpTool- Returns:
- a list of parameter descriptions
-
execute
Description copied from interface:McpToolExecutes the tool with the provided parameters.- Specified by:
executein interfaceMcpTool- Parameters:
params- the parameters to use- Returns:
- the result of the execution
- Throws:
McpToolException- if the tool execution fails
-
getPduRequestSchemaJson
Returns the JSON Schema (Draft 2020-12) for thepduinput parameter of this tool.- Returns:
- JSON Schema string
-
getSnmpTargetAddrEntryCreateRowSampleJson
Returns a sample SET PDU JSON that creates a new row in the SNMP-TARGET-MIBsnmpTargetAddrTable(1.3.6.1.6.3.12.1.2.1) usingcreateAndGo(4).The sample uses the row name
"test"(ASCII: 116.101.115.116). Because the INDEX isIMPLIED 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
C0A8016400A1encodes 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
Returns the JSON Schema (Draft 2020-12) for the JSON object returned by this tool.- Returns:
- JSON Schema string
-