aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run-mcp-tool.sh
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-12-12 12:22:51 +0800
committerGitHub <noreply@github.com>2024-12-12 12:22:51 +0800
commit3584b5c31f4f1f1baa1c350fa46a18752f8bf7c4 (patch)
tree586df9099399c8c8a3a0e9abd85d7d4577726231 /scripts/run-mcp-tool.sh
parent2fc9b476907e6fb830fd57f69d59c794548ad28b (diff)
downloadllm-functions-docker-3584b5c31f4f1f1baa1c350fa46a18752f8bf7c4.tar.gz
feat: support env var `LLM_DUMP_RESULTS` (#144)
Diffstat (limited to 'scripts/run-mcp-tool.sh')
-rwxr-xr-xscripts/run-mcp-tool.sh34
1 files changed, 10 insertions, 24 deletions
diff --git a/scripts/run-mcp-tool.sh b/scripts/run-mcp-tool.sh
index 11d3d0b..08beafd 100755
--- a/scripts/run-mcp-tool.sh
+++ b/scripts/run-mcp-tool.sh
@@ -1,4 +1,7 @@
#!/usr/bin/env bash
+
+# Usage: ./run-mcp-tool.sh <tool-name> <tool-data>
+
set -e
main() {
@@ -53,9 +56,8 @@ run() {
tool_data="$(echo "$tool_data" | sed 's/\\/\\\\/g')"
fi
- no_llm_output=0
if [[ -z "$LLM_OUTPUT" ]]; then
- no_llm_output=1
+ is_temp_llm_output=1
export LLM_OUTPUT="$(mktemp)"
fi
curl -sS "http://localhost:${MCP_BRIDGE_PORT:-8808}/tools/$tool_name" \
@@ -63,40 +65,24 @@ run() {
-H 'content-type: application/json' \
-d "$tool_data" > "$LLM_OUTPUT"
- if [[ "$no_llm_output" -eq 1 ]]; then
+ if [[ "$is_temp_llm_output" -eq 1 ]]; then
cat "$LLM_OUTPUT"
else
- dump_result
+ dump_result "$tool_name"
fi
}
dump_result() {
- if [ ! -t 1 ]; then
+ if [[ "$LLM_OUTPUT" == "/dev/stdout" ]] || [[ -z "$LLM_DUMP_RESULTS" ]] || [[ ! -t 1 ]]; then
return;
fi
-
- local agent_env_name agent_env_value func_env_name func_env_value show_result=0
- agent_env_name="LLM_AGENT_DUMP_RESULT_$(echo "$LLM_AGENT_NAME" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
- agent_env_value="${!agent_env_name:-"$LLM_AGENT_DUMP_RESULT"}"
- func_env_name="${agent_env_name}_$(echo "$LLM_AGENT_FUNC" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
- func_env_value="${!func_env_name}"
- if [[ "$agent_env_value" == "1" || "$agent_env_value" == "true" ]]; then
- if [[ "$func_env_value" != "0" && "$func_env_value" != "false" ]]; then
- show_result=1
- fi
- else
- if [[ "$func_env_value" == "1" || "$func_env_value" == "true" ]]; then
- show_result=1
- fi
- fi
- if [[ "$show_result" -ne 1 ]]; then
- return
- fi
- cat <<EOF
+ if grep -q -w -E "$LLM_DUMP_RESULTS" <<<"$1"; then
+ cat <<EOF
$(echo -e "\e[2m")----------------------
$(cat "$LLM_OUTPUT")
----------------------$(echo -e "\e[0m")
EOF
+ fi
}
main "$@"