Class GenericGenaiAdapter<TExchange,TSpecification>

java.lang.Object
org.machanism.machai.ai.provider.AbstractAIProvider
org.machanism.machai.mcp.server.GenericGenaiAdapter<TExchange,TSpecification>
Type Parameters:
TExchange - the type representing the server exchange/context
TSpecification - the type representing the tool specification
All Implemented Interfaces:
Genai
Direct Known Subclasses:
HttpStatelessGenericGenaiAdapter, HttpStreamableGenericGenaiAdapter, StdioGenaiAdapter

public class GenericGenaiAdapter<TExchange,TSpecification> extends AbstractAIProvider
A generic adapter for integrating GenAI tools with different server implementations.

This class abstracts the process of registering tools and their schemas, allowing for flexible integration with various server types by parameterizing the exchange and specification types.

Since:
1.2.0
Author:
Viktor Tovstyi
  • Field Details

  • Constructor Details

    • GenericGenaiAdapter

      GenericGenaiAdapter(List<TSpecification> toolSpecifications, AbstractMcpServer.ToolSpecificationBuilder<TExchange> builder)
      Constructs a new GenericGenaiAdapter.
      Parameters:
      toolSpecifications - the list to which tool specifications will be added
      builder - the builder responsible for creating tool and specification objects
  • Method Details

    • addTool

      protected void addTool(String name, String description, ToolFunction function, ParamDescriptor... paramsDesc)
      Register tool implementation for the adapter. If you need to implement a custom tool use FunctionTools.
      Specified by:
      addTool in class AbstractAIProvider
      Parameters:
      name - the name of the tool
      description - the description of the tool
      function - the function to execute when the tool is called
      paramsDesc - the parameter descriptions for the tool, each in the format "name:type:required:description"
    • addPropDescription

      private void addPropDescription(Map<String,com.anthropic.core.JsonValue> properties, List<String> required, ParamDescriptor pDesc)
      Adds a property description to the tool schema.
      Parameters:
      properties - the map of property names to their JSON schema values
      required - the list of required property names
      pDesc - the parameter description in the format "name:type:required:description"
    • toHumanReadable

      public static String toHumanReadable(String toolName)
      Converts a function tool name in Python style (snake_case or camelCase) to a human-readable format. Examples: "my_function_tool" -> "My Tool Tool" "doSomething_cool" -> "Do Something Cool" "anotherToolName" -> "Another Tool Name"
      Parameters:
      toolName - the function tool name to convert
      Returns:
      the human-readable format
    • perform

      public String perform()