'use client'; import React, { useCallback, useState } from 'react'; import { X, Trash2, AlertTriangle, Shield, FileJson, Settings2, Tags, } from 'lucide-react'; import type { ToolDefinition, ToolAnnotations, SchemaProperty, } from '@mcpengine/ai-pipeline/types'; import { ParamEditor } from './ParamEditor'; import { AuthConfigPanel } from './AuthConfigPanel'; interface ToolInspectorProps { tool: ToolDefinition; onChange: (tool: ToolDefinition) => void; onDelete: (toolName: string) => void; onClose: () => void; } export function ToolInspector({ tool, onChange, onDelete, onClose }: ToolInspectorProps) { const [outputExpanded, setOutputExpanded] = useState(false); // Update a top-level field const updateField = useCallback( (field: K, value: ToolDefinition[K]) => { onChange({ ...tool, [field]: value }); }, [tool, onChange] ); // Update annotations const updateAnnotation = useCallback( (key: keyof ToolAnnotations, value: boolean) => { onChange({ ...tool, annotations: { ...tool.annotations, [key]: value, }, }); }, [tool, onChange] ); // Update a single parameter const updateParam = useCallback( (paramName: string, updates: Partial) => { const newProps = { ...tool.inputSchema.properties }; newProps[paramName] = { ...newProps[paramName], ...updates }; onChange({ ...tool, inputSchema: { ...tool.inputSchema, properties: newProps }, }); }, [tool, onChange] ); // Remove a parameter const removeParam = useCallback( (paramName: string) => { const newProps = { ...tool.inputSchema.properties }; delete newProps[paramName]; const newRequired = (tool.inputSchema.required ?? []).filter( (r) => r !== paramName ); onChange({ ...tool, inputSchema: { ...tool.inputSchema, properties: newProps, required: newRequired, }, }); }, [tool, onChange] ); // Toggle required status const toggleRequired = useCallback( (paramName: string) => { const required = tool.inputSchema.required ?? []; const isReq = required.includes(paramName); onChange({ ...tool, inputSchema: { ...tool.inputSchema, required: isReq ? required.filter((r) => r !== paramName) : [...required, paramName], }, }); }, [tool, onChange] ); // Add a new parameter const addParam = useCallback(() => { const name = `param_${Object.keys(tool.inputSchema.properties).length + 1}`; onChange({ ...tool, inputSchema: { ...tool.inputSchema, properties: { ...tool.inputSchema.properties, [name]: { type: 'string', description: '' }, }, }, }); }, [tool, onChange]); const paramEntries = Object.entries(tool.inputSchema?.properties ?? {}); return (
{/* Header */}

Tool Inspector

{/* Scrollable content */}
{/* Name + Description */}
updateField('name', e.target.value)} className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-100 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/30 outline-none transition-colors" />