mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 08:01:38 +00:00
filter out tools with too long names
This commit is contained in:
@@ -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<Tool> = 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
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
newTokenLabel = $bindable(undefined)
|
||||
}: Props = $props()
|
||||
|
||||
const MAX_PATH_LENGTH = 55
|
||||
|
||||
let newToken = $state<string | undefined>(undefined)
|
||||
let newMcpToken = $state<string | undefined>(undefined)
|
||||
let newTokenExpiration = $state<number | undefined>(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}
|
||||
</Alert>
|
||||
{:else}
|
||||
{#if longPathWarning}
|
||||
<Alert type="warning" title="Some paths are too long" size="xs">
|
||||
{longPathWarning}
|
||||
</Alert>
|
||||
{/if}
|
||||
<span class="block text-xs text-tertiary"
|
||||
>Scripts & Flows that will be available via MCP</span
|
||||
>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
{#if includedRunnables.length <= 5}
|
||||
{#each includedRunnables as scriptOrFlow}
|
||||
{#if validRunnables.length <= 5}
|
||||
{#each validRunnables as scriptOrFlow}
|
||||
<Badge rounded small color="blue">{scriptOrFlow}</Badge>
|
||||
{/each}
|
||||
{:else}
|
||||
{#each includedRunnables.slice(0, 3) as scriptOrFlow}
|
||||
{#each validRunnables.slice(0, 3) as scriptOrFlow}
|
||||
<Badge rounded small color="blue">{scriptOrFlow}</Badge>
|
||||
{/each}
|
||||
<Badge rounded small color="dark-gray">
|
||||
+{includedRunnables.length - 3} more
|
||||
+{validRunnables.length - 3} more
|
||||
</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user