Execute a database tool by name. This is the dispatcher function that maps tool calls from the LLM to the actual function implementations. Args: tool_name: Name of the tool to execute arguments: Tool arguments from the LLM sid: Server ID did: Databa
(
tool_name: str,
arguments: dict,
sid: int,
did: int
)
| 785 | |
| 786 | |
| 787 | def execute_tool( |
| 788 | tool_name: str, |
| 789 | arguments: dict, |
| 790 | sid: int, |
| 791 | did: int |
| 792 | ) -> dict: |
| 793 | """ |
| 794 | Execute a database tool by name. |
| 795 | |
| 796 | This is the dispatcher function that maps tool calls from the LLM |
| 797 | to the actual function implementations. |
| 798 | |
| 799 | Args: |
| 800 | tool_name: Name of the tool to execute |
| 801 | arguments: Tool arguments from the LLM |
| 802 | sid: Server ID |
| 803 | did: Database ID |
| 804 | |
| 805 | Returns: |
| 806 | Dictionary containing the tool result |
| 807 | |
| 808 | Raises: |
| 809 | DatabaseToolError: If the tool execution fails |
| 810 | ValueError: If the tool name is not recognized |
| 811 | """ |
| 812 | if tool_name == "execute_sql_query": |
| 813 | query = arguments.get("query") |
| 814 | if not query: |
| 815 | raise DatabaseToolError( |
| 816 | "Missing required argument: query", |
| 817 | code="INVALID_ARGUMENTS" |
| 818 | ) |
| 819 | return execute_readonly_query(sid, did, query) |
| 820 | |
| 821 | elif tool_name == "get_database_schema": |
| 822 | return get_database_schema(sid, did) |
| 823 | |
| 824 | elif tool_name == "get_table_columns": |
| 825 | schema_name = arguments.get("schema_name") |
| 826 | table_name = arguments.get("table_name") |
| 827 | if not schema_name or not table_name: |
| 828 | raise DatabaseToolError( |
| 829 | "Missing required arguments: schema_name and table_name", |
| 830 | code="INVALID_ARGUMENTS" |
| 831 | ) |
| 832 | return get_table_columns(sid, did, schema_name, table_name) |
| 833 | |
| 834 | elif tool_name == "get_table_info": |
| 835 | schema_name = arguments.get("schema_name") |
| 836 | table_name = arguments.get("table_name") |
| 837 | if not schema_name or not table_name: |
| 838 | raise DatabaseToolError( |
| 839 | "Missing required arguments: schema_name and table_name", |
| 840 | code="INVALID_ARGUMENTS" |
| 841 | ) |
| 842 | return get_table_info(sid, did, schema_name, table_name) |
| 843 | |
| 844 | else: |
no test coverage detected