Class McpSnmpTable

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

public class McpSnmpTable extends Object implements McpTool
MCP Tool that retrieves SNMP tabular data from a named SnmpMcpServer.ServerConfiguration.SnmpTargetConfig and returns it as JSON.

The response uses a tabular format with a header row (column OIDs) and data rows aligned with the TableEvent model. Cell instance OIDs are included by default and can be suppressed via the includeOids parameter.

Progress (number of retrieved rows) is sent to the MCP client via McpSyncServerExchange.progressNotification(McpSchema.ProgressNotification) during retrieval. Register this tool using toSyncToolSpec() rather than the generic SnmpMcpServer.registerTool() so that the exchange is passed through.

Since:
0.1.0
  • Field Details

    • TOOL_ID

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

      public static final String TABLE_RESULT_SCHEMA_RESOURCE_URI
      MCP resource URI for the table result JSON schema.
      See Also:
  • Constructor Details

    • McpSnmpTable

      public McpSnmpTable(Supplier<List<SnmpMcpServer.ServerConfiguration.SnmpTargetConfig>> snmpTargetsSupplier, com.snmp4j.smi.SmiManager smiManager)
      Creates a new SNMP table retrieval tool.
      Parameters:
      snmpTargetsSupplier - supplies the list of configured SNMP targets
      smiManager - used for OID and type resolution; 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
    • 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
    • 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
    • callTool

      public io.modelcontextprotocol.spec.McpSchema.CallToolResult callTool(io.modelcontextprotocol.server.McpSyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request)
      Executes the tool within an active MCP server exchange, enabling progress notifications.
      Parameters:
      exchange - the active server exchange for sending notifications
      request - the MCP tool call request containing arguments
      Returns:
      the MCP call tool result
    • toSyncToolSpec

      public io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification toSyncToolSpec()
      Returns a McpServerFeatures.SyncToolSpecification for direct server registration. This variant passes the MCP exchange through to callTool(McpSyncServerExchange, McpSchema.CallToolRequest), enabling progress notifications during table retrieval.

      Usage: syncServer.addTool(mcpSnmpTable.toSyncToolSpec());

      Returns:
      sync tool specification ready to pass to McpSyncServer.addTool()
    • getTableResultSchemaJson

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