search_commands_tool
Search command history by keyword across names, categories, and contexts to find relevant AI commands from usage logs.
Instructions
Search command history by keyword.
Searches across command name, category, and context fields.
Args:
query: Search keyword
limit: Max results (default 20)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| limit | No |
Implementation Reference
- src/mcp_commands/server.py:103-117 (handler)The search_commands_tool handler function that executes the search logic. Takes a query string and optional limit, calls the storage layer search_commands function, and returns JSON-formatted results.@mcp.tool() def search_commands_tool(query: str, limit: int = 20) -> str: """ Search command history by keyword. Searches across command name, category, and context fields. Args: query: Search keyword limit: Max results (default 20) """ rows = search_commands(query=query, limit=limit) if not rows: return f"No records matching '{query}'." return json.dumps(rows, ensure_ascii=False, indent=2)
- src/mcp_commands/server.py:103-103 (registration)The @mcp.tool() decorator that registers search_commands_tool as an MCP tool with the FastMCP server.@mcp.tool()
- src/mcp_commands/storage.py:172-192 (helper)The underlying search_commands function that performs the database query. Uses PostgreSQL ILIKE to search across command, category, and context fields. Returns a list of dictionaries representing matching records.def search_commands( query: str, limit: int = 20, ) -> list[dict]: """Full-text search across command, category, and context fields.""" conn = get_connection() with conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cur: cur.execute( """ SELECT * FROM command_log WHERE command ILIKE %s OR category ILIKE %s OR context ILIKE %s ORDER BY used_at DESC LIMIT %s """, (f"%{query}%", f"%{query}%", f"%{query}%", limit), ) rows = cur.fetchall() conn.close() return [_row_to_dict(r) for r in rows]