Class McpMibSemanticSearch

java.lang.Object
org.snmp4j.mcp.tool.mib.semantic.McpMibSemanticSearch
All Implemented Interfaces:
McpTool

public class McpMibSemanticSearch extends Object implements McpTool
MCP tool that performs semantic (vector-similarity) search over all MIB objects currently loaded in the server's SmiManager.

How it works

  1. On first call (or after a module reload), the tool builds a vector index by embedding every loaded MIB object using the configured EmbeddingClient.
  2. The index is persisted as a GZIP'd JSON file next to the MIB repository so it can be reloaded on server restart without re-embedding.
  3. Subsequent queries embed the natural-language query string and rank all indexed objects by cosine similarity.

Configuration

Set the OPENAI_API_KEY environment variable (or the openai.api.key JVM system property) before starting the server. If neither is set, the tool is registered, but every call returns an error explaining what is missing.
Since:
0.1.0
  • Field Details

    • TOOL_ID

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

    • McpMibSemanticSearch

      public McpMibSemanticSearch(com.snmp4j.smi.SmiManager smiManager, EmbeddingClient embeddingClient, Path repositoryDir)
      Creates a new semantic search tool.
      Parameters:
      smiManager - provides access to loaded MIB objects for index building
      embeddingClient - embedding backend; may be null (tool will report an error on use)
      repositoryDir - directory where the index cache file is stored; use null to write it in the current working directory
  • 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
    • rebuildAsync

      public void rebuildAsync()
      Triggers an asynchronous (re-)build of the embedding index. Safe to call concurrently; only one build runs at a time.