mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
using mcn components
This commit is contained in:
@@ -5,6 +5,7 @@ import type { NextRequest } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
||||
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
||||
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
||||
import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
|
||||
|
||||
const logger = createLogger('WorkflowMcpToolsAPI')
|
||||
@@ -15,22 +16,6 @@ interface RouteParams {
|
||||
id: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a workflow name to be a valid MCP tool name.
|
||||
* Tool names should be lowercase, alphanumeric with underscores.
|
||||
*/
|
||||
function sanitizeToolName(name: string): string {
|
||||
return (
|
||||
name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s_-]/g, '')
|
||||
.replace(/[\s-]+/g, '_')
|
||||
.replace(/_+/g, '_')
|
||||
.replace(/^_|_$/g, '')
|
||||
.substring(0, 64) || 'workflow_tool'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a workflow has a valid start block that can accept inputs
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
import { Skeleton } from '@/components/ui'
|
||||
import { cn } from '@/lib/core/utils/cn'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { generateToolInputSchema, sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
||||
import {
|
||||
useAddWorkflowMcpTool,
|
||||
useDeleteWorkflowMcpTool,
|
||||
@@ -46,21 +47,6 @@ interface McpToolDeployProps {
|
||||
onAddedToServer?: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a workflow name to be a valid MCP tool name.
|
||||
*/
|
||||
function sanitizeToolName(name: string): string {
|
||||
return (
|
||||
name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s_-]/g, '')
|
||||
.replace(/[\s-]+/g, '_')
|
||||
.replace(/_+/g, '_')
|
||||
.replace(/^_|_$/g, '')
|
||||
.substring(0, 64) || 'workflow_tool'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract input format from workflow blocks using SubBlockStore
|
||||
* The actual input format values are stored in useSubBlockStore, not directly in the block structure
|
||||
@@ -131,53 +117,12 @@ function extractInputFormat(
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate JSON Schema from input format
|
||||
* Generate JSON Schema from input format using the shared utility
|
||||
*/
|
||||
function generateParameterSchema(
|
||||
inputFormat: Array<{ name: string; type: string }>
|
||||
): Record<string, unknown> {
|
||||
if (inputFormat.length === 0) {
|
||||
return {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
}
|
||||
}
|
||||
|
||||
const properties: Record<string, { type: string; description: string }> = {}
|
||||
const required: string[] = []
|
||||
|
||||
for (const field of inputFormat) {
|
||||
let jsonType = 'string'
|
||||
switch (field.type) {
|
||||
case 'number':
|
||||
jsonType = 'number'
|
||||
break
|
||||
case 'boolean':
|
||||
jsonType = 'boolean'
|
||||
break
|
||||
case 'object':
|
||||
jsonType = 'object'
|
||||
break
|
||||
case 'array':
|
||||
case 'files':
|
||||
jsonType = 'array'
|
||||
break
|
||||
default:
|
||||
jsonType = 'string'
|
||||
}
|
||||
|
||||
properties[field.name] = {
|
||||
type: jsonType,
|
||||
description: field.name,
|
||||
}
|
||||
required.push(field.name)
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'object',
|
||||
properties,
|
||||
required,
|
||||
}
|
||||
return generateToolInputSchema(inputFormat) as unknown as Record<string, unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user