From d48e82f17ea5243bf903f98b7448096f42f775f7 Mon Sep 17 00:00:00 2001 From: NA-Wen Date: Wed, 11 Mar 2026 12:06:33 +0800 Subject: [PATCH] add tool list routes --- Makefile | 2 +- server/routes/__init__.py | 5 +++-- server/routes/tools.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 server/routes/tools.py diff --git a/Makefile b/Makefile index 6f8dab97..17689ceb 100644 --- a/Makefile +++ b/Makefile @@ -43,4 +43,4 @@ validate-yamls: ## Validate all YAML configuration files help: ## Display this help message @python -c "import re; \ p=r'$(firstword $(MAKEFILE_LIST))'.strip(); \ - [print(f'{m[0]:<20} {m[1]}') for m in re.findall(r'^([a-zA-Z_-]+):.*?## (.*)$$', open(p, encoding='utf-8').read(), re.M)]" | sort + [print(f'{m[0]:<20} {m[1]}') for m in re.findall(r'^([a-zA-Z_-]+):.*?## (.*)$$', open(p, encoding='utf-8').read(), re.M)]" | sort \ No newline at end of file diff --git a/server/routes/__init__.py b/server/routes/__init__.py index c79bb05b..09bcff2d 100755 --- a/server/routes/__init__.py +++ b/server/routes/__init__.py @@ -1,6 +1,6 @@ """Aggregates API routers.""" -from . import artifacts, execute, execute_sync, health, sessions, uploads, vuegraphs, workflows, websocket, batch +from . import artifacts, execute, execute_sync, health, sessions, uploads, vuegraphs, workflows, websocket, batch, tools ALL_ROUTERS = [ health.router, @@ -12,7 +12,8 @@ ALL_ROUTERS = [ batch.router, execute.router, execute_sync.router, + tools.router, websocket.router, ] -__all__ = ["ALL_ROUTERS"] \ No newline at end of file +__all__ = ["ALL_ROUTERS"] diff --git a/server/routes/tools.py b/server/routes/tools.py new file mode 100644 index 00000000..7bc6e0b0 --- /dev/null +++ b/server/routes/tools.py @@ -0,0 +1,29 @@ +from fastapi import APIRouter + +from utils.function_catalog import get_function_catalog + +router = APIRouter() + + +@router.get("/api/tools/local") +def list_local_tools(): + catalog = get_function_catalog() + metadata = catalog.list_metadata() + tools = [] + for name, meta in metadata.items(): + tools.append( + { + "name": name, + "description": meta.description, + "parameters": meta.parameters_schema, + "module": meta.module_name, + "file_path": meta.file_path, + } + ) + tools.sort(key=lambda item: item["name"]) + return { + "success": True, + "count": len(tools), + "tools": tools, + "load_error": str(catalog.load_error) if catalog.load_error else None, + } \ No newline at end of file