aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-12-13 08:20:51 +0800
committerGitHub <noreply@github.com>2024-12-13 08:20:51 +0800
commit8ace93beb813a431b4f26e277f8c0bcebdfa8511 (patch)
treef654dafb8e28347bf7f2f503e72cfdaf5ed9e5a5
parent8e8b2f736b8e635396e713e219c8fe8575a6f491 (diff)
downloadllm-functions-docker-8ace93beb813a431b4f26e277f8c0bcebdfa8511.tar.gz
feat(mcp): add LLM_MCP_NEED_CONFIRM and LLM_MCP_SKIP_CONFIRM (#149)
-rw-r--r--docs/environment-variables.md8
-rwxr-xr-xscripts/run-mcp-tool.sh19
2 files changed, 24 insertions, 3 deletions
diff --git a/docs/environment-variables.md b/docs/environment-variables.md
index a3216b9..4d86ea5 100644
--- a/docs/environment-variables.md
+++ b/docs/environment-variables.md
@@ -21,6 +21,8 @@
## Provided by users
-| Name | Description |
-| ------------------ | --------------------------------------------------------------------------------------------- |
-| `LLM_DUMP_RESULTS` | Controls whether to print the execution results of the tool, e.g. `get_current_weather\|fs.*\|todo:.*`, `.*` |
+| Name | Description |
+| ---------------------- | ------------------------------------------------------------------------------------------------------------ |
+| `LLM_DUMP_RESULTS` | Controls whether to print the execution results of the tool, e.g. `get_current_weather\|fs.*\|todo:.*`, `.*` |
+| `LLM_MCP_NEED_CONFIRM`| Controls whether to prompt for confirmation before executing certain tools, e.g., `git_commit\|git_reset`, `.*` . |
+| `LLM_MCP_SKIP_CONFIRM`| Controls whether to bypass confirmation requests for certain tools, e.g., `git_status\|git_diff.*`, `.*` . | \ No newline at end of file
diff --git a/scripts/run-mcp-tool.sh b/scripts/run-mcp-tool.sh
index 08beafd..fb987e1 100755
--- a/scripts/run-mcp-tool.sh
+++ b/scripts/run-mcp-tool.sh
@@ -60,6 +60,25 @@ run() {
is_temp_llm_output=1
export LLM_OUTPUT="$(mktemp)"
fi
+
+ if [[ -n "$LLM_MCP_SKIP_CONFIRM" ]]; then
+ if grep -q -w -E "$LLM_MCP_SKIP_CONFIRM" <<<"$tool_name"; then
+ skip_confirm=1
+ fi
+ fi
+ if [[ -n "$LLM_MCP_NEED_CONFIRM" ]]; then
+ if grep -q -w -E "$LLM_MCP_NEED_CONFIRM" <<<"$tool_name"; then
+ skip_confirm=0
+ fi
+ fi
+ if [[ -t 1 ]] && [[ "$skip_confirm" -ne 1 ]]; then
+ read -r -p "Are you sure you want to continue? [Y/n] " ans
+ if [[ "$ans" == "N" || "$ans" == "n" ]]; then
+ echo "error: canceld!" 2>&1
+ exit 1
+ fi
+ fi
+
curl -sS "http://localhost:${MCP_BRIDGE_PORT:-8808}/tools/$tool_name" \
-X POST \
-H 'content-type: application/json' \