@llmindset/hf-mcp-server 0.2.46 → 0.2.48
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 +296 -157
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/transport/base-transport.d.ts +12 -0
- package/dist/server/transport/base-transport.d.ts.map +1 -1
- package/dist/server/transport/base-transport.js +25 -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 +6 -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 +10 -2
- package/dist/server/transport/stateless-http-transport.js.map +1 -1
- package/dist/server/transport/streamable-http-transport.d.ts.map +1 -1
- package/dist/server/transport/streamable-http-transport.js +7 -2
- package/dist/server/transport/streamable-http-transport.js.map +1 -1
- package/dist/server/utils/gradio-discovery.d.ts.map +1 -1
- package/dist/server/utils/gradio-discovery.js +4 -1
- package/dist/server/utils/gradio-discovery.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 +41 -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/transport-metrics.d.ts +22 -0
- package/dist/shared/transport-metrics.d.ts.map +1 -1
- package/dist/shared/transport-metrics.js +70 -0
- package/dist/shared/transport-metrics.js.map +1 -1
- package/dist/web/assets/main-B_3qWYai.js +197 -0
- package/dist/web/index.html +1 -1
- package/package.json +2 -2
- package/dist/web/assets/main-b77rOMBk.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,aAw7BlG,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,37 @@ 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 = Math.round(performance.now() - start);
|
|
60
|
+
const successOptions = config.successOptions?.(result) ?? {};
|
|
61
|
+
const { success: successOverride, ...restSuccessOptions } = successOptions;
|
|
62
|
+
const resultHasError = typeof result === 'object' &&
|
|
63
|
+
result !== null &&
|
|
64
|
+
'isError' in result &&
|
|
65
|
+
Boolean(result.isError);
|
|
66
|
+
const successFlag = successOverride ?? !resultHasError;
|
|
67
|
+
logFn(config.methodName, config.query, config.parameters, {
|
|
68
|
+
...config.baseOptions,
|
|
69
|
+
...restSuccessOptions,
|
|
70
|
+
durationMs,
|
|
71
|
+
success: successFlag,
|
|
72
|
+
});
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const durationMs = Math.round(performance.now() - start);
|
|
77
|
+
logFn(config.methodName, config.query, config.parameters, {
|
|
78
|
+
...config.baseOptions,
|
|
79
|
+
durationMs,
|
|
80
|
+
success: false,
|
|
81
|
+
error,
|
|
82
|
+
});
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
54
86
|
const server = new McpServer({
|
|
55
87
|
name: '@huggingface/mcp-services',
|
|
56
88
|
version: version,
|
|
@@ -91,13 +123,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
91
123
|
});
|
|
92
124
|
}
|
|
93
125
|
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
|
-
|
|
126
|
+
const summaryText = await runWithQueryLogging(logPromptQuery, {
|
|
127
|
+
methodName: USER_SUMMARY_PROMPT_CONFIG.name,
|
|
128
|
+
query: params.user_id,
|
|
129
|
+
parameters: { user_id: params.user_id },
|
|
130
|
+
baseOptions: getLoggingOptions(),
|
|
131
|
+
successOptions: (text) => ({
|
|
132
|
+
totalResults: 1,
|
|
133
|
+
resultsShared: 1,
|
|
134
|
+
responseCharCount: text.length,
|
|
135
|
+
}),
|
|
136
|
+
}, async () => {
|
|
137
|
+
const userSummary = new UserSummaryPrompt(hfToken);
|
|
138
|
+
return userSummary.generateSummary(params);
|
|
101
139
|
});
|
|
102
140
|
return {
|
|
103
141
|
description: `User summary for ${params.user_id}`,
|
|
@@ -113,13 +151,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
113
151
|
};
|
|
114
152
|
});
|
|
115
153
|
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
|
-
|
|
154
|
+
const summaryText = await runWithQueryLogging(logPromptQuery, {
|
|
155
|
+
methodName: PAPER_SUMMARY_PROMPT_CONFIG.name,
|
|
156
|
+
query: params.paper_id,
|
|
157
|
+
parameters: { paper_id: params.paper_id },
|
|
158
|
+
baseOptions: getLoggingOptions(),
|
|
159
|
+
successOptions: (text) => ({
|
|
160
|
+
totalResults: 1,
|
|
161
|
+
resultsShared: 1,
|
|
162
|
+
responseCharCount: text.length,
|
|
163
|
+
}),
|
|
164
|
+
}, async () => {
|
|
165
|
+
const paperSummary = new PaperSummaryPrompt(hfToken);
|
|
166
|
+
return paperSummary.generateSummary(params);
|
|
123
167
|
});
|
|
124
168
|
return {
|
|
125
169
|
description: `Paper summary for ${params.paper_id}`,
|
|
@@ -135,13 +179,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
135
179
|
};
|
|
136
180
|
});
|
|
137
181
|
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
|
-
|
|
182
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
183
|
+
methodName: MODEL_DETAIL_PROMPT_CONFIG.name,
|
|
184
|
+
query: params.model_id,
|
|
185
|
+
parameters: { model_id: params.model_id },
|
|
186
|
+
baseOptions: getLoggingOptions(),
|
|
187
|
+
successOptions: (details) => ({
|
|
188
|
+
totalResults: details.totalResults,
|
|
189
|
+
resultsShared: details.resultsShared,
|
|
190
|
+
responseCharCount: details.formatted.length,
|
|
191
|
+
}),
|
|
192
|
+
}, async () => {
|
|
193
|
+
const modelDetail = new ModelDetailTool(hfToken, undefined);
|
|
194
|
+
return modelDetail.getDetails(params.model_id, true);
|
|
145
195
|
});
|
|
146
196
|
return {
|
|
147
197
|
description: `Model details for ${params.model_id}`,
|
|
@@ -157,13 +207,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
157
207
|
};
|
|
158
208
|
});
|
|
159
209
|
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
|
-
|
|
210
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
211
|
+
methodName: DATASET_DETAIL_PROMPT_CONFIG.name,
|
|
212
|
+
query: params.dataset_id,
|
|
213
|
+
parameters: { dataset_id: params.dataset_id },
|
|
214
|
+
baseOptions: getLoggingOptions(),
|
|
215
|
+
successOptions: (details) => ({
|
|
216
|
+
totalResults: details.totalResults,
|
|
217
|
+
resultsShared: details.resultsShared,
|
|
218
|
+
responseCharCount: details.formatted.length,
|
|
219
|
+
}),
|
|
220
|
+
}, async () => {
|
|
221
|
+
const datasetDetail = new DatasetDetailTool(hfToken, undefined);
|
|
222
|
+
return datasetDetail.getDetails(params.dataset_id, true);
|
|
167
223
|
});
|
|
168
224
|
return {
|
|
169
225
|
description: `Dataset details for ${params.dataset_id}`,
|
|
@@ -179,78 +235,115 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
179
235
|
};
|
|
180
236
|
});
|
|
181
237
|
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
|
-
|
|
238
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
239
|
+
methodName: SEMANTIC_SEARCH_TOOL_CONFIG.name,
|
|
240
|
+
query: params.query,
|
|
241
|
+
parameters: { limit: params.limit, mcp: params.mcp },
|
|
242
|
+
baseOptions: getLoggingOptions(),
|
|
243
|
+
successOptions: (formatted) => ({
|
|
244
|
+
totalResults: formatted.totalResults,
|
|
245
|
+
resultsShared: formatted.resultsShared,
|
|
246
|
+
responseCharCount: formatted.formatted.length,
|
|
247
|
+
}),
|
|
248
|
+
}, async () => {
|
|
249
|
+
const semanticSearch = new SpaceSearchTool(hfToken);
|
|
250
|
+
const searchResult = await semanticSearch.search(params.query, params.limit, params.mcp);
|
|
251
|
+
return formatSearchResults(params.query, searchResult.results, searchResult.totalCount);
|
|
190
252
|
});
|
|
191
253
|
return {
|
|
192
254
|
content: [{ type: 'text', text: result.formatted }],
|
|
193
255
|
};
|
|
194
256
|
});
|
|
195
257
|
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
|
-
|
|
258
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
259
|
+
methodName: MODEL_SEARCH_TOOL_CONFIG.name,
|
|
260
|
+
query: params.query || `sort:${params.sort || 'trendingScore'}`,
|
|
261
|
+
parameters: params,
|
|
262
|
+
baseOptions: getLoggingOptions(),
|
|
263
|
+
successOptions: (formatted) => ({
|
|
264
|
+
totalResults: formatted.totalResults,
|
|
265
|
+
resultsShared: formatted.resultsShared,
|
|
266
|
+
responseCharCount: formatted.formatted.length,
|
|
267
|
+
}),
|
|
268
|
+
}, async () => {
|
|
269
|
+
const modelSearch = new ModelSearchTool(hfToken);
|
|
270
|
+
return modelSearch.searchWithParams(params);
|
|
203
271
|
});
|
|
204
272
|
return {
|
|
205
273
|
content: [{ type: 'text', text: result.formatted }],
|
|
206
274
|
};
|
|
207
275
|
});
|
|
208
276
|
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
|
-
|
|
277
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
278
|
+
methodName: MODEL_DETAIL_TOOL_CONFIG.name,
|
|
279
|
+
query: params.model_id,
|
|
280
|
+
parameters: { model_id: params.model_id },
|
|
281
|
+
baseOptions: getLoggingOptions(),
|
|
282
|
+
successOptions: (details) => ({
|
|
283
|
+
totalResults: details.totalResults,
|
|
284
|
+
resultsShared: details.resultsShared,
|
|
285
|
+
responseCharCount: details.formatted.length,
|
|
286
|
+
}),
|
|
287
|
+
}, async () => {
|
|
288
|
+
const modelDetail = new ModelDetailTool(hfToken, undefined);
|
|
289
|
+
return modelDetail.getDetails(params.model_id, false);
|
|
216
290
|
});
|
|
217
291
|
return {
|
|
218
292
|
content: [{ type: 'text', text: result.formatted }],
|
|
219
293
|
};
|
|
220
294
|
});
|
|
221
295
|
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
|
-
|
|
296
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
297
|
+
methodName: PAPER_SEARCH_TOOL_CONFIG.name,
|
|
298
|
+
query: params.query,
|
|
299
|
+
parameters: { results_limit: params.results_limit, concise_only: params.concise_only },
|
|
300
|
+
baseOptions: getLoggingOptions(),
|
|
301
|
+
successOptions: (formatted) => ({
|
|
302
|
+
totalResults: formatted.totalResults,
|
|
303
|
+
resultsShared: formatted.resultsShared,
|
|
304
|
+
responseCharCount: formatted.formatted.length,
|
|
305
|
+
}),
|
|
306
|
+
}, async () => {
|
|
307
|
+
const paperSearchTool = new PaperSearchTool(hfToken);
|
|
308
|
+
return paperSearchTool.search(params.query, params.results_limit, params.concise_only);
|
|
228
309
|
});
|
|
229
310
|
return {
|
|
230
311
|
content: [{ type: 'text', text: result.formatted }],
|
|
231
312
|
};
|
|
232
313
|
});
|
|
233
314
|
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
|
-
|
|
315
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
316
|
+
methodName: DATASET_SEARCH_TOOL_CONFIG.name,
|
|
317
|
+
query: params.query || `sort:${params.sort || 'trendingScore'}`,
|
|
318
|
+
parameters: params,
|
|
319
|
+
baseOptions: getLoggingOptions(),
|
|
320
|
+
successOptions: (formatted) => ({
|
|
321
|
+
totalResults: formatted.totalResults,
|
|
322
|
+
resultsShared: formatted.resultsShared,
|
|
323
|
+
responseCharCount: formatted.formatted.length,
|
|
324
|
+
}),
|
|
325
|
+
}, async () => {
|
|
326
|
+
const datasetSearch = new DatasetSearchTool(hfToken);
|
|
327
|
+
return datasetSearch.searchWithParams(params);
|
|
241
328
|
});
|
|
242
329
|
return {
|
|
243
330
|
content: [{ type: 'text', text: result.formatted }],
|
|
244
331
|
};
|
|
245
332
|
});
|
|
246
333
|
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
|
-
|
|
334
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
335
|
+
methodName: DATASET_DETAIL_TOOL_CONFIG.name,
|
|
336
|
+
query: params.dataset_id,
|
|
337
|
+
parameters: { dataset_id: params.dataset_id },
|
|
338
|
+
baseOptions: getLoggingOptions(),
|
|
339
|
+
successOptions: (details) => ({
|
|
340
|
+
totalResults: details.totalResults,
|
|
341
|
+
resultsShared: details.resultsShared,
|
|
342
|
+
responseCharCount: details.formatted.length,
|
|
343
|
+
}),
|
|
344
|
+
}, async () => {
|
|
345
|
+
const datasetDetail = new DatasetDetailTool(hfToken, undefined);
|
|
346
|
+
return datasetDetail.getDetails(params.dataset_id, false);
|
|
254
347
|
});
|
|
255
348
|
return {
|
|
256
349
|
content: [{ type: 'text', text: result.formatted }],
|
|
@@ -272,31 +365,43 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
272
365
|
const allowReadme = hasReadmeFlag(currentSelection.enabledToolIds);
|
|
273
366
|
const wantReadme = params.include_readme === true;
|
|
274
367
|
const includeReadme = allowReadme && wantReadme;
|
|
275
|
-
const tool = new HubInspectTool(hfToken, undefined);
|
|
276
|
-
const result = await tool.inspect(params, includeReadme);
|
|
277
368
|
const repoIdsParam = params.repo_ids;
|
|
278
369
|
const repoIds = Array.isArray(repoIdsParam) ? repoIdsParam : [];
|
|
279
370
|
const firstRepoId = typeof repoIds[0] === 'string' ? repoIds[0] : '';
|
|
280
371
|
const repoType = params.repo_type;
|
|
281
372
|
const repoTypeSafe = repoType === 'model' || repoType === 'dataset' || repoType === 'space' ? repoType : undefined;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
373
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
374
|
+
methodName: HUB_INSPECT_TOOL_CONFIG.name,
|
|
375
|
+
query: firstRepoId,
|
|
376
|
+
parameters: { count: repoIds.length, repo_type: repoTypeSafe, include_readme: includeReadme },
|
|
377
|
+
baseOptions: getLoggingOptions(),
|
|
378
|
+
successOptions: (details) => ({
|
|
379
|
+
totalResults: details.totalResults,
|
|
380
|
+
resultsShared: details.resultsShared,
|
|
381
|
+
responseCharCount: details.formatted.length,
|
|
382
|
+
}),
|
|
383
|
+
}, async () => {
|
|
384
|
+
const tool = new HubInspectTool(hfToken, undefined);
|
|
385
|
+
return tool.inspect(params, includeReadme);
|
|
287
386
|
});
|
|
288
387
|
return {
|
|
289
388
|
content: [{ type: 'text', text: result.formatted }],
|
|
290
389
|
};
|
|
291
390
|
});
|
|
292
391
|
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
|
-
|
|
392
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
393
|
+
methodName: DOCS_SEMANTIC_SEARCH_CONFIG.name,
|
|
394
|
+
query: params.query,
|
|
395
|
+
parameters: { product: params.product },
|
|
396
|
+
baseOptions: getLoggingOptions(),
|
|
397
|
+
successOptions: (formatted) => ({
|
|
398
|
+
totalResults: formatted.totalResults,
|
|
399
|
+
resultsShared: formatted.resultsShared,
|
|
400
|
+
responseCharCount: formatted.formatted.length,
|
|
401
|
+
}),
|
|
402
|
+
}, async () => {
|
|
403
|
+
const docSearch = new DocSearchTool(hfToken);
|
|
404
|
+
return docSearch.search(params);
|
|
300
405
|
});
|
|
301
406
|
return {
|
|
302
407
|
content: [{ type: 'text', text: result.formatted }],
|
|
@@ -334,13 +439,19 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
334
439
|
};
|
|
335
440
|
});
|
|
336
441
|
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
|
-
|
|
442
|
+
const result = await runWithQueryLogging(logPromptQuery, {
|
|
443
|
+
methodName: USE_SPACE_TOOL_CONFIG.name,
|
|
444
|
+
query: params.space_id,
|
|
445
|
+
parameters: { space_id: params.space_id },
|
|
446
|
+
baseOptions: getLoggingOptions(),
|
|
447
|
+
successOptions: (useSpaceResult) => ({
|
|
448
|
+
totalResults: useSpaceResult.metadata.totalResults,
|
|
449
|
+
resultsShared: useSpaceResult.metadata.resultsShared,
|
|
450
|
+
responseCharCount: useSpaceResult.metadata.formatted.length,
|
|
451
|
+
}),
|
|
452
|
+
}, async () => {
|
|
453
|
+
const useSpaceTool = new UseSpaceTool(hfToken, undefined);
|
|
454
|
+
return formatUseSpaceResult(useSpaceTool, params);
|
|
344
455
|
});
|
|
345
456
|
return {
|
|
346
457
|
content: result.content,
|
|
@@ -348,14 +459,20 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
348
459
|
});
|
|
349
460
|
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
461
|
const isAuthenticated = !!hfToken;
|
|
351
|
-
const jobsTool = new HfJobsTool(hfToken, isAuthenticated, username);
|
|
352
|
-
const result = await jobsTool.execute(params);
|
|
353
462
|
const loggedOperation = params.operation ?? 'no-operation';
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
463
|
+
const result = await runWithQueryLogging(logSearchQuery, {
|
|
464
|
+
methodName: HF_JOBS_TOOL_CONFIG.name,
|
|
465
|
+
query: loggedOperation,
|
|
466
|
+
parameters: params.args || {},
|
|
467
|
+
baseOptions: getLoggingOptions(),
|
|
468
|
+
successOptions: (jobResult) => ({
|
|
469
|
+
totalResults: jobResult.totalResults,
|
|
470
|
+
resultsShared: jobResult.resultsShared,
|
|
471
|
+
responseCharCount: jobResult.formatted.length,
|
|
472
|
+
}),
|
|
473
|
+
}, async () => {
|
|
474
|
+
const jobsTool = new HfJobsTool(hfToken, isAuthenticated, username);
|
|
475
|
+
return jobsTool.execute(params);
|
|
359
476
|
});
|
|
360
477
|
return {
|
|
361
478
|
content: [{ type: 'text', text: result.formatted }],
|
|
@@ -373,69 +490,72 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
373
490
|
isError: true,
|
|
374
491
|
};
|
|
375
492
|
}
|
|
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
|
-
|
|
493
|
+
const loggedOperation = params.operation ?? 'no-operation';
|
|
494
|
+
if (params.operation === 'invoke') {
|
|
495
|
+
const startTime = Date.now();
|
|
496
|
+
let success = false;
|
|
497
|
+
try {
|
|
498
|
+
const spaceTool = new SpaceTool(hfToken);
|
|
499
|
+
const result = await spaceTool.execute(params, extra);
|
|
500
|
+
if ('result' in result && result.result) {
|
|
501
|
+
const invokeResult = result;
|
|
502
|
+
success = !invokeResult.isError;
|
|
503
|
+
const stripImageContent = noImageContentHeaderEnabled || toolSelection.enabledToolIds.includes('NO_GRADIO_IMAGE_CONTENT');
|
|
504
|
+
const postProcessOptions = {
|
|
505
|
+
stripImageContent,
|
|
506
|
+
toolName: DYNAMIC_SPACE_TOOL_CONFIG.name,
|
|
507
|
+
outwardFacingName: DYNAMIC_SPACE_TOOL_CONFIG.name,
|
|
508
|
+
sessionInfo,
|
|
509
|
+
spaceName: params.space_name,
|
|
510
|
+
};
|
|
511
|
+
const processedResult = applyResultPostProcessing(invokeResult.result, postProcessOptions);
|
|
512
|
+
const warningsContent = invokeResult.warnings.length > 0
|
|
513
|
+
? [
|
|
514
|
+
{
|
|
515
|
+
type: 'text',
|
|
516
|
+
text: (invokeResult.warnings.length === 1 ? 'Warning:\n' : 'Warnings:\n') +
|
|
517
|
+
invokeResult.warnings.map((w) => `- ${w}`).join('\n') +
|
|
518
|
+
'\n',
|
|
519
|
+
},
|
|
520
|
+
]
|
|
521
|
+
: [];
|
|
522
|
+
const durationMs = Date.now() - startTime;
|
|
523
|
+
const responseContent = [...warningsContent, ...processedResult.content];
|
|
524
|
+
logGradioEvent(params.space_name || 'unknown-space', sessionInfo?.clientSessionId || 'unknown', {
|
|
525
|
+
durationMs,
|
|
526
|
+
isAuthenticated: !!hfToken,
|
|
527
|
+
clientName: sessionInfo?.clientInfo?.name,
|
|
528
|
+
clientVersion: sessionInfo?.clientInfo?.version,
|
|
529
|
+
success,
|
|
530
|
+
error: invokeResult.isError ? 'Tool returned isError=true' : undefined,
|
|
531
|
+
responseSizeBytes: JSON.stringify(responseContent).length,
|
|
532
|
+
isDynamic: true,
|
|
533
|
+
});
|
|
534
|
+
return {
|
|
535
|
+
content: responseContent,
|
|
536
|
+
...(invokeResult.isError && { isError: true }),
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
const toolResult = result;
|
|
540
|
+
success = !toolResult.isError;
|
|
541
|
+
const durationMs = Date.now() - startTime;
|
|
542
|
+
logSearchQuery(DYNAMIC_SPACE_TOOL_CONFIG.name, loggedOperation, params, {
|
|
543
|
+
...getLoggingOptions(),
|
|
544
|
+
totalResults: toolResult.totalResults,
|
|
545
|
+
resultsShared: toolResult.resultsShared,
|
|
546
|
+
responseCharCount: toolResult.formatted.length,
|
|
547
|
+
durationMs,
|
|
410
548
|
success,
|
|
411
|
-
error: invokeResult.isError ? 'Tool returned isError=true' : undefined,
|
|
412
|
-
responseSizeBytes: JSON.stringify(responseContent).length,
|
|
413
|
-
isDynamic: true,
|
|
414
549
|
});
|
|
415
550
|
return {
|
|
416
|
-
content:
|
|
417
|
-
...(
|
|
551
|
+
content: [{ type: 'text', text: toolResult.formatted }],
|
|
552
|
+
...(toolResult.isError && { isError: true }),
|
|
418
553
|
};
|
|
419
554
|
}
|
|
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();
|
|
555
|
+
catch (err) {
|
|
556
|
+
const durationMs = Date.now() - startTime;
|
|
437
557
|
logGradioEvent(params.space_name || 'unknown-space', sessionInfo?.clientSessionId || 'unknown', {
|
|
438
|
-
durationMs
|
|
558
|
+
durationMs,
|
|
439
559
|
isAuthenticated: !!hfToken,
|
|
440
560
|
clientName: sessionInfo?.clientInfo?.name,
|
|
441
561
|
clientVersion: sessionInfo?.clientInfo?.version,
|
|
@@ -443,9 +563,28 @@ export const createServerFactory = (_webServerInstance, sharedApiClient) => {
|
|
|
443
563
|
error: err,
|
|
444
564
|
isDynamic: true,
|
|
445
565
|
});
|
|
566
|
+
throw err;
|
|
446
567
|
}
|
|
447
|
-
throw err;
|
|
448
568
|
}
|
|
569
|
+
const toolResult = await runWithQueryLogging(logSearchQuery, {
|
|
570
|
+
methodName: DYNAMIC_SPACE_TOOL_CONFIG.name,
|
|
571
|
+
query: loggedOperation,
|
|
572
|
+
parameters: params,
|
|
573
|
+
baseOptions: getLoggingOptions(),
|
|
574
|
+
successOptions: (result) => ({
|
|
575
|
+
totalResults: result.totalResults,
|
|
576
|
+
resultsShared: result.resultsShared,
|
|
577
|
+
responseCharCount: result.formatted.length,
|
|
578
|
+
}),
|
|
579
|
+
}, async () => {
|
|
580
|
+
const spaceTool = new SpaceTool(hfToken);
|
|
581
|
+
const result = await spaceTool.execute(params, extra);
|
|
582
|
+
return result;
|
|
583
|
+
});
|
|
584
|
+
return {
|
|
585
|
+
content: [{ type: 'text', text: toolResult.formatted }],
|
|
586
|
+
...(toolResult.isError && { isError: true }),
|
|
587
|
+
};
|
|
449
588
|
});
|
|
450
589
|
if (sessionInfo?.clientInfo?.name === 'openai-mcp') {
|
|
451
590
|
logger.debug('Registering Gradio widget resource for skybridge client');
|