@llmindset/hf-mcp-server 0.2.45 → 0.2.47
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/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +290 -157
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/transport/base-transport.d.ts +3 -0
- package/dist/server/transport/base-transport.d.ts.map +1 -1
- package/dist/server/transport/base-transport.js +15 -0
- package/dist/server/transport/base-transport.js.map +1 -1
- package/dist/server/transport/sse-transport.d.ts.map +1 -1
- package/dist/server/transport/sse-transport.js +4 -0
- package/dist/server/transport/sse-transport.js.map +1 -1
- package/dist/server/transport/stateless-http-transport.d.ts.map +1 -1
- package/dist/server/transport/stateless-http-transport.js +7 -2
- package/dist/server/transport/stateless-http-transport.js.map +1 -1
- package/dist/server/utils/query-logger.d.ts +13 -13
- package/dist/server/utils/query-logger.d.ts.map +1 -1
- package/dist/server/utils/query-logger.js +39 -4
- package/dist/server/utils/query-logger.js.map +1 -1
- package/dist/server/web-server.d.ts.map +1 -1
- package/dist/server/web-server.js +1 -0
- package/dist/server/web-server.js.map +1 -1
- package/dist/shared/bouquet-presets.d.ts.map +1 -1
- package/dist/shared/bouquet-presets.js +2 -2
- package/dist/shared/bouquet-presets.js.map +1 -1
- package/dist/shared/transport-metrics.d.ts +6 -0
- package/dist/shared/transport-metrics.d.ts.map +1 -1
- package/dist/shared/transport-metrics.js +16 -0
- package/dist/shared/transport-metrics.js.map +1 -1
- package/dist/web/assets/main-Dkj9oFuQ.js +197 -0
- package/dist/web/index.html +1 -1
- package/dist/web/mcp-welcome.html +15 -15
- package/package.json +2 -2
- package/dist/web/assets/main-BTa3PJAr.js +0 -197
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":"AAiEA,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,+BAA+B,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAS9E,eAAO,MAAM,gBAAgB,EAAE,WAG9B,CAAC;AAGF,eAAO,MAAM,oBAAoB,EAAE,WAGlC,CAAC;AAQF,eAAO,MAAM,mBAAmB,GAAI,oBAAoB,SAAS,EAAE,iBAAiB,YAAY,KAAG,aAi7BlG,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
|
+
import { performance } from 'node:perf_hooks';
|
|
3
4
|
import { whoAmI } from '@huggingface/hub';
|
|
4
5
|
import { SpaceSearchTool, formatSearchResults, SEMANTIC_SEARCH_TOOL_CONFIG, ModelSearchTool, MODEL_SEARCH_TOOL_CONFIG, ModelDetailTool, MODEL_DETAIL_TOOL_CONFIG, MODEL_DETAIL_PROMPT_CONFIG, PaperSearchTool, PAPER_SEARCH_TOOL_CONFIG, DatasetSearchTool, DATASET_SEARCH_TOOL_CONFIG, DatasetDetailTool, DATASET_DETAIL_TOOL_CONFIG, DATASET_DETAIL_PROMPT_CONFIG, HUB_INSPECT_TOOL_CONFIG, HubInspectTool, DuplicateSpaceTool, formatDuplicateResult, SpaceInfoTool, formatSpaceInfoResult, SpaceFilesTool, UseSpaceTool, USE_SPACE_TOOL_CONFIG, formatUseSpaceResult, UserSummaryPrompt, USER_SUMMARY_PROMPT_CONFIG, PaperSummaryPrompt, PAPER_SUMMARY_PROMPT_CONFIG, CONFIG_GUIDANCE, TOOL_ID_GROUPS, DOCS_SEMANTIC_SEARCH_CONFIG, DocSearchTool, DOC_FETCH_CONFIG, DocFetchTool, HF_JOBS_TOOL_CONFIG, HfJobsTool, DYNAMIC_SPACE_TOOL_CONFIG, SpaceTool, } from '@llmindset/hf-mcp';
|
|
5
6
|
import { logger } from './utils/logger.js';
|
|
6
|
-
import { logSearchQuery, logPromptQuery, logGradioEvent } from './utils/query-logger.js';
|
|
7
|
+
import { logSearchQuery, logPromptQuery, logGradioEvent, } from './utils/query-logger.js';
|
|
7
8
|
import { DEFAULT_SPACE_TOOLS } from '../shared/settings.js';
|
|
8
9
|
import { extractAuthBouquetAndMix } from './utils/auth-utils.js';
|
|
9
10
|
import { ToolSelectionStrategy } from './utils/tool-selection-strategy.js';
|
|
@@ -51,6 +52,31 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
51
52
|
logger.debug({ sessionInfo, options }, 'Query logging options:');
|
|
52
53
|
return options;
|
|
53
54
|
};
|
|
55
|
+
const runWithQueryLogging = async (logFn, config, work) => {
|
|
56
|
+
const start = performance.now();
|
|
57
|
+
try {
|
|
58
|
+
const result = await work();
|
|
59
|
+
const durationMs = performance.now() - start;
|
|
60
|
+
const successOptions = config.successOptions?.(result) ?? {};
|
|
61
|
+
logFn(config.methodName, config.query, config.parameters, {
|
|
62
|
+
...config.baseOptions,
|
|
63
|
+
...successOptions,
|
|
64
|
+
durationMs,
|
|
65
|
+
success: true,
|
|
66
|
+
});
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const durationMs = performance.now() - start;
|
|
71
|
+
logFn(config.methodName, config.query, config.parameters, {
|
|
72
|
+
...config.baseOptions,
|
|
73
|
+
durationMs,
|
|
74
|
+
success: false,
|
|
75
|
+
error,
|
|
76
|
+
});
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
54
80
|
const server = new McpServer({
|
|
55
81
|
name: '@huggingface/mcp-services',
|
|
56
82
|
version: version,
|
|
@@ -91,13 +117,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
91
117
|
});
|
|
92
118
|
}
|
|
93
119
|
server.prompt(USER_SUMMARY_PROMPT_CONFIG.name, USER_SUMMARY_PROMPT_CONFIG.description, USER_SUMMARY_PROMPT_CONFIG.schema.shape, async (params) => {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
const summaryText = await runWithQueryLogging(logPromptQuery, {
|
|
121
|
+
methodName: USER_SUMMARY_PROMPT_CONFIG.name,
|
|
122
|
+
query: params.user_id,
|
|
123
|
+
parameters: { user_id: params.user_id },
|
|
124
|
+
baseOptions: getLoggingOptions(),
|
|
125
|
+
successOptions: (text) => ({
|
|
126
|
+
totalResults: 1,
|
|
127
|
+
resultsShared: 1,
|
|
128
|
+
responseCharCount: text.length,
|
|
129
|
+
}),
|
|
130
|
+
}, async () => {
|
|
131
|
+
const userSummary = new UserSummaryPrompt(hfToken);
|
|
132
|
+
return userSummary.generateSummary(params);
|
|
101
133
|
});
|
|
102
134
|
return {
|
|
103
135
|
description: `User summary for ${params.user_id}`,
|
|
@@ -113,13 +145,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
113
145
|
};
|
|
114
146
|
});
|
|
115
147
|
server.prompt(PAPER_SUMMARY_PROMPT_CONFIG.name, PAPER_SUMMARY_PROMPT_CONFIG.description, PAPER_SUMMARY_PROMPT_CONFIG.schema.shape, async (params) => {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
const summaryText = await runWithQueryLogging(logPromptQuery, {
|
|
149
|
+
methodName: PAPER_SUMMARY_PROMPT_CONFIG.name,
|
|
150
|
+
query: params.paper_id,
|
|
151
|
+
parameters: { paper_id: params.paper_id },
|
|
152
|
+
baseOptions: getLoggingOptions(),
|
|
153
|
+
successOptions: (text) => ({
|
|
154
|
+
totalResults: 1,
|
|
155
|
+
resultsShared: 1,
|
|
156
|
+
responseCharCount: text.length,
|
|
157
|
+
}),
|
|
158
|
+
}, async () => {
|
|
159
|
+
const paperSummary = new PaperSummaryPrompt(hfToken);
|
|
160
|
+
return paperSummary.generateSummary(params);
|
|
123
161
|
});
|
|
124
162
|
return {
|
|
125
163
|
description: `Paper summary for ${params.paper_id}`,
|
|
@@ -135,13 +173,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
135
173
|
};
|
|
136
174
|
});
|
|
137
175
|
server.prompt(MODEL_DETAIL_PROMPT_CONFIG.name, MODEL_DETAIL_PROMPT_CONFIG.description, MODEL_DETAIL_PROMPT_CONFIG.schema.shape, async (params) => {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
176
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
177
|
+
methodName: MODEL_DETAIL_PROMPT_CONFIG.name,
|
|
178
|
+
query: params.model_id,
|
|
179
|
+
parameters: { model_id: params.model_id },
|
|
180
|
+
baseOptions: getLoggingOptions(),
|
|
181
|
+
successOptions: (details) => ({
|
|
182
|
+
totalResults: details.totalResults,
|
|
183
|
+
resultsShared: details.resultsShared,
|
|
184
|
+
responseCharCount: details.formatted.length,
|
|
185
|
+
}),
|
|
186
|
+
}, async () => {
|
|
187
|
+
const modelDetail = new ModelDetailTool(hfToken, undefined);
|
|
188
|
+
return modelDetail.getDetails(params.model_id, true);
|
|
145
189
|
});
|
|
146
190
|
return {
|
|
147
191
|
description: `Model details for ${params.model_id}`,
|
|
@@ -157,13 +201,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
157
201
|
};
|
|
158
202
|
});
|
|
159
203
|
server.prompt(DATASET_DETAIL_PROMPT_CONFIG.name, DATASET_DETAIL_PROMPT_CONFIG.description, DATASET_DETAIL_PROMPT_CONFIG.schema.shape, async (params) => {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
204
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
205
|
+
methodName: DATASET_DETAIL_PROMPT_CONFIG.name,
|
|
206
|
+
query: params.dataset_id,
|
|
207
|
+
parameters: { dataset_id: params.dataset_id },
|
|
208
|
+
baseOptions: getLoggingOptions(),
|
|
209
|
+
successOptions: (details) => ({
|
|
210
|
+
totalResults: details.totalResults,
|
|
211
|
+
resultsShared: details.resultsShared,
|
|
212
|
+
responseCharCount: details.formatted.length,
|
|
213
|
+
}),
|
|
214
|
+
}, async () => {
|
|
215
|
+
const datasetDetail = new DatasetDetailTool(hfToken, undefined);
|
|
216
|
+
return datasetDetail.getDetails(params.dataset_id, true);
|
|
167
217
|
});
|
|
168
218
|
return {
|
|
169
219
|
description: `Dataset details for ${params.dataset_id}`,
|
|
@@ -179,78 +229,115 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
179
229
|
};
|
|
180
230
|
});
|
|
181
231
|
toolInstances[SEMANTIC_SEARCH_TOOL_CONFIG.name] = server.tool(SEMANTIC_SEARCH_TOOL_CONFIG.name, SEMANTIC_SEARCH_TOOL_CONFIG.description, SEMANTIC_SEARCH_TOOL_CONFIG.schema.shape, SEMANTIC_SEARCH_TOOL_CONFIG.annotations, async (params) => {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
232
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
233
|
+
methodName: SEMANTIC_SEARCH_TOOL_CONFIG.name,
|
|
234
|
+
query: params.query,
|
|
235
|
+
parameters: { limit: params.limit, mcp: params.mcp },
|
|
236
|
+
baseOptions: getLoggingOptions(),
|
|
237
|
+
successOptions: (formatted) => ({
|
|
238
|
+
totalResults: formatted.totalResults,
|
|
239
|
+
resultsShared: formatted.resultsShared,
|
|
240
|
+
responseCharCount: formatted.formatted.length,
|
|
241
|
+
}),
|
|
242
|
+
}, async () => {
|
|
243
|
+
const semanticSearch = new SpaceSearchTool(hfToken);
|
|
244
|
+
const searchResult = await semanticSearch.search(params.query, params.limit, params.mcp);
|
|
245
|
+
return formatSearchResults(params.query, searchResult.results, searchResult.totalCount);
|
|
190
246
|
});
|
|
191
247
|
return {
|
|
192
248
|
content: [{ type: 'text', text: result.formatted }],
|
|
193
249
|
};
|
|
194
250
|
});
|
|
195
251
|
toolInstances[MODEL_SEARCH_TOOL_CONFIG.name] = server.tool(MODEL_SEARCH_TOOL_CONFIG.name, MODEL_SEARCH_TOOL_CONFIG.description, MODEL_SEARCH_TOOL_CONFIG.schema.shape, MODEL_SEARCH_TOOL_CONFIG.annotations, async (params) => {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
252
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
253
|
+
methodName: MODEL_SEARCH_TOOL_CONFIG.name,
|
|
254
|
+
query: params.query || `sort:${params.sort || 'trendingScore'}`,
|
|
255
|
+
parameters: params,
|
|
256
|
+
baseOptions: getLoggingOptions(),
|
|
257
|
+
successOptions: (formatted) => ({
|
|
258
|
+
totalResults: formatted.totalResults,
|
|
259
|
+
resultsShared: formatted.resultsShared,
|
|
260
|
+
responseCharCount: formatted.formatted.length,
|
|
261
|
+
}),
|
|
262
|
+
}, async () => {
|
|
263
|
+
const modelSearch = new ModelSearchTool(hfToken);
|
|
264
|
+
return modelSearch.searchWithParams(params);
|
|
203
265
|
});
|
|
204
266
|
return {
|
|
205
267
|
content: [{ type: 'text', text: result.formatted }],
|
|
206
268
|
};
|
|
207
269
|
});
|
|
208
270
|
toolInstances[MODEL_DETAIL_TOOL_CONFIG.name] = server.tool(MODEL_DETAIL_TOOL_CONFIG.name, MODEL_DETAIL_TOOL_CONFIG.description, MODEL_DETAIL_TOOL_CONFIG.schema.shape, MODEL_DETAIL_TOOL_CONFIG.annotations, async (params) => {
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
271
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
272
|
+
methodName: MODEL_DETAIL_TOOL_CONFIG.name,
|
|
273
|
+
query: params.model_id,
|
|
274
|
+
parameters: { model_id: params.model_id },
|
|
275
|
+
baseOptions: getLoggingOptions(),
|
|
276
|
+
successOptions: (details) => ({
|
|
277
|
+
totalResults: details.totalResults,
|
|
278
|
+
resultsShared: details.resultsShared,
|
|
279
|
+
responseCharCount: details.formatted.length,
|
|
280
|
+
}),
|
|
281
|
+
}, async () => {
|
|
282
|
+
const modelDetail = new ModelDetailTool(hfToken, undefined);
|
|
283
|
+
return modelDetail.getDetails(params.model_id, false);
|
|
216
284
|
});
|
|
217
285
|
return {
|
|
218
286
|
content: [{ type: 'text', text: result.formatted }],
|
|
219
287
|
};
|
|
220
288
|
});
|
|
221
289
|
toolInstances[PAPER_SEARCH_TOOL_CONFIG.name] = server.tool(PAPER_SEARCH_TOOL_CONFIG.name, PAPER_SEARCH_TOOL_CONFIG.description, PAPER_SEARCH_TOOL_CONFIG.schema.shape, PAPER_SEARCH_TOOL_CONFIG.annotations, async (params) => {
|
|
222
|
-
const result = await
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
290
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
291
|
+
methodName: PAPER_SEARCH_TOOL_CONFIG.name,
|
|
292
|
+
query: params.query,
|
|
293
|
+
parameters: { results_limit: params.results_limit, concise_only: params.concise_only },
|
|
294
|
+
baseOptions: getLoggingOptions(),
|
|
295
|
+
successOptions: (formatted) => ({
|
|
296
|
+
totalResults: formatted.totalResults,
|
|
297
|
+
resultsShared: formatted.resultsShared,
|
|
298
|
+
responseCharCount: formatted.formatted.length,
|
|
299
|
+
}),
|
|
300
|
+
}, async () => {
|
|
301
|
+
const paperSearchTool = new PaperSearchTool(hfToken);
|
|
302
|
+
return paperSearchTool.search(params.query, params.results_limit, params.concise_only);
|
|
228
303
|
});
|
|
229
304
|
return {
|
|
230
305
|
content: [{ type: 'text', text: result.formatted }],
|
|
231
306
|
};
|
|
232
307
|
});
|
|
233
308
|
toolInstances[DATASET_SEARCH_TOOL_CONFIG.name] = server.tool(DATASET_SEARCH_TOOL_CONFIG.name, DATASET_SEARCH_TOOL_CONFIG.description, DATASET_SEARCH_TOOL_CONFIG.schema.shape, DATASET_SEARCH_TOOL_CONFIG.annotations, async (params) => {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
309
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
310
|
+
methodName: DATASET_SEARCH_TOOL_CONFIG.name,
|
|
311
|
+
query: params.query || `sort:${params.sort || 'trendingScore'}`,
|
|
312
|
+
parameters: params,
|
|
313
|
+
baseOptions: getLoggingOptions(),
|
|
314
|
+
successOptions: (formatted) => ({
|
|
315
|
+
totalResults: formatted.totalResults,
|
|
316
|
+
resultsShared: formatted.resultsShared,
|
|
317
|
+
responseCharCount: formatted.formatted.length,
|
|
318
|
+
}),
|
|
319
|
+
}, async () => {
|
|
320
|
+
const datasetSearch = new DatasetSearchTool(hfToken);
|
|
321
|
+
return datasetSearch.searchWithParams(params);
|
|
241
322
|
});
|
|
242
323
|
return {
|
|
243
324
|
content: [{ type: 'text', text: result.formatted }],
|
|
244
325
|
};
|
|
245
326
|
});
|
|
246
327
|
toolInstances[DATASET_DETAIL_TOOL_CONFIG.name] = server.tool(DATASET_DETAIL_TOOL_CONFIG.name, DATASET_DETAIL_TOOL_CONFIG.description, DATASET_DETAIL_TOOL_CONFIG.schema.shape, DATASET_DETAIL_TOOL_CONFIG.annotations, async (params) => {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
328
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
329
|
+
methodName: DATASET_DETAIL_TOOL_CONFIG.name,
|
|
330
|
+
query: params.dataset_id,
|
|
331
|
+
parameters: { dataset_id: params.dataset_id },
|
|
332
|
+
baseOptions: getLoggingOptions(),
|
|
333
|
+
successOptions: (details) => ({
|
|
334
|
+
totalResults: details.totalResults,
|
|
335
|
+
resultsShared: details.resultsShared,
|
|
336
|
+
responseCharCount: details.formatted.length,
|
|
337
|
+
}),
|
|
338
|
+
}, async () => {
|
|
339
|
+
const datasetDetail = new DatasetDetailTool(hfToken, undefined);
|
|
340
|
+
return datasetDetail.getDetails(params.dataset_id, false);
|
|
254
341
|
});
|
|
255
342
|
return {
|
|
256
343
|
content: [{ type: 'text', text: result.formatted }],
|
|
@@ -272,31 +359,43 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
272
359
|
const allowReadme = hasReadmeFlag(currentSelection.enabledToolIds);
|
|
273
360
|
const wantReadme = params.include_readme === true;
|
|
274
361
|
const includeReadme = allowReadme && wantReadme;
|
|
275
|
-
const tool = new HubInspectTool(hfToken, undefined);
|
|
276
|
-
const result = await tool.inspect(params, includeReadme);
|
|
277
362
|
const repoIdsParam = params.repo_ids;
|
|
278
363
|
const repoIds = Array.isArray(repoIdsParam) ? repoIdsParam : [];
|
|
279
364
|
const firstRepoId = typeof repoIds[0] === 'string' ? repoIds[0] : '';
|
|
280
365
|
const repoType = params.repo_type;
|
|
281
366
|
const repoTypeSafe = repoType === 'model' || repoType === 'dataset' || repoType === 'space' ? repoType : undefined;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
367
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
368
|
+
methodName: HUB_INSPECT_TOOL_CONFIG.name,
|
|
369
|
+
query: firstRepoId,
|
|
370
|
+
parameters: { count: repoIds.length, repo_type: repoTypeSafe, include_readme: includeReadme },
|
|
371
|
+
baseOptions: getLoggingOptions(),
|
|
372
|
+
successOptions: (details) => ({
|
|
373
|
+
totalResults: details.totalResults,
|
|
374
|
+
resultsShared: details.resultsShared,
|
|
375
|
+
responseCharCount: details.formatted.length,
|
|
376
|
+
}),
|
|
377
|
+
}, async () => {
|
|
378
|
+
const tool = new HubInspectTool(hfToken, undefined);
|
|
379
|
+
return tool.inspect(params, includeReadme);
|
|
287
380
|
});
|
|
288
381
|
return {
|
|
289
382
|
content: [{ type: 'text', text: result.formatted }],
|
|
290
383
|
};
|
|
291
384
|
});
|
|
292
385
|
toolInstances[DOCS_SEMANTIC_SEARCH_CONFIG.name] = server.tool(DOCS_SEMANTIC_SEARCH_CONFIG.name, DOCS_SEMANTIC_SEARCH_CONFIG.description, DOCS_SEMANTIC_SEARCH_CONFIG.schema.shape, DOCS_SEMANTIC_SEARCH_CONFIG.annotations, async (params) => {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
386
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
387
|
+
methodName: DOCS_SEMANTIC_SEARCH_CONFIG.name,
|
|
388
|
+
query: params.query,
|
|
389
|
+
parameters: { product: params.product },
|
|
390
|
+
baseOptions: getLoggingOptions(),
|
|
391
|
+
successOptions: (formatted) => ({
|
|
392
|
+
totalResults: formatted.totalResults,
|
|
393
|
+
resultsShared: formatted.resultsShared,
|
|
394
|
+
responseCharCount: formatted.formatted.length,
|
|
395
|
+
}),
|
|
396
|
+
}, async () => {
|
|
397
|
+
const docSearch = new DocSearchTool(hfToken);
|
|
398
|
+
return docSearch.search(params);
|
|
300
399
|
});
|
|
301
400
|
return {
|
|
302
401
|
content: [{ type: 'text', text: result.formatted }],
|
|
@@ -334,13 +433,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
334
433
|
};
|
|
335
434
|
});
|
|
336
435
|
toolInstances[USE_SPACE_TOOL_CONFIG.name] = server.tool(USE_SPACE_TOOL_CONFIG.name, USE_SPACE_TOOL_CONFIG.description, USE_SPACE_TOOL_CONFIG.schema.shape, USE_SPACE_TOOL_CONFIG.annotations, async (params) => {
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
436
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
437
|
+
methodName: USE_SPACE_TOOL_CONFIG.name,
|
|
438
|
+
query: params.space_id,
|
|
439
|
+
parameters: { space_id: params.space_id },
|
|
440
|
+
baseOptions: getLoggingOptions(),
|
|
441
|
+
successOptions: (useSpaceResult) => ({
|
|
442
|
+
totalResults: useSpaceResult.metadata.totalResults,
|
|
443
|
+
resultsShared: useSpaceResult.metadata.resultsShared,
|
|
444
|
+
responseCharCount: useSpaceResult.metadata.formatted.length,
|
|
445
|
+
}),
|
|
446
|
+
}, async () => {
|
|
447
|
+
const useSpaceTool = new UseSpaceTool(hfToken, undefined);
|
|
448
|
+
return formatUseSpaceResult(useSpaceTool, params);
|
|
344
449
|
});
|
|
345
450
|
return {
|
|
346
451
|
content: result.content,
|
|
@@ -348,14 +453,20 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
348
453
|
});
|
|
349
454
|
toolInstances[HF_JOBS_TOOL_CONFIG.name] = server.tool(HF_JOBS_TOOL_CONFIG.name, HF_JOBS_TOOL_CONFIG.description, HF_JOBS_TOOL_CONFIG.schema.shape, HF_JOBS_TOOL_CONFIG.annotations, async (params) => {
|
|
350
455
|
const isAuthenticated = !!hfToken;
|
|
351
|
-
const jobsTool = new HfJobsTool(hfToken, isAuthenticated, username);
|
|
352
|
-
const result = await jobsTool.execute(params);
|
|
353
456
|
const loggedOperation = params.operation ?? 'no-operation';
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
457
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
458
|
+
methodName: HF_JOBS_TOOL_CONFIG.name,
|
|
459
|
+
query: loggedOperation,
|
|
460
|
+
parameters: params.args || {},
|
|
461
|
+
baseOptions: getLoggingOptions(),
|
|
462
|
+
successOptions: (jobResult) => ({
|
|
463
|
+
totalResults: jobResult.totalResults,
|
|
464
|
+
resultsShared: jobResult.resultsShared,
|
|
465
|
+
responseCharCount: jobResult.formatted.length,
|
|
466
|
+
}),
|
|
467
|
+
}, async () => {
|
|
468
|
+
const jobsTool = new HfJobsTool(hfToken, isAuthenticated, username);
|
|
469
|
+
return jobsTool.execute(params);
|
|
359
470
|
});
|
|
360
471
|
return {
|
|
361
472
|
content: [{ type: 'text', text: result.formatted }],
|
|
@@ -373,69 +484,72 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
373
484
|
isError: true,
|
|
374
485
|
};
|
|
375
486
|
}
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
stripImageContent
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
'
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
487
|
+
const loggedOperation = params.operation ?? 'no-operation';
|
|
488
|
+
if (params.operation === 'invoke') {
|
|
489
|
+
const startTime = Date.now();
|
|
490
|
+
let success = false;
|
|
491
|
+
try {
|
|
492
|
+
const spaceTool = new SpaceTool(hfToken);
|
|
493
|
+
const result = await spaceTool.execute(params, extra);
|
|
494
|
+
if ('result' in result && result.result) {
|
|
495
|
+
const invokeResult = result;
|
|
496
|
+
success = !invokeResult.isError;
|
|
497
|
+
const stripImageContent = noImageContentHeaderEnabled || toolSelection.enabledToolIds.includes('NO_GRADIO_IMAGE_CONTENT');
|
|
498
|
+
const postProcessOptions = {
|
|
499
|
+
stripImageContent,
|
|
500
|
+
toolName: DYNAMIC_SPACE_TOOL_CONFIG.name,
|
|
501
|
+
outwardFacingName: DYNAMIC_SPACE_TOOL_CONFIG.name,
|
|
502
|
+
sessionInfo,
|
|
503
|
+
spaceName: params.space_name,
|
|
504
|
+
};
|
|
505
|
+
const processedResult = applyResultPostProcessing(invokeResult.result, postProcessOptions);
|
|
506
|
+
const warningsContent = invokeResult.warnings.length > 0
|
|
507
|
+
? [
|
|
508
|
+
{
|
|
509
|
+
type: 'text',
|
|
510
|
+
text: (invokeResult.warnings.length === 1 ? 'Warning:\n' : 'Warnings:\n') +
|
|
511
|
+
invokeResult.warnings.map((w) => `- ${w}`).join('\n') +
|
|
512
|
+
'\n',
|
|
513
|
+
},
|
|
514
|
+
]
|
|
515
|
+
: [];
|
|
516
|
+
const durationMs = Date.now() - startTime;
|
|
517
|
+
const responseContent = [...warningsContent, ...processedResult.content];
|
|
518
|
+
logGradioEvent(params.space_name || 'unknown-space', sessionInfo?.clientSessionId || 'unknown', {
|
|
519
|
+
durationMs,
|
|
520
|
+
isAuthenticated: !!hfToken,
|
|
521
|
+
clientName: sessionInfo?.clientInfo?.name,
|
|
522
|
+
clientVersion: sessionInfo?.clientInfo?.version,
|
|
523
|
+
success,
|
|
524
|
+
error: invokeResult.isError ? 'Tool returned isError=true' : undefined,
|
|
525
|
+
responseSizeBytes: JSON.stringify(responseContent).length,
|
|
526
|
+
isDynamic: true,
|
|
527
|
+
});
|
|
528
|
+
return {
|
|
529
|
+
content: responseContent,
|
|
530
|
+
...(invokeResult.isError && { isError: true }),
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
const toolResult = result;
|
|
534
|
+
success = !toolResult.isError;
|
|
535
|
+
const durationMs = Date.now() - startTime;
|
|
536
|
+
logSearchQuery(DYNAMIC_SPACE_TOOL_CONFIG.name, loggedOperation, params, {
|
|
537
|
+
...getLoggingOptions(),
|
|
538
|
+
totalResults: toolResult.totalResults,
|
|
539
|
+
resultsShared: toolResult.resultsShared,
|
|
540
|
+
responseCharCount: toolResult.formatted.length,
|
|
541
|
+
durationMs,
|
|
410
542
|
success,
|
|
411
|
-
error: invokeResult.isError ? 'Tool returned isError=true' : undefined,
|
|
412
|
-
responseSizeBytes: JSON.stringify(responseContent).length,
|
|
413
|
-
isDynamic: true,
|
|
414
543
|
});
|
|
415
544
|
return {
|
|
416
|
-
content:
|
|
417
|
-
...(
|
|
545
|
+
content: [{ type: 'text', text: toolResult.formatted }],
|
|
546
|
+
...(toolResult.isError && { isError: true }),
|
|
418
547
|
};
|
|
419
548
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const loggedOperation = params.operation ?? 'no-operation';
|
|
423
|
-
logSearchQuery(DYNAMIC_SPACE_TOOL_CONFIG.name, loggedOperation, params, {
|
|
424
|
-
...getLoggingOptions(),
|
|
425
|
-
totalResults: toolResult.totalResults,
|
|
426
|
-
resultsShared: toolResult.resultsShared,
|
|
427
|
-
responseCharCount: toolResult.formatted.length,
|
|
428
|
-
});
|
|
429
|
-
return {
|
|
430
|
-
content: [{ type: 'text', text: toolResult.formatted }],
|
|
431
|
-
...(toolResult.isError && { isError: true }),
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
catch (err) {
|
|
435
|
-
if (params.operation === 'invoke') {
|
|
436
|
-
const endTime = Date.now();
|
|
549
|
+
catch (err) {
|
|
550
|
+
const durationMs = Date.now() - startTime;
|
|
437
551
|
logGradioEvent(params.space_name || 'unknown-space', sessionInfo?.clientSessionId || 'unknown', {
|
|
438
|
-
durationMs
|
|
552
|
+
durationMs,
|
|
439
553
|
isAuthenticated: !!hfToken,
|
|
440
554
|
clientName: sessionInfo?.clientInfo?.name,
|
|
441
555
|
clientVersion: sessionInfo?.clientInfo?.version,
|
|
@@ -443,9 +557,28 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
443
557
|
error: err,
|
|
444
558
|
isDynamic: true,
|
|
445
559
|
});
|
|
560
|
+
throw err;
|
|
446
561
|
}
|
|
447
|
-
throw err;
|
|
448
562
|
}
|
|
563
|
+
const toolResult = await runWithQueryLogging(logSearchQuery, {
|
|
564
|
+
methodName: DYNAMIC_SPACE_TOOL_CONFIG.name,
|
|
565
|
+
query: loggedOperation,
|
|
566
|
+
parameters: params,
|
|
567
|
+
baseOptions: getLoggingOptions(),
|
|
568
|
+
successOptions: (result) => ({
|
|
569
|
+
totalResults: result.totalResults,
|
|
570
|
+
resultsShared: result.resultsShared,
|
|
571
|
+
responseCharCount: result.formatted.length,
|
|
572
|
+
}),
|
|
573
|
+
}, async () => {
|
|
574
|
+
const spaceTool = new SpaceTool(hfToken);
|
|
575
|
+
const result = await spaceTool.execute(params, extra);
|
|
576
|
+
return result;
|
|
577
|
+
});
|
|
578
|
+
return {
|
|
579
|
+
content: [{ type: 'text', text: toolResult.formatted }],
|
|
580
|
+
...(toolResult.isError && { isError: true }),
|
|
581
|
+
};
|
|
449
582
|
});
|
|
450
583
|
if (sessionInfo?.clientInfo?.name === 'openai-mcp') {
|
|
451
584
|
logger.debug('Registering Gradio widget resource for skybridge client');
|