From c84e6d6db5c637ad8aacfdd41cf96fc1d2b85cec Mon Sep 17 00:00:00 2001 From: Evan Huus Date: Mon, 4 May 2026 06:19:41 -0400 Subject: [PATCH] server: Add a simple get_datetime server tool (#22649) --- common/arg.cpp | 2 +- tools/server/README.md | 2 +- tools/server/server-tools.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/common/arg.cpp b/common/arg.cpp index dd8ce40a6..8f54ee38c 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -2864,7 +2864,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex {"--tools"}, "TOOL1,TOOL2,...", "experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)\n" "specify \"all\" to enable all tools\n" - "available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff", + "available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff, get_datetime", [](common_params & params, const std::string & value) { params.server_tools = parse_csv_row(value); } diff --git a/tools/server/README.md b/tools/server/README.md index eda875951..a0cfdbb6f 100644 --- a/tools/server/README.md +++ b/tools/server/README.md @@ -191,7 +191,7 @@ For the full list of features, please refer to [server's changelog](https://gith | `--webui-config JSON` | JSON that provides default WebUI settings (overrides WebUI defaults)
(env: LLAMA_ARG_WEBUI_CONFIG) | | `--webui-config-file PATH` | JSON file that provides default WebUI settings (overrides WebUI defaults)
(env: LLAMA_ARG_WEBUI_CONFIG_FILE) | | `--webui-mcp-proxy, --no-webui-mcp-proxy` | experimental: whether to enable MCP CORS proxy - do not enable in untrusted environments (default: disabled)
(env: LLAMA_ARG_WEBUI_MCP_PROXY) | -| `--tools TOOL1,TOOL2,...` | experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)
specify "all" to enable all tools
available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff
(env: LLAMA_ARG_TOOLS) | +| `--tools TOOL1,TOOL2,...` | experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)
specify "all" to enable all tools
available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, apply_diff, get_datetime
(env: LLAMA_ARG_TOOLS) | | `--webui, --no-webui` | whether to enable the Web UI (default: enabled)
(env: LLAMA_ARG_WEBUI) | | `--embedding, --embeddings` | restrict to only support embedding use case; use only with dedicated embedding models (default: disabled)
(env: LLAMA_ARG_EMBEDDINGS) | | `--rerank, --reranking` | enable reranking endpoint on server (default: disabled)
(env: LLAMA_ARG_RERANKING) | diff --git a/tools/server/server-tools.cpp b/tools/server/server-tools.cpp index 81e360de4..49bec4be4 100644 --- a/tools/server/server-tools.cpp +++ b/tools/server/server-tools.cpp @@ -693,6 +693,35 @@ struct server_tool_apply_diff : server_tool { } }; +// +// get_datetime: returns the current date and time +// + +struct server_tool_get_datetime : server_tool { + server_tool_get_datetime() { + name = "get_datetime"; + display_name = "Get Date & Time"; + permission_write = false; + } + + json get_definition() override { + return { + {"type", "function"}, + {"function", { + {"name", name}, + {"description", "Returns the current date and time"}, + }}, + }; + } + + json invoke(json) override { + auto now = std::chrono::system_clock::now(); + auto time = std::chrono::system_clock::to_time_t(now); + + return {{"result", std::ctime(&time)}}; + } +}; + // // public API // @@ -706,6 +735,7 @@ static std::vector> build_tools() { tools.push_back(std::make_unique()); tools.push_back(std::make_unique()); tools.push_back(std::make_unique()); + tools.push_back(std::make_unique()); return tools; }