Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI SingleStore Search Tool

From Leeroopedia
Knowledge Sources
Domains Database Integration, Semantic Search, Tool Integration
Last Updated 2026-02-11 00:00 GMT

Overview

SingleStoreSearchTool is a CrewAI tool for executing secure SELECT and SHOW queries against SingleStore databases with connection pooling, table validation, and comprehensive connection configuration.

Description

The tool extends BaseTool and conditionally imports singlestoredb.connect and sqlalchemy.pool.QueuePool, prompting for installation if the packages are unavailable. It provides a security-first design that restricts queries to only SELECT and SHOW statements.

Key implementation features:

  • Connection pooling -- Uses SQLAlchemy's QueuePool with configurable pool_size (default 5), max_overflow (default 10), and timeout (default 30s) for efficient connection management.
  • Schema introspection -- During initialization, _initialize_tables validates that specified tables exist by running SHOW TABLES and SHOW COLUMNS, then updates the tool's description with actual table schema information including column names and types.
  • Comprehensive connection parameters -- Supports basic connection (host, user, password, port, database), SSL/TLS configuration (ssl_key, ssl_cert, ssl_ca, ssl_disabled, ssl_cipher, ssl_verify_cert), advanced options (autocommit, charset, credential_type), result formatting (results_type, buffered, results_format), and data type handling (nan_as_null, inf_as_null, vector_data_format, parse_json).
  • Query validation -- The _validate_query method enforces that only queries starting with "select" or "show" are executed, preventing write operations.
  • Environment variable support -- Multiple optional environment variables (SINGLESTOREDB_URL, _HOST, _PORT, _USER, _PASSWORD, _DATABASE, SSL vars, _CONNECT_TIMEOUT) for flexible configuration.

Usage

Use this tool when agents need to query SingleStore databases for data analysis, reporting, or semantic search. Its read-only query restriction makes it safe for production data exploration workflows.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/tools/singlestore_search_tool/singlestore_search_tool.py
  • Lines: 1-438

Signature

class SingleStoreSearchTool(BaseTool):
    name: str = "Search a database's table(s) content"
    description: str = "A tool that can be used to semantic search a query from a database."
    args_schema: type[BaseModel] = SingleStoreSearchToolSchema
    package_dependencies: list[str] = ["singlestoredb", "SQLAlchemy"]
    connection_args: dict = Field(default_factory=dict)
    connection_pool: Any | None = None

    def __init__(
        self,
        tables: list[str] | None = None,
        host: str | None = None,
        user: str | None = None,
        password: str | None = None,
        port: int | None = None,
        database: str | None = None,
        pool_size: int | None = 5,
        max_overflow: int | None = 10,
        timeout: float | None = 30,
        # Plus SSL, advanced, result formatting, and data type parameters
        **kwargs,
    ): ...

Import

from crewai_tools.tools.singlestore_search_tool.singlestore_search_tool import SingleStoreSearchTool

I/O Contract

Inputs

Name Type Required Description
search_query str Yes SQL query to execute; only SELECT and SHOW queries are supported

Constructor Parameters

Name Type Required Description
tables list[str] No List of table names to work with; if empty, all tables are used
host str No Database host address
user str No Database username
password str No Database password
port int No Database port number
database str No Database name
pool_size int No Maximum connections in pool (default: 5)
max_overflow int No Maximum overflow connections beyond pool_size (default: 10)
timeout float No Connection timeout in seconds (default: 30)

Outputs

Name Type Description
return str Formatted search results as comma-separated rows prefixed with "Search Results:", or "No results found.", or an error message

Usage Examples

Basic Usage

from crewai_tools.tools.singlestore_search_tool.singlestore_search_tool import SingleStoreSearchTool

tool = SingleStoreSearchTool(
    host="svc-abc123.svc.singlestore.com",
    port=3306,
    user="admin",
    password="secret",
    database="analytics",
    tables=["customers", "orders"],
    pool_size=5,
)

# Execute a SELECT query
result = tool._run(search_query="SELECT name, email FROM customers WHERE active = 1")
print(result)

# View table schema
result = tool._run(search_query="SHOW COLUMNS FROM customers")
print(result)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment