Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

[MCP Gateway] QA - MCP Tool Testing Playground (#12520)

Ishaan Jaff23759c9a64b3
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/ToolTestPanel.tsx b/ui/litellm-dashboard/src/components/mcp_tools/ToolTestPanel.tsx
new file mode 100644
index 00000000000..4718dcd5d2f
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/mcp_tools/ToolTestPanel.tsx
@@ -0,0 +1,566 @@
+import React from "react";
+import { Button, Callout, TextInput } from "@tremor/react";
+import { MCPTool, InputSchema } from "./types";
+import { Form, Tooltip, message } from "antd";
+import { InfoCircleOutlined, ClockCircleOutlined } from "@ant-design/icons";
+
+const AuthBanner = ({ needsAuth, authValue }: { needsAuth: boolean; authValue?: string | null }) => {
+ if (!needsAuth || (needsAuth && authValue)) {
+ return (
+ <Callout title="Authentication" color="green" className="mb-3">
+ This tool does not require authentication or has authentication added.
+ </Callout>
+ );
+ }
+
+ if (needsAuth && !authValue) {
+ return (
+ <Callout title="Authentication required" color="yellow" className="mb-3">
+ Please provide authentication details if this tool call requires auth.
+ </Callout>
+ );
+ }
+ return null;
+};
+
+export function ToolTestPanel({
+ tool,
+ needsAuth,
+ authValue,
+ onSubmit,
+ isLoading,
+ result,
+ error,
+ onClose,
+}: {
+ tool: MCPTool;
+ needsAuth: boolean;
+ authValue?: string | null;
+ onSubmit: (args: Record<string, any>) => void;
+ isLoading: boolean;
+ result: any | null;
+ error: Error | null;
+ onClose: () => void;
+}) {
+ const [form] = Form.useForm();
+ const [viewMode, setViewMode] = React.useState<'formatted' | 'json'>('formatted');
+ const [startTime, setStartTime] = React.useState<number | null>(null);
+ const [duration, setDuration] = React.useState<number | null>(null);
+
+ // Create a placeholder schema if we only have the "tool_input_schema" string
+ const schema: InputSchema = React.useMemo(() => {
+ if (typeof tool.inputSchema === "string") {
+ // Default schema with a single text field
+ return {
+ type: "object",
+ properties: {
+ input: {
+ type: "string",
+ description: "Input for this tool",
+ },
+ },
+ required: ["input"],
+ };
+ }
+ return tool.inputSchema as InputSchema;
+ }, [tool.inputSchema]);
+
+ const handleSubmit = (values: Record<string, any>) => {
+ const start = Date.now();
+ setStartTime(start);
+ setDuration(null);
+ onSubmit(values);
+ };
+
+ // Track when result changes to calculate duration
+ React.useEffect(() => {
+ if (startTime && (result || error)) {
+ const endTime = Date.now();
+ setDuration(endTime - startTime);
+ }
+ }, [result, error, startTime]);
+
+ const copyToClipboard = async (text: string) => {
+ try {
+ // Try modern clipboard API first
+ if (navigator.clipboard && window.isSecureContext) {
+ await navigator.clipboard.writeText(text);
+ return true;
+ } else {
+ // Fallback for non-secure contexts (like 0.0.0.0)
+ const textArea = document.createElement('textarea');
+ textArea.value = text;
+ textArea.style.position = 'fixed';
+ textArea.style.opacity = '0';
+ document.body.appendChild(textArea);
+ textArea.focus();
+ textArea.select();
+
+ const successful = document.execCommand('copy');
+ document.body.removeChild(textArea);
+
+ if (!successful) {
+ throw new Error('execCommand failed');
+ }
+ return true;
+ }
+ } catch (error) {
+ console.error('Copy failed:', error);
+ return false;
+ }
+ };
+
+ const handleCopyResult = async () => {
+ const success = await copyToClipboard(JSON.stringify(result, null, 2));
+ if (success) {
+ message.success('Result copied to clipboard');
+ } else {
+ message.error('Failed to copy result');
+ }
+ };
+
+ const handleCopyToolName = async () => {
+ const success = await copyToClipboard(tool.name);
+ if (success) {
+ message.success('Tool name copied to clipboard');
+ } else {
+ message.error('Failed to copy tool name');
+ }
+ };
+
+ return (
+ <div className="space-y-4 h-full">
+ {/* Compact Header */}
+ <div className="flex items-center justify-between pb-3 border-b border-gray-200">
+ <div className="flex items-center space-x-3">
+ {tool.mcp_info.logo_url && (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img
+ src={tool.mcp_info.logo_url}
+ alt={`${tool.mcp_info.server_name} logo`}
+ className="w-6 h-6 object-contain"
+ />
+ )}
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center space-x-2 mb-1">
+ <h2 className="text-lg font-semibold text-gray-900">Test Tool:</h2>
+ <div
+ className="group inline-flex items-center space-x-1 bg-slate-50 hover:bg-slate-100 px-3 py-1 rounded-md cursor-pointer transition-colors border border-slate-200"
+ onClick={handleCopyToolName}
+ title="Click to copy tool name"
+ >
+ <span className="font-mono text-slate-700 font-medium text-sm">
+ {tool.name}
+ </span>
+ <svg
+ className="w-3 h-3 text-slate-400 group-hover:text-slate-600 transition-colors"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
+ />
+ </svg>
+ </div>
+ </div>
+ <p className="text-xs text-gray-600">{tool.description}</p>
+ <p className="text-xs text-gray-500">Provider: {tool.mcp_info.server_name}</p>
+ </div>
+ </div>
+ <Button
+ onClick={onClose}
+ variant="light"
+ size="sm"
+ className="text-gray-500 hover:text-gray-700"
+ >
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </Button>
+ </div>
+
+ {/* Auth Banner */}
+ <AuthBanner needsAuth={needsAuth} authValue={authValue} />
+
+ {/* Two Column Layout - Always Side by Side */}
+ <div className="grid grid-cols-2 gap-4 h-full">
+ {/* Left Column - Input Parameters */}
+ <div className="bg-white border border-gray-200 rounded-lg">
+ <div className="border-b border-gray-100 px-4 py-2">
+ <div className="flex items-center justify-between">
+ <h3 className="text-sm font-semibold text-gray-900">Input Parameters</h3>
+ <Tooltip title="Configure the input parameters for this tool call">
+ <InfoCircleOutlined className="text-gray-400 hover:text-gray-600" />
+ </Tooltip>
+ </div>
+ </div>
+
+ <div className="p-4">
+ <Form form={form} onFinish={handleSubmit} layout="vertical" className="space-y-3">
+ {typeof tool.inputSchema === "string" ? (
+ <div className="space-y-3">
+ <Form.Item
+ label={
+ <span className="text-sm font-medium text-gray-700">
+ Input <span className="text-red-500">*</span>
+ </span>
+ }
+ name="input"
+ rules={[{ required: true, message: "Please enter input for this tool" }]}
+ className="mb-3"
+ >
+ <TextInput
+ placeholder="Enter input for this tool"
+ className="rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"
+ />
+ </Form.Item>
+ </div>
+ ) : schema.properties === undefined ? (
+ <div className="text-center py-6 bg-gray-50 rounded-lg border border-gray-200">
+ <div className="max-w-sm mx-auto">
+ <h4 className="text-sm font-medium text-gray-900 mb-1">No Parameters Required</h4>
+ <p className="text-xs text-gray-500">This tool can be called without any input parameters.</p>
+ </div>
+ </div>
+ ) : (
+ <div className="space-y-3">
+ {Object.entries(schema.properties).map(([key, prop]) => (
+ <Form.Item
+ key={key}
+ label={
+ <span className="text-sm font-medium text-gray-700 flex items-center">
+ {key}{" "}
+ {schema.required?.includes(key) && <span className="text-red-500">*</span>}
+ {prop.description && (
+ <Tooltip title={prop.description}>
+ <InfoCircleOutlined className="ml-2 text-gray-400 hover:text-gray-600" />
+ </Tooltip>
+ )}
+ </span>
+ }
+ name={key}
+ rules={[
+ {
+ required: schema.required?.includes(key),
+ message: `Please enter ${key}`,
+ },
+ ]}
+ className="mb-3"
+ >
+ {prop.type === "string" && (
+ <TextInput
+ placeholder={prop.description || `Enter ${key}`}
+ className="rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"
+ />
+ )}
+
+ {prop.type === "number" && (
+ <input
+ type="number"
+ placeholder={prop.description || `Enter ${key}`}
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm transition-colors"
+ />
+ )}
+
+ {prop.type === "boolean" && (
+ <div className="flex items-center space-x-3 p-3 bg-gray-50 rounded-lg border border-gray-200">
+ <input
+ type="checkbox"
+ className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded transition-colors"
+ />
+ <span className="text-sm text-gray-700">Enable this option</span>
+ </div>
+ )}
+ </Form.Item>
+ ))}
+ </div>
+ )}
+
+ <div className="pt-3 border-t border-gray-100">
+ <Button
+ onClick={() => form.submit()}
+ disabled={isLoading}
+ variant="primary"
+ className="w-full"
+ loading={isLoading}
+ >
+ {isLoading ? "Calling Tool..." : (result || error) ? "Call Again" : "Call Tool"}
+ </Button>
+ </div>
+ </Form>
+ </div>
+ </div>
+
+ {/* Right Column - Tool Result */}
+ <div className="bg-white border border-gray-200 rounded-lg">
+ <div className="border-b border-gray-100 px-4 py-2">
+ <h3 className="text-sm font-semibold text-gray-900">Tool Result</h3>
+ </div>
+
+ <div className="p-4">
+ {!result && !error && !isLoading ? (
+ /* Empty State */
+ <div className="flex flex-col justify-center items-center h-48 text-gray-500">
+ <div className="text-center max-w-sm">
+ <div className="mb-3">
+ <svg className="mx-auto h-12 w-12 text-gray-300" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1} d="M13 10V3L4 14h7v7l9-11h-7z" />
+ </svg>
+ </div>
+ <h4 className="text-sm font-medium text-gray-900 mb-1">Ready to Call Tool</h4>
+ <p className="text-xs text-gray-500 leading-relaxed">
+ Configure the input parameters and click &quot;Call Tool&quot; to see the results here.
+ </p>
+ </div>
+ </div>
+ ) : (
+ <div className="space-y-3">
+ {/* Result Control Bar */}
+ {result && !isLoading && !error && (
+ <div className="p-2 bg-green-50 border border-green-200 rounded-lg">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center space-x-2">
+ <svg className="h-4 w-4 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
+ </svg>
+ <h4 className="text-xs font-medium text-green-900">Tool executed successfully</h4>
+ {duration !== null && (
+ <span className="text-xs text-green-600 ml-1">
+ • {(duration / 1000).toFixed(2)}s
+ </span>
+ )}
+ </div>
+
+ <div className="flex items-center space-x-1">
+ <div className="flex bg-white rounded border border-green-300 p-0.5">
+ <button
+ onClick={() => setViewMode('formatted')}
+ className={`px-2 py-1 text-xs font-medium rounded transition-colors ${
+ viewMode === 'formatted'
+ ? 'bg-green-100 text-green-800'
+ : 'text-green-600 hover:text-green-800'
+ }`}
+ >
+ Formatted
+ </button>
+ <button
+ onClick={() => setViewMode('json')}
+ className={`px-2 py-1 text-xs font-medium rounded transition-colors ${
+ viewMode === 'json'
+ ? 'bg-green-100 text-green-800'
+ : 'text-green-600 hover:text-green-800'
+ }`}
+ >
+ JSON
+ </button>
+ </div>
+
+ <button
+ onClick={handleCopyResult}
+ className="p-1 hover:bg-green-100 rounded text-green-700"
+ title="Copy response"
+ >
+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
+ </svg>
+ </button>
+ </div>
+ </div>
+ </div>
+ )}
+
+ <div className="max-h-96 overflow-y-auto">
+ {isLoading && (
+ <div className="flex flex-col justify-center items-center h-48 text-gray-500">
+ <div className="relative">
+ <div className="animate-spin rounded-full h-8 w-8 border-2 border-gray-200"></div>
+ <div className="animate-spin rounded-full h-8 w-8 border-2 border-blue-600 border-t-transparent absolute top-0"></div>
+ </div>
+ <p className="text-sm font-medium mt-3">Calling tool...</p>
+ <p className="text-xs text-gray-400 mt-1">Please wait while we process your request</p>
+ </div>
+ )}
+
+ {error && (
+ <div className="bg-red-50 border border-red-200 rounded-lg p-3">
+ <div className="flex items-start space-x-2">
+ <div className="flex-shrink-0">
+ <svg className="h-4 w-4 text-red-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
+ </svg>
+ </div>
+ <div className="flex-1">
+ <div className="flex items-center space-x-2 mb-1">
+ <h4 className="text-xs font-medium text-red-900">Tool Call Failed</h4>
+ {duration !== null && (
+ <span className="text-xs text-red-600">
+ • {(duration / 1000).toFixed(2)}s
+ </span>
+ )}
+ </div>
+ <div className="bg-white border border-red-200 rounded p-2 max-h-48 overflow-y-auto">
+ <pre className="text-xs whitespace-pre-wrap text-red-700 font-mono">{error.message}</pre>
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+
+ {result && !isLoading && !error && (
+ <div className="space-y-3">
+ {viewMode === 'formatted' ? (
+ // Formatted View
+ result.map((content: any, idx: number) => (
+ <div key={idx} className="border border-gray-200 rounded-lg overflow-hidden">
+ {content.type === "text" && (
+ <div>
+ <div className="bg-gray-50 px-3 py-1 border-b border-gray-200">
+ <span className="text-xs font-medium text-gray-700 uppercase tracking-wide">Text Response</span>
+ </div>
+ <div className="p-3">
+ <div className="bg-white rounded border border-gray-200 max-h-64 overflow-y-auto">
+ <div className="p-3 space-y-2">
+ {content.text.split('\n\n').map((section: string, sectionIndex: number) => {
+ if (section.trim() === '') return null;
+
+ // Handle headers (## or ###)
+ if (section.startsWith('##')) {
+ const headerText = section.replace(/^#+\s/, '');
+ return (
+ <div key={sectionIndex} className="border-b border-gray-200 pb-1 mb-2">
+ <h3 className="text-sm font-semibold text-gray-900">{headerText}</h3>
+ </div>
+ );
+ }
+
+ // Handle URL-containing sections
+ const urlRegex = /(https?:\/\/[^\s\)]+)/g;
+ if (urlRegex.test(section)) {
+ const parts = section.split(urlRegex);
+ return (
+ <div key={sectionIndex} className="bg-blue-50 border border-blue-200 rounded p-2">
+ <div className="text-xs text-gray-700 leading-relaxed whitespace-pre-wrap">
+ {parts.map((part, partIndex) => {
+ if (urlRegex.test(part)) {
+ return (
+ <a
+ key={partIndex}
+ href={part}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 hover:text-blue-800 underline break-all"
+ >
+ {part}
+ </a>
+ );
+ }
+ return part;
+ })}
+ </div>
+ </div>
+ );
+ }
+
+ // Handle score information
+ if (section.includes('Score:')) {
+ return (
+ <div key={sectionIndex} className="bg-green-50 border-l-4 border-green-400 p-2 rounded-r">
+ <p className="text-xs text-green-800 font-medium whitespace-pre-wrap">{section}</p>
+ </div>
+ );
+ }
+
+ // Regular content sections
+ return (
+ <div key={sectionIndex} className="bg-gray-50 rounded p-2 border border-gray-200">
+ <div className="text-xs text-gray-700 leading-relaxed whitespace-pre-wrap font-mono">
+ {section}
+ </div>
+ </div>
+ );
+ }).filter(Boolean)}
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+
+ {content.type === "image" && content.url && (
+ <div>
+ <div className="bg-gray-50 px-3 py-1 border-b border-gray-200">
+ <span className="text-xs font-medium text-gray-700 uppercase tracking-wide">Image Response</span>
+ </div>
+ <div className="p-3">
+ <div className="bg-gray-50 rounded p-3 border border-gray-200">
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ src={content.url}
+ alt="Tool result"
+ className="max-w-full h-auto rounded shadow-sm"
+ />
+ </div>
+ </div>
+ </div>
+ )}
+
+ {content.type === "embedded_resource" && (
+ <div>
+ <div className="bg-gray-50 px-3 py-1 border-b border-gray-200">
+ <span className="text-xs font-medium text-gray-700 uppercase tracking-wide">Embedded Resource</span>
+ </div>
+ <div className="p-3">
+ <div className="flex items-center space-x-2 p-3 bg-blue-50 border border-blue-200 rounded">
+ <div className="flex-shrink-0">
+ <svg className="h-5 w-5 text-blue-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ </div>
+ <div className="flex-1">
+ <p className="text-xs font-medium text-blue-900">Resource Type: {content.resource_type}</p>
+ {content.url && (
+ <a
+ href={content.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="inline-flex items-center text-xs text-blue-600 hover:text-blue-800 hover:underline mt-1 transition-colors"
+ >
+ View Resource
+ <svg className="ml-1 h-3 w-3" fill="currentColor" viewBox="0 0 20 20">
+ <path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z" />
+ <path d="M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z" />
+ </svg>
+ </a>
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ ))
+ ) : (
+ // JSON View
+ <div className="bg-white rounded border border-gray-200">
+ <div className="p-3 overflow-auto max-h-80 bg-gray-50">
+ <pre className="text-xs font-mono whitespace-pre-wrap break-all text-gray-800">
+ {JSON.stringify(result, null, 2)}
+ </pre>
+ </div>
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/columns.tsx b/ui/litellm-dashboard/src/components/mcp_tools/columns.tsx
deleted file mode 100644
index 92ebd23ebb9..00000000000
--- a/ui/litellm-dashboard/src/components/mcp_tools/columns.tsx
+++ /dev/null
@@ -1,348 +0,0 @@
-import React from "react";
-import { ColumnDef } from "@tanstack/react-table";
-import { MCPTool, InputSchema } from "./types";
-import { Button, Callout, Icon } from "@tremor/react"
-
-const AuthBanner = ({needsAuth, authValue}: {needsAuth: boolean, authValue?: string | null}) => {
- if(!needsAuth || (needsAuth && authValue)) {
- return (
- <Callout
- title="Authentication"
- color="green"
- className="mb-4"
- >
- This tool does not require authentication or has authentication added.
- </Callout>
- )
- }
-
- if (needsAuth && !authValue) {
- return (
- <Callout
- title="Authentication required"
- color="yellow"
- className="mb-4"
- >
- Please provide authentication details if this tool call requires auth.
- </Callout>
- );
- }
- return null;
-}
-
-export const columns: ColumnDef<MCPTool>[] = [
- {
- accessorKey: "mcp_info.server_name",
- header: "Provider",
- cell: ({ row }) => {
- const serverName = row.original.mcp_info.server_name;
- const logoUrl = row.original.mcp_info.logo_url;
-
- return (
- <div className="flex items-center space-x-2">
- {logoUrl && (
- <img
- src={logoUrl}
- alt={`${serverName} logo`}
- className="h-5 w-5 object-contain"
- />
- )}
- <span className="font-medium">{serverName}</span>
- </div>
- );
- },
- },
- {
- accessorKey: "name",
- header: "Tool Name",
- cell: ({ row }) => {
- const name = row.getValue("name") as string;
- return (
- <div>
- <span className="font-mono text-sm">{name}</span>
- </div>
- );
- },
- },
- {
- accessorKey: "description",
- header: "Description",
- cell: ({ row }) => {
- const description = row.getValue("description") as string;
- return (
- <div className="max-w-md">
- <span className="text-sm text-gray-700">{description}</span>
- </div>
- );
- },
- },
- {
- id: "actions",
- header: "Actions",
- cell: ({ row }) => {
- const tool = row.original;
-
- return (
- <div className="flex items-center space-x-2">
- <Button
- size="xs"
- variant="light"
- className="font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]"
- onClick={() => {
- if (typeof row.original.onToolSelect === 'function') {
- row.original.onToolSelect(tool);
- }
- }}
- >
- Test Tool
- </Button>
- </div>
- );
- },
- },
-];
-
-// Tool Panel component to display when a tool is selected
-export function ToolTestPanel({
- tool,
- needsAuth,
- authValue,
- onSubmit,
- isLoading,
- result,
- error,
- onClose
-}: {
- tool: MCPTool;
- needsAuth: boolean;
- authValue?: string | null;
- onSubmit: (args: Record<string, any>) => void;
- isLoading: boolean;
- result: any | null;
- error: Error | null;
- onClose: () => void;
-}) {
- const [formState, setFormState] = React.useState<Record<string, any>>({});
-
- // Create a placeholder schema if we only have the "tool_input_schema" string
- const schema: InputSchema = React.useMemo(() => {
- if (typeof tool.inputSchema === 'string') {
- // Default schema with a single text field
- return {
- type: "object",
- properties: {
- input: {
- type: "string",
- description: "Input for this tool"
- }
- },
- required: ["input"]
- };
- }
- return tool.inputSchema as InputSchema;
- }, [tool.inputSchema]);
-
- const handleInputChange = (key: string, value: any) => {
- setFormState(prev => ({
- ...prev,
- [key]: value
- }));
- };
-
- const handleSubmit = (e: React.FormEvent) => {
- e.preventDefault();
- onSubmit(formState);
- };
-
- return (
- <div className="bg-white rounded-lg shadow-lg border p-6 max-w-4xl w-full">
- <div className="flex justify-between items-start mb-4">
- <div>
- <h2 className="text-xl font-bold">Test Tool: <span className="font-mono">{tool.name}</span></h2>
- <p className="text-gray-600">{tool.description}</p>
- <p className="text-sm text-gray-500 mt-1">Provider: {tool.mcp_info.server_name}</p>
- </div>
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
- <AuthBanner
- needsAuth={needsAuth}
- authValue={authValue}
- />
- </div>
- <button
- onClick={onClose}
- className="p-1 rounded-full hover:bg-gray-200"
- >
- <svg
- xmlns="http://www.w3.org/2000/svg"
- width="20"
- height="20"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- strokeWidth="2"
- strokeLinecap="round"
- strokeLinejoin="round"
- >
- <line x1="18" y1="6" x2="6" y2="18"></line>
- <line x1="6" y1="6" x2="18" y2="18"></line>
- </svg>
- </button>
- </div>
-
- <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
- {/* Form Section */}
- <div className="bg-gray-50 p-4 rounded-lg">
- <h3 className="font-medium mb-4">Input Parameters</h3>
- <form onSubmit={handleSubmit}>
- {typeof tool.inputSchema === 'string' ? (
- <div className="mb-4">
- <p className="text-xs text-gray-500 mb-1">This tool uses a dynamic input schema.</p>
- <div className="mb-4">
- <label className="block text-sm font-medium text-gray-700 mb-1">
- Input <span className="text-red-500">*</span>
- </label>
- <input
- type="text"
- value={formState.input || ""}
- onChange={(e) => handleInputChange("input", e.target.value)}
- required
- className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
- />
- </div>
- </div>
- ) : schema.properties === undefined ? (
- <p className="text-xs">None</p>
- ): (
- Object.entries(schema.properties).map(([key, prop]) => (
- <div key={key} className="mb-4">
- <label className="block text-sm font-medium text-gray-700 mb-1">
- {key}{" "}
- {schema.required?.includes(key) && (
- <span className="text-red-500">*</span>
- )}
- </label>
- {prop.description && (
- <p className="text-xs text-gray-500 mb-1">{prop.description}</p>
- )}
-
- {/* Render appropriate input based on type */}
- {prop.type === "string" && (
- <input
- type="text"
- value={formState[key] || ""}
- onChange={(e) => handleInputChange(key, e.target.value)}
- required={schema.required?.includes(key)}
- className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
- />
- )}
-
- {prop.type === "number" && (
- <input
- type="number"
- value={formState[key] || ""}
- onChange={(e) => handleInputChange(key, parseFloat(e.target.value))}
- required={schema.required?.includes(key)}
- className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
- />
- )}
-
- {prop.type === "boolean" && (
- <div className="flex items-center">
- <input
- type="checkbox"
- checked={formState[key] || false}
- onChange={(e) => handleInputChange(key, e.target.checked)}
- className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
- />
- <span className="ml-2 text-sm text-gray-600">Enable</span>
- </div>
- )}
- </div>
- ))
- )}
-
- <div className="mt-6">
- <Button
- type="submit"
- disabled={isLoading}
- className="w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white"
- >
- {isLoading ? "Calling..." : "Call Tool"}
- </Button>
- </div>
- </form>
- </div>
-
- {/* Result Section */}
- <div className="bg-gray-50 p-4 rounded-lg overflow-auto max-h-[500px]">
- <h3 className="font-medium mb-4">Result</h3>
-
- {isLoading && (
- <div className="flex justify-center items-center py-8">
- <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-700"></div>
- </div>
- )}
-
- {error && (
- <div className="bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-md">
- <p className="font-medium">Error</p>
- <pre className="mt-2 text-xs overflow-auto whitespace-pre-wrap">{error.message}</pre>
- </div>
- )}
-
- {result && !isLoading && !error && (
- <div>
- {result.map((content: any, idx: number) => (
- <div key={idx} className="mb-4">
- {content.type === "text" && (
- <div className="bg-white border p-3 rounded-md">
- <p className="whitespace-pre-wrap text-sm">{content.text}</p>
- </div>
- )}
-
- {content.type === "image" && content.url && (
- <div className="bg-white border p-3 rounded-md">
- <img src={content.url} alt="Tool result" className="max-w-full h-auto rounded" />
- </div>
- )}
-
- {content.type === "embedded_resource" && (
- <div className="bg-white border p-3 rounded-md">
- <p className="text-sm font-medium">Embedded Resource</p>
- <p className="text-xs text-gray-500">Type: {content.resource_type}</p>
- {content.url && (
- <a
- href={content.url}
- target="_blank"
- rel="noopener noreferrer"
- className="text-sm text-blue-600 hover:underline"
- >
- View Resource
- </a>
- )}
- </div>
- )}
- </div>
- ))}
-
- <div className="mt-2">
- <details className="text-xs">
- <summary className="cursor-pointer text-gray-500 hover:text-gray-700">Raw JSON Response</summary>
- <pre className="mt-2 bg-gray-100 p-2 rounded-md overflow-auto max-h-[300px]">
- {JSON.stringify(result, null, 2)}
- </pre>
- </details>
- </div>
- </div>
- )}
-
- {!result && !isLoading && !error && (
- <div className="text-center py-8 text-gray-500">
- <p>The result will appear here after you call the tool.</p>
- </div>
- )}
- </div>
- </div>
- </div>
- );
-}
\ No newline at end of file
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/mcp_tools.tsx b/ui/litellm-dashboard/src/components/mcp_tools/mcp_tools.tsx
index 4a6b78cb14f..4674fe36423 100644
--- a/ui/litellm-dashboard/src/components/mcp_tools/mcp_tools.tsx
+++ b/ui/litellm-dashboard/src/components/mcp_tools/mcp_tools.tsx
@@ -1,7 +1,6 @@
import React, { useState } from "react";
import { useQuery, useMutation } from "@tanstack/react-query";
-import { DataTable } from "../view_logs/table";
-import { columns, ToolTestPanel } from "./columns";
+import { ToolTestPanel } from "./ToolTestPanel";
import {
MCPTool,
MCPToolsViewerProps,
@@ -11,7 +10,8 @@ import {
import { listMCPTools, callMCPTool } from "../networking";
import { Modal, Input, Form } from "antd";
-import { Button } from "@tremor/react";
+import { Button, Card, Title, Text } from "@tremor/react";
+import { RobotOutlined, ApiOutlined, KeyOutlined, SafetyOutlined, ToolOutlined } from "@ant-design/icons";
import { AUTH_TYPE } from "./types";
@@ -91,10 +91,12 @@ export const AuthModal = ({
const AuthSection = ({
authType,
- onAuthSubmit
+ onAuthSubmit,
+ hasAuth
}: {
authType: string | null | undefined;
onAuthSubmit: (value: string) => void;
+ hasAuth: boolean;
}) => {
const [modalVisible, setModalVisible] = useState(false);
@@ -108,47 +110,33 @@ const AuthSection = ({
const handleModalCancel = () => setModalVisible(false);
return (
- <>
- <Button onClick={handleAddAuth}>
- Add Auth
- </Button>
+ <div className="space-y-3">
+ <div className="flex items-center justify-between">
+ <Text className="text-sm font-medium text-gray-700">
+ Authentication {hasAuth ? '✓' : ''}
+ </Text>
+ <Button
+ onClick={handleAddAuth}
+ size="sm"
+ variant="secondary"
+ className="text-xs"
+ >
+ {hasAuth ? 'Update' : 'Add Auth'}
+ </Button>
+ </div>
+ <Text className="text-xs text-gray-500">
+ {hasAuth ? 'Authentication configured' : 'Some tools may require authentication'}
+ </Text>
<AuthModal
visible={modalVisible}
onOk={handleModalOk}
onCancel={handleModalCancel}
authType={authType}
/>
- </>
+ </div>
);
};
-// Wrapper to handle the type mismatch between MCPTool and DataTable's expected type
-function DataTableWrapper({
- columns,
- data,
- isLoading,
-}: {
- columns: any;
- data: MCPTool[];
- isLoading: boolean;
-}) {
- // Create a dummy renderSubComponent and getRowCanExpand function
- const renderSubComponent = () => <div />;
- const getRowCanExpand = () => false;
-
- return (
- <DataTable
- columns={columns as any}
- data={data as any}
- isLoading={isLoading}
- renderSubComponent={renderSubComponent}
- getRowCanExpand={getRowCanExpand}
- loadingMessage="🚅 Loading tools..."
- noDataMessage="No tools found"
- />
- );
-}
-
const MCPToolsViewer = ({
serverId,
accessToken,
@@ -156,7 +144,6 @@ const MCPToolsViewer = ({
userRole,
userID,
}: MCPToolsViewerProps) => {
- const [searchTerm, setSearchTerm] = useState("");
const [mcpAuthValue, setMcpAuthValue] = useState("");
const [selectedTool, setSelectedTool] = useState<MCPTool | null>(null);
const [toolResult, setToolResult] = useState<CallMCPToolResponse | null>(null);
@@ -188,78 +175,164 @@ const MCPToolsViewer = ({
},
});
- // Add onToolSelect handler to each tool
- const toolsData = React.useMemo(() => {
- if (!mcpToolsResponse) return [];
+ const toolsData = mcpToolsResponse?.tools || [];
+ const hasAuth = mcpAuthValue !== "";
- return (mcpToolsResponse.tools || []).map((tool: MCPTool) => ({
- ...tool,
- onToolSelect: (tool: MCPTool) => {
- setSelectedTool(tool);
- setToolResult(null);
- setToolError(null);
- },
- }));
- }, [mcpToolsResponse]);
+ return (
+ <div className="w-full h-screen p-4 bg-white">
+ <Card className="w-full rounded-xl shadow-md overflow-hidden">
+ <div className="flex h-[80vh] w-full gap-4">
+ {/* Left Sidebar with Controls */}
+ <div className="w-1/4 p-4 bg-gray-50 flex flex-col">
+ <Title className="text-xl font-semibold mb-6 mt-2">MCP Tools</Title>
+
+ <div className="flex flex-col flex-1 space-y-6">
+ {/* Tool Selection */}
+ <div className="flex flex-col flex-1">
+ <Text className="font-medium block mb-3 text-gray-700 flex items-center">
+ <ToolOutlined className="mr-2" /> Available Tools
+ {toolsData.length > 0 && (
+ <span className="ml-2 bg-blue-100 text-blue-800 text-xs font-medium px-2 py-0.5 rounded-full">
+ {toolsData.length}
+ </span>
+ )}
+ </Text>
+
+ {/* Loading State */}
+ {isLoadingTools && (
+ <div className="flex flex-col items-center justify-center py-8 bg-white border border-gray-200 rounded-lg">
+ <div className="relative mb-3">
+ <div className="animate-spin rounded-full h-6 w-6 border-2 border-gray-200"></div>
+ <div className="animate-spin rounded-full h-6 w-6 border-2 border-blue-600 border-t-transparent absolute top-0"></div>
+ </div>
+ <p className="text-xs font-medium text-gray-700">Loading tools...</p>
+ </div>
+ )}
- // Error message display
- const errorMessage = mcpToolsResponse?.error ? (
- <div className="p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50">
- <p className="font-medium">Error: {mcpToolsResponse.message}</p>
- {mcpToolsResponse.error === "server_not_found" && (
- <p className="mt-2">The specified server could not be found. Please check the server ID and try again.</p>
- )}
- {mcpToolsResponse.error === "server_error" && (
- <p className="mt-2">There was an error connecting to the server. Please try again later or contact support if the issue persists.</p>
- )}
- {mcpToolsResponse.error === "unexpected_error" && (
- <p className="mt-2">An unexpected error occurred. Please try again later or contact support if the issue persists.</p>
- )}
- </div>
- ) : null;
+ {/* Error State */}
+ {mcpToolsResponse?.error && (
+ <div className="p-3 text-xs text-red-800 rounded-lg bg-red-50 border border-red-200">
+ <p className="font-medium">Error: {mcpToolsResponse.message}</p>
+ </div>
+ )}
- // No tools message
- const noToolsMessage = !isLoadingTools && !mcpToolsResponse?.error && (!toolsData || toolsData.length === 0) ? (
- <div className="p-4 mb-4 text-sm text-gray-800 rounded-lg bg-gray-50">
- <p className="font-medium">No tools available</p>
- <p className="mt-2">No tools were found for this server. This could be because:</p>
- <ul className="list-disc list-inside mt-2">
- <li>The server has not registered any tools</li>
- <li>There was an error connecting to the server</li>
- <li>The server is still initializing</li>
- </ul>
- </div>
- ) : null;
+ {/* No Tools State */}
+ {!isLoadingTools && !mcpToolsResponse?.error && (!toolsData || toolsData.length === 0) && (
+ <div className="p-4 text-center bg-white border border-gray-200 rounded-lg">
+ <div className="mx-auto w-8 h-8 bg-gray-200 rounded-full flex items-center justify-center mb-2">
+ <svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 8.172V5L8 4z" />
+ </svg>
+ </div>
+ <p className="text-xs font-medium text-gray-700 mb-1">No tools available</p>
+ <p className="text-xs text-gray-500">No tools found for this server</p>
+ </div>
+ )}
- return (
- <div className="space-y-4">
- {errorMessage}
- {noToolsMessage}
- <DataTableWrapper
- columns={columns}
- data={toolsData}
- isLoading={isLoadingTools}
- />
- {selectedTool && (
- <ToolTestPanel
- tool={selectedTool}
- needsAuth={mcpServerHasAuth(auth_type)}
- authValue={mcpAuthValue}
- onSubmit={(args) => {
- executeTool({ tool: selectedTool, arguments: args, authValue: mcpAuthValue });
- }}
- result={toolResult}
- error={toolError}
- isLoading={isCallingTool}
- onClose={() => setSelectedTool(null)}
- />
- )}
- {mcpServerHasAuth(auth_type) && (
- <AuthSection
- authType={auth_type}
- onAuthSubmit={(value) => setMcpAuthValue(value)}
- />
- )}
+ {/* Tools List */}
+ {!isLoadingTools && !mcpToolsResponse?.error && toolsData.length > 0 && (
+ <div className="space-y-2 flex-1 overflow-y-auto">
+ {toolsData.map((tool: MCPTool) => (
+ <div
+ key={tool.name}
+ className={`border rounded-lg p-3 cursor-pointer transition-all hover:shadow-sm ${
+ selectedTool?.name === tool.name
+ ? 'border-blue-500 bg-blue-50 ring-1 ring-blue-200'
+ : 'border-gray-200 bg-white hover:border-gray-300'
+ }`}
+ onClick={() => {
+ setSelectedTool(tool);
+ setToolResult(null);
+ setToolError(null);
+ }}
+ >
+ <div className="flex items-start space-x-2">
+ {tool.mcp_info.logo_url && (
+ <img
+ src={tool.mcp_info.logo_url}
+ alt={`${tool.mcp_info.server_name} logo`}
+ className="w-4 h-4 object-contain flex-shrink-0 mt-0.5"
+ />
+ )}
+ <div className="flex-1 min-w-0">
+ <h4 className="font-mono text-xs font-medium text-gray-900 truncate">
+ {tool.name}
+ </h4>
+ <p className="text-xs text-gray-500 truncate">{tool.mcp_info.server_name}</p>
+ <p className="text-xs text-gray-600 mt-1 line-clamp-2 leading-relaxed">
+ {tool.description}
+ </p>
+ </div>
+ </div>
+ {selectedTool?.name === tool.name && (
+ <div className="mt-2 pt-2 border-t border-blue-200">
+ <div className="flex items-center text-xs font-medium text-blue-700">
+ <svg className="w-3 h-3 mr-1" fill="currentColor" viewBox="0 0 20 20">
+ <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
+ </svg>
+ Selected
+ </div>
+ </div>
+ )}
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+
+ {/* Authentication Section */}
+ {mcpServerHasAuth(auth_type) && (
+ <div className="pt-4 border-t border-gray-200 flex-shrink-0">
+ <Text className="font-medium block mb-3 text-gray-700 flex items-center">
+ <SafetyOutlined className="mr-2" /> Authentication
+ </Text>
+ <AuthSection
+ authType={auth_type}
+ onAuthSubmit={(value) => setMcpAuthValue(value)}
+ hasAuth={hasAuth}
+ />
+ </div>
+ )}
+ </div>
+ </div>
+
+ {/* Main Testing Area */}
+ <div className="w-3/4 flex flex-col bg-white">
+ <div className="p-4 border-b border-gray-200 flex justify-between items-center">
+ <Title className="text-xl font-semibold mb-0">Tool Testing Playground</Title>
+ </div>
+
+ <div className="flex-1 overflow-auto p-4">
+ {!selectedTool ? (
+ /* Empty State */
+ <div className="h-full flex flex-col items-center justify-center text-gray-400">
+ <RobotOutlined style={{ fontSize: '48px', marginBottom: '16px' }} />
+ <Text className="text-lg font-medium text-gray-600 mb-2">Select a Tool to Test</Text>
+ <Text className="text-center text-gray-500 max-w-md">
+ Choose a tool from the left sidebar to start testing its functionality with custom inputs.
+ </Text>
+ </div>
+ ) : (
+ /* Tool Test Panel */
+ <div className="h-full">
+ <ToolTestPanel
+ tool={selectedTool}
+ needsAuth={mcpServerHasAuth(auth_type)}
+ authValue={mcpAuthValue}
+ onSubmit={(args) => {
+ executeTool({ tool: selectedTool, arguments: args, authValue: mcpAuthValue });
+ }}
+ result={toolResult}
+ error={toolError}
+ isLoading={isCallingTool}
+ onClose={() => setSelectedTool(null)}
+ />
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ </Card>
</div>
);
};