Package org.machanism.machai.mcp.server
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/contextTSpecification- the type representing the tool specification
- All Implemented Interfaces:
Genai
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 Summary
Fields inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
chatModel, config, DEFAULT_WEBSEARCH_TYPE_NAME, instructions, lastUsage, LINE_SEPARATOR, LOG_INPUTS_PROP_NAME, LOG_LINE_LENG, LOG_SECTION_SEPARATOR, MAX_OUTPUT_TOKENS, maxOutputTokens, maxToolCalls, MCP_PROP_NAME_PREFIX, PARAGRAPH_SEPARATOR, PASSWORD_PROP_NAME, PROJECT_DIR_PARAM_NAME, projectDir, SERVERID_PROP_NAME, timeoutSec, USERNAME_PROP_NAME -
Constructor Summary
ConstructorsConstructorDescriptionGenericGenaiAdapter(List<TSpecification> toolSpecifications, AbstractMcpServer.ToolSpecificationBuilder<TExchange> builder) Constructs a new GenericGenaiAdapter. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTool(String name, String description, ToolFunction function, ParamDescriptor... paramsDesc) Registers a new tool with the adapter.perform()static StringtoHumanReadable(String toolName) Converts a function tool name in Python style (snake_case or camelCase) to a human-readable format.Methods inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
addMcpServer, addMcpServers, addPrompt, addPrompts, addTools, addWebSearch, addWebSearch, clear, getParamValue, getProjectDir, getTimeout, init, inputsLog, instructions, logInputs, logInputsSpec, normalize, prompt, safelyInvokeTool, setProjectDir, setTimeout, setWorkingDir
-
Constructor Details
-
GenericGenaiAdapter
public GenericGenaiAdapter(List<TSpecification> toolSpecifications, AbstractMcpServer.ToolSpecificationBuilder<TExchange> builder) Constructs a new GenericGenaiAdapter.- Parameters:
toolSpecifications- the list to which tool specifications will be addedbuilder- the builder responsible for creating tool and specification objects
-
-
Method Details
-
addTool
protected void addTool(String name, String description, ToolFunction function, ParamDescriptor... paramsDesc) Registers a new tool with the adapter.- Specified by:
addToolin classAbstractAIProvider- Parameters:
name- the name of the tooldescription- the description of the toolfunction- the function to execute when the tool is calledparamsDesc- the parameter descriptions for the tool, each in the format "name:type:required:description"
-
toHumanReadable
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
-