From 131f54379dbb70a4091c0f8dcee4816dea0dd23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=96=93=E5=B6=8B=20=E5=B0=86=E5=B9=B3?= Date: Thu, 18 Sep 2025 12:29:56 +0900 Subject: [PATCH] feat: add archived records support to SOQL query tool --- tools/soql_query.py | 21 ++++++++++++++------- tools/soql_query.yaml | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/tools/soql_query.py b/tools/soql_query.py index bade4ed..e3632e7 100644 --- a/tools/soql_query.py +++ b/tools/soql_query.py @@ -31,7 +31,9 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag session_manager = SalesforceSessionManager(username, password_with_token, login_url, self.session.storage) soql_query = tool_parameters.get("soql_query", "").strip() + include_archived = tool_parameters.get("include_archived", False) logger.info(f"SOQL query to execute: {soql_query[:100]}{'...' if len(soql_query) > 100 else ''}") + logger.info(f"Include archived records: {include_archived}") if not soql_query: logger.error("SOQL query is empty") @@ -48,8 +50,10 @@ def make_api_call(session_id: str, instance_url: str) -> requests.Response: } encoded_query = urllib.parse.quote(soql_query) - url = f"{instance_url}/services/data/v63.0/query?q={encoded_query}" - logger.info(f"Making Salesforce API call to: {instance_url}/services/data/v63.0/query") + # Use queryAll endpoint for archived records, standard query endpoint otherwise + endpoint = "queryAll" if include_archived else "query" + url = f"{instance_url}/services/data/v63.0/{endpoint}?q={encoded_query}" + logger.info(f"Making Salesforce API call to: {instance_url}/services/data/v63.0/{endpoint}") return requests.get(url, headers=headers, timeout=30) try: @@ -87,15 +91,18 @@ def make_api_call(session_id: str, instance_url: str) -> requests.Response: "totalSize": result_data.get("totalSize", 0), "done": result_data.get("done", True), "records": result_data.get("records", []), - "query": soql_query + "query": soql_query, + "includeArchived": include_archived } if formatted_result["totalSize"] > 0: - summary = f"Query executed successfully. Found {formatted_result['totalSize']} record(s)." - logger.info(f"SOQL query completed successfully, found {formatted_result['totalSize']} records") + archive_info = " (including archived records)" if include_archived else "" + summary = f"Query executed successfully. Found {formatted_result['totalSize']} record(s){archive_info}." + logger.info(f"SOQL query completed successfully, found {formatted_result['totalSize']} records{archive_info}") else: - summary = "Query executed successfully. No records found." - logger.info("SOQL query completed successfully, no records found") + archive_info = " (including archived records)" if include_archived else "" + summary = f"Query executed successfully. No records found{archive_info}." + logger.info(f"SOQL query completed successfully, no records found{archive_info}") yield self.create_text_message(summary) yield self.create_json_message(formatted_result) diff --git a/tools/soql_query.yaml b/tools/soql_query.yaml index eb9cff5..5cc140f 100644 --- a/tools/soql_query.yaml +++ b/tools/soql_query.yaml @@ -25,6 +25,20 @@ parameters: pt_BR: A consulta para executar no Salesforce. Deve usar sintaxe SOQL válida. llm_description: The SOQL query string to execute against Salesforce. Must use valid SOQL syntax. Example queries - SELECT Id, Name FROM Account LIMIT 10; SELECT Id, Email FROM Contact WHERE Name = 'John Doe'; SELECT Id, Channel_Type__c FROM Holistic_Engagement__c WHERE Person__r.Contact__r.Name = 'John Doe' LIMIT 10 form: llm + - name: include_archived + type: boolean + required: false + default: false + label: + en_US: Include Archived Records + zh_Hans: 包含已归档记录 + pt_BR: Incluir Registros Arquivados + human_description: + en_US: Whether to include archived/deleted records in the query results. When enabled, uses queryAll endpoint to retrieve all records including archived ones. + zh_Hans: 是否在查询结果中包含已归档/已删除的记录。启用时,使用 queryAll 端点检索包括已归档记录在内的所有记录。 + pt_BR: Se deve incluir registros arquivados/excluídos nos resultados da consulta. Quando habilitado, usa o endpoint queryAll para recuperar todos os registros, incluindo os arquivados. + llm_description: Set to true to include archived and deleted records in the query results. This uses Salesforce's queryAll endpoint instead of the standard query endpoint. Useful for retrieving historical data or archived records. + form: form extra: python: source: tools/soql_query.py @@ -43,3 +57,6 @@ output_schema: query: type: string description: The original SOQL query that was executed + includeArchived: + type: boolean + description: Whether archived records were included in the query results