7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
feat(mcp): provider_list, quota_outlook and clear_cache tools (#1513)
suantea (asuan_suan)20a1c4fc4009
diff --git a/server/src/__tests__/routes/mcp.test.ts b/server/src/__tests__/routes/mcp.test.tsindex 15b8f14d..531f976d 100644--- a/server/src/__tests__/routes/mcp.test.ts+++ b/server/src/__tests__/routes/mcp.test.ts@@ -134,10 +134,13 @@ describe('MCP server (/mcp, stateless Streamable HTTP)', () => {expect(names).toEqual(['ask_freellmapi','cache_stats',+ 'clear_cache','compression_stats','healthcheck','list_models','provider_health',+ 'provider_list',+ 'quota_outlook','routing_info','set_routing_strategy','usage_summary',@@ -147,7 +150,10 @@ describe('MCP server (/mcp, stateless Streamable HTTP)', () => {expect(tool.title.length).toBeGreaterThan(5);expect(tool.description.length).toBeGreaterThan(20);expect(tool.inputSchema.type).toBe('object');- expect(tool.annotations.destructiveHint).toBe(false);+ // clear_cache is the one intentionally destructive tool; all others are safe.+ if (tool.name !== 'clear_cache') {+ expect(tool.annotations.destructiveHint).toBe(false);+ }expect(typeof tool.annotations.readOnlyHint).toBe('boolean');expect(typeof tool.annotations.openWorldHint).toBe('boolean');}@@ -192,7 +198,7 @@ describe('MCP server (/mcp, stateless Streamable HTTP)', () => {});it('usage, health, cache, and compression stats answer on an empty install', async () => {- for (const name of ['healthcheck', 'usage_summary', 'provider_health', 'cache_stats', 'compression_stats']) {+ for (const name of ['healthcheck', 'usage_summary', 'provider_health', 'cache_stats', 'compression_stats', 'quota_outlook']) {const { body } = await rpc({ jsonrpc: '2.0', id: 7, method: 'tools/call', params: { name } });expect(body.result.content[0].type).toBe('text');expect(body.result.structuredContent).toEqual(toolResultJson(body));diff --git a/server/src/routes/mcp.ts b/server/src/routes/mcp.tsindex b2cc5ada..95605f86 100644--- a/server/src/routes/mcp.ts+++ b/server/src/routes/mcp.ts@@ -7,8 +7,9 @@ import { buildModelListing } from '../services/model-listing.js';import { supportedParametersForPlatforms } from '../lib/sampling-params.js';import { getRoutingScores, getRoutingStrategy, setRoutingStrategy } from '../services/router.js';import type { RoutingStrategy } from '../services/scoring.js';-import { getCacheStats } from '../services/cache.js';+import { getCacheStats, clearCache } from '../services/cache.js';import { getCompressionStats } from '../services/compression/stats.js';+import { getQuotaOutlook } from '../services/quota-outlook.js';import { sanitizeProviderErrorMessage } from '../lib/error-redaction.js';import { z } from 'zod';@@ -130,6 +131,39 @@ function providerHealth(): unknown {return Object.fromEntries([...byPlatform.entries()].sort(([a], [b]) => a.localeCompare(b)));}+function providerList(): unknown {+ const db = getDb();+ const keys = db.prepare(`+ SELECT platform, COUNT(*) AS n,+ SUM(CASE WHEN status = 'healthy' THEN 1 ELSE 0 END) AS healthy,+ SUM(CASE WHEN status = 'rate_limited' THEN 1 ELSE 0 END) AS rate_limited,+ SUM(CASE WHEN status = 'invalid' THEN 1 ELSE 0 END) AS invalid,+ SUM(CASE WHEN status = 'error' THEN 1 ELSE 0 END) AS error+ FROM api_keys WHERE enabled = 1+ GROUP BY platform+ ORDER BY platform+ `).all() as Array<{ platform: string; n: number; healthy: number; rate_limited: number; invalid: number; error: number }>;+ return keys.map(k => ({+ platform: k.platform,+ total_keys: k.n,+ healthy: k.healthy,+ rate_limited: k.rate_limited,+ invalid: k.invalid,+ error: k.error,+ }));+}++function clearCacheTool(): unknown {+ const n = clearCache();+ return { cleared_entries: n };+}++// Forecasting which free pools are about to run dry is the single most useful+// thing an agent can ask before committing to a long task on the free tier.+function quotaOutlook(): unknown {+ return getQuotaOutlook();+}+const USAGE_RANGES: Record<string, number> = { '24h': 24, '7d': 24 * 7, '30d': 24 * 30 };function usageSummary(args: Record<string, unknown>): unknown {@@ -515,6 +549,27 @@ const TOOLS: Record<string, McpTool> = {annotations: READ_ONLY_LOCAL,run: () => getCompressionStats(),},+ provider_list: {+ title: 'List providers and key status',+ description: 'All platforms with enabled API keys, showing total keys and per-status breakdown (healthy/rate_limited/invalid/error).',+ inputSchema: { type: 'object', properties: {} },+ annotations: READ_ONLY_LOCAL,+ run: () => providerList(),+ },+ clear_cache: {+ title: 'Clear response cache',+ description: 'Flush all cached responses. Returns the number of entries removed.',+ inputSchema: { type: 'object', properties: {} },+ annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false },+ run: () => clearCacheTool(),+ },+ quota_outlook: {+ title: 'Forecast free-tier quota',+ description: 'Per-pool free-tier quota: remaining requests, observed burn rate, estimated exhaustion time, and warnings (exhausting_soon/low_balance). Use before long or token-heavy tasks to see which providers may run dry.',+ inputSchema: { type: 'object', properties: {} },+ annotations: READ_ONLY_LOCAL,+ run: () => quotaOutlook(),+ },};// ── JSON-RPC dispatch ────────────────────────────────────────────────────@@ -538,7 +593,7 @@ async function dispatchRpc(msg: JsonRpcRequest, id: number | string | null, req:protocolVersion: PROTOCOL_VERSION,capabilities: { tools: {} },serverInfo: { name: 'freellmapi', version: '1.0.0' },- instructions: 'Use ask_freellmapi when the user explicitly asks FreeLLMAPI or one of its models to perform a text task. Use healthcheck before troubleshooting availability; list_models for model choice; provider_health, usage_summary, cache_stats, compression_stats, and routing_info for diagnostics. set_routing_strategy changes server state. web_search searches the web through the configured search providers.',+ instructions: 'Use ask_freellmapi when the user explicitly asks FreeLLMAPI or one of its models to perform a text task. Use healthcheck before troubleshooting availability; list_models for model choice; provider_health, provider_list, usage_summary, cache_stats, compression_stats, quota_outlook, and routing_info for diagnostics. set_routing_strategy changes server state. web_search searches the web through the configured search providers. clear_cache flushes cached responses.',});}case 'ping':