mcp-config: request /v1/model/info, so a versioned-route grant actually works
A virtual key's allowed_routes is matched on the exact path: granting "/v1/model/info" does not also grant "/model/info". MCP_SYNC_GATEWAY has no /v1 suffix, so this asked for the UNVERSIONED path — meaning a key scoped to the versioned route still got a 403, still fell back to names-only, and still produced a config with no context limits, with nothing in the output to say so. Two correct-looking pieces of config that did not meet. Tries the versioned path first and falls back to the unversioned one, so it works whichever way a key happens to be scoped. With the route granted this now discovers limits live instead of leaning on the base-config floor. The floor stays: it is what keeps opencode correct if the key ever loses the route again, and live values override it field by field. Verified that the two agree — discovery returns exactly the 195584 / 261120 the floor declares — and the Claude models, which the floor does not cover, picked up 998976 and 198976 for the first time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FoDK4wwB1Twty5gwiriYLf
This commit is contained in:
+13
-2
@@ -212,10 +212,21 @@ _mcp_sync_refresh() {
|
|||||||
# context limit, and won't know a model can call tools). /model/info has
|
# context limit, and won't know a model can call tools). /model/info has
|
||||||
# them. Best-effort: a key still scoped to llm_api_routes 403s here, and
|
# them. Best-effort: a key still scoped to llm_api_routes 403s here, and
|
||||||
# we fall back to names-only, exactly as before.
|
# we fall back to names-only, exactly as before.
|
||||||
|
# VERSIONED PATH FIRST. LiteLLM serves this metadata at both /model/info and
|
||||||
|
# /v1/model/info, but a virtual key's allowed_routes is matched on the exact
|
||||||
|
# path — granting "/v1/model/info" does NOT also grant "/model/info". Since
|
||||||
|
# MCP_SYNC_GATEWAY has no /v1 suffix, the unversioned path is what this used
|
||||||
|
# to request, so a key scoped to the versioned route still got a 403 and
|
||||||
|
# still silently fell back to names-only. Try both, versioned first, so it
|
||||||
|
# works whichever way the key is scoped.
|
||||||
_info=""
|
_info=""
|
||||||
if [ -n "${LITELLM_KEY:-}" ]; then
|
if [ -n "${LITELLM_KEY:-}" ]; then
|
||||||
_info="$(curl -fsS -m 8 -H "Authorization: Bearer $LITELLM_KEY" \
|
for _mi_path in /v1/model/info /model/info; do
|
||||||
"$MCP_SYNC_GATEWAY/model/info" 2>/dev/null)" || _info=""
|
_info="$(curl -fsS -m 8 -H "Authorization: Bearer $LITELLM_KEY" \
|
||||||
|
"$MCP_SYNC_GATEWAY$_mi_path" 2>/dev/null)" || _info=""
|
||||||
|
[ -n "$_info" ] && break
|
||||||
|
done
|
||||||
|
unset _mi_path
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Merge and deploy. python3 validates the base (don't clobber good config
|
# 3. Merge and deploy. python3 validates the base (don't clobber good config
|
||||||
|
|||||||
Reference in New Issue
Block a user