@vespermcp/mcp-server 1.3.0 → 1.4.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/build/index.js +1327 -1318
- package/build/lib/mcp-analytics.js +164 -0
- package/build/lib/plan-resolve.js +10 -2
- package/mcp-config-template.json +2 -3
- package/package.json +2 -3
- package/scripts/postinstall.cjs +45 -9
- package/scripts/wizard.cjs +45 -7
- package/scripts/wizard.js +2 -2
- package/wizard.cjs +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { getSupabaseAdminClient, resolveUserIdFromApiKey } from "./plan-resolve.js";
|
|
2
|
+
import { inferSourceFromDatasetId, normalizeProviderSource, PLAN_GATE_EXEMPT_TOOLS, } from "./plan-gate.js";
|
|
3
|
+
function truncateDatasetName(raw) {
|
|
4
|
+
const t = raw.trim();
|
|
5
|
+
if (!t)
|
|
6
|
+
return "unknown";
|
|
7
|
+
return t.length > 256 ? t.slice(0, 253) + "..." : t;
|
|
8
|
+
}
|
|
9
|
+
function pickDatasetName(args) {
|
|
10
|
+
const a = args || {};
|
|
11
|
+
const candidates = [
|
|
12
|
+
a.dataset_id,
|
|
13
|
+
a.query,
|
|
14
|
+
a.datasetId,
|
|
15
|
+
a.url,
|
|
16
|
+
a.file_path,
|
|
17
|
+
];
|
|
18
|
+
for (const c of candidates) {
|
|
19
|
+
if (typeof c === "string" && c.trim()) {
|
|
20
|
+
return truncateDatasetName(c);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return "unknown";
|
|
24
|
+
}
|
|
25
|
+
function pickSource(toolName, args) {
|
|
26
|
+
const a = args || {};
|
|
27
|
+
const explicit = normalizeProviderSource(String(a.source ?? ""));
|
|
28
|
+
if (explicit)
|
|
29
|
+
return explicit;
|
|
30
|
+
const fromId = inferSourceFromDatasetId(String(a.dataset_id ?? a.query ?? ""));
|
|
31
|
+
if (fromId)
|
|
32
|
+
return fromId;
|
|
33
|
+
if (toolName === "vesper_web_find" && Array.isArray(a.sources) && a.sources.length > 0) {
|
|
34
|
+
return String(a.sources[0]).toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function pickFormat(args) {
|
|
39
|
+
const a = args || {};
|
|
40
|
+
const f = a.format ?? a.target_format ?? a.output_format;
|
|
41
|
+
if (typeof f === "string" && f.trim())
|
|
42
|
+
return f.trim().toLowerCase().slice(0, 32);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function mapToolToEvent(toolName) {
|
|
46
|
+
switch (toolName) {
|
|
47
|
+
case "vesper_search":
|
|
48
|
+
case "discover_datasets":
|
|
49
|
+
case "vesper_web_find":
|
|
50
|
+
case "vesper.extract_web":
|
|
51
|
+
case "get_dataset_info":
|
|
52
|
+
return { event_type: "dataset_search" };
|
|
53
|
+
case "download_dataset":
|
|
54
|
+
case "vesper_download_assets":
|
|
55
|
+
return { event_type: "dataset_download" };
|
|
56
|
+
case "quality_analyze":
|
|
57
|
+
case "analyze_quality":
|
|
58
|
+
case "analyze_image_quality":
|
|
59
|
+
case "analyze_media_quality":
|
|
60
|
+
case "generate_quality_report":
|
|
61
|
+
case "preview_cleaning":
|
|
62
|
+
return { event_type: "quality_analysis" };
|
|
63
|
+
case "prepare_dataset":
|
|
64
|
+
return { event_type: "dataset_prepare" };
|
|
65
|
+
case "export_dataset":
|
|
66
|
+
case "vesper_convert_format":
|
|
67
|
+
return { event_type: "export" };
|
|
68
|
+
default:
|
|
69
|
+
return { event_type: "data_processed" };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function mapToolToEventWithArgs(toolName, args) {
|
|
73
|
+
if (toolName === "unified_dataset_api") {
|
|
74
|
+
const op = String(args.operation ?? "").trim().toLowerCase();
|
|
75
|
+
if (op === "discover" || op === "providers" || op === "info") {
|
|
76
|
+
return { event_type: "dataset_search" };
|
|
77
|
+
}
|
|
78
|
+
if (op === "download") {
|
|
79
|
+
return { event_type: "dataset_download" };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return mapToolToEvent(toolName);
|
|
83
|
+
}
|
|
84
|
+
async function hasAnalyticsConsent(userId) {
|
|
85
|
+
const supabase = getSupabaseAdminClient();
|
|
86
|
+
if (!supabase)
|
|
87
|
+
return false;
|
|
88
|
+
const { data, error } = await supabase
|
|
89
|
+
.from("analytics_consent")
|
|
90
|
+
.select("consented")
|
|
91
|
+
.eq("user_id", userId)
|
|
92
|
+
.maybeSingle();
|
|
93
|
+
if (error) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return data?.consented === true;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* After each MCP tool call: insert one row into `analytics_events` (same table as
|
|
100
|
+
* `/api/analytics/ingest` and the landing Operations tab) when the user has opted in
|
|
101
|
+
* and `VESPER_API_KEY` / `api_key` resolves to a user.
|
|
102
|
+
*/
|
|
103
|
+
export async function recordMcpToolAnalyticsAfterCall(opts) {
|
|
104
|
+
if (process.env.VESPER_DISABLE_MCP_ANALYTICS === "1" || process.env.VESPER_DISABLE_MCP_ANALYTICS === "true") {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const toolName = String(opts.toolName || "").trim();
|
|
108
|
+
if (!toolName || PLAN_GATE_EXEMPT_TOOLS.has(toolName)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const supabase = getSupabaseAdminClient();
|
|
112
|
+
if (!supabase) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const args = opts.args || {};
|
|
116
|
+
const apiKey = String(args.api_key ?? process.env.VESPER_API_KEY ?? "").trim();
|
|
117
|
+
if (!apiKey) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const userId = await resolveUserIdFromApiKey(apiKey);
|
|
121
|
+
if (!userId) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!(await hasAnalyticsConsent(userId))) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const { event_type } = mapToolToEventWithArgs(toolName, args);
|
|
128
|
+
const dataset_name = pickDatasetName(args);
|
|
129
|
+
const source = pickSource(toolName, args);
|
|
130
|
+
const format = pickFormat(args);
|
|
131
|
+
const metadata = {
|
|
132
|
+
mcp_tool: toolName,
|
|
133
|
+
ok: opts.result !== undefined && opts.result.isError !== true,
|
|
134
|
+
};
|
|
135
|
+
if (opts.result?.isError) {
|
|
136
|
+
const first = opts.result.content?.[0];
|
|
137
|
+
if (first && typeof first.text === "string") {
|
|
138
|
+
metadata.error_preview = first.text.slice(0, 500);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const row = {
|
|
142
|
+
user_id: userId,
|
|
143
|
+
event_type,
|
|
144
|
+
dataset_name,
|
|
145
|
+
source: source || null,
|
|
146
|
+
format: format || null,
|
|
147
|
+
size_bytes: null,
|
|
148
|
+
quality_score: null,
|
|
149
|
+
metadata,
|
|
150
|
+
created_at: new Date().toISOString(),
|
|
151
|
+
};
|
|
152
|
+
let { error } = await supabase.from("analytics_events").insert(row);
|
|
153
|
+
// Older DBs may lack `dataset_prepare` in CHECK constraint — fall back.
|
|
154
|
+
if (error && event_type === "dataset_prepare" && /check|constraint/i.test(error.message || "")) {
|
|
155
|
+
({ error } = await supabase.from("analytics_events").insert({
|
|
156
|
+
...row,
|
|
157
|
+
event_type: "data_processed",
|
|
158
|
+
metadata: { ...metadata, event_type_fallback: "dataset_prepare" },
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
if (error) {
|
|
162
|
+
console.error("[mcp-analytics] insert failed:", error.message);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -45,7 +45,7 @@ async function getUserPlanForUserId(userId) {
|
|
|
45
45
|
}
|
|
46
46
|
return "free";
|
|
47
47
|
}
|
|
48
|
-
async function
|
|
48
|
+
async function lookupUserByApiKey(apiKey) {
|
|
49
49
|
const supabase = getSupabase();
|
|
50
50
|
if (!supabase)
|
|
51
51
|
return null;
|
|
@@ -59,6 +59,14 @@ async function resolveUserFromApiKey(apiKey) {
|
|
|
59
59
|
}
|
|
60
60
|
return { userId: data.user_id };
|
|
61
61
|
}
|
|
62
|
+
/** For analytics / profile sync — same lookup as plan gate. */
|
|
63
|
+
export async function resolveUserIdFromApiKey(apiKey) {
|
|
64
|
+
const row = await lookupUserByApiKey(apiKey);
|
|
65
|
+
return row?.userId ?? null;
|
|
66
|
+
}
|
|
67
|
+
export function getSupabaseAdminClient() {
|
|
68
|
+
return getSupabase();
|
|
69
|
+
}
|
|
62
70
|
/**
|
|
63
71
|
* Central gate: same rules as `landing/lib/plan-entitlements` + landing analytics ingest.
|
|
64
72
|
*/
|
|
@@ -77,7 +85,7 @@ export async function enforcePlanGateForTool(toolName, args) {
|
|
|
77
85
|
message: "Plan enforcement is enabled (Supabase configured). Set `VESPER_API_KEY` in the MCP env or pass `api_key` on tool calls to your Vesper API key so your tier can be verified.",
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
|
-
const user = await
|
|
88
|
+
const user = await lookupUserByApiKey(apiKey);
|
|
81
89
|
if (!user) {
|
|
82
90
|
return {
|
|
83
91
|
ok: false,
|
package/mcp-config-template.json
CHANGED
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
"vespermcp"
|
|
10
10
|
],
|
|
11
11
|
"env": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"HF_TOKEN": "your-huggingface-token"
|
|
12
|
+
"VESPER_API_KEY": "your-key-from-getvesper.dev",
|
|
13
|
+
"VESPER_API_URL": "https://getvesper.dev"
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vespermcp/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "AI-powered dataset discovery, quality analysis, and preparation MCP server with multimodal support (text, image, audio, video)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"vespermcp": "build/index.js"
|
|
9
|
-
"vesper-wizard": "wizard.cjs"
|
|
8
|
+
"vespermcp": "build/index.js"
|
|
10
9
|
},
|
|
11
10
|
"files": [
|
|
12
11
|
"build/**/*",
|
package/scripts/postinstall.cjs
CHANGED
|
@@ -135,6 +135,37 @@ function getClaudeConfigPath() {
|
|
|
135
135
|
|
|
136
136
|
const configPath = getClaudeConfigPath();
|
|
137
137
|
|
|
138
|
+
function readVesperConfigToml() {
|
|
139
|
+
const p = path.join(vesperDataDir, 'config.toml');
|
|
140
|
+
if (!fs.existsSync(p)) return {};
|
|
141
|
+
const content = fs.readFileSync(p, 'utf8');
|
|
142
|
+
const obj = {};
|
|
143
|
+
for (const line of content.split('\n')) {
|
|
144
|
+
const m = line.match(/^\s*(\w+)\s*=\s*"(.*)"\s*$/);
|
|
145
|
+
if (m) obj[m[1]] = m[2];
|
|
146
|
+
}
|
|
147
|
+
return obj;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function getMcpVesperApiUrl() {
|
|
151
|
+
const raw = (process.env.VESPER_API_URL || '').trim();
|
|
152
|
+
return raw.replace(/\/$/, '') || 'https://getvesper.dev';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function buildClaudeMcpVesperEntry() {
|
|
156
|
+
const vesperToml = readVesperConfigToml();
|
|
157
|
+
const apiKey = String(vesperToml.api_key || '').trim();
|
|
158
|
+
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
159
|
+
return {
|
|
160
|
+
command: npxCmd,
|
|
161
|
+
args: ['-y', '-p', '@vespermcp/mcp-server@latest', 'vespermcp'],
|
|
162
|
+
env: {
|
|
163
|
+
VESPER_API_KEY: apiKey || 'your-key-from-getvesper.dev',
|
|
164
|
+
VESPER_API_URL: getMcpVesperApiUrl(),
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
138
169
|
if (configPath && fs.existsSync(configPath)) {
|
|
139
170
|
try {
|
|
140
171
|
const configContent = fs.readFileSync(configPath, 'utf8');
|
|
@@ -142,17 +173,22 @@ if (configPath && fs.existsSync(configPath)) {
|
|
|
142
173
|
|
|
143
174
|
if (!config.mcpServers) config.mcpServers = {};
|
|
144
175
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
176
|
+
const entry = buildClaudeMcpVesperEntry();
|
|
177
|
+
const existing = config.mcpServers.vesper;
|
|
178
|
+
const isLegacy =
|
|
179
|
+
existing &&
|
|
180
|
+
existing.command === 'vesper' &&
|
|
181
|
+
existing.env &&
|
|
182
|
+
Object.prototype.hasOwnProperty.call(existing.env, 'HF_TOKEN');
|
|
153
183
|
|
|
184
|
+
if (!existing) {
|
|
185
|
+
config.mcpServers.vesper = entry;
|
|
186
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
187
|
+
console.log(`✅ Automatically added 'vesper' (npx + VESPER_* env) to ${configPath}`);
|
|
188
|
+
} else if (isLegacy) {
|
|
189
|
+
config.mcpServers.vesper = entry;
|
|
154
190
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
155
|
-
console.log(`✅
|
|
191
|
+
console.log(`✅ Updated legacy Vesper MCP entry to npx + VESPER_* env in ${configPath}`);
|
|
156
192
|
} else {
|
|
157
193
|
console.log(`ℹ️ 'vesper' is already configured in ${configPath}`);
|
|
158
194
|
}
|
package/scripts/wizard.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// ─────────────────────────────────────────────────────────────
|
|
4
|
-
//
|
|
5
|
-
// Run: npx
|
|
4
|
+
// @vespermcp/setup — Zero-friction local setup for Vesper MCP
|
|
5
|
+
// Run: npx @vespermcp/setup@latest
|
|
6
6
|
// ─────────────────────────────────────────────────────────────
|
|
7
7
|
|
|
8
8
|
const fs = require('fs');
|
|
@@ -379,6 +379,46 @@ ${dim('────────────────────────
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
// ── MCP Auto-Config ──────────────────────────────────────────
|
|
382
|
+
function getMcpVesperApiUrl() {
|
|
383
|
+
const raw = (process.env.VESPER_API_URL || '').trim();
|
|
384
|
+
return raw.replace(/\/$/, '') || 'https://getvesper.dev';
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function buildMcpServerEntry() {
|
|
388
|
+
const npxCmd = IS_WIN ? 'npx.cmd' : 'npx';
|
|
389
|
+
const state = readToml(CONFIG_TOML);
|
|
390
|
+
const apiKey = String(state.api_key || '').trim();
|
|
391
|
+
return {
|
|
392
|
+
command: npxCmd,
|
|
393
|
+
args: ['-y', '-p', '@vespermcp/mcp-server@latest', 'vespermcp'],
|
|
394
|
+
env: {
|
|
395
|
+
VESPER_API_URL: getMcpVesperApiUrl(),
|
|
396
|
+
VESPER_API_KEY: apiKey || 'your-key-from-getvesper.dev',
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function escapeTomlDoubleQuoted(value) {
|
|
402
|
+
return String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function upsertTomlMcpVesperBlock(content, serverEntry) {
|
|
406
|
+
const key = escapeTomlDoubleQuoted(serverEntry.env.VESPER_API_KEY);
|
|
407
|
+
const url = escapeTomlDoubleQuoted(serverEntry.env.VESPER_API_URL);
|
|
408
|
+
const block =
|
|
409
|
+
`[mcp_servers.vesper]\n` +
|
|
410
|
+
`command = "${serverEntry.command}"\n` +
|
|
411
|
+
`args = [${serverEntry.args.map((a) => `"${a}"`).join(', ')}]\n\n` +
|
|
412
|
+
`[mcp_servers.vesper.env]\n` +
|
|
413
|
+
`VESPER_API_KEY = "${key}"\n` +
|
|
414
|
+
`VESPER_API_URL = "${url}"\n`;
|
|
415
|
+
const re = /\[mcp_servers\.vesper\][\s\S]*?(?=\n\[|$)/;
|
|
416
|
+
if (re.test(content)) {
|
|
417
|
+
return content.replace(re, block.trim() + '\n');
|
|
418
|
+
}
|
|
419
|
+
return content + (content && !content.endsWith('\n') ? '\n' : '') + block;
|
|
420
|
+
}
|
|
421
|
+
|
|
382
422
|
function getAllAgentConfigs() {
|
|
383
423
|
const isMac = process.platform === 'darwin';
|
|
384
424
|
return [
|
|
@@ -424,15 +464,13 @@ function getAllAgentConfigs() {
|
|
|
424
464
|
}
|
|
425
465
|
|
|
426
466
|
function installMcpToAgent(agent) {
|
|
427
|
-
const
|
|
428
|
-
const serverEntry = { command: npxCmd, args: ['-y', '-p', '@vespermcp/mcp-server@latest', 'vespermcp'] };
|
|
467
|
+
const serverEntry = buildMcpServerEntry();
|
|
429
468
|
|
|
430
469
|
try {
|
|
431
470
|
if (agent.format === 'toml') {
|
|
432
471
|
let content = fs.existsSync(agent.path) ? fs.readFileSync(agent.path, 'utf8') : '';
|
|
433
|
-
if (content.includes('[mcp_servers.vesper]')) return true;
|
|
434
472
|
ensureDir(path.dirname(agent.path));
|
|
435
|
-
content
|
|
473
|
+
content = upsertTomlMcpVesperBlock(content, serverEntry);
|
|
436
474
|
fs.writeFileSync(agent.path, content, 'utf8');
|
|
437
475
|
return true;
|
|
438
476
|
}
|
|
@@ -477,7 +515,7 @@ async function checkServerHealth() {
|
|
|
477
515
|
// ── Main Wizard ──────────────────────────────────────────────
|
|
478
516
|
async function main() {
|
|
479
517
|
if (!isInteractiveTerminal()) {
|
|
480
|
-
console.error(red('
|
|
518
|
+
console.error(red('@vespermcp/setup is interactive and cannot run in MCP stdio mode.'));
|
|
481
519
|
console.error(dim('Use this command for MCP server runtime instead:'));
|
|
482
520
|
console.error(cyan('npx -y -p @vespermcp/mcp-server@latest vespermcp'));
|
|
483
521
|
process.exit(2);
|
package/scripts/wizard.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// ─────────────────────────────────────────────────────────────
|
|
4
|
-
//
|
|
5
|
-
// Run: npx
|
|
4
|
+
// @vespermcp/setup — Zero-friction local setup for Vesper MCP
|
|
5
|
+
// Run: npx @vespermcp/setup@latest
|
|
6
6
|
// ─────────────────────────────────────────────────────────────
|
|
7
7
|
|
|
8
8
|
const fs = require('fs');
|
package/wizard.cjs
CHANGED
|
File without changes
|