Implementation:CrewAIInc CrewAI MySQL Search Tool
| Knowledge Sources | |
|---|---|
| Domains | Tools, RAG, Database |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
MySQLSearchTool enables semantic search within MySQL database tables using RAG technology for natural language queries.
Description
The MySQLSearchTool extends RagTool with MySQL-specific functionality, transforming traditional SQL table access into semantic search. It requires a db_uri field for database connection. During initialization, it accepts a table_name, constructs a SELECT * query for that table, and adds the result to the RAG knowledge base with DataType.MYSQL and the database URI as metadata. The tool description is updated to reference the specific table name. The overridden add() method wraps table names in SELECT * FROM queries before delegating to the parent. The _run() method accepts semantic search queries with optional similarity_threshold and limit parameters, delegating to the parent RagTool's semantic search capabilities for natural language matching against the indexed table data.
Usage
Use this tool when a CrewAI agent needs to query MySQL database content using natural language rather than SQL syntax, making database exploration more intuitive and accessible for AI agents.
Code Reference
Source Location
- Repository: CrewAI
- File: lib/crewai-tools/src/crewai_tools/tools/mysql_search_tool/mysql_search_tool.py
- Lines: 1-46
Signature
class MySQLSearchTool(RagTool):
name: str = "Search a database's table content"
description: str = "A tool that can be used to semantic search a query from a database table's content."
args_schema: type[BaseModel] = MySQLSearchToolSchema
db_uri: str = Field(..., description="Mandatory database URI")
def __init__(self, table_name: str, **kwargs): ...
def add(self, table_name: str, **kwargs: Any) -> None: ...
def _run(
self,
search_query: str,
similarity_threshold: float | None = None,
limit: int | None = None,
**kwargs: Any,
) -> Any: ...
Import
from crewai_tools import MySQLSearchTool
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| db_uri | str | Yes | MySQL database connection URI |
| table_name | str | Yes | Name of the MySQL table to index for semantic search |
| search_query | str | Yes | Natural language search query to run against the table content |
| similarity_threshold | float or None | No | Minimum similarity score for returned results |
| limit | int or None | No | Maximum number of results to return |
Outputs
| Name | Type | Description |
|---|---|---|
| _run() returns | Any | Semantically matched content from the MySQL table |
Usage Examples
Basic Usage
from crewai_tools import MySQLSearchTool
tool = MySQLSearchTool(
table_name="products",
db_uri="mysql://user:password@localhost:3306/mydb",
)
result = tool._run(search_query="high performance laptop computers")