aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-12-12 13:18:54 +0800
committerGitHub <noreply@github.com>2024-12-12 13:18:54 +0800
commit40c13b9fa9dd0fab2f2964a32818d0265b545ede (patch)
tree3cca7fad6a20e75b55fc3763d65b3240a549b2bc
parente8ffb414c424a59523f94db5e8aba86b723b5b7e (diff)
downloadllm-functions-docker-40c13b9fa9dd0fab2f2964a32818d0265b545ede.tar.gz
refactor(mcp): improve docs and script (#146)
-rw-r--r--README.md5
-rw-r--r--mcp/bridge/README.md5
-rwxr-xr-x[-rw-r--r--]scripts/mcp.sh29
3 files changed, 27 insertions, 12 deletions
diff --git a/README.md b/README.md
index df3f0f2..21a0d0e 100644
--- a/README.md
+++ b/README.md
@@ -184,6 +184,11 @@ documents:
Refer to [./agents/demo](https://github.com/sigoden/llm-functions/tree/main/agents/demo) for examples of how to implement a agent.
+## MCP (Model Context Protocol)
+
+- [mcp/server](./mcp/server/): Let LLM-Functions tools/agents be used through the Model Context Protocol.
+- [mcp/bridge](./mcp/bridge/): Let external MCP tools be used by LLM-Functions.
+
## License
The project is under the MIT License, Refer to the [LICENSE](https://github.com/sigoden/llm-functions/blob/main/LICENSE) file for detailed information.
diff --git a/mcp/bridge/README.md b/mcp/bridge/README.md
index bffa30c..40bf24c 100644
--- a/mcp/bridge/README.md
+++ b/mcp/bridge/README.md
@@ -1,6 +1,6 @@
# MCP-Bridge
-Let MCP tools be used by LLM functions.
+Let external MCP tools be used by LLM-Functions.
## Get Started
@@ -39,4 +39,5 @@ Let MCP tools be used by LLM functions.
argc mcp start
```
-> Run `argc mcp stop` to stop the bridge server, recover functions.json \ No newline at end of file
+> Run `argc mcp stop` to stop the bridge server, recover functions.json
+> Run `argc mcp logs` to check the server's logs. \ No newline at end of file
diff --git a/scripts/mcp.sh b/scripts/mcp.sh
index e974476..bb83aa3 100644..100755
--- a/scripts/mcp.sh
+++ b/scripts/mcp.sh
@@ -25,8 +25,7 @@ start() {
nohup node "$index_js" "$llm_functions_dir" > "$MCP_DIR/mcp-bridge.log" 2>&1 &
wait-for-server
echo "Merge MCP tools into functions.json"
- merge-functions > "$MCP_DIR/functions.json"
- cp -f "$MCP_DIR/functions.json" "$FUNCTIONS_JSON_PATH"
+ "$0" merge-functions -S
build-bin
}
@@ -40,15 +39,13 @@ stop() {
kill -9 "$pid" > /dev/null 2>&1 || true
fi
fi
- mkdir -p "$MCP_DIR"
- unmerge-functions > "$MCP_DIR/functions.original.json"
- cp -f "$MCP_DIR/functions.original.json" "$FUNCTIONS_JSON_PATH"
+ "$0" recovery-functions -S
}
-# @cmd Call mcp tool
+# @cmd Run the tool
# @arg tool![`_choice_tool`] The tool name
# @arg json The json data
-call() {
+run@tool() {
if [[ -z "$argc_json" ]]; then
declaration="$(build-declarations | jq --arg tool "$argc_tool" -r '.[] | select(.name == $tool)')"
if [[ -n "$declaration" ]]; then
@@ -89,17 +86,29 @@ build-bin() {
}
# @cmd Merge mcp tools into functions.json
+# @flag -S --save Save to functions.json
merge-functions() {
- jq --argjson json1 "$(unmerge-functions)" --argjson json2 "$(build-declarations)" -n '($json1 + $json2)'
+ result="$(jq --argjson json1 "$("$0" recovery-functions)" --argjson json2 "$(build-declarations)" -n '($json1 + $json2)')"
+ if [[ -n "$argc_save" ]]; then
+ printf "%s" "$result" > "$FUNCTIONS_JSON_PATH"
+ else
+ printf "%s" "$result"
+ fi
}
# @cmd Unmerge mcp tools from functions.json
-unmerge-functions() {
+# @flag -S --save Save to functions.json
+recovery-functions() {
functions="[]"
if [[ -f "$FUNCTIONS_JSON_PATH" ]]; then
functions="$(cat "$FUNCTIONS_JSON_PATH")"
fi
- printf "%s" "$functions" | jq 'map(select(has("mcp") | not))'
+ result="$(printf "%s" "$functions" | jq 'map(select(has("mcp") | not))')"
+ if [[ -n "$argc_save" ]]; then
+ printf "%s" "$result" > "$FUNCTIONS_JSON_PATH"
+ else
+ printf "%s" "$result"
+ fi
}
# @cmd Build tools to bin