@qmediat.io/gemini-code-context-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/LICENSE +21 -0
- package/README.md +159 -0
- package/dist/auth/credentials-store.d.ts +47 -0
- package/dist/auth/credentials-store.d.ts.map +1 -0
- package/dist/auth/credentials-store.js +215 -0
- package/dist/auth/credentials-store.js.map +1 -0
- package/dist/auth/fingerprint.d.ts +8 -0
- package/dist/auth/fingerprint.d.ts.map +1 -0
- package/dist/auth/fingerprint.js +12 -0
- package/dist/auth/fingerprint.js.map +1 -0
- package/dist/auth/init-command.d.ts +9 -0
- package/dist/auth/init-command.d.ts.map +1 -0
- package/dist/auth/init-command.js +279 -0
- package/dist/auth/init-command.js.map +1 -0
- package/dist/auth/profile-loader.d.ts +28 -0
- package/dist/auth/profile-loader.d.ts.map +1 -0
- package/dist/auth/profile-loader.js +107 -0
- package/dist/auth/profile-loader.js.map +1 -0
- package/dist/cache/cache-manager.d.ts +78 -0
- package/dist/cache/cache-manager.d.ts.map +1 -0
- package/dist/cache/cache-manager.js +364 -0
- package/dist/cache/cache-manager.js.map +1 -0
- package/dist/cache/files-uploader.d.ts +42 -0
- package/dist/cache/files-uploader.d.ts.map +1 -0
- package/dist/cache/files-uploader.js +176 -0
- package/dist/cache/files-uploader.js.map +1 -0
- package/dist/cache/ttl-watcher.d.ts +21 -0
- package/dist/cache/ttl-watcher.d.ts.map +1 -0
- package/dist/cache/ttl-watcher.js +75 -0
- package/dist/cache/ttl-watcher.js.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +34 -0
- package/dist/config.js.map +1 -0
- package/dist/gemini/client.d.ts +7 -0
- package/dist/gemini/client.d.ts.map +1 -0
- package/dist/gemini/client.js +19 -0
- package/dist/gemini/client.js.map +1 -0
- package/dist/gemini/model-registry.d.ts +25 -0
- package/dist/gemini/model-registry.d.ts.map +1 -0
- package/dist/gemini/model-registry.js +70 -0
- package/dist/gemini/model-registry.js.map +1 -0
- package/dist/gemini/models.d.ts +23 -0
- package/dist/gemini/models.d.ts.map +1 -0
- package/dist/gemini/models.js +98 -0
- package/dist/gemini/models.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/globs.d.ts +25 -0
- package/dist/indexer/globs.d.ts.map +1 -0
- package/dist/indexer/globs.js +210 -0
- package/dist/indexer/globs.js.map +1 -0
- package/dist/indexer/hasher.d.ts +31 -0
- package/dist/indexer/hasher.d.ts.map +1 -0
- package/dist/indexer/hasher.js +61 -0
- package/dist/indexer/hasher.js.map +1 -0
- package/dist/indexer/workspace-scanner.d.ts +27 -0
- package/dist/indexer/workspace-scanner.d.ts.map +1 -0
- package/dist/indexer/workspace-scanner.js +77 -0
- package/dist/indexer/workspace-scanner.js.map +1 -0
- package/dist/manifest/db.d.ts +38 -0
- package/dist/manifest/db.d.ts.map +1 -0
- package/dist/manifest/db.js +223 -0
- package/dist/manifest/db.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +117 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/ask.tool.d.ts +34 -0
- package/dist/tools/ask.tool.d.ts.map +1 -0
- package/dist/tools/ask.tool.js +216 -0
- package/dist/tools/ask.tool.js.map +1 -0
- package/dist/tools/clear.tool.d.ts +15 -0
- package/dist/tools/clear.tool.d.ts.map +1 -0
- package/dist/tools/clear.tool.js +31 -0
- package/dist/tools/clear.tool.js.map +1 -0
- package/dist/tools/code.tool.d.ts +42 -0
- package/dist/tools/code.tool.d.ts.map +1 -0
- package/dist/tools/code.tool.js +327 -0
- package/dist/tools/code.tool.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +14 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +37 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +16 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/reindex.tool.d.ts +21 -0
- package/dist/tools/reindex.tool.d.ts.map +1 -0
- package/dist/tools/reindex.tool.js +62 -0
- package/dist/tools/reindex.tool.js.map +1 -0
- package/dist/tools/status.tool.d.ts +15 -0
- package/dist/tools/status.tool.d.ts.map +1 -0
- package/dist/tools/status.tool.js +105 -0
- package/dist/tools/status.tool.js.map +1 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cost-estimator.d.ts +32 -0
- package/dist/utils/cost-estimator.d.ts.map +1 -0
- package/dist/utils/cost-estimator.js +83 -0
- package/dist/utils/cost-estimator.js.map +1 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +21 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +20 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +41 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/progress.d.ts +16 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +47 -0
- package/dist/utils/progress.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `status` tool — snapshot of cache state and cost savings for a workspace.
|
|
3
|
+
*/
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { listAvailableModels } from '../gemini/model-registry.js';
|
|
7
|
+
import { microsToDollars } from '../utils/cost-estimator.js';
|
|
8
|
+
import { errorResult, textResult } from './registry.js';
|
|
9
|
+
export const statusInputSchema = z.object({
|
|
10
|
+
workspace: z.string().optional().describe('Workspace path (default: cwd).'),
|
|
11
|
+
});
|
|
12
|
+
function formatTtl(expiresAt) {
|
|
13
|
+
if (expiresAt === null)
|
|
14
|
+
return '—';
|
|
15
|
+
const diff = expiresAt - Date.now();
|
|
16
|
+
if (diff <= 0)
|
|
17
|
+
return 'expired';
|
|
18
|
+
const mins = Math.floor(diff / 60000);
|
|
19
|
+
const hours = Math.floor(mins / 60);
|
|
20
|
+
return hours > 0 ? `${hours}h ${mins % 60}m` : `${mins}m`;
|
|
21
|
+
}
|
|
22
|
+
export const statusTool = {
|
|
23
|
+
name: 'status',
|
|
24
|
+
title: 'Context cache status',
|
|
25
|
+
description: 'Inspect the cache state for a workspace: file count, cache ID, TTL remaining, cumulative cost, and savings from cache hits. Also lists models available to the current API key.',
|
|
26
|
+
schema: statusInputSchema,
|
|
27
|
+
async execute(input, ctx) {
|
|
28
|
+
try {
|
|
29
|
+
const workspaceRoot = resolve(input.workspace ?? process.cwd());
|
|
30
|
+
const ws = ctx.manifest.getWorkspace(workspaceRoot);
|
|
31
|
+
const files = ctx.manifest.getFiles(workspaceRoot);
|
|
32
|
+
const stats = ctx.manifest.workspaceStats(workspaceRoot);
|
|
33
|
+
const models = await listAvailableModels(ctx.client).catch(() => []);
|
|
34
|
+
const structured = {
|
|
35
|
+
workspace: workspaceRoot,
|
|
36
|
+
auth: {
|
|
37
|
+
source: ctx.config.auth.source,
|
|
38
|
+
keyFingerprint: ctx.config.auth.keyFingerprint,
|
|
39
|
+
},
|
|
40
|
+
defaultModel: ctx.config.defaultModel,
|
|
41
|
+
dailyBudgetUsd: Number.isFinite(ctx.config.dailyBudgetUsd)
|
|
42
|
+
? ctx.config.dailyBudgetUsd
|
|
43
|
+
: null,
|
|
44
|
+
spentTodayUsd: microsToDollars(ctx.manifest.todaysCostMicros(Date.now())),
|
|
45
|
+
availableModels: models.map((m) => ({
|
|
46
|
+
id: m.id,
|
|
47
|
+
inputTokenLimit: m.inputTokenLimit,
|
|
48
|
+
supportsThinking: m.supportsThinking,
|
|
49
|
+
})),
|
|
50
|
+
workspaceState: ws
|
|
51
|
+
? {
|
|
52
|
+
filesHash: ws.filesHash,
|
|
53
|
+
model: ws.model,
|
|
54
|
+
cacheId: ws.cacheId,
|
|
55
|
+
cacheExpiresAt: ws.cacheExpiresAt,
|
|
56
|
+
cacheTtlRemaining: formatTtl(ws.cacheExpiresAt),
|
|
57
|
+
trackedFiles: files.length,
|
|
58
|
+
createdAt: ws.createdAt,
|
|
59
|
+
updatedAt: ws.updatedAt,
|
|
60
|
+
}
|
|
61
|
+
: null,
|
|
62
|
+
usage: {
|
|
63
|
+
callCount: stats.callCount,
|
|
64
|
+
totalCachedTokens: stats.totalCachedTokens,
|
|
65
|
+
totalUncachedTokens: stats.totalUncachedTokens,
|
|
66
|
+
totalCostUsd: microsToDollars(stats.totalCostMicros),
|
|
67
|
+
last24hCostUsd: microsToDollars(stats.last24hCostMicros),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const human = [
|
|
71
|
+
`workspace: ${workspaceRoot}`,
|
|
72
|
+
`auth source: ${ctx.config.auth.source} (${ctx.config.auth.keyFingerprint})`,
|
|
73
|
+
`default model: ${ctx.config.defaultModel}`,
|
|
74
|
+
`budget: ${Number.isFinite(ctx.config.dailyBudgetUsd) ? `$${ctx.config.dailyBudgetUsd.toFixed(2)}/day` : 'unlimited'} (today: $${microsToDollars(ctx.manifest.todaysCostMicros(Date.now())).toFixed(4)})`,
|
|
75
|
+
`available models (${models.length}):`,
|
|
76
|
+
...models
|
|
77
|
+
.slice(0, 8)
|
|
78
|
+
.map((m) => ` - ${m.id} (${m.inputTokenLimit?.toLocaleString() ?? '?'} in / ${m.outputTokenLimit?.toLocaleString() ?? '?'} out${m.supportsThinking ? ', thinking' : ''})`),
|
|
79
|
+
'',
|
|
80
|
+
ws ? 'workspace cache:' : 'workspace cache: (none yet — ask or code will create it)',
|
|
81
|
+
...(ws
|
|
82
|
+
? [
|
|
83
|
+
` cache_id: ${ws.cacheId ?? 'none (inline fallback)'}`,
|
|
84
|
+
` ttl: ${formatTtl(ws.cacheExpiresAt)}`,
|
|
85
|
+
` model: ${ws.model}`,
|
|
86
|
+
` files_hash: ${ws.filesHash.slice(0, 16)}…`,
|
|
87
|
+
` tracked_files: ${files.length}`,
|
|
88
|
+
]
|
|
89
|
+
: []),
|
|
90
|
+
'',
|
|
91
|
+
'usage:',
|
|
92
|
+
` calls: ${stats.callCount}`,
|
|
93
|
+
` cached tokens: ${stats.totalCachedTokens.toLocaleString()}`,
|
|
94
|
+
` input tokens: ${stats.totalUncachedTokens.toLocaleString()}`,
|
|
95
|
+
` total cost: $${microsToDollars(stats.totalCostMicros).toFixed(4)}`,
|
|
96
|
+
` last 24h: $${microsToDollars(stats.last24hCostMicros).toFixed(4)}`,
|
|
97
|
+
].join('\n');
|
|
98
|
+
return textResult(human, structured);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
return errorResult(`status failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=status.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.tool.js","sourceRoot":"","sources":["../../src/tools/status.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAuB,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;CAC5E,CAAC,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AAc,CAAC,EAAE;wBACjD,mBAAmB,EAAE,CAAC,KAAK,EAAE;wBAC7B,mBAAmB,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG;wBAC/C,oBAAoB,KAAK,CAAC,MAAM,EAAE;qBACnC;oBACH,CAAC,CAAC,EAAE,CAAC;gBACP,EAAE;gBACF,QAAQ;gBACR,oBAAoB,KAAK,CAAC,SAAS,EAAE;gBACrC,oBAAoB,KAAK,CAAC,iBAAiB,CAAC,cAAc,EAAE,EAAE;gBAC9D,oBAAoB,KAAK,CAAC,mBAAmB,CAAC,cAAc,EAAE,EAAE;gBAChE,qBAAqB,eAAe,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBACxE,qBAAqB,eAAe,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;aAC3E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,OAAO,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,WAAW,CAAC,kBAAkB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;CACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared domain types for @qmediat.io/gemini-code-context-mcp.
|
|
3
|
+
*/
|
|
4
|
+
/** Auth strategies for the Gemini API. */
|
|
5
|
+
export type AuthProfile = {
|
|
6
|
+
kind: 'api-key';
|
|
7
|
+
apiKey: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'vertex';
|
|
10
|
+
project: string;
|
|
11
|
+
location: string;
|
|
12
|
+
};
|
|
13
|
+
/** Resolved model info returned from the registry. */
|
|
14
|
+
export interface ResolvedModel {
|
|
15
|
+
/** Alias the user requested (e.g. `latest-pro`) or literal ID. */
|
|
16
|
+
requested: string;
|
|
17
|
+
/** Actual model ID to send to Gemini API. */
|
|
18
|
+
resolved: string;
|
|
19
|
+
/** True if we had to fall back because the requested model was unavailable. */
|
|
20
|
+
fallbackApplied: boolean;
|
|
21
|
+
/** Input token limit advertised by the model. */
|
|
22
|
+
inputTokenLimit: number | null;
|
|
23
|
+
/** Output token limit advertised by the model. */
|
|
24
|
+
outputTokenLimit: number | null;
|
|
25
|
+
}
|
|
26
|
+
/** Canonical workspace row stored in the manifest DB. */
|
|
27
|
+
export interface WorkspaceRow {
|
|
28
|
+
workspaceRoot: string;
|
|
29
|
+
filesHash: string;
|
|
30
|
+
model: string;
|
|
31
|
+
systemPromptHash: string;
|
|
32
|
+
cacheId: string | null;
|
|
33
|
+
cacheExpiresAt: number | null;
|
|
34
|
+
fileIds: string[];
|
|
35
|
+
createdAt: number;
|
|
36
|
+
updatedAt: number;
|
|
37
|
+
}
|
|
38
|
+
/** Per-file row stored in the manifest DB. */
|
|
39
|
+
export interface FileRow {
|
|
40
|
+
workspaceRoot: string;
|
|
41
|
+
relpath: string;
|
|
42
|
+
contentHash: string;
|
|
43
|
+
fileId: string | null;
|
|
44
|
+
uploadedAt: number | null;
|
|
45
|
+
expiresAt: number | null;
|
|
46
|
+
}
|
|
47
|
+
/** Usage metric row for cost reporting. */
|
|
48
|
+
export interface UsageMetricRow {
|
|
49
|
+
workspaceRoot: string;
|
|
50
|
+
toolName: string;
|
|
51
|
+
model: string | null;
|
|
52
|
+
cachedTokens: number | null;
|
|
53
|
+
uncachedTokens: number | null;
|
|
54
|
+
costUsdMicro: number | null;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
occurredAt: number;
|
|
57
|
+
}
|
|
58
|
+
/** Metadata attached to tool responses so Claude Code can show stats. */
|
|
59
|
+
export interface CallMetadata {
|
|
60
|
+
resolvedModel: string;
|
|
61
|
+
contextWindow: number | null;
|
|
62
|
+
cachedTokens: number;
|
|
63
|
+
uncachedTokens: number;
|
|
64
|
+
costEstimateUsd: number;
|
|
65
|
+
cacheHit: boolean;
|
|
66
|
+
durationMs: number;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,0CAA0C;AAC1C,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,eAAe,EAAE,OAAO,CAAC;IACzB,iDAAiD;IACjD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,8CAA8C;AAC9C,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,2CAA2C;AAC3C,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approximate cost estimator for reporting (not billing authoritative).
|
|
3
|
+
*
|
|
4
|
+
* Rates are per million tokens and reflect public Gemini API pricing as of
|
|
5
|
+
* 2026-04. Update when Google changes pricing; values can also be overridden
|
|
6
|
+
* at runtime via `GEMINI_PRICING_OVERRIDES` (JSON).
|
|
7
|
+
*/
|
|
8
|
+
export interface PricingEntry {
|
|
9
|
+
inputPerMillion: number;
|
|
10
|
+
outputPerMillion: number;
|
|
11
|
+
/** Cached tokens are billed at a reduced rate. Optional — falls back to 0.25× input. */
|
|
12
|
+
cachedInputPerMillion?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface CostInputs {
|
|
15
|
+
model: string;
|
|
16
|
+
uncachedInputTokens: number;
|
|
17
|
+
cachedInputTokens: number;
|
|
18
|
+
outputTokens: number;
|
|
19
|
+
thinkingTokens?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Estimated cost in USD (float). Multiply by 1e6 for micros before storing. */
|
|
22
|
+
export declare function estimateCostUsd(input: CostInputs): number;
|
|
23
|
+
export declare function toMicrosUsd(dollars: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Raw conversion: `micros → dollars` as a full-precision float. Sub-cent values
|
|
26
|
+
* survive, so `usageMetrics` tracking of e.g. $0.0043 calls remains visible.
|
|
27
|
+
* Use `formatDollarsToCents` when you want 2-decimal presentation.
|
|
28
|
+
*/
|
|
29
|
+
export declare function microsToDollars(micros: number): number;
|
|
30
|
+
/** Round a dollar amount to cents. Presentation helper. */
|
|
31
|
+
export declare function formatDollarsToCents(dollars: number): number;
|
|
32
|
+
//# sourceMappingURL=cost-estimator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-estimator.d.ts","sourceRoot":"","sources":["../../src/utils/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AA8CD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAWzD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approximate cost estimator for reporting (not billing authoritative).
|
|
3
|
+
*
|
|
4
|
+
* Rates are per million tokens and reflect public Gemini API pricing as of
|
|
5
|
+
* 2026-04. Update when Google changes pricing; values can also be overridden
|
|
6
|
+
* at runtime via `GEMINI_PRICING_OVERRIDES` (JSON).
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_PRICING = {
|
|
9
|
+
// Conservative defaults — if the actual rate is lower, users see a pleasant surprise.
|
|
10
|
+
'gemini-3-pro-preview': { inputPerMillion: 3.5, outputPerMillion: 10.5 },
|
|
11
|
+
'gemini-3.1-pro-preview': { inputPerMillion: 3.5, outputPerMillion: 10.5 },
|
|
12
|
+
'gemini-3-flash-preview': { inputPerMillion: 0.3, outputPerMillion: 2.5 },
|
|
13
|
+
'gemini-3.1-flash-image-preview': { inputPerMillion: 0.3, outputPerMillion: 2.5 },
|
|
14
|
+
'gemini-3.1-flash-lite-preview': { inputPerMillion: 0.1, outputPerMillion: 0.4 },
|
|
15
|
+
'gemini-2.5-pro': { inputPerMillion: 2.5, outputPerMillion: 10 },
|
|
16
|
+
'gemini-2.5-flash': { inputPerMillion: 0.3, outputPerMillion: 2.5 },
|
|
17
|
+
'gemini-2.5-flash-lite': { inputPerMillion: 0.1, outputPerMillion: 0.4 },
|
|
18
|
+
};
|
|
19
|
+
let overrides = null;
|
|
20
|
+
function loadOverrides() {
|
|
21
|
+
if (overrides !== null)
|
|
22
|
+
return overrides;
|
|
23
|
+
const raw = process.env.GEMINI_PRICING_OVERRIDES;
|
|
24
|
+
if (!raw) {
|
|
25
|
+
overrides = {};
|
|
26
|
+
return overrides;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(raw);
|
|
30
|
+
if (parsed && typeof parsed === 'object') {
|
|
31
|
+
overrides = parsed;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
overrides = {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
overrides = {};
|
|
39
|
+
}
|
|
40
|
+
return overrides;
|
|
41
|
+
}
|
|
42
|
+
function pricingFor(model) {
|
|
43
|
+
const ov = loadOverrides();
|
|
44
|
+
if (ov?.[model])
|
|
45
|
+
return ov[model];
|
|
46
|
+
if (DEFAULT_PRICING[model])
|
|
47
|
+
return DEFAULT_PRICING[model];
|
|
48
|
+
// Fallback heuristic: pro-class if name contains 'pro', otherwise flash-class.
|
|
49
|
+
if (model.includes('pro'))
|
|
50
|
+
return { inputPerMillion: 3.5, outputPerMillion: 10.5 };
|
|
51
|
+
if (model.includes('lite'))
|
|
52
|
+
return { inputPerMillion: 0.1, outputPerMillion: 0.4 };
|
|
53
|
+
return { inputPerMillion: 0.3, outputPerMillion: 2.5 };
|
|
54
|
+
}
|
|
55
|
+
/** Estimated cost in USD (float). Multiply by 1e6 for micros before storing. */
|
|
56
|
+
export function estimateCostUsd(input) {
|
|
57
|
+
const p = pricingFor(input.model);
|
|
58
|
+
const cachedRate = p.cachedInputPerMillion ?? p.inputPerMillion * 0.25;
|
|
59
|
+
const uncached = (input.uncachedInputTokens / 1_000_000) * p.inputPerMillion;
|
|
60
|
+
const cached = (input.cachedInputTokens / 1_000_000) * cachedRate;
|
|
61
|
+
const output = (input.outputTokens / 1_000_000) * p.outputPerMillion;
|
|
62
|
+
// Thinking tokens are currently billed as output tokens on Gemini Pro family.
|
|
63
|
+
const thinking = input.thinkingTokens
|
|
64
|
+
? (input.thinkingTokens / 1_000_000) * p.outputPerMillion
|
|
65
|
+
: 0;
|
|
66
|
+
return uncached + cached + output + thinking;
|
|
67
|
+
}
|
|
68
|
+
export function toMicrosUsd(dollars) {
|
|
69
|
+
return Math.round(dollars * 1_000_000);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Raw conversion: `micros → dollars` as a full-precision float. Sub-cent values
|
|
73
|
+
* survive, so `usageMetrics` tracking of e.g. $0.0043 calls remains visible.
|
|
74
|
+
* Use `formatDollarsToCents` when you want 2-decimal presentation.
|
|
75
|
+
*/
|
|
76
|
+
export function microsToDollars(micros) {
|
|
77
|
+
return micros / 1_000_000;
|
|
78
|
+
}
|
|
79
|
+
/** Round a dollar amount to cents. Presentation helper. */
|
|
80
|
+
export function formatDollarsToCents(dollars) {
|
|
81
|
+
return Math.round(dollars * 100) / 100;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=cost-estimator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-estimator.js","sourceRoot":"","sources":["../../src/utils/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,eAAe,GAAiC;IACpD,sFAAsF;IACtF,sBAAsB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE;IACxE,wBAAwB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC1E,wBAAwB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;IACzE,gCAAgC,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;IACjF,+BAA+B,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;IAChF,gBAAgB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EA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G,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal leveled logger. Writes to stderr so it never collides with MCP stdio transport.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
+
export declare const logger: {
|
|
6
|
+
debug: (msg: string) => void;
|
|
7
|
+
info: (msg: string) => void;
|
|
8
|
+
warn: (msg: string) => void;
|
|
9
|
+
error: (msg: string) => void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAgB3D,eAAO,MAAM,MAAM;iBACJ,MAAM,KAAG,IAAI;gBACd,MAAM,KAAG,IAAI;gBACb,MAAM,KAAG,IAAI;iBACZ,MAAM,KAAG,IAAI;CAC3B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal leveled logger. Writes to stderr so it never collides with MCP stdio transport.
|
|
3
|
+
*/
|
|
4
|
+
const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
5
|
+
const PREFIX = '[gemini-code-context-mcp]';
|
|
6
|
+
function currentLevel() {
|
|
7
|
+
const raw = (process.env.GEMINI_CODE_CONTEXT_LOG_LEVEL ?? 'info').toLowerCase();
|
|
8
|
+
return LEVELS[raw] ?? LEVELS.info;
|
|
9
|
+
}
|
|
10
|
+
function write(level, message) {
|
|
11
|
+
if (LEVELS[level] < currentLevel())
|
|
12
|
+
return;
|
|
13
|
+
process.stderr.write(`${PREFIX} [${level}] ${message}\n`);
|
|
14
|
+
}
|
|
15
|
+
export const logger = {
|
|
16
|
+
debug: (msg) => write('debug', msg),
|
|
17
|
+
info: (msg) => write('info', msg),
|
|
18
|
+
warn: (msg) => write('warn', msg),
|
|
19
|
+
error: (msg) => write('error', msg),
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,MAAM,GAA6B,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAEtF,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAE3C,SAAS,YAAY;IACnB,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAChF,OAAO,MAAM,CAAC,GAAe,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,SAAS,KAAK,CAAC,KAAe,EAAE,OAAe;IAC7C,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,YAAY,EAAE;QAAE,OAAO;IAC3C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK,KAAK,KAAK,OAAO,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,GAAW,EAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC;IACjD,IAAI,EAAE,CAAC,GAAW,EAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC;IAC/C,IAAI,EAAE,CAAC,GAAW,EAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC;IAC/C,KAAK,EAAE,CAAC,GAAW,EAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC;CAClD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XDG-compliant paths for qmediat config and state.
|
|
3
|
+
*/
|
|
4
|
+
/** Config directory — `~/.config/qmediat/` (or `$XDG_CONFIG_HOME/qmediat/`). */
|
|
5
|
+
export declare function qmediatConfigDir(): string;
|
|
6
|
+
/**
|
|
7
|
+
* State directory for manifest DB.
|
|
8
|
+
*
|
|
9
|
+
* Follows XDG base-dir when `XDG_STATE_HOME` is set (per spec:
|
|
10
|
+
* https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).
|
|
11
|
+
* Otherwise defaults to `~/.qmediat/gemini-code-context-mcp/` — pre-XDG for
|
|
12
|
+
* backwards compatibility with existing installs. Users on strict-XDG systems
|
|
13
|
+
* (NixOS, some BSDs) can set `XDG_STATE_HOME=~/.local/state` to route here.
|
|
14
|
+
*/
|
|
15
|
+
export declare function qmediatStateDir(): string;
|
|
16
|
+
/** Path to credentials file for a given profile. */
|
|
17
|
+
export declare function credentialsPath(): string;
|
|
18
|
+
/** Path to manifest SQLite DB. */
|
|
19
|
+
export declare function manifestDbPath(): string;
|
|
20
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,gFAAgF;AAChF,wBAAgB,gBAAgB,IAAI,MAAM,CAWzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAMxC;AAED,oDAAoD;AACpD,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,kCAAkC;AAClC,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XDG-compliant paths for qmediat config and state.
|
|
3
|
+
*/
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
/** Config directory — `~/.config/qmediat/` (or `$XDG_CONFIG_HOME/qmediat/`). */
|
|
7
|
+
export function qmediatConfigDir() {
|
|
8
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
9
|
+
// In test mode, require an explicit sandbox via XDG_CONFIG_HOME to prevent
|
|
10
|
+
// accidental reads/writes against the developer's real credentials file.
|
|
11
|
+
if (process.env.NODE_ENV === 'test' && (!xdg || xdg.length === 0)) {
|
|
12
|
+
throw new Error('qmediatConfigDir() refuses to resolve in NODE_ENV=test without XDG_CONFIG_HOME set — ' +
|
|
13
|
+
'set it to a temp directory to avoid polluting real ~/.config/qmediat credentials.');
|
|
14
|
+
}
|
|
15
|
+
return xdg && xdg.length > 0 ? join(xdg, 'qmediat') : join(homedir(), '.config', 'qmediat');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* State directory for manifest DB.
|
|
19
|
+
*
|
|
20
|
+
* Follows XDG base-dir when `XDG_STATE_HOME` is set (per spec:
|
|
21
|
+
* https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).
|
|
22
|
+
* Otherwise defaults to `~/.qmediat/gemini-code-context-mcp/` — pre-XDG for
|
|
23
|
+
* backwards compatibility with existing installs. Users on strict-XDG systems
|
|
24
|
+
* (NixOS, some BSDs) can set `XDG_STATE_HOME=~/.local/state` to route here.
|
|
25
|
+
*/
|
|
26
|
+
export function qmediatStateDir() {
|
|
27
|
+
const xdg = process.env.XDG_STATE_HOME;
|
|
28
|
+
if (xdg && xdg.length > 0) {
|
|
29
|
+
return join(xdg, 'qmediat', 'gemini-code-context-mcp');
|
|
30
|
+
}
|
|
31
|
+
return join(homedir(), '.qmediat', 'gemini-code-context-mcp');
|
|
32
|
+
}
|
|
33
|
+
/** Path to credentials file for a given profile. */
|
|
34
|
+
export function credentialsPath() {
|
|
35
|
+
return join(qmediatConfigDir(), 'credentials');
|
|
36
|
+
}
|
|
37
|
+
/** Path to manifest SQLite DB. */
|
|
38
|
+
export function manifestDbPath() {
|
|
39
|
+
return join(qmediatStateDir(), 'manifest.db');
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,gFAAgF;AAChF,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IACxC,2EAA2E;IAC3E,yEAAyE;IACzE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CACb,uFAAuF;YACrF,mFAAmF,CACtF,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC9F,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACvC,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,yBAAyB,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,yBAAyB,CAAC,CAAC;AAChE,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,gBAAgB,EAAE,EAAE,aAAa,CAAC,CAAC;AACjD,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,eAAe,EAAE,EAAE,aAAa,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP progress notification helper.
|
|
3
|
+
*
|
|
4
|
+
* MCP hosts can cancel or time out long-running tool calls if they don't see
|
|
5
|
+
* activity. We emit `notifications/progress` on a ~25s cadence plus on meaningful
|
|
6
|
+
* milestones (upload started, cache built, generating).
|
|
7
|
+
*/
|
|
8
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
9
|
+
export interface ProgressEmitter {
|
|
10
|
+
/** Emit a progress update. Safe to call without a progressToken. */
|
|
11
|
+
emit(message: string, progress?: number, total?: number): void;
|
|
12
|
+
/** Stop the keepalive interval and release resources. */
|
|
13
|
+
stop(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function createProgressEmitter(server: Server, progressToken: string | number | undefined): ProgressEmitter;
|
|
16
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/utils/progress.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAIxE,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,yDAAyD;IACzD,IAAI,IAAI,IAAI,CAAC;CACd;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GACzC,eAAe,CAyCjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP progress notification helper.
|
|
3
|
+
*
|
|
4
|
+
* MCP hosts can cancel or time out long-running tool calls if they don't see
|
|
5
|
+
* activity. We emit `notifications/progress` on a ~25s cadence plus on meaningful
|
|
6
|
+
* milestones (upload started, cache built, generating).
|
|
7
|
+
*/
|
|
8
|
+
const KEEPALIVE_MS = 25_000;
|
|
9
|
+
export function createProgressEmitter(server, progressToken) {
|
|
10
|
+
if (progressToken === undefined) {
|
|
11
|
+
return {
|
|
12
|
+
emit: () => {
|
|
13
|
+
/* no-op — host didn't subscribe to progress */
|
|
14
|
+
},
|
|
15
|
+
stop: () => { },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
let lastMessage = 'working…';
|
|
19
|
+
let lastProgress = 0;
|
|
20
|
+
let lastTotal;
|
|
21
|
+
const send = (message, progress, total) => {
|
|
22
|
+
lastMessage = message;
|
|
23
|
+
lastProgress = progress;
|
|
24
|
+
lastTotal = total;
|
|
25
|
+
void server
|
|
26
|
+
.notification({
|
|
27
|
+
method: 'notifications/progress',
|
|
28
|
+
params: {
|
|
29
|
+
progressToken,
|
|
30
|
+
progress,
|
|
31
|
+
...(total !== undefined ? { total } : {}),
|
|
32
|
+
message,
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
.catch(() => {
|
|
36
|
+
/* swallow — best-effort notification */
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const keepalive = setInterval(() => {
|
|
40
|
+
send(lastMessage, lastProgress, lastTotal);
|
|
41
|
+
}, KEEPALIVE_MS);
|
|
42
|
+
return {
|
|
43
|
+
emit: (message, progress, total) => send(message, progress ?? lastProgress + 1, total),
|
|
44
|
+
stop: () => clearInterval(keepalive),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"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AE,CAAC,aAAa,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qmediat.io/gemini-code-context-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server that gives Claude Code persistent memory of your codebase, backed by Gemini's 2M-token context. Drop-in upgrade over the abandoned gemini-mcp-tool.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"gemini",
|
|
9
|
+
"claude-code",
|
|
10
|
+
"context-cache",
|
|
11
|
+
"files-api",
|
|
12
|
+
"code-review",
|
|
13
|
+
"2m-context"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/qmediat/gemini-code-context-mcp#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/qmediat/gemini-code-context-mcp/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/qmediat/gemini-code-context-mcp.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Quantum Media Technologies sp. z o.o.",
|
|
26
|
+
"email": "contact@qmt.email",
|
|
27
|
+
"url": "https://www.qmediat.io"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"bin": {
|
|
33
|
+
"gemini-code-context-mcp": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"CHANGELOG.md"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22.0.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"dev": "tsx watch src/index.ts",
|
|
47
|
+
"start": "node dist/index.js",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"test:coverage": "vitest run --coverage",
|
|
51
|
+
"test:integration": "vitest run test/integration",
|
|
52
|
+
"lint": "biome check src test",
|
|
53
|
+
"format": "biome format --write src test",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm run test && npm run build",
|
|
56
|
+
"inspector": "npx @modelcontextprotocol/inspector node dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@google/genai": "^1.0.0",
|
|
60
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
61
|
+
"better-sqlite3": "^11.0.0",
|
|
62
|
+
"zod": "^3.23.0",
|
|
63
|
+
"zod-to-json-schema": "^3.24.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@biomejs/biome": "^1.9.0",
|
|
67
|
+
"@changesets/cli": "^2.27.0",
|
|
68
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
69
|
+
"@types/node": "^22.0.0",
|
|
70
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
71
|
+
"tsx": "^4.19.0",
|
|
72
|
+
"typescript": "^5.6.0",
|
|
73
|
+
"vitest": "^4.1.0"
|
|
74
|
+
},
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public"
|
|
77
|
+
}
|
|
78
|
+
}
|