lmcp-tool: auto-map a bare http(s):// positional arg to url=
Agents (esp. small models) keep calling `fetch_url https://...` positionally
instead of `fetch_url url="https://..."`. The key=value parser turned a bare
URL into {"<url>":""} with no `url` key, so the server rejected it with the
misleading "url must start with http:// or https://". Now a lone http(s)://
positional is mapped to url=, killing this recurring pi-agent failure. Explicit
key=value and raw-JSON forms are unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EWpfhDgYNA21tETDP9ueBE
This commit is contained in:
+11
-1
@@ -7,6 +7,7 @@
|
|||||||
#
|
#
|
||||||
# lmcp-tool list # DISCOVERY: available tools + descriptions
|
# lmcp-tool list # DISCOVERY: available tools + descriptions
|
||||||
# lmcp-tool <tool> key=value [key=value ...] # args as pairs — NO json-in-shell (apostrophe-safe)
|
# lmcp-tool <tool> key=value [key=value ...] # args as pairs — NO json-in-shell (apostrophe-safe)
|
||||||
|
# lmcp-tool fetch_url https://example.com # a bare http(s):// arg is auto-mapped to url=
|
||||||
# lmcp-tool <tool> '{"k":"v"}' # raw JSON (single arg starting with '{')
|
# lmcp-tool <tool> '{"k":"v"}' # raw JSON (single arg starting with '{')
|
||||||
#
|
#
|
||||||
# Prefer key=value: `sic host lmcp-tool web_search "query=today's news"` — an apostrophe
|
# Prefer key=value: `sic host lmcp-tool web_search "query=today's news"` — an apostrophe
|
||||||
@@ -59,7 +60,16 @@ elif [ $# -eq 1 ] && [ "${1#\{}" != "$1" ]; then
|
|||||||
args="$1" # single arg starting with '{' = raw JSON
|
args="$1" # single arg starting with '{' = raw JSON
|
||||||
else
|
else
|
||||||
args=$(python3 -c 'import sys, json
|
args=$(python3 -c 'import sys, json
|
||||||
print(json.dumps({a.partition("=")[0]: a.partition("=")[2] for a in sys.argv[1:]}))' "$@") \
|
args = {}
|
||||||
|
for a in sys.argv[1:]:
|
||||||
|
if "=" in a:
|
||||||
|
k, _, v = a.partition("=")
|
||||||
|
args[k] = v
|
||||||
|
elif a.startswith(("http://", "https://")):
|
||||||
|
args["url"] = a # bare URL -> url= (agents keep passing it positionally)
|
||||||
|
else:
|
||||||
|
args[a] = ""
|
||||||
|
print(json.dumps(args))' "$@") \
|
||||||
|| { echo "lmcp-tool: could not build args from key=value pairs" >&2; exit 2; }
|
|| { echo "lmcp-tool: could not build args from key=value pairs" >&2; exit 2; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user