@llmindset/hf-mcp 0.2.50 → 0.2.51
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/space/commands/discover.d.ts +6 -1
- package/dist/space/commands/discover.d.ts.map +1 -1
- package/dist/space/commands/discover.js +60 -87
- package/dist/space/commands/discover.js.map +1 -1
- package/dist/space/commands/dynamic-find.d.ts +3 -0
- package/dist/space/commands/dynamic-find.d.ts.map +1 -0
- package/dist/space/commands/dynamic-find.js +109 -0
- package/dist/space/commands/dynamic-find.js.map +1 -0
- package/dist/space/space-tool.d.ts +22 -10
- package/dist/space/space-tool.d.ts.map +1 -1
- package/dist/space/space-tool.js +93 -17
- package/dist/space/space-tool.js.map +1 -1
- package/dist/space/types.d.ts +22 -4
- package/dist/space/types.d.ts.map +1 -1
- package/dist/space/types.js +22 -4
- package/dist/space/types.js.map +1 -1
- package/package.json +1 -1
- package/src/space/commands/discover.ts +87 -123
- package/src/space/commands/dynamic-find.ts +156 -0
- package/src/space/space-tool.ts +126 -22
- package/src/space/types.ts +44 -5
package/dist/space/types.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const OPERATION_NAMES: readonly ["
|
|
2
|
+
export declare const OPERATION_NAMES: readonly ["find", "view_parameters", "invoke"];
|
|
3
|
+
export declare const DYNAMIC_OPERATION_NAMES: readonly ["discover", "view_parameters", "invoke"];
|
|
3
4
|
export type OperationName = (typeof OPERATION_NAMES)[number];
|
|
5
|
+
export type DynamicOperationName = (typeof DYNAMIC_OPERATION_NAMES)[number];
|
|
6
|
+
export declare function isDynamicSpaceMode(): boolean;
|
|
7
|
+
export declare function getOperationNames(): readonly string[];
|
|
4
8
|
export declare const spaceArgsSchema: z.ZodObject<{
|
|
5
|
-
operation: z.ZodOptional<z.ZodEnum<["
|
|
9
|
+
operation: z.ZodOptional<z.ZodEnum<["find", "view_parameters", "invoke"]>>;
|
|
6
10
|
space_name: z.ZodOptional<z.ZodString>;
|
|
7
11
|
parameters: z.ZodOptional<z.ZodString>;
|
|
8
12
|
search_query: z.ZodOptional<z.ZodString>;
|
|
@@ -10,16 +14,30 @@ export declare const spaceArgsSchema: z.ZodObject<{
|
|
|
10
14
|
}, "strip", z.ZodTypeAny, {
|
|
11
15
|
limit?: number | undefined;
|
|
12
16
|
parameters?: string | undefined;
|
|
13
|
-
operation?: "
|
|
17
|
+
operation?: "find" | "view_parameters" | "invoke" | undefined;
|
|
14
18
|
space_name?: string | undefined;
|
|
15
19
|
search_query?: string | undefined;
|
|
16
20
|
}, {
|
|
17
21
|
limit?: number | undefined;
|
|
18
22
|
parameters?: string | undefined;
|
|
19
|
-
operation?: "
|
|
23
|
+
operation?: "find" | "view_parameters" | "invoke" | undefined;
|
|
20
24
|
space_name?: string | undefined;
|
|
21
25
|
search_query?: string | undefined;
|
|
22
26
|
}>;
|
|
27
|
+
export declare const dynamicSpaceArgsSchema: z.ZodObject<{
|
|
28
|
+
operation: z.ZodOptional<z.ZodEnum<["discover", "view_parameters", "invoke"]>>;
|
|
29
|
+
space_name: z.ZodOptional<z.ZodString>;
|
|
30
|
+
parameters: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
parameters?: string | undefined;
|
|
33
|
+
operation?: "view_parameters" | "invoke" | "discover" | undefined;
|
|
34
|
+
space_name?: string | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
parameters?: string | undefined;
|
|
37
|
+
operation?: "view_parameters" | "invoke" | "discover" | undefined;
|
|
38
|
+
space_name?: string | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
export declare function getSpaceArgsSchema(): z.ZodObject<z.ZodRawShape>;
|
|
23
41
|
export type SpaceArgs = z.infer<typeof spaceArgsSchema>;
|
|
24
42
|
export interface ParameterInfo {
|
|
25
43
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,eAAe,gDAAiD,CAAC;AAC9E,eAAO,MAAM,uBAAuB,oDAAqD,CAAC;AAC1F,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAK5E,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAKD,wBAAgB,iBAAiB,IAAI,SAAS,MAAM,EAAE,CAErD;AAKD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;EAgB1B,CAAC;AAKH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EASjC,CAAC;AAKH,wBAAgB,kBAAkB,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAE/D;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAKxD,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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AM,EAAE;QACP,OAAO,EAAE,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/space/types.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const OPERATION_NAMES = ['
|
|
2
|
+
export const OPERATION_NAMES = ['find', 'view_parameters', 'invoke'];
|
|
3
|
+
export const DYNAMIC_OPERATION_NAMES = ['discover', 'view_parameters', 'invoke'];
|
|
4
|
+
export function isDynamicSpaceMode() {
|
|
5
|
+
return !!process.env.DYNAMIC_SPACE_DATA;
|
|
6
|
+
}
|
|
7
|
+
export function getOperationNames() {
|
|
8
|
+
return isDynamicSpaceMode() ? DYNAMIC_OPERATION_NAMES : OPERATION_NAMES;
|
|
9
|
+
}
|
|
3
10
|
export const spaceArgsSchema = z.object({
|
|
4
11
|
operation: z.enum(OPERATION_NAMES).optional().describe('Operation to execute.'),
|
|
5
12
|
space_name: z
|
|
@@ -10,11 +17,22 @@ export const spaceArgsSchema = z.object({
|
|
|
10
17
|
search_query: z
|
|
11
18
|
.string()
|
|
12
19
|
.optional()
|
|
13
|
-
.describe('For
|
|
14
|
-
limit: z.number().optional().describe('For
|
|
20
|
+
.describe('For find operation: Search query or task category (e.g. "Image Generation", "OCR", "FLUX image generation") to find MCP-enabled Spaces. Call with blank query to see task hints.'),
|
|
21
|
+
limit: z.number().optional().describe('For find operation: Maximum number of results to return (default: 10)'),
|
|
15
22
|
});
|
|
23
|
+
export const dynamicSpaceArgsSchema = z.object({
|
|
24
|
+
operation: z.enum(DYNAMIC_OPERATION_NAMES).optional().describe('Operation to execute.'),
|
|
25
|
+
space_name: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('The Hugging Face space ID (format: "username/space-name"). Required for view_parameters and invoke operations.'),
|
|
29
|
+
parameters: z.string().optional().describe('For invoke operation: JSON object string of parameters'),
|
|
30
|
+
});
|
|
31
|
+
export function getSpaceArgsSchema() {
|
|
32
|
+
return isDynamicSpaceMode() ? dynamicSpaceArgsSchema : spaceArgsSchema;
|
|
33
|
+
}
|
|
16
34
|
export const FILE_INPUT_HELP_MESSAGE = 'Provide a publicly accessible URL (http:// or https://) for the Gradio file input. ' +
|
|
17
|
-
"Content
|
|
35
|
+
"Content previously generated by 'invoke' is usable, as well as Hub Repository URLs. ";
|
|
18
36
|
export function isFileDataProperty(prop) {
|
|
19
37
|
return (prop.title === 'ImageData' ||
|
|
20
38
|
prop.title === 'FileData' ||
|
package/dist/space/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,CAAU,CAAC;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,UAAU,EAAE,iBAAiB,EAAE,QAAQ,CAAU,CAAC;AAO1F,MAAM,UAAU,kBAAkB;IACjC,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;AACzC,CAAC;AAKD,MAAM,UAAU,iBAAiB;IAChC,OAAO,kBAAkB,EAAE,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,eAAe,CAAC;AACzE,CAAC;AAKD,MAAM,CAAC,MA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CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAChE,KAAK,CACL,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC7C,IAAI,CAAC,MAAM,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAErC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;AAClF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,156 +1,120 @@
|
|
|
1
1
|
import type { ToolResult } from '../../types/tool-result.js';
|
|
2
|
-
import { SpaceSearchTool, type SpaceSearchResult } from '../../space-search.js';
|
|
3
2
|
import { escapeMarkdown } from '../../utilities.js';
|
|
4
3
|
|
|
5
|
-
// Default number of results to return
|
|
6
|
-
const DEFAULT_RESULTS_LIMIT = 10;
|
|
7
|
-
|
|
8
4
|
/**
|
|
9
|
-
* Prompt configuration for discover operation
|
|
10
|
-
* These prompts can be easily tweaked to adjust
|
|
5
|
+
* Prompt configuration for discover operation (from DYNAMIC_SPACE_DATA)
|
|
6
|
+
* These prompts can be easily tweaked to adjust behavior
|
|
11
7
|
*/
|
|
12
|
-
const DISCOVER_PROMPTS = {
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- Image Generation
|
|
17
|
-
- Video Generation
|
|
18
|
-
- Text Generation
|
|
19
|
-
- Visual QA
|
|
20
|
-
- Language Translation
|
|
21
|
-
- Speech Synthesis
|
|
22
|
-
- 3D Modeling
|
|
23
|
-
- Object Detection
|
|
24
|
-
- Text Analysis
|
|
25
|
-
- Image Editing
|
|
26
|
-
- Code Generation
|
|
27
|
-
- Question Answering
|
|
28
|
-
- Data Visualization
|
|
29
|
-
- Voice Cloning
|
|
30
|
-
- Background Removal
|
|
31
|
-
- OCR
|
|
32
|
-
- Image Captioning
|
|
33
|
-
- Sentiment Analysis
|
|
34
|
-
- Music Generation
|
|
35
|
-
- Style Transfer
|
|
36
|
-
|
|
37
|
-
To discover MCP-enabled Spaces for a specific task, call this operation with a search query:
|
|
38
|
-
|
|
39
|
-
**Example:**
|
|
40
|
-
\`\`\`json
|
|
41
|
-
{
|
|
42
|
-
"operation": "discover",
|
|
43
|
-
"search_query": "image generation",
|
|
44
|
-
"limit": 10
|
|
45
|
-
}
|
|
46
|
-
\`\`\``,
|
|
47
|
-
|
|
48
|
-
// Header for search results
|
|
49
|
-
RESULTS_HEADER: (query: string, showing: number, total: number) => {
|
|
50
|
-
const showingText = showing < total ? `Showing ${showing} of ${total} results` : `All ${showing} results`;
|
|
51
|
-
return `# MCP Space Discovery Results for "${query}" (${showingText})
|
|
8
|
+
export const DISCOVER_PROMPTS = {
|
|
9
|
+
// Header for results
|
|
10
|
+
RESULTS_HEADER: `**Available Spaces:**
|
|
52
11
|
|
|
53
|
-
These
|
|
12
|
+
These spaces can be invoked using the \`dynamic_space\` tool.
|
|
54
13
|
Use \`"operation": "view_parameters"\` to inspect a space's parameters before invoking.
|
|
55
14
|
|
|
56
|
-
|
|
57
|
-
},
|
|
15
|
+
`,
|
|
58
16
|
|
|
59
17
|
// No results message
|
|
60
|
-
NO_RESULTS:
|
|
61
|
-
`No MCP-enabled Spaces found for "${query}".
|
|
18
|
+
NO_RESULTS: `No spaces available in the configured list.`,
|
|
62
19
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- Task-focused queries (e.g., "text generation", "object detection")
|
|
66
|
-
- Different task categories (e.g., "video generation", "image classification")`,
|
|
20
|
+
// Error fetching
|
|
21
|
+
FETCH_ERROR: (url: string, error: string): string => `Error fetching space list from ${url}: ${error}`,
|
|
67
22
|
};
|
|
68
23
|
|
|
69
24
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* @param searchQuery - The search query or task category
|
|
73
|
-
* @param limit - Maximum number of results to return
|
|
74
|
-
* @param hfToken - Optional HuggingFace API token
|
|
75
|
-
* @returns Formatted search results
|
|
25
|
+
* Parse CSV content into space entries
|
|
26
|
+
* Expected format: space_id,category,description
|
|
76
27
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
28
|
+
function parseCsvContent(content: string): Array<{ id: string; category: string; description: string }> {
|
|
29
|
+
const lines = content.trim().split('\n');
|
|
30
|
+
const results: Array<{ id: string; category: string; description: string }> = [];
|
|
31
|
+
|
|
32
|
+
for (const line of lines) {
|
|
33
|
+
if (!line.trim()) continue;
|
|
34
|
+
|
|
35
|
+
// Parse CSV with quoted fields
|
|
36
|
+
const match = line.match(/^([^,]+),([^,]+),"([^"]*)"$/) || line.match(/^([^,]+),([^,]+),(.*)$/);
|
|
37
|
+
|
|
38
|
+
if (match && match[1] && match[2] && match[3]) {
|
|
39
|
+
results.push({
|
|
40
|
+
id: match[1].trim(),
|
|
41
|
+
category: match[2].trim(),
|
|
42
|
+
description: match[3].trim(),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
89
45
|
}
|
|
90
46
|
|
|
91
|
-
|
|
92
|
-
// Use SpaceSearchTool to search for MCP-enabled spaces only
|
|
93
|
-
const searchTool = new SpaceSearchTool(hfToken);
|
|
94
|
-
const { results, totalCount } = await searchTool.search(
|
|
95
|
-
searchQuery,
|
|
96
|
-
limit,
|
|
97
|
-
true // mcp = true (only MCP-enabled spaces)
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
// Format and return results
|
|
101
|
-
return formatDiscoverResults(searchQuery, results, totalCount);
|
|
102
|
-
} catch (error) {
|
|
103
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
104
|
-
return {
|
|
105
|
-
formatted: `Error discovering spaces: ${errorMessage}`,
|
|
106
|
-
totalResults: 0,
|
|
107
|
-
resultsShared: 0,
|
|
108
|
-
isError: true,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
47
|
+
return results;
|
|
111
48
|
}
|
|
112
49
|
|
|
113
50
|
/**
|
|
114
|
-
*
|
|
115
|
-
* Note: Author column is omitted as it's superfluous for invocation purposes
|
|
116
|
-
* Duplication is OK for the mean time; space_search will be rolled in to a general tool
|
|
51
|
+
* Format results as a markdown table
|
|
117
52
|
*/
|
|
118
|
-
function formatDiscoverResults(
|
|
53
|
+
function formatDiscoverResults(results: Array<{ id: string; category: string; description: string }>): string {
|
|
119
54
|
if (results.length === 0) {
|
|
55
|
+
return DISCOVER_PROMPTS.NO_RESULTS;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let markdown = DISCOVER_PROMPTS.RESULTS_HEADER;
|
|
59
|
+
|
|
60
|
+
// Table header
|
|
61
|
+
markdown += '| Space ID | Category | Description |\n';
|
|
62
|
+
markdown += '|----------|----------|-------------|\n';
|
|
63
|
+
|
|
64
|
+
// Table rows
|
|
65
|
+
for (const result of results) {
|
|
66
|
+
markdown +=
|
|
67
|
+
`| \`${escapeMarkdown(result.id)}\` ` +
|
|
68
|
+
`| ${escapeMarkdown(result.category)} ` +
|
|
69
|
+
`| ${escapeMarkdown(result.description)} |\n`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return markdown;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Discover spaces from a configured URL (DYNAMIC_SPACE_DATA)
|
|
77
|
+
* Fetches CSV content and returns as markdown table
|
|
78
|
+
*/
|
|
79
|
+
export async function discoverSpaces(): Promise<ToolResult> {
|
|
80
|
+
const url = process.env.DYNAMIC_SPACE_DATA;
|
|
81
|
+
|
|
82
|
+
if (!url) {
|
|
120
83
|
return {
|
|
121
|
-
formatted:
|
|
84
|
+
formatted: 'Error: DYNAMIC_SPACE_DATA environment variable is not set.',
|
|
122
85
|
totalResults: 0,
|
|
123
86
|
resultsShared: 0,
|
|
87
|
+
isError: true,
|
|
124
88
|
};
|
|
125
89
|
}
|
|
126
90
|
|
|
127
|
-
|
|
91
|
+
try {
|
|
92
|
+
const response = await fetch(url);
|
|
128
93
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
return {
|
|
96
|
+
formatted: DISCOVER_PROMPTS.FETCH_ERROR(url, `HTTP ${response.status}`),
|
|
97
|
+
totalResults: 0,
|
|
98
|
+
resultsShared: 0,
|
|
99
|
+
isError: true,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
132
102
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const title = result.title || 'Untitled';
|
|
136
|
-
const description = result.shortDescription || result.ai_short_description || 'No description';
|
|
137
|
-
const id = result.id || '';
|
|
138
|
-
const emoji = result.emoji ? escapeMarkdown(result.emoji) + ' ' : '';
|
|
139
|
-
const relevance = result.semanticRelevancyScore ? (result.semanticRelevancyScore * 100).toFixed(1) + '%' : 'N/A';
|
|
103
|
+
const content = await response.text();
|
|
104
|
+
const results = parseCsvContent(content);
|
|
140
105
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
106
|
+
return {
|
|
107
|
+
formatted: formatDiscoverResults(results),
|
|
108
|
+
totalResults: results.length,
|
|
109
|
+
resultsShared: results.length,
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
113
|
+
return {
|
|
114
|
+
formatted: DISCOVER_PROMPTS.FETCH_ERROR(url, errorMessage),
|
|
115
|
+
totalResults: 0,
|
|
116
|
+
resultsShared: 0,
|
|
117
|
+
isError: true,
|
|
118
|
+
};
|
|
149
119
|
}
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
formatted: markdown,
|
|
153
|
-
totalResults: totalCount,
|
|
154
|
-
resultsShared: results.length,
|
|
155
|
-
};
|
|
156
120
|
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { ToolResult } from '../../types/tool-result.js';
|
|
2
|
+
import { SpaceSearchTool, type SpaceSearchResult } from '../../space-search.js';
|
|
3
|
+
import { escapeMarkdown } from '../../utilities.js';
|
|
4
|
+
|
|
5
|
+
// Default number of results to return
|
|
6
|
+
const DEFAULT_RESULTS_LIMIT = 10;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Prompt configuration for discover operation
|
|
10
|
+
* These prompts can be easily tweaked to adjust the search behavior
|
|
11
|
+
*/
|
|
12
|
+
const FIND_PROMPTS = {
|
|
13
|
+
// Task hints shown when called with blank query
|
|
14
|
+
TASK_HINTS: `Here are some examples of tasks that dynamic spaces can perform:
|
|
15
|
+
|
|
16
|
+
- Image Generation
|
|
17
|
+
- Video Generation
|
|
18
|
+
- Text Generation
|
|
19
|
+
- Visual QA
|
|
20
|
+
- Language Translation
|
|
21
|
+
- Speech Synthesis
|
|
22
|
+
- 3D Modeling
|
|
23
|
+
- Object Detection
|
|
24
|
+
- Text Analysis
|
|
25
|
+
- Image Editing
|
|
26
|
+
- Code Generation
|
|
27
|
+
- Question Answering
|
|
28
|
+
- Data Visualization
|
|
29
|
+
- Voice Cloning
|
|
30
|
+
- Background Removal
|
|
31
|
+
- OCR
|
|
32
|
+
- Image Captioning
|
|
33
|
+
- Sentiment Analysis
|
|
34
|
+
- Music Generation
|
|
35
|
+
- Style Transfer
|
|
36
|
+
|
|
37
|
+
To find MCP-enabled Spaces for a specific task, call this operation with a search query:
|
|
38
|
+
|
|
39
|
+
**Example:**
|
|
40
|
+
\`\`\`json
|
|
41
|
+
{
|
|
42
|
+
"operation": "find",
|
|
43
|
+
"search_query": "image generation",
|
|
44
|
+
"limit": 10
|
|
45
|
+
}
|
|
46
|
+
\`\`\``,
|
|
47
|
+
|
|
48
|
+
// Header for search results
|
|
49
|
+
RESULTS_HEADER: (query: string, showing: number, total: number) => {
|
|
50
|
+
const showingText = showing < total ? `Showing ${showing} of ${total} results` : `All ${showing} results`;
|
|
51
|
+
return `# MCP Space Find Results for "${query}" (${showingText})
|
|
52
|
+
|
|
53
|
+
These MCP-enabled Spaces can be invoked using the \`dynamic_space\` tool.
|
|
54
|
+
Use \`"operation": "view_parameters"\` to inspect a space's parameters before invoking.
|
|
55
|
+
|
|
56
|
+
`;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// No results message
|
|
60
|
+
NO_RESULTS: (query: string) =>
|
|
61
|
+
`No MCP-enabled Spaces found for "${query}".
|
|
62
|
+
|
|
63
|
+
Try:
|
|
64
|
+
- Broader search terms (e.g., "image generation" instead of specific model names)
|
|
65
|
+
- Task-focused queries (e.g., "text generation", "object detection")
|
|
66
|
+
- Different task categories (e.g., "video generation", "image classification")`,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Discovers MCP-enabled Spaces based on search criteria
|
|
71
|
+
*
|
|
72
|
+
* @param searchQuery - The search query or task category
|
|
73
|
+
* @param limit - Maximum number of results to return
|
|
74
|
+
* @param hfToken - Optional HuggingFace API token
|
|
75
|
+
* @returns Formatted search results
|
|
76
|
+
*/
|
|
77
|
+
export async function findSpaces(
|
|
78
|
+
searchQuery?: string,
|
|
79
|
+
limit: number = DEFAULT_RESULTS_LIMIT,
|
|
80
|
+
hfToken?: string
|
|
81
|
+
): Promise<ToolResult> {
|
|
82
|
+
// Return task hints when called with blank query
|
|
83
|
+
if (!searchQuery || searchQuery.trim() === '') {
|
|
84
|
+
return {
|
|
85
|
+
formatted: FIND_PROMPTS.TASK_HINTS,
|
|
86
|
+
totalResults: 0,
|
|
87
|
+
resultsShared: 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// Use SpaceSearchTool to search for MCP-enabled spaces only
|
|
93
|
+
const searchTool = new SpaceSearchTool(hfToken);
|
|
94
|
+
const { results, totalCount } = await searchTool.search(
|
|
95
|
+
searchQuery,
|
|
96
|
+
limit,
|
|
97
|
+
true // mcp = true (only MCP-enabled spaces)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Format and return results
|
|
101
|
+
return formatFindResults(searchQuery, results, totalCount);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
104
|
+
return {
|
|
105
|
+
formatted: `Error discovering spaces: ${errorMessage}`,
|
|
106
|
+
totalResults: 0,
|
|
107
|
+
resultsShared: 0,
|
|
108
|
+
isError: true,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Formats discover results as a markdown table
|
|
115
|
+
* Note: Author column is omitted as it's superfluous for invocation purposes
|
|
116
|
+
* Duplication is OK for the mean time; space_search will be rolled in to a general tool
|
|
117
|
+
*/
|
|
118
|
+
function formatFindResults(query: string, results: SpaceSearchResult[], totalCount: number): ToolResult {
|
|
119
|
+
if (results.length === 0) {
|
|
120
|
+
return {
|
|
121
|
+
formatted: FIND_PROMPTS.NO_RESULTS(query),
|
|
122
|
+
totalResults: 0,
|
|
123
|
+
resultsShared: 0,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let markdown = FIND_PROMPTS.RESULTS_HEADER(query, results.length, totalCount);
|
|
128
|
+
|
|
129
|
+
// Table header (without Author column)
|
|
130
|
+
markdown += '| Space | Description | Space ID | Category | Likes | Trending | Relevance |\n';
|
|
131
|
+
markdown += '|-------|-------------|----------|----------|-------|----------|----------|\n';
|
|
132
|
+
|
|
133
|
+
// Table rows
|
|
134
|
+
for (const result of results) {
|
|
135
|
+
const title = result.title || 'Untitled';
|
|
136
|
+
const description = result.shortDescription || result.ai_short_description || 'No description';
|
|
137
|
+
const id = result.id || '';
|
|
138
|
+
const emoji = result.emoji ? escapeMarkdown(result.emoji) + ' ' : '';
|
|
139
|
+
const relevance = result.semanticRelevancyScore ? (result.semanticRelevancyScore * 100).toFixed(1) + '%' : 'N/A';
|
|
140
|
+
|
|
141
|
+
markdown +=
|
|
142
|
+
`| ${emoji}[${escapeMarkdown(title)}](https://hf.co/spaces/${id}) ` +
|
|
143
|
+
`| ${escapeMarkdown(description)} ` +
|
|
144
|
+
`| \`${escapeMarkdown(id)}\` ` +
|
|
145
|
+
`| \`${escapeMarkdown(result.ai_category ?? '-')}\` ` +
|
|
146
|
+
`| ${escapeMarkdown(result.likes?.toString() ?? '-')} ` +
|
|
147
|
+
`| ${escapeMarkdown(result.trendingScore?.toString() ?? '-')} ` +
|
|
148
|
+
`| ${relevance} |\n`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
formatted: markdown,
|
|
153
|
+
totalResults: totalCount,
|
|
154
|
+
resultsShared: results.length,
|
|
155
|
+
};
|
|
156
|
+
}
|