Skip to content

Tharga.Cache.Mcp: expose cache via MCP#41

Merged
poxet merged 8 commits intomasterfrom
develop
May 3, 2026
Merged

Tharga.Cache.Mcp: expose cache via MCP#41
poxet merged 8 commits intomasterfrom
develop

Conversation

@poxet
Copy link
Copy Markdown
Contributor

@poxet poxet commented May 3, 2026

Summary

New package Tharga.Cache.Mcp that plugs into Tharga.Mcp and exposes the cache to MCP-aware AI clients.

Closes the cross-project request "MCP Provider for Cache monitoring" (Quilt4Net Server / PlutusWave / Florida / Eplicta).

Registration

builder.Services.AddCache(/* ... */);
builder.Services.AddThargaMcp(mcp => mcp.AddCache());
// ...
app.UseThargaMcp();

The naming follows the established AddMongoDB / AddPlatform / AddCommunication pattern on IThargaMcpBuilder (the request mentioned AddMcpCache() but consistency wins).

Resources

URI Description
cache://types Per type: name, persist backend (Memory/Redis/MongoDB/File), item count, total size, StaleWhileRevalidate, ReturnDefaultOnFirstLoad
cache://items Flat list of items: type, key, size, fresh span, expires, last accessed, access count, load duration, stale flag
cache://health Connectivity status of each persistence backend (ICacheMonitor.GetHealthTypes())
cache://queue Current fetch queue depth

Tools

Name Action
cache.clear_stale ICacheMonitor.ClearStale()
cache.clear_all ICacheMonitor.ClearAll()

Deferred (out of scope for v1)

  • Per-key cache.evict — would need a new method on ICacheMonitor (e.g. EvictAsync(Type, Key)) or a reflective hack via IEternalCache.DropAsync<T>(key). Add when a consumer asks.
  • Hit/miss countersCacheItemInfo only tracks AccessCount (total reads). True hit/miss tracking requires new instrumentation in CacheBase/CacheMonitor. Separate change.

Other changes

  • New project Tharga.Cache.Mcp/ (net8/9/10), README, added to solution.
  • WebApi sample wired up at /mcp (RequireAuth=false for the demo).
  • CI workflow packs Tharga.Cache.Mcp in both stable and pre-release Pack steps.
  • 10 new unit tests in Tharga.Cache.Tests.

Test plan

  • CI build is green (453 tests with the Integration/TimeCritical filter).
  • Run the WebApi sample, hit /mcp with an MCP client, verify the four resources read and both tools execute.
  • After approval, Tharga.Cache.Mcp v0.5.x publishes to NuGet alongside the other packages.

poxet added 8 commits May 3, 2026 11:41
- AddCache() extension on IThargaMcpBuilder registers both providers.
- CacheResourceProvider exposes four System-scope resources:
  cache://types, cache://items, cache://health, cache://queue.
- CacheToolProvider exposes two System-scope tools:
  cache.clear_stale and cache.clear_all.
- Persist type names are surfaced with the leading 'I' stripped
  (Memory/Redis/MongoDB/File) to match the Blazor UI convention.
10 tests covering:
- Resource provider: lists 4 descriptors; each resource read returns
  well-formed JSON (types, items, health, queue); unknown URI returns
  explanatory text.
- Tool provider: lists 2 tools; clear_stale and clear_all delegate to
  ICacheMonitor; unknown tool returns IsError=true.

Tharga.Cache.Tests now references Tharga.Cache.Mcp directly to keep
the MCP tests alongside the rest of the unit tests.
The sample now exposes the cache via MCP at /mcp:
- AddThargaMcp(mcp => { mcp.Options.RequireAuth = false; mcp.AddCache(); })
- app.UseThargaMcp()

RequireAuth is set to false so the sample is reachable without auth
middleware. Production consumers leave it true and wire their own
authorization.
Per the updated shared-instructions, completed features live in the
project's Plan directory ($DOC_ROOT/Tharga/plans/Toolkit/Cache/done/),
not inside the repo's .claude/. Moved all 9 archived feature files out
and deleted the now-empty .claude/features-done/ folder.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

@poxet poxet merged commit 1901bc6 into master May 3, 2026
4 of 5 checks passed
@poxet poxet deleted the develop branch May 3, 2026 10:10
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.

1 participant