HANAMLToolkit
- class hana_ai.tools.toolkit.HANAMLToolkit(connection_context, used_tools=None, return_direct=None, audit_enabled: bool = True, audit_log_path: str | None = None, audit_service_name: str = 'hana-ai-mcp-service', audit_environment: str = 'local', trust_proxy_headers: bool | None = None, trusted_proxy_cidrs: list[str] | str | None = None)
Toolkit for interacting with HANA SQL.
- Parameters:
- connection_contextConnectionContext
Connection context to the HANA database.
- used_toolslist, optional
List of tools to use. If None or 'all', all tools are used. Default to None.
Examples
Assume cc is a connection to a SAP HANA instance:
>>> from hana_ai.tools.toolkit import HANAMLToolkit >>> from hana_ai.agents.hanaml_agent_with_memory import HANAMLAgentWithMemory
>>> tools = HANAMLToolkit(connection_context=cc, used_tools='all').get_tools() >>> chatbot = HANAMLAgentWithMemory(llm=llm, toos=tools, session_id='hana_ai_test', n_messages=10)
- add_custom_tool(tool: BaseTool)
Add a custom tool to the toolkit.
- Parameters:
- toolBaseTool
Custom tool to add.
Note
The tool must be a subclass of BaseTool. Please follow the guide to create the custom tools https://python.langchain.com/docs/how_to/custom_tools/.
- delete_tool(tool_name: str)
Delete a tool from the toolkit.
- Parameters:
- tool_namestr
Name of the tool to delete.
- reset_tools(tools: List[BaseTool] | None = None)
Reset the toolkit's tools.
- Parameters:
- toolslist of BaseTool or list of str, optional
If provided, the toolkit will only contain these tools. When a list of strings is provided, tools will be matched by name from the default tools. If None, reset to default tools.
- set_bas(bas=True)
Set the BAS mode for all tools in the toolkit.
- set_vectordb(vectordb)
Set the vector database.
- Parameters:
- vectordbHANAMLinVectorEngine
Vector database.
- is_port_available(port: int) bool
检查端口是否可用
- launch_mcp_server(server_name: str = 'HANATools', host: str = '127.0.0.1', transport: str = 'stdio', port: int = 8001, auth_token: str | None = None, max_retries: int = 5)
Launch the MCP server with the specified configuration. This method initializes the MCP server, registers all tools, and starts the server in a background thread. If the specified port is occupied, it will try the next port up to max_retries times.
- Parameters:
- server_namestr
Name of the server. Default is "HANATools".
- hoststr
Host address for the server.
- transport{"stdio", "sse", "http"}
Transport protocol to use. Default is "stdio". Can be "sse" for Server-Sent Events.
- portint
Network port to use for server transports that require a port (SSE/HTTP). Default is 8001. Ignored for stdio.
- auth_tokenstr, optional
Authentication token for the server. If provided, the server will require this token for access.
- max_retriesint
Maximum number of retries to find an available port. Default is 5.
- get_tools() List[BaseTool]
Get the tools in the toolkit.
- stop_mcp_server(host: str = '127.0.0.1', port: int = 8001, transport: str = 'sse', force: bool = False, timeout: float = 5.0) bool
停止指定地址与端口的 MCP 服务。
- stop_all_mcp_servers(force: bool = False, timeout: float = 5.0) int
关闭全部已注册 MCP 服务。