mcp-config: add mcp-sync to force a refresh, ignoring the TTL

The sync runs only at shell start and is throttled to MCP_SYNC_TTL (1h), so a
model added on the gateway can take up to an hour AND a new terminal before
opencode sees it. There was no way to say "fetch it now", so the recurring
symptom was "I added a model and it isn't showing up" -- with a healthy
gateway and a correctly-scoped key.

`mcp-sync` re-sources the hook with the throttle disabled and prints the
resulting model list, so it also answers "what does the client actually have?"
in one step.

README gains a section splitting the two failure modes: a model the gateway
returns but opencode lacks is a stale client; a model the gateway does not
return is a LiteLLM model_list / key-scoping problem.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-13 13:57:49 -04:00
co-authored by Claude Opus 4.8
parent 35befbe1e3
commit cd09df07f6
2 changed files with 56 additions and 1 deletions
+27
View File
@@ -211,4 +211,31 @@ _mcp_sync_skills
# the synced file so it is layered on top of the user's global opencode.json.
[ -f "$MCP_SYNC_DEST" ] && export OPENCODE_CONFIG="$MCP_SYNC_DEST"
# --- mcp-sync: force a refresh now, ignoring the TTL ------------------------
# The automatic sync above runs ONLY at shell start and is throttled to
# MCP_SYNC_TTL (1h). So a model or MCP server added on the gateway can take up
# to an hour AND a new terminal before it shows up in opencode -- which reads
# as "my new model isn't there" when in fact the gateway is fine and the local
# config is just stale. Run `mcp-sync` to pull it immediately.
#
# Defined for the interactive shell (zsh/bash), which is the only place sync.sh
# is sourced; the hyphen in the name is fine there.
MCP_SYNC_SELF="${MCP_SYNC_SELF:-$HOME/.config/mcp-sync/sync.sh}"
mcp-sync() {
[ -f "$MCP_SYNC_SELF" ] || {
printf 'mcp-sync: %s not found\n' "$MCP_SYNC_SELF" >&2; return 1
}
# Re-source with the throttle disabled; this redefines and re-runs everything.
# shellcheck disable=SC1090
MCP_SYNC_TTL=0 . "$MCP_SYNC_SELF" || return 1
command -v python3 >/dev/null 2>&1 || { printf 'mcp-sync: refreshed.\n' >&2; return 0; }
MCP_SYNC_PY_DEST="$MCP_SYNC_DEST" MCP_SYNC_PY_PROVIDER="$MCP_SYNC_PROVIDER" \
python3 - <<'PYEOF' >&2
import json, os
cfg = json.load(open(os.environ["MCP_SYNC_PY_DEST"]))
models = cfg.get("provider", {}).get(os.environ["MCP_SYNC_PY_PROVIDER"], {}).get("models", {})
print(f"mcp-sync: {len(models)} models -> {', '.join(models) or '(none)'}")
PYEOF
}
unset -f _mcp_sync_export_key _mcp_sync_refresh _mcp_sync_skills 2>/dev/null || true