|
11 | 11 | import jsonref |
12 | 12 | from mcpadapt.smolagents_adapter import _sanitize_function_name |
13 | 13 |
|
14 | | -from consts.const import DEFAULT_USER_ID, LOCAL_MCP_SERVER, DATA_PROCESS_SERVICE |
| 14 | +from consts.const import LOCAL_MCP_SERVER, DATA_PROCESS_SERVICE |
15 | 15 | from consts.exceptions import MCPConnectionError, ToolExecutionException, NotFoundException |
16 | 16 | from consts.model import ToolInstanceInfoRequest, ToolInfo, ToolSourceEnum, ToolValidateRequest |
17 | 17 | from database.remote_mcp_db import get_mcp_records_by_tenant, get_mcp_server_by_name_and_tenant |
|
22 | 22 | update_tool_table_from_scan_tool_list, |
23 | 23 | search_last_tool_instance_by_tool_id, |
24 | 24 | ) |
25 | | -from database.user_tenant_db import get_all_tenant_ids |
26 | 25 | from services.file_management_service import get_llm_model |
27 | 26 | from services.vectordatabase_service import get_embedding_model, get_vector_db_core |
28 | 27 | from services.tenant_config_service import get_selected_knowledge_list, build_knowledge_name_mapping |
@@ -367,71 +366,6 @@ async def list_all_tools(tenant_id: str): |
367 | 366 | return formatted_tools |
368 | 367 |
|
369 | 368 |
|
370 | | -async def initialize_tools_on_startup(): |
371 | | - """ |
372 | | - Initialize and scan all tools during server startup for all tenants |
373 | | - |
374 | | - This function scans all available tools (local, LangChain, and MCP) |
375 | | - and updates the database with the latest tool information for all tenants. |
376 | | - """ |
377 | | - |
378 | | - logger.info("Starting tool initialization on server startup...") |
379 | | - |
380 | | - try: |
381 | | - # Get all tenant IDs from the database |
382 | | - tenant_ids = get_all_tenant_ids() |
383 | | - |
384 | | - if not tenant_ids: |
385 | | - logger.warning("No tenants found in database, skipping tool initialization") |
386 | | - return |
387 | | - |
388 | | - logger.info(f"Found {len(tenant_ids)} tenants: {tenant_ids}") |
389 | | - |
390 | | - total_tools = 0 |
391 | | - successful_tenants = 0 |
392 | | - failed_tenants = [] |
393 | | - |
394 | | - # Process each tenant |
395 | | - for tenant_id in tenant_ids: |
396 | | - try: |
397 | | - logger.info(f"Initializing tools for tenant: {tenant_id}") |
398 | | - |
399 | | - # Add timeout to prevent hanging during startup |
400 | | - try: |
401 | | - await asyncio.wait_for( |
402 | | - update_tool_list(tenant_id=tenant_id, user_id=DEFAULT_USER_ID), |
403 | | - timeout=60.0 # 60 seconds timeout per tenant |
404 | | - ) |
405 | | - |
406 | | - # Get the count of tools for this tenant |
407 | | - tools_info = query_all_tools(tenant_id) |
408 | | - tenant_tool_count = len(tools_info) |
409 | | - total_tools += tenant_tool_count |
410 | | - successful_tenants += 1 |
411 | | - |
412 | | - logger.info(f"Tenant {tenant_id}: {tenant_tool_count} tools initialized") |
413 | | - |
414 | | - except asyncio.TimeoutError: |
415 | | - logger.error(f"Tool initialization timed out for tenant {tenant_id}") |
416 | | - failed_tenants.append(f"{tenant_id} (timeout)") |
417 | | - |
418 | | - except Exception as e: |
419 | | - logger.error(f"Tool initialization failed for tenant {tenant_id}: {str(e)}") |
420 | | - failed_tenants.append(f"{tenant_id} (error: {str(e)})") |
421 | | - |
422 | | - # Log final results |
423 | | - logger.info("Tool initialization completed!") |
424 | | - logger.info(f"Total tools available across all tenants: {total_tools}") |
425 | | - logger.info(f"Successfully processed: {successful_tenants}/{len(tenant_ids)} tenants") |
426 | | - |
427 | | - if failed_tenants: |
428 | | - logger.warning(f"Failed tenants: {', '.join(failed_tenants)}") |
429 | | - |
430 | | - except Exception as e: |
431 | | - logger.error(f"❌ Tool initialization failed: {str(e)}") |
432 | | - raise |
433 | | - |
434 | | - |
435 | 369 | def load_last_tool_config_impl(tool_id: int, tenant_id: str, user_id: str): |
436 | 370 | """ |
437 | 371 | Load the last tool configuration for a given tool ID |
|
0 commit comments