@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.
@@ -1,7 +1,16 @@
1
1
  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
- import { spaceArgsSchema, OPERATION_NAMES, type OperationName, type SpaceArgs, type InvokeResult } from './types.js';
4
+ import type { z } from 'zod';
5
+ import {
6
+ spaceArgsSchema,
7
+ type SpaceArgs,
8
+ type InvokeResult,
9
+ isDynamicSpaceMode,
10
+ getOperationNames,
11
+ getSpaceArgsSchema,
12
+ } from './types.js';
13
+ import { findSpaces } from './commands/dynamic-find.js';
5
14
  import { discoverSpaces } from './commands/discover.js';
6
15
  import { viewParameters } from './commands/view-parameters.js';
7
16
  import { invokeSpace } from './commands/invoke.js';
@@ -14,7 +23,7 @@ export * from './types.js';
14
23
  */
15
24
  const USAGE_INSTRUCTIONS = `# Gradio Space Interaction
16
25
 
17
- Dynamically interact with any Gradio MCP Space. Discover dynamic spaces, view space parameter schemas, and invoke spaces.
26
+ Dynamically interact with any Gradio MCP Space. Find spaces, view space parameter schemas, and invoke spaces.
18
27
 
19
28
  ## Supported Schema Types
20
29
 
@@ -25,17 +34,17 @@ Dynamically interact with any Gradio MCP Space. Discover dynamic spaces, view sp
25
34
  - Shallow objects (one level deep)
26
35
  - FileData (as URL strings)
27
36
 
28
- To use spaces with complex schemas, add them from huggingface.co/settings/mcp.
37
+ To use spaces with complex schemas, add them from huggingface.co/settings/mcp.
29
38
 
30
39
  ## Available Operations
31
40
 
32
- ### discover
41
+ ### Find
33
42
  Find MCP-enabled Spaces for available for invocation based on task-focused or semantic searches.
34
43
 
35
44
  **Example:**
36
45
  \`\`\`json
37
46
  {
38
- "operation": "discover",
47
+ "operation": "find",
39
48
  "search_query": "image generation",
40
49
  "limit": 10
41
50
  }
@@ -66,7 +75,7 @@ Execute a space's first tool with provided parameters.
66
75
 
67
76
  ## Workflow
68
77
 
69
- 1. **Discover Spaces** - Use \`discover\` to find MCP-enabled spaces for your task
78
+ 1. **Find Spaces** - Use \`find\` to find MCP-enabled spaces for your task
70
79
  2. **Inspect Parameters** - Use \`view_parameters\` to see what a space accepts
71
80
  3. **Invoke the Space** - Use \`invoke\` with the required parameters
72
81
 
@@ -86,17 +95,108 @@ For parameters that accept files (FileData types):
86
95
  - Required parameters are clearly marked and validated
87
96
  `;
88
97
 
98
+ /**
99
+ * Usage instructions for dynamic mode (when DYNAMIC_SPACE_DATA is set)
100
+ * Simplified instructions focusing on discover/view_parameters/invoke workflow
101
+ */
102
+ const DYNAMIC_USAGE_INSTRUCTIONS = `# Gradio Space Interaction
103
+
104
+ Dynamically use Gradio MCP Spaces. Discover available spaces, view their parameter schemas, and invoke them. Use "discover" to find recommended spaces for tasks.
105
+
106
+ ## Available Operations
107
+
108
+ ### discover
109
+ List recommended spaces and their categories.
110
+
111
+ **Example:**
112
+ \`\`\`json
113
+ {
114
+ "operation": "discover"
115
+ }
116
+ \`\`\`
117
+
118
+ ### view_parameters
119
+ Display the parameter schema for a space's first tool.
120
+
121
+ **Example:**
122
+ \`\`\`json
123
+ {
124
+ "operation": "view_parameters",
125
+ "space_name": "evalstate/FLUX1_schnell"
126
+ }
127
+ \`\`\`
128
+
129
+ ### invoke
130
+ Execute a space's first tool with provided parameters.
131
+
132
+ **Example:**
133
+ \`\`\`json
134
+ {
135
+ "operation": "invoke",
136
+ "space_name": "evalstate/FLUX1_schnell",
137
+ "parameters": "{\\"prompt\\": \\"a cute cat\\", \\"num_steps\\": 4}"
138
+ }
139
+ \`\`\`
140
+
141
+ ## Workflow
142
+
143
+ 1. **Discover Spaces** - Use \`discover\` to see available spaces
144
+ 2. **Inspect Parameters** - Use \`view_parameters\` to see what a space accepts
145
+ 3. **Invoke the Space** - Use \`invoke\` with the required parameters
146
+
147
+ ## File Handling
148
+
149
+ For parameters that accept files (FileData types):
150
+ - Provide a publicly accessible URL (http:// or https://)
151
+ - Example: \`{"image": "https://example.com/photo.jpg"}\`
152
+ - Output url's from one tool may be used as inputs to another.
153
+ `;
154
+
155
+ /**
156
+ * Get the appropriate usage instructions based on mode
157
+ */
158
+ function getUsageInstructions(): string {
159
+ return isDynamicSpaceMode() ? DYNAMIC_USAGE_INSTRUCTIONS : USAGE_INSTRUCTIONS;
160
+ }
161
+
89
162
  /**
90
163
  * Space tool configuration
164
+ * Returns dynamic config based on environment
165
+ */
166
+ export function getDynamicSpaceToolConfig(): {
167
+ name: string;
168
+ description: string;
169
+ schema: z.ZodObject<z.ZodRawShape>;
170
+ annotations: { title: string; readOnlyHint: boolean; openWorldHint: boolean };
171
+ } {
172
+ const dynamicMode = isDynamicSpaceMode();
173
+ return {
174
+ name: 'dynamic_space',
175
+ description: dynamicMode
176
+ ? 'Discover, inspect (view parameter schema) and dynamically invoke Gradio MCP Spaces to conduct ML Tasks including Image Generation, Background Removal, Text to Speech and more ' +
177
+ 'Call with no operation for full usage instructions.'
178
+ : 'Find (semantic/task search), inspect (view parameter schema) and dynamically invoke Gradio MCP Spaces. ' +
179
+ 'Call with no operation for full usage instructions.',
180
+ schema: getSpaceArgsSchema(),
181
+ annotations: {
182
+ title: 'Dynamically use Gradio Applications',
183
+ readOnlyHint: false,
184
+ openWorldHint: true,
185
+ },
186
+ };
187
+ }
188
+
189
+ /**
190
+ * Space tool configuration (static, for backward compatibility)
91
191
  */
92
192
  export const DYNAMIC_SPACE_TOOL_CONFIG = {
93
193
  name: 'dynamic_space',
94
194
  description:
95
- 'Discover (semantic/task search), inspect (view parameter schema) and dynamically invoke Gradio MCP Spaces to perform various ML Tasks. ' +
195
+ 'Find (semantic/task search), inspect (view parameter schema) and dynamically invoke Gradio MCP Spaces. ' +
96
196
  'Call with no operation for full usage instructions.',
97
197
  schema: spaceArgsSchema,
98
198
  annotations: {
99
- title: 'Gradio Space Interaction',
199
+ title: 'Dynamically use Gradio Applications',
100
200
  readOnlyHint: false,
101
201
  openWorldHint: true,
102
202
  },
@@ -126,7 +226,7 @@ export class SpaceTool {
126
226
  // If no operation provided, return usage instructions
127
227
  if (!requestedOperation) {
128
228
  return {
129
- formatted: USAGE_INSTRUCTIONS,
229
+ formatted: getUsageInstructions(),
130
230
  totalResults: 1,
131
231
  resultsShared: 1,
132
232
  };
@@ -134,10 +234,11 @@ export class SpaceTool {
134
234
 
135
235
  // Validate operation
136
236
  const normalizedOperation = requestedOperation.toLowerCase();
137
- if (!isOperationName(normalizedOperation)) {
237
+ const validOperations = getOperationNames();
238
+ if (!validOperations.includes(normalizedOperation)) {
138
239
  return {
139
240
  formatted: `Unknown operation: "${requestedOperation}"
140
- Available operations: ${OPERATION_NAMES.join(', ')}
241
+ Available operations: ${validOperations.join(', ')}
141
242
 
142
243
  Call this tool with no operation for full usage instructions.`,
143
244
  totalResults: 0,
@@ -149,8 +250,11 @@ Call this tool with no operation for full usage instructions.`,
149
250
  // Execute operation
150
251
  try {
151
252
  switch (normalizedOperation) {
253
+ case 'find':
254
+ return await this.handleFind(params);
255
+
152
256
  case 'discover':
153
- return await this.handleDiscover(params);
257
+ return await this.handleDiscover();
154
258
 
155
259
  case 'view_parameters':
156
260
  return await this.handleViewParameters(params);
@@ -178,10 +282,17 @@ Call this tool with no operation for full usage instructions.`,
178
282
  }
179
283
 
180
284
  /**
181
- * Handle discover operation
285
+ * Handle find operation
182
286
  */
183
- private async handleDiscover(params: SpaceArgs): Promise<ToolResult> {
184
- return await discoverSpaces(params.search_query, params.limit, this.hfToken);
287
+ private async handleFind(params: SpaceArgs): Promise<ToolResult> {
288
+ return await findSpaces(params.search_query, params.limit, this.hfToken);
289
+ }
290
+
291
+ /**
292
+ * Handle discover operation (for dynamic space mode)
293
+ */
294
+ private async handleDiscover(): Promise<ToolResult> {
295
+ return await discoverSpaces();
185
296
  }
186
297
 
187
298
  /**
@@ -260,10 +371,3 @@ Use "view_parameters" to see what parameters this space accepts.`,
260
371
  return await invokeSpace(params.space_name, params.parameters, this.hfToken, extra);
261
372
  }
262
373
  }
263
-
264
- /**
265
- * Type guard for operation names
266
- */
267
- function isOperationName(value: string): value is OperationName {
268
- return (OPERATION_NAMES as readonly string[]).includes(value);
269
- }
@@ -2,12 +2,30 @@ import { z } from 'zod';
2
2
 
3
3
  /**
4
4
  * Operations supported by the space tool
5
+ * Standard mode: find, view_parameters, invoke
6
+ * Dynamic mode (DYNAMIC_SPACE_DATA): discover, view_parameters, invoke
5
7
  */
6
- export const OPERATION_NAMES = ['discover', 'view_parameters', 'invoke'] as const;
8
+ export const OPERATION_NAMES = ['find', 'view_parameters', 'invoke'] as const;
9
+ export const DYNAMIC_OPERATION_NAMES = ['discover', 'view_parameters', 'invoke'] as const;
7
10
  export type OperationName = (typeof OPERATION_NAMES)[number];
11
+ export type DynamicOperationName = (typeof DYNAMIC_OPERATION_NAMES)[number];
8
12
 
9
13
  /**
10
- * Zod schema for operation arguments
14
+ * Check if dynamic space mode is enabled
15
+ */
16
+ export function isDynamicSpaceMode(): boolean {
17
+ return !!process.env.DYNAMIC_SPACE_DATA;
18
+ }
19
+
20
+ /**
21
+ * Get the appropriate operation names based on mode
22
+ */
23
+ export function getOperationNames(): readonly string[] {
24
+ return isDynamicSpaceMode() ? DYNAMIC_OPERATION_NAMES : OPERATION_NAMES;
25
+ }
26
+
27
+ /**
28
+ * Zod schema for operation arguments (standard mode)
11
29
  */
12
30
  export const spaceArgsSchema = z.object({
13
31
  operation: z.enum(OPERATION_NAMES).optional().describe('Operation to execute.'),
@@ -22,11 +40,32 @@ export const spaceArgsSchema = z.object({
22
40
  .string()
23
41
  .optional()
24
42
  .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.'
43
+ '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.'
26
44
  ),
27
- limit: z.number().optional().describe('For discover operation: Maximum number of results to return (default: 10)'),
45
+ limit: z.number().optional().describe('For find operation: Maximum number of results to return (default: 10)'),
28
46
  });
29
47
 
48
+ /**
49
+ * Zod schema for operation arguments (dynamic mode with DYNAMIC_SPACE_DATA)
50
+ */
51
+ export const dynamicSpaceArgsSchema = z.object({
52
+ operation: z.enum(DYNAMIC_OPERATION_NAMES).optional().describe('Operation to execute.'),
53
+ space_name: z
54
+ .string()
55
+ .optional()
56
+ .describe(
57
+ 'The Hugging Face space ID (format: "username/space-name"). Required for view_parameters and invoke operations.'
58
+ ),
59
+ parameters: z.string().optional().describe('For invoke operation: JSON object string of parameters'),
60
+ });
61
+
62
+ /**
63
+ * Get the appropriate schema based on mode
64
+ */
65
+ export function getSpaceArgsSchema(): z.ZodObject<z.ZodRawShape> {
66
+ return isDynamicSpaceMode() ? dynamicSpaceArgsSchema : spaceArgsSchema;
67
+ }
68
+
30
69
  export type SpaceArgs = z.infer<typeof spaceArgsSchema>;
31
70
 
32
71
  /**
@@ -96,7 +135,7 @@ export interface JsonSchema {
96
135
  */
97
136
  export const FILE_INPUT_HELP_MESSAGE =
98
137
  '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. ";
138
+ "Content previously generated by 'invoke' is usable, as well as Hub Repository URLs. ";
100
139
 
101
140
  /**
102
141
  * Check if a property is a FileData type