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
- Direct Known Subclasses:
HttpStatelessGenericGenaiAdapter,HttpStreamableGenericGenaiAdapter,StdioGenaiAdapter
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
FieldsModifier and TypeFieldDescriptionprivate final AbstractMcpServer.ToolSpecificationBuilder<TExchange> private final org.slf4j.Loggerprivate final List<TSpecification> Fields inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
chatModel, DEFAULT_WEBSEARCH_TYPE_NAME, instructions, LINE_SEPARATOR, 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 TypeMethodDescriptionprivate voidaddPropDescription(Map<String, com.anthropic.core.JsonValue> properties, List<String> required, ParamDescriptor pDesc) Adds a property description to the tool schema.protected voidaddTool(String name, String description, ToolFunction function, ParamDescriptor... paramsDesc) Register tool implementation for 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, addResource, addResources, addTools, addWebSearch, addWebSearch, clear, getConfigurator, getEnabledTools, getParamValue, getProjectDir, getTimeout, init, instructions, isErrorHandling, normalize, prompt, safelyInvokeTool, setEnabledTools, setErrorHandling, setProjectDir, setTimeout
-
Field Details
-
log
private final org.slf4j.Logger log -
toolSpecifications
-
builder
-
-
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 addedbuilder- 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 useFunctionTools.- 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"
-
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 valuesrequired- the list of required property namespDesc- the parameter description 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
-