Skip to content

Commit 08ca758

Browse files
author
priyanshu.solanki
committed
using mcn components
1 parent 5f76c2a commit 08ca758

File tree

2 files changed

+4
-74
lines changed
  • apps/sim/app
    • api/mcp/workflow-servers/[id]/tools
    • workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/mcp-tool

2 files changed

+4
-74
lines changed

apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { NextRequest } from 'next/server'
55
import { createLogger } from '@/lib/logs/console/logger'
66
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
77
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
8+
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
89
import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
910

1011
const logger = createLogger('WorkflowMcpToolsAPI')
@@ -15,22 +16,6 @@ interface RouteParams {
1516
id: string
1617
}
1718

18-
/**
19-
* Sanitize a workflow name to be a valid MCP tool name.
20-
* Tool names should be lowercase, alphanumeric with underscores.
21-
*/
22-
function sanitizeToolName(name: string): string {
23-
return (
24-
name
25-
.toLowerCase()
26-
.replace(/[^a-z0-9\s_-]/g, '')
27-
.replace(/[\s-]+/g, '_')
28-
.replace(/_+/g, '_')
29-
.replace(/^_|_$/g, '')
30-
.substring(0, 64) || 'workflow_tool'
31-
)
32-
}
33-
3419
/**
3520
* Check if a workflow has a valid start block that can accept inputs
3621
*/

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/mcp-tool/mcp-tool.tsx

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { Skeleton } from '@/components/ui'
2525
import { cn } from '@/lib/core/utils/cn'
2626
import { createLogger } from '@/lib/logs/console/logger'
27+
import { generateToolInputSchema, sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
2728
import {
2829
useAddWorkflowMcpTool,
2930
useDeleteWorkflowMcpTool,
@@ -46,21 +47,6 @@ interface McpToolDeployProps {
4647
onAddedToServer?: () => void
4748
}
4849

49-
/**
50-
* Sanitize a workflow name to be a valid MCP tool name.
51-
*/
52-
function sanitizeToolName(name: string): string {
53-
return (
54-
name
55-
.toLowerCase()
56-
.replace(/[^a-z0-9\s_-]/g, '')
57-
.replace(/[\s-]+/g, '_')
58-
.replace(/_+/g, '_')
59-
.replace(/^_|_$/g, '')
60-
.substring(0, 64) || 'workflow_tool'
61-
)
62-
}
63-
6450
/**
6551
* Extract input format from workflow blocks using SubBlockStore
6652
* The actual input format values are stored in useSubBlockStore, not directly in the block structure
@@ -131,53 +117,12 @@ function extractInputFormat(
131117
}
132118

133119
/**
134-
* Generate JSON Schema from input format
120+
* Generate JSON Schema from input format using the shared utility
135121
*/
136122
function generateParameterSchema(
137123
inputFormat: Array<{ name: string; type: string }>
138124
): Record<string, unknown> {
139-
if (inputFormat.length === 0) {
140-
return {
141-
type: 'object',
142-
properties: {},
143-
}
144-
}
145-
146-
const properties: Record<string, { type: string; description: string }> = {}
147-
const required: string[] = []
148-
149-
for (const field of inputFormat) {
150-
let jsonType = 'string'
151-
switch (field.type) {
152-
case 'number':
153-
jsonType = 'number'
154-
break
155-
case 'boolean':
156-
jsonType = 'boolean'
157-
break
158-
case 'object':
159-
jsonType = 'object'
160-
break
161-
case 'array':
162-
case 'files':
163-
jsonType = 'array'
164-
break
165-
default:
166-
jsonType = 'string'
167-
}
168-
169-
properties[field.name] = {
170-
type: jsonType,
171-
description: field.name,
172-
}
173-
required.push(field.name)
174-
}
175-
176-
return {
177-
type: 'object',
178-
properties,
179-
required,
180-
}
125+
return generateToolInputSchema(inputFormat) as unknown as Record<string, unknown>
181126
}
182127

183128
/**

0 commit comments

Comments
 (0)