Skip to content

Keep Sharesight's portfolio list and single-day reports warm - #27

Merged
robdevops merged 2 commits into
mainfrom
claude/keep-cache-warm
Oct 8, 2026
Merged

robdevops merged 2 commits into
mainfrom
claude/keep-cache-warm

Conversation

@robdevops

Copy link
Copy Markdown
Owner

Summary

A keep_warm option on MCP servers refetches cached results in the background just before the 30-minute cache_ttl expires, so asking about a portfolio never waits on a cold fetch. Sharesight is configured with {"list_portfolios": null, "get_performance_report": 0}: the portfolio list always, and get_performance_report only for a single-day window (start_date equal to end_date).

Behaviour

  • An entry is refetched about 30 seconds before it expires, but only if someone asked for it since it was last fetched. A query nobody repeats is dropped at the next expiry, so it stops costing API calls.
  • A refetch that fails or returns an error drops the entry, and the next real request fetches it again.
  • Calls outside the window rule (longer windows, undated reports) are still cached for the full TTL, just never refreshed. That includes the daily holding-news check, which asks for a portfolio with no dates.
  • keep_warm takes a list of tool names or {tool: longest start_date..end_date window in days, 0 = a single day}. A name that matches no tool is warned about, like blocked_tools.

Files

  • lib/mcp/server.py: cache entries carry their tool and arguments; a background loop runs while the server is connected. The module is now 325 lines, a little over the ~300 guideline.
  • mcp_servers.json, README.md: config and documentation.
  • tests/test_mcp.py: refresh before expiry and serving the refreshed copy, idle entries dropped, window rule for days 0 and 1, failed refresh, unknown name warning, shipped config pinned.

Test plan

  • make check on Python 3.13.5 (ruff + pytest): 220 passed
  • CI check job on this PR
  • Live Sharesight behaviour is not exercised (no network in tests)

🤖 Generated with Claude Code

https://claude.ai/code/session_014k4kywyN5dAo39izUPvxbw


Generated by Claude Code

claude added 2 commits October 8, 2026 03:13
keep_warm on the sharesight server: list_portfolios, and get_performance_report only for a
start_date..end_date window of at most one day. Those results are refetched in the background
just before the 30-minute cache expires, but only while someone asked for them since the last
fetch (an idle query is dropped, so it stops costing API calls). A failed refresh drops the entry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014k4kywyN5dAo39izUPvxbw
get_performance_report is kept warm only when start_date equals end_date. Tests cover both limits.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014k4kywyN5dAo39izUPvxbw
@robdevops
robdevops merged commit b8955df into main Oct 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants