query_departments
Retrieve bakery department information by ID or name to access product categories and organizational data for sales analysis and inventory management.
Instructions
Query department master data. Returns all departments or filter by ID/name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| department_id | No | Department ID. Optional. | |
| department_name | No | Department name to search (partial match). Optional. |
Implementation Reference
- src/bakery_data_mcp/server.py:333-351 (handler)Implements the handler logic for the 'query_departments' tool. Constructs a dynamic SQL query to select from the 'departments' table, applying optional filters for 'department_id' and 'department_name' (partial match), executes it, and returns the results as JSON-formatted text content.elif name == "query_departments": query = "SELECT * FROM departments WHERE 1=1" params = [] if "department_id" in arguments: query += " AND department_id = ?" params.append(arguments["department_id"]) if "department_name" in arguments: query += " AND department_name LIKE ?" params.append(f"%{arguments['department_name']}%") cursor.execute(query, params) results = cursor.fetchall() return [TextContent( type="text", text=json.dumps(results, ensure_ascii=False, indent=2) )]
- src/bakery_data_mcp/server.py:127-143 (registration)Registers the 'query_departments' tool in the list_tools() function, providing its name, description, and input schema for validation.Tool( name="query_departments", description="Query department master data. Returns all departments or filter by ID/name.", inputSchema={ "type": "object", "properties": { "department_id": { "type": "number", "description": "Department ID. Optional." }, "department_name": { "type": "string", "description": "Department name to search (partial match). Optional." } } } ),
- Defines the input schema for the 'query_departments' tool, specifying optional parameters for department_id (number) and department_name (string).inputSchema={ "type": "object", "properties": { "department_id": { "type": "number", "description": "Department ID. Optional." }, "department_name": { "type": "string", "description": "Department name to search (partial match). Optional." } } }