From 5d43ea69add422ac6259a8be549e6ebeafd86cc4 Mon Sep 17 00:00:00 2001 From: centdix Date: Sun, 28 Sep 2025 13:08:51 +0000 Subject: [PATCH] filter out tools with too long names --- backend/windmill-api/src/mcp/server.rs | 75 +++++++++++-------- .../components/settings/CreateToken.svelte | 26 ++++++- 2 files changed, 64 insertions(+), 37 deletions(-) diff --git a/backend/windmill-api/src/mcp/server.rs b/backend/windmill-api/src/mcp/server.rs index fa8644b5b8..fffbc8fa5b 100644 --- a/backend/windmill-api/src/mcp/server.rs +++ b/backend/windmill-api/src/mcp/server.rs @@ -50,6 +50,9 @@ use rmcp::transport::streamable_http_server::{ }; use windmill_common::error::JsonResult; +// MCP clients do not allow names longer than 60 characters +const MAX_PATH_LENGTH: usize = 60; + /// MCP Server Runner - implements the core MCP protocol handlers #[derive(Clone)] pub struct Runner {} @@ -381,45 +384,51 @@ impl ServerHandler for Runner { let mut tools: Vec = Vec::new(); for script in scripts { - tools.push( - Runner::create_tool_from_item( - &script, - user_db, - authed, - &workspace_id, - &mut resources_cache, - &resources_types, - ) - .await?, - ); + if script.get_path_or_id().len() <= MAX_PATH_LENGTH { + tools.push( + Runner::create_tool_from_item( + &script, + user_db, + authed, + &workspace_id, + &mut resources_cache, + &resources_types, + ) + .await?, + ); + } } for flow in flows { - tools.push( - Runner::create_tool_from_item( - &flow, - user_db, - authed, - &workspace_id, - &mut resources_cache, - &resources_types, - ) - .await?, - ); + if flow.get_path_or_id().len() <= MAX_PATH_LENGTH { + tools.push( + Runner::create_tool_from_item( + &flow, + user_db, + authed, + &workspace_id, + &mut resources_cache, + &resources_types, + ) + .await?, + ); + } } for hub_script in hub_scripts { - tools.push( - Runner::create_tool_from_item( - &hub_script, - user_db, - authed, - &workspace_id, - &mut resources_cache, - &resources_types, - ) - .await?, - ); + if hub_script.get_path_or_id().len() <= MAX_PATH_LENGTH { + tools.push( + Runner::create_tool_from_item( + &hub_script, + user_db, + authed, + &workspace_id, + &mut resources_cache, + &resources_types, + ) + .await?, + ); + } } // Add endpoint tools from the generated MCP tools diff --git a/frontend/src/lib/components/settings/CreateToken.svelte b/frontend/src/lib/components/settings/CreateToken.svelte index 18341375ed..e1d93dcf40 100644 --- a/frontend/src/lib/components/settings/CreateToken.svelte +++ b/frontend/src/lib/components/settings/CreateToken.svelte @@ -39,6 +39,8 @@ newTokenLabel = $bindable(undefined) }: Props = $props() + const MAX_PATH_LENGTH = 55 + let newToken = $state(undefined) let newMcpToken = $state(undefined) let newTokenExpiration = $state(undefined) @@ -124,6 +126,17 @@ : 'Create your first scripts or flows to make them available via MCP.' ) const noScriptsOrFlowsAvailableWarning = $derived(includedRunnables.length === 0 ? warning : '') + const longPathRunnables = $derived( + includedRunnables.filter((path) => path.length > MAX_PATH_LENGTH) + ) + const validRunnables = $derived( + includedRunnables.filter((path) => path.length <= MAX_PATH_LENGTH) + ) + const longPathWarning = $derived( + longPathRunnables.length > 0 + ? `${longPathRunnables.length} script(s)/flow(s) have paths longer than 60 characters and will be excluded from MCP tools. Consider shortening the paths: ${longPathRunnables.slice(0, 3).join(', ')}${longPathRunnables.length > 3 ? ` and ${longPathRunnables.length - 3} more` : ''}` + : '' + ) $effect(() => { if (mcpCreationMode) { @@ -406,20 +419,25 @@ {noScriptsOrFlowsAvailableWarning} {:else} + {#if longPathWarning} + + {longPathWarning} + + {/if} Scripts & Flows that will be available via MCP
- {#if includedRunnables.length <= 5} - {#each includedRunnables as scriptOrFlow} + {#if validRunnables.length <= 5} + {#each validRunnables as scriptOrFlow} {scriptOrFlow} {/each} {:else} - {#each includedRunnables.slice(0, 3) as scriptOrFlow} + {#each validRunnables.slice(0, 3) as scriptOrFlow} {scriptOrFlow} {/each} - +{includedRunnables.length - 3} more + +{validRunnables.length - 3} more {/if}