@llmindset/hf-mcp 0.2.45 → 0.2.46
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 +3 -0
- package/dist/space/commands/discover.d.ts.map +1 -0
- package/dist/space/commands/discover.js +109 -0
- package/dist/space/commands/discover.js.map +1 -0
- package/dist/space/space-tool.d.ts +10 -3
- package/dist/space/space-tool.d.ts.map +1 -1
- package/dist/space/space-tool.js +25 -13
- package/dist/space/space-tool.js.map +1 -1
- package/dist/space/types.d.ts +10 -4
- package/dist/space/types.d.ts.map +1 -1
- package/dist/space/types.js +12 -7
- package/dist/space/types.js.map +1 -1
- package/package.json +1 -1
- package/src/space/commands/discover.ts +156 -0
- package/src/space/space-tool.ts +30 -13
- package/src/space/types.ts +16 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../../src/space/commands/discover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AA4E7D,wBAAsB,cAAc,CACnC,WAAW,CAAC,EAAE,MAAM,EACpB,KAAK,GAAE,MAA8B,EACrC,OAAO,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,UAAU,CAAC,CA8BrB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SpaceSearchTool } from '../../space-search.js';
|
|
2
|
+
import { escapeMarkdown } from '../../utilities.js';
|
|
3
|
+
const DEFAULT_RESULTS_LIMIT = 10;
|
|
4
|
+
const DISCOVER_PROMPTS = {
|
|
5
|
+
TASK_HINTS: `Here are some examples of tasks that dynamic spaces can perform:
|
|
6
|
+
|
|
7
|
+
- Image Generation
|
|
8
|
+
- Video Generation
|
|
9
|
+
- Text Generation
|
|
10
|
+
- Visual QA
|
|
11
|
+
- Language Translation
|
|
12
|
+
- Speech Synthesis
|
|
13
|
+
- 3D Modeling
|
|
14
|
+
- Object Detection
|
|
15
|
+
- Text Analysis
|
|
16
|
+
- Image Editing
|
|
17
|
+
- Code Generation
|
|
18
|
+
- Question Answering
|
|
19
|
+
- Data Visualization
|
|
20
|
+
- Voice Cloning
|
|
21
|
+
- Background Removal
|
|
22
|
+
- OCR
|
|
23
|
+
- Image Captioning
|
|
24
|
+
- Sentiment Analysis
|
|
25
|
+
- Music Generation
|
|
26
|
+
- Style Transfer
|
|
27
|
+
|
|
28
|
+
To discover MCP-enabled Spaces for a specific task, call this operation with a search query:
|
|
29
|
+
|
|
30
|
+
**Example:**
|
|
31
|
+
\`\`\`json
|
|
32
|
+
{
|
|
33
|
+
"operation": "discover",
|
|
34
|
+
"search_query": "image generation",
|
|
35
|
+
"limit": 10
|
|
36
|
+
}
|
|
37
|
+
\`\`\``,
|
|
38
|
+
RESULTS_HEADER: (query, showing, total) => {
|
|
39
|
+
const showingText = showing < total ? `Showing ${showing} of ${total} results` : `All ${showing} results`;
|
|
40
|
+
return `# MCP Space Discovery Results for "${query}" (${showingText})
|
|
41
|
+
|
|
42
|
+
These MCP-enabled Spaces can be invoked using the \`dynamic_space\` tool.
|
|
43
|
+
Use \`"operation": "view_parameters"\` to inspect a space's parameters before invoking.
|
|
44
|
+
|
|
45
|
+
`;
|
|
46
|
+
},
|
|
47
|
+
NO_RESULTS: (query) => `No MCP-enabled Spaces found for "${query}".
|
|
48
|
+
|
|
49
|
+
Try:
|
|
50
|
+
- Broader search terms (e.g., "image generation" instead of specific model names)
|
|
51
|
+
- Task-focused queries (e.g., "text generation", "object detection")
|
|
52
|
+
- Different task categories (e.g., "video generation", "image classification")`,
|
|
53
|
+
};
|
|
54
|
+
export async function discoverSpaces(searchQuery, limit = DEFAULT_RESULTS_LIMIT, hfToken) {
|
|
55
|
+
if (!searchQuery || searchQuery.trim() === '') {
|
|
56
|
+
return {
|
|
57
|
+
formatted: DISCOVER_PROMPTS.TASK_HINTS,
|
|
58
|
+
totalResults: 0,
|
|
59
|
+
resultsShared: 0,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const searchTool = new SpaceSearchTool(hfToken);
|
|
64
|
+
const { results, totalCount } = await searchTool.search(searchQuery, limit, true);
|
|
65
|
+
return formatDiscoverResults(searchQuery, results, totalCount);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
69
|
+
return {
|
|
70
|
+
formatted: `Error discovering spaces: ${errorMessage}`,
|
|
71
|
+
totalResults: 0,
|
|
72
|
+
resultsShared: 0,
|
|
73
|
+
isError: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function formatDiscoverResults(query, results, totalCount) {
|
|
78
|
+
if (results.length === 0) {
|
|
79
|
+
return {
|
|
80
|
+
formatted: DISCOVER_PROMPTS.NO_RESULTS(query),
|
|
81
|
+
totalResults: 0,
|
|
82
|
+
resultsShared: 0,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
let markdown = DISCOVER_PROMPTS.RESULTS_HEADER(query, results.length, totalCount);
|
|
86
|
+
markdown += '| Space | Description | Space ID | Category | Likes | Trending | Relevance |\n';
|
|
87
|
+
markdown += '|-------|-------------|----------|----------|-------|----------|----------|\n';
|
|
88
|
+
for (const result of results) {
|
|
89
|
+
const title = result.title || 'Untitled';
|
|
90
|
+
const description = result.shortDescription || result.ai_short_description || 'No description';
|
|
91
|
+
const id = result.id || '';
|
|
92
|
+
const emoji = result.emoji ? escapeMarkdown(result.emoji) + ' ' : '';
|
|
93
|
+
const relevance = result.semanticRelevancyScore ? (result.semanticRelevancyScore * 100).toFixed(1) + '%' : 'N/A';
|
|
94
|
+
markdown +=
|
|
95
|
+
`| ${emoji}[${escapeMarkdown(title)}](https://hf.co/spaces/${id}) ` +
|
|
96
|
+
`| ${escapeMarkdown(description)} ` +
|
|
97
|
+
`| \`${escapeMarkdown(id)}\` ` +
|
|
98
|
+
`| \`${escapeMarkdown(result.ai_category ?? '-')}\` ` +
|
|
99
|
+
`| ${escapeMarkdown(result.likes?.toString() ?? '-')} ` +
|
|
100
|
+
`| ${escapeMarkdown(result.trendingScore?.toString() ?? '-')} ` +
|
|
101
|
+
`| ${relevance} |\n`;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
formatted: markdown,
|
|
105
|
+
totalResults: totalCount,
|
|
106
|
+
resultsShared: results.length,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=discover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.js","sourceRoot":"","sources":["../../../src/space/commands/discover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA0B,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAMjC,MAAM,gBAAgB,GAAG;IAExB,UAAU,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCN;IAGN,cAAc,EAAE,CAAC,KAAa,EAAE,OAAe,EAAE,KAAa,EAAE,EAAE;QACjE,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,OAAO,UAAU,CAAC;QAC1G,OAAO,sCAAsC,KAAK,MAAM,WAAW;;;;;CAKpE,CAAC;IACD,CAAC;IAGD,UAAU,EAAE,CAAC,KAAa,EAAE,EAAE,CAC7B,oCAAoC,KAAK;;;;;+EAKoC;CAC9E,CAAC;AAUF,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,WAAoB,EACpB,QAAgB,qBAAqB,EACrC,OAAgB;IAGhB,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,OAAO;YACN,SAAS,EAAE,gBAAgB,CAAC,UAAU;YACtC,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B,IAAI,MAAM,CAAC,oBAAoB,IAAI,gBAAgB,CAAC;QAC/F,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,MAAM,SAAS,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,sBAAsB,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;QAEjH,QAAQ;YACP,KAAK,KAAK,IAAI,cAAc,CAAC,KAAK,CAAC,0BAA0B,EAAE,IAAI;gBACnE,KAAK,cAAc,CAAC,WAAW,CAAC,GAAG;gBACnC,OAAO,cAAc,CAAC,EAAE,CAAC,KAAK;gBAC9B,OAAO,cAAc,CAAC,MAAM,CAAC,WAAW,IAAI,GAAG,CAAC,KAAK;gBACrD,KAAK,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,GAAG;gBACvD,KAAK,cAAc,CAAC,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,GAAG;gBAC/D,KAAK,SAAS,MAAM,CAAC;IACvB,CAAC;IAED,OAAO;QACN,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,UAAU;QACxB,aAAa,EAAE,OAAO,CAAC,MAAM;KAC7B,CAAC;AACH,CAAC"}
|
|
@@ -7,17 +7,23 @@ export declare const DYNAMIC_SPACE_TOOL_CONFIG: {
|
|
|
7
7
|
readonly name: "dynamic_space";
|
|
8
8
|
readonly description: string;
|
|
9
9
|
readonly schema: import("zod").ZodObject<{
|
|
10
|
-
operation: import("zod").ZodOptional<import("zod").ZodEnum<["view_parameters", "invoke"]>>;
|
|
10
|
+
operation: import("zod").ZodOptional<import("zod").ZodEnum<["discover", "view_parameters", "invoke"]>>;
|
|
11
11
|
space_name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
12
|
parameters: import("zod").ZodOptional<import("zod").ZodString>;
|
|
13
|
+
search_query: import("zod").ZodOptional<import("zod").ZodString>;
|
|
14
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
13
15
|
}, "strip", import("zod").ZodTypeAny, {
|
|
16
|
+
limit?: number | undefined;
|
|
14
17
|
parameters?: string | undefined;
|
|
15
|
-
operation?: "view_parameters" | "invoke" | undefined;
|
|
18
|
+
operation?: "discover" | "view_parameters" | "invoke" | undefined;
|
|
16
19
|
space_name?: string | undefined;
|
|
20
|
+
search_query?: string | undefined;
|
|
17
21
|
}, {
|
|
22
|
+
limit?: number | undefined;
|
|
18
23
|
parameters?: string | undefined;
|
|
19
|
-
operation?: "view_parameters" | "invoke" | undefined;
|
|
24
|
+
operation?: "discover" | "view_parameters" | "invoke" | undefined;
|
|
20
25
|
space_name?: string | undefined;
|
|
26
|
+
search_query?: string | undefined;
|
|
21
27
|
}>;
|
|
22
28
|
readonly annotations: {
|
|
23
29
|
readonly title: "Gradio Space Interaction";
|
|
@@ -29,6 +35,7 @@ export declare class SpaceTool {
|
|
|
29
35
|
private hfToken?;
|
|
30
36
|
constructor(hfToken?: string);
|
|
31
37
|
execute(params: SpaceArgs, extra?: RequestHandlerExtra<ServerRequest, ServerNotification>): Promise<InvokeResult | ToolResult>;
|
|
38
|
+
private handleDiscover;
|
|
32
39
|
private handleViewParameters;
|
|
33
40
|
private handleInvoke;
|
|
34
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-tool.d.ts","sourceRoot":"","sources":["../../src/space/space-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAwD,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"space-tool.d.ts","sourceRoot":"","sources":["../../src/space/space-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAwD,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAMrH,cAAc,YAAY,CAAC;AAkF3B,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAW5B,CAAC;AAKX,qBAAa,SAAS;IACrB,OAAO,CAAC,OAAO,CAAC,CAAS;gBAEb,OAAO,CAAC,EAAE,MAAM;IAStB,OAAO,CACZ,MAAM,EAAE,SAAS,EACjB,KAAK,CAAC,EAAE,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,GAC5D,OAAO,CAAC,YAAY,GAAG,UAAU,CAAC;YA4DvB,cAAc;YAOd,oBAAoB;YAyBpB,YAAY;CA+C1B"}
|
package/dist/space/space-tool.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { spaceArgsSchema, OPERATION_NAMES } from './types.js';
|
|
2
|
+
import { discoverSpaces } from './commands/discover.js';
|
|
2
3
|
import { viewParameters } from './commands/view-parameters.js';
|
|
3
4
|
import { invokeSpace } from './commands/invoke.js';
|
|
4
5
|
export * from './types.js';
|
|
5
6
|
const USAGE_INSTRUCTIONS = `# Gradio Space Interaction
|
|
6
7
|
|
|
7
|
-
Dynamically interact with any Gradio MCP Space.
|
|
8
|
+
Dynamically interact with any Gradio MCP Space. Discover dynamic spaces, view space parameter schemas, and invoke spaces.
|
|
8
9
|
|
|
9
10
|
## Supported Schema Types
|
|
10
11
|
|
|
@@ -15,16 +16,22 @@ Dynamically interact with any Gradio MCP Space. View parameter schemas or invoke
|
|
|
15
16
|
- Shallow objects (one level deep)
|
|
16
17
|
- FileData (as URL strings)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
- Deeply nested objects (2+ levels)
|
|
20
|
-
- Arrays of objects
|
|
21
|
-
- Union types
|
|
22
|
-
- Recursive schemas
|
|
23
|
-
|
|
24
|
-
For spaces with complex schemas, direct the user to huggingface.co/settings/mcp to add the space via settings panel.
|
|
19
|
+
To use spaces with complex schemas, add them from huggingface.co/settings/mcp.
|
|
25
20
|
|
|
26
21
|
## Available Operations
|
|
27
22
|
|
|
23
|
+
### discover
|
|
24
|
+
Find MCP-enabled Spaces for available for invocation based on task-focused or semantic searches.
|
|
25
|
+
|
|
26
|
+
**Example:**
|
|
27
|
+
\`\`\`json
|
|
28
|
+
{
|
|
29
|
+
"operation": "discover",
|
|
30
|
+
"search_query": "image generation",
|
|
31
|
+
"limit": 10
|
|
32
|
+
}
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
28
35
|
### view_parameters
|
|
29
36
|
Display the parameter schema for a space's first tool.
|
|
30
37
|
|
|
@@ -50,9 +57,9 @@ Execute a space's first tool with provided parameters.
|
|
|
50
57
|
|
|
51
58
|
## Workflow
|
|
52
59
|
|
|
53
|
-
1. **Discover
|
|
54
|
-
2. **
|
|
55
|
-
3. **
|
|
60
|
+
1. **Discover Spaces** - Use \`discover\` to find MCP-enabled spaces for your task
|
|
61
|
+
2. **Inspect Parameters** - Use \`view_parameters\` to see what a space accepts
|
|
62
|
+
3. **Invoke the Space** - Use \`invoke\` with the required parameters
|
|
56
63
|
|
|
57
64
|
## File Handling
|
|
58
65
|
|
|
@@ -63,6 +70,7 @@ For parameters that accept files (FileData types):
|
|
|
63
70
|
|
|
64
71
|
## Tips
|
|
65
72
|
|
|
73
|
+
- Focus searches on specific tasks (e.g., "video generation", "object detection")
|
|
66
74
|
- The tool automatically applies default values for optional parameters
|
|
67
75
|
- Unknown parameters generate warnings but are still passed through (permissive inputs)
|
|
68
76
|
- Enum parameters show all allowed values in view_parameters
|
|
@@ -70,8 +78,7 @@ For parameters that accept files (FileData types):
|
|
|
70
78
|
`;
|
|
71
79
|
export const DYNAMIC_SPACE_TOOL_CONFIG = {
|
|
72
80
|
name: 'dynamic_space',
|
|
73
|
-
description: '
|
|
74
|
-
'Supports simple parameter types (strings, numbers, booleans, arrays, enums, shallow objects). ' +
|
|
81
|
+
description: 'Discover (semantic/task search), inspect (view parameter schema) and dynamically invoke Gradio MCP Spaces to perform various ML Tasks. ' +
|
|
75
82
|
'Call with no operation for full usage instructions.',
|
|
76
83
|
schema: spaceArgsSchema,
|
|
77
84
|
annotations: {
|
|
@@ -108,6 +115,8 @@ Call this tool with no operation for full usage instructions.`,
|
|
|
108
115
|
}
|
|
109
116
|
try {
|
|
110
117
|
switch (normalizedOperation) {
|
|
118
|
+
case 'discover':
|
|
119
|
+
return await this.handleDiscover(params);
|
|
111
120
|
case 'view_parameters':
|
|
112
121
|
return await this.handleViewParameters(params);
|
|
113
122
|
case 'invoke':
|
|
@@ -131,6 +140,9 @@ Call this tool with no operation for full usage instructions.`,
|
|
|
131
140
|
};
|
|
132
141
|
}
|
|
133
142
|
}
|
|
143
|
+
async handleDiscover(params) {
|
|
144
|
+
return await discoverSpaces(params.search_query, params.limit, this.hfToken);
|
|
145
|
+
}
|
|
134
146
|
async handleViewParameters(params) {
|
|
135
147
|
if (!params.space_name) {
|
|
136
148
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-tool.js","sourceRoot":"","sources":["../../src/space/space-tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAyD,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B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K,CAAC,oBAAoB,CAAC,MAAiB;QACnD,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACxB,OAAO;gBACN,SAAS,EAAE;;;;;;;;OAQR;gBACH,YAAY,EAAE,CAAC;gBACf,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,IAAI;aACb,CAAC;QACH,CAAC;QAED,OAAO,MAAM,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAMO,KAAK,CAAC,YAAY,CACzB,MAAiB,EACjB,KAA8D;QAG9D,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACxB,OAAO;gBACN,SAAS,EAAE;;;;;;;;;OASR;gBACH,YAAY,EAAE,CAAC;gBACf,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,IAAI;aACb,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACxB,OAAO;gBACN,SAAS,EAAE;;;;;;;;mBAQI,MAAM,CAAC,UAAU;;;;;iEAK6B;gBAC7D,YAAY,EAAE,CAAC;gBACf,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,IAAI;aACb,CAAC;QACH,CAAC;QAED,OAAO,MAAM,WAAW,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACrF,CAAC;CACD;AAKD,SAAS,eAAe,CAAC,KAAa;IACrC,OAAQ,eAAqC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/space/types.d.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const OPERATION_NAMES: readonly ["view_parameters", "invoke"];
|
|
2
|
+
export declare const OPERATION_NAMES: readonly ["discover", "view_parameters", "invoke"];
|
|
3
3
|
export type OperationName = (typeof OPERATION_NAMES)[number];
|
|
4
4
|
export declare const spaceArgsSchema: z.ZodObject<{
|
|
5
|
-
operation: z.ZodOptional<z.ZodEnum<["view_parameters", "invoke"]>>;
|
|
5
|
+
operation: z.ZodOptional<z.ZodEnum<["discover", "view_parameters", "invoke"]>>;
|
|
6
6
|
space_name: z.ZodOptional<z.ZodString>;
|
|
7
7
|
parameters: z.ZodOptional<z.ZodString>;
|
|
8
|
+
search_query: z.ZodOptional<z.ZodString>;
|
|
9
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
8
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
limit?: number | undefined;
|
|
9
12
|
parameters?: string | undefined;
|
|
10
|
-
operation?: "view_parameters" | "invoke" | undefined;
|
|
13
|
+
operation?: "discover" | "view_parameters" | "invoke" | undefined;
|
|
11
14
|
space_name?: string | undefined;
|
|
15
|
+
search_query?: string | undefined;
|
|
12
16
|
}, {
|
|
17
|
+
limit?: number | undefined;
|
|
13
18
|
parameters?: string | undefined;
|
|
14
|
-
operation?: "view_parameters" | "invoke" | undefined;
|
|
19
|
+
operation?: "discover" | "view_parameters" | "invoke" | undefined;
|
|
15
20
|
space_name?: string | undefined;
|
|
21
|
+
search_query?: string | undefined;
|
|
16
22
|
}>;
|
|
17
23
|
export type SpaceArgs = z.infer<typeof spaceArgsSchema>;
|
|
18
24
|
export interface ParameterInfo {
|
|
@@ -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;AAKxB,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,eAAe,oDAAqD,CAAC;AAClF,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe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kB,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAKD,MAAM,WAAW,UAAU;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAKD,eAAO,MAAM,uBAAuB,QAEmD,CAAC;AAKxF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAOpE;AAKD,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAIvD;AAMD,MAAM,WAAW,YAAY;IAC5B,MAAM,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,15 +1,20 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const OPERATION_NAMES = ['view_parameters', 'invoke'];
|
|
2
|
+
export const OPERATION_NAMES = ['discover', 'view_parameters', 'invoke'];
|
|
3
3
|
export const spaceArgsSchema = z.object({
|
|
4
|
-
operation: z
|
|
5
|
-
|
|
4
|
+
operation: z.enum(OPERATION_NAMES).optional().describe('Operation to execute.'),
|
|
5
|
+
space_name: z
|
|
6
|
+
.string()
|
|
6
7
|
.optional()
|
|
7
|
-
.describe('
|
|
8
|
-
space_name: z.string().optional().describe('The Hugging Face space ID (format: "username/space-name")'),
|
|
8
|
+
.describe('The Hugging Face space ID (format: "username/space-name"). Required for view_parameters and invoke operations.'),
|
|
9
9
|
parameters: z.string().optional().describe('For invoke operation: JSON object string of parameters'),
|
|
10
|
+
search_query: z
|
|
11
|
+
.string()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('For discover 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.'),
|
|
14
|
+
limit: z.number().optional().describe('For discover operation: Maximum number of results to return (default: 10)'),
|
|
10
15
|
});
|
|
11
|
-
export const FILE_INPUT_HELP_MESSAGE = 'Provide a publicly accessible URL (http:// or https://)
|
|
12
|
-
|
|
16
|
+
export const FILE_INPUT_HELP_MESSAGE = 'Provide a publicly accessible URL (http:// or https://) for the Gradio file input. ' +
|
|
17
|
+
"Content previuosly generated by 'invoke' is usable, as well as Hub Repository URLs. ";
|
|
13
18
|
export function isFileDataProperty(prop) {
|
|
14
19
|
return (prop.title === 'ImageData' ||
|
|
15
20
|
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;AAKxB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,iBAAiB,EAAE,QAAQ,CAAU,CAAC;AAMlF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IAC/E,UAAU,EAAE,CAAC;SACX,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACR,gHAAgH,CAChH;IACF,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wDAAwD,CAAC;IACpG,YAAY,EAAE,CAAC;SACb,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACR,sLAAsL,CACtL;IACF,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2EAA2E,CAAC;CAClH,CAAC,CAAC;AAqEH,MAAM,CAAC,MAAM,uBAAuB,GACnC,qFAAqF;IACrF,sFAAsF,CAAC;AAKxF,MAAM,UAAU,kBAAkB,CAAC,IAAwB;IAC1D,OAAO,CACN,IAAI,CAAC,KAAK,KAAK,WAAW;QAC1B,IAAI,CAAC,KAAK,KAAK,UAAU;QACzB,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
|
@@ -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 DISCOVER_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 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})
|
|
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 discoverSpaces(
|
|
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: DISCOVER_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 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
|
+
}
|
|
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 formatDiscoverResults(query: string, results: SpaceSearchResult[], totalCount: number): ToolResult {
|
|
119
|
+
if (results.length === 0) {
|
|
120
|
+
return {
|
|
121
|
+
formatted: DISCOVER_PROMPTS.NO_RESULTS(query),
|
|
122
|
+
totalResults: 0,
|
|
123
|
+
resultsShared: 0,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let markdown = DISCOVER_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
|
+
}
|
package/src/space/space-tool.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ToolResult } from '../types/tool-result.js';
|
|
|
2
2
|
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
4
|
import { spaceArgsSchema, OPERATION_NAMES, type OperationName, type SpaceArgs, type InvokeResult } from './types.js';
|
|
5
|
+
import { discoverSpaces } from './commands/discover.js';
|
|
5
6
|
import { viewParameters } from './commands/view-parameters.js';
|
|
6
7
|
import { invokeSpace } from './commands/invoke.js';
|
|
7
8
|
|
|
@@ -13,7 +14,7 @@ export * from './types.js';
|
|
|
13
14
|
*/
|
|
14
15
|
const USAGE_INSTRUCTIONS = `# Gradio Space Interaction
|
|
15
16
|
|
|
16
|
-
Dynamically interact with any Gradio MCP Space.
|
|
17
|
+
Dynamically interact with any Gradio MCP Space. Discover dynamic spaces, view space parameter schemas, and invoke spaces.
|
|
17
18
|
|
|
18
19
|
## Supported Schema Types
|
|
19
20
|
|
|
@@ -24,16 +25,22 @@ Dynamically interact with any Gradio MCP Space. View parameter schemas or invoke
|
|
|
24
25
|
- Shallow objects (one level deep)
|
|
25
26
|
- FileData (as URL strings)
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
- Deeply nested objects (2+ levels)
|
|
29
|
-
- Arrays of objects
|
|
30
|
-
- Union types
|
|
31
|
-
- Recursive schemas
|
|
32
|
-
|
|
33
|
-
For spaces with complex schemas, direct the user to huggingface.co/settings/mcp to add the space via settings panel.
|
|
28
|
+
To use spaces with complex schemas, add them from huggingface.co/settings/mcp.
|
|
34
29
|
|
|
35
30
|
## Available Operations
|
|
36
31
|
|
|
32
|
+
### discover
|
|
33
|
+
Find MCP-enabled Spaces for available for invocation based on task-focused or semantic searches.
|
|
34
|
+
|
|
35
|
+
**Example:**
|
|
36
|
+
\`\`\`json
|
|
37
|
+
{
|
|
38
|
+
"operation": "discover",
|
|
39
|
+
"search_query": "image generation",
|
|
40
|
+
"limit": 10
|
|
41
|
+
}
|
|
42
|
+
\`\`\`
|
|
43
|
+
|
|
37
44
|
### view_parameters
|
|
38
45
|
Display the parameter schema for a space's first tool.
|
|
39
46
|
|
|
@@ -59,9 +66,9 @@ Execute a space's first tool with provided parameters.
|
|
|
59
66
|
|
|
60
67
|
## Workflow
|
|
61
68
|
|
|
62
|
-
1. **Discover
|
|
63
|
-
2. **
|
|
64
|
-
3. **
|
|
69
|
+
1. **Discover Spaces** - Use \`discover\` to find MCP-enabled spaces for your task
|
|
70
|
+
2. **Inspect Parameters** - Use \`view_parameters\` to see what a space accepts
|
|
71
|
+
3. **Invoke the Space** - Use \`invoke\` with the required parameters
|
|
65
72
|
|
|
66
73
|
## File Handling
|
|
67
74
|
|
|
@@ -72,6 +79,7 @@ For parameters that accept files (FileData types):
|
|
|
72
79
|
|
|
73
80
|
## Tips
|
|
74
81
|
|
|
82
|
+
- Focus searches on specific tasks (e.g., "video generation", "object detection")
|
|
75
83
|
- The tool automatically applies default values for optional parameters
|
|
76
84
|
- Unknown parameters generate warnings but are still passed through (permissive inputs)
|
|
77
85
|
- Enum parameters show all allowed values in view_parameters
|
|
@@ -84,8 +92,7 @@ For parameters that accept files (FileData types):
|
|
|
84
92
|
export const DYNAMIC_SPACE_TOOL_CONFIG = {
|
|
85
93
|
name: 'dynamic_space',
|
|
86
94
|
description:
|
|
87
|
-
'
|
|
88
|
-
'Supports simple parameter types (strings, numbers, booleans, arrays, enums, shallow objects). ' +
|
|
95
|
+
'Discover (semantic/task search), inspect (view parameter schema) and dynamically invoke Gradio MCP Spaces to perform various ML Tasks. ' +
|
|
89
96
|
'Call with no operation for full usage instructions.',
|
|
90
97
|
schema: spaceArgsSchema,
|
|
91
98
|
annotations: {
|
|
@@ -142,6 +149,9 @@ Call this tool with no operation for full usage instructions.`,
|
|
|
142
149
|
// Execute operation
|
|
143
150
|
try {
|
|
144
151
|
switch (normalizedOperation) {
|
|
152
|
+
case 'discover':
|
|
153
|
+
return await this.handleDiscover(params);
|
|
154
|
+
|
|
145
155
|
case 'view_parameters':
|
|
146
156
|
return await this.handleViewParameters(params);
|
|
147
157
|
|
|
@@ -167,6 +177,13 @@ Call this tool with no operation for full usage instructions.`,
|
|
|
167
177
|
}
|
|
168
178
|
}
|
|
169
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Handle discover operation
|
|
182
|
+
*/
|
|
183
|
+
private async handleDiscover(params: SpaceArgs): Promise<ToolResult> {
|
|
184
|
+
return await discoverSpaces(params.search_query, params.limit, this.hfToken);
|
|
185
|
+
}
|
|
186
|
+
|
|
170
187
|
/**
|
|
171
188
|
* Handle view_parameters operation
|
|
172
189
|
*/
|
package/src/space/types.ts
CHANGED
|
@@ -3,19 +3,28 @@ import { z } from 'zod';
|
|
|
3
3
|
/**
|
|
4
4
|
* Operations supported by the space tool
|
|
5
5
|
*/
|
|
6
|
-
export const OPERATION_NAMES = ['view_parameters', 'invoke'] as const;
|
|
6
|
+
export const OPERATION_NAMES = ['discover', 'view_parameters', 'invoke'] as const;
|
|
7
7
|
export type OperationName = (typeof OPERATION_NAMES)[number];
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Zod schema for operation arguments
|
|
11
11
|
*/
|
|
12
12
|
export const spaceArgsSchema = z.object({
|
|
13
|
-
operation: z
|
|
14
|
-
|
|
13
|
+
operation: z.enum(OPERATION_NAMES).optional().describe('Operation to execute.'),
|
|
14
|
+
space_name: z
|
|
15
|
+
.string()
|
|
15
16
|
.optional()
|
|
16
|
-
.describe(
|
|
17
|
-
|
|
17
|
+
.describe(
|
|
18
|
+
'The Hugging Face space ID (format: "username/space-name"). Required for view_parameters and invoke operations.'
|
|
19
|
+
),
|
|
18
20
|
parameters: z.string().optional().describe('For invoke operation: JSON object string of parameters'),
|
|
21
|
+
search_query: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe(
|
|
25
|
+
'For discover 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.'
|
|
26
|
+
),
|
|
27
|
+
limit: z.number().optional().describe('For discover operation: Maximum number of results to return (default: 10)'),
|
|
19
28
|
});
|
|
20
29
|
|
|
21
30
|
export type SpaceArgs = z.infer<typeof spaceArgsSchema>;
|
|
@@ -86,8 +95,8 @@ export interface JsonSchema {
|
|
|
86
95
|
* File input help message constant
|
|
87
96
|
*/
|
|
88
97
|
export const FILE_INPUT_HELP_MESSAGE =
|
|
89
|
-
'Provide a publicly accessible URL (http:// or https://)
|
|
90
|
-
|
|
98
|
+
'Provide a publicly accessible URL (http:// or https://) for the Gradio file input. ' +
|
|
99
|
+
"Content previuosly generated by 'invoke' is usable, as well as Hub Repository URLs. ";
|
|
91
100
|
|
|
92
101
|
/**
|
|
93
102
|
* Check if a property is a FileData type
|