Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/app/src/server/transport/base-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,25 @@ export abstract class BaseTransport {
* @returns true if this is a tools/call for a Gradio tool, false otherwise
*/
protected isGradioToolCall(requestBody: unknown): boolean {
const body = requestBody as { method?: string; params?: { name?: string } } | undefined;
const body = requestBody as { method?: string; params?: { name?: string; arguments?: unknown } } | undefined;
const methodName = body?.method || 'unknown';

// Check if this is a tools/call with a valid tool name
if (methodName === 'tools/call' && body?.params && typeof body.params === 'object' && 'name' in body.params) {
const toolName = body.params.name;
if (typeof toolName === 'string') {
return isGradioTool(toolName);
// Check for standard Gradio tools (gr<number>_ or grp<number>_)
if (isGradioTool(toolName)) {
return true;
}

// Special case: dynamic_space with "invoke" operation needs streaming
if (toolName === 'dynamic_space' && body.params.arguments) {
const args = body.params.arguments as { operation?: string } | undefined;
if (args?.operation === 'invoke') {
return true;
}
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions packages/app/src/server/utils/gradio-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Utility functions for handling Gradio endpoint detection and configuration
*/
import { DYNAMIC_SPACE_TOOL_CONFIG } from '@llmindset/hf-mcp';
import type { SpaceTool } from '../../shared/settings.js';
import { GRADIO_PREFIX, GRADIO_PRIVATE_PREFIX } from '../../shared/constants.js';
import { logger } from './logger.js';
Expand All @@ -17,14 +16,12 @@ import { getGradioSpaces } from './gradio-discovery.js';
* @example
* isGradioTool('gr1_evalstate_flux1_schnell') // true
* isGradioTool('grp2_private_tool') // true
* isGradioTool('dynamic_space') // true
* isGradioTool('hf_doc_search') // false
* isGradioTool('regular_tool') // false
*/
export function isGradioTool(toolName: string): boolean {
// Gradio tools follow pattern: gr<number>_<name> or grp<number>_<name>
// Also includes the special dynamic_space tool
return /^grp?\d+_/.test(toolName) || toolName === DYNAMIC_SPACE_TOOL_CONFIG.name;
return /^grp?\d+_/.test(toolName);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions packages/app/test/server/utils/gradio-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ describe('isGradioTool', () => {
expect(isGradioTool('grp10_test')).toBe(true);
});

it('should detect dynamic_space tool', () => {
expect(isGradioTool('dynamic_space')).toBe(true);
});

it('should detect real-world Gradio tool names', () => {
expect(isGradioTool('gr1_evalstate_flux1_schnell')).toBe(true);
expect(isGradioTool('grp3_my_private_space')).toBe(true);
Expand Down Expand Up @@ -51,6 +47,7 @@ describe('isGradioTool', () => {
expect(isGradioTool('hf_doc_search')).toBe(false);
expect(isGradioTool('hf_model_search')).toBe(false);
expect(isGradioTool('hf_whoami')).toBe(false);
expect(isGradioTool('dynamic_space')).toBe(false);
});

it('should reject tools with missing number', () => {
Expand Down