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]

basic UI rendering of MCP tools

Ishaan Jaffb381dde9ac52
diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx
index f480501b586..a4256b3f4be 100644
--- a/ui/litellm-dashboard/src/app/page.tsx
+++ b/ui/litellm-dashboard/src/app/page.tsx
@@ -32,6 +32,8 @@ import GuardrailsPanel from "@/components/guardrails";
import TransformRequestPanel from "@/components/transform_request";
import { fetchUserModels } from "@/components/create_key_button";
import { fetchTeams } from "@/components/common_components/fetch_teams";
+import MCPToolsViewer from "@/components/mcp_tools";
+
function getCookie(name: string) {
const cookieValue = document.cookie
.split("; ")
@@ -347,6 +349,12 @@ export default function CreateKeyPage() {
accessToken={accessToken}
allTeams={teams as Team[] ?? []}
/>
+ ) : page == "mcp-tools" ? (
+ <MCPToolsViewer
+ accessToken={accessToken}
+ userRole={userRole}
+ userID={userID}
+ />
) : page == "new_usage" ? (
<NewUsagePage
userID={userID}
diff --git a/ui/litellm-dashboard/src/components/leftnav.tsx b/ui/litellm-dashboard/src/components/leftnav.tsx
index 3713a40cdc8..8879ba6eeff 100644
--- a/ui/litellm-dashboard/src/components/leftnav.tsx
+++ b/ui/litellm-dashboard/src/components/leftnav.tsx
@@ -20,7 +20,8 @@ import {
SafetyOutlined,
ExperimentOutlined,
ThunderboltOutlined,
- LockOutlined
+ LockOutlined,
+ ToolOutlined,
} from '@ant-design/icons';
import { old_admin_roles, v2_admin_role_names, all_admin_roles, rolesAllowedToSeeUsage, rolesWithWriteAccess } from '../utils/roles';
@@ -69,6 +70,7 @@ const menuItems: MenuItem[] = [
{ key: "10", page: "budgets", label: "Budgets", icon: <BankOutlined />, roles: all_admin_roles },
{ key: "11", page: "guardrails", label: "Guardrails", icon: <SafetyOutlined />, roles: all_admin_roles },
{ key: "12", page: "new_usage", label: "New Usage", icon: <BarChartOutlined />, roles: all_admin_roles },
+ { key: "18", page: "mcp-tools", label: "MCP Tools", icon: <ToolOutlined />, roles: all_admin_roles },
]
},
{
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/columns.tsx b/ui/litellm-dashboard/src/components/mcp_tools/columns.tsx
new file mode 100644
index 00000000000..5e347a7e1ea
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/mcp_tools/columns.tsx
@@ -0,0 +1,306 @@
+import React from "react";
+import { ColumnDef } from "@tanstack/react-table";
+import { MCPTool, InputSchema } from "./types";
+
+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
+ onClick={() => {
+ if (typeof row.original.onToolSelect === 'function') {
+ row.original.onToolSelect(tool);
+ }
+ }}
+ className="px-3 py-1 text-xs rounded-md bg-blue-600 text-white hover:bg-blue-700"
+ >
+ Test Tool
+ </button>
+ </div>
+ );
+ },
+ },
+];
+
+// Tool Panel component to display when a tool is selected
+export function ToolTestPanel({
+ tool,
+ onSubmit,
+ isLoading,
+ result,
+ error,
+ onClose
+}: {
+ tool: MCPTool;
+ 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>
+ <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>
+ ) : (
+ 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 bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50"
+ >
+ {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/types.tsx b/ui/litellm-dashboard/src/components/mcp_tools/types.tsx
new file mode 100644
index 00000000000..7bbb76fa237
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/mcp_tools/types.tsx
@@ -0,0 +1,71 @@
+// Define the structure for tool input schema properties
+export interface InputSchemaProperty {
+ type: string;
+ description?: string;
+ }
+
+ // Define the structure for the input schema of a tool
+ export interface InputSchema {
+ type: "object";
+ properties: Record<string, InputSchemaProperty>;
+ required?: string[];
+ }
+
+ // Define MCP provider info
+ export interface MCPInfo {
+ server_name: string;
+ logo_url?: string;
+ }
+
+ // Define the structure for a single MCP tool
+ export interface MCPTool {
+ name: string;
+ description: string;
+ inputSchema: InputSchema | string; // API returns string "tool_input_schema" or the actual schema
+ mcp_info: MCPInfo;
+ // Function to select a tool (added in the component)
+ onToolSelect?: (tool: MCPTool) => void;
+ }
+
+ // Define the response structure for the listMCPTools endpoint - now a flat array
+ export type ListMCPToolsResponse = MCPTool[];
+
+ // Define the argument structure for calling an MCP tool
+ export interface CallMCPToolArgs {
+ name: string;
+ arguments: Record<string, any> | null;
+ server_name?: string; // Now using server_name from mcp_info
+ }
+
+ // Define the possible content types in the response
+ export interface MCPTextContent {
+ type: "text";
+ text: string;
+ annotations?: any;
+ }
+
+ export interface MCPImageContent {
+ type: "image";
+ url?: string;
+ data?: string;
+ }
+
+ export interface MCPEmbeddedResource {
+ type: "embedded_resource";
+ resource_type?: string;
+ url?: string;
+ data?: any;
+ }
+
+ // Define the union type for the content array in the response
+ export type MCPContent = MCPTextContent | MCPImageContent | MCPEmbeddedResource;
+
+ // Define the response structure for the callMCPTool endpoint
+ export type CallMCPToolResponse = MCPContent[];
+
+ // Props for the main component
+ export interface MCPToolsViewerProps {
+ accessToken: string | null;
+ userRole: string | null;
+ userID: string | null;
+ }
\ No newline at end of file
diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx
index 83d258e532e..57a2dd3331f 100644
--- a/ui/litellm-dashboard/src/components/networking.tsx
+++ b/ui/litellm-dashboard/src/components/networking.tsx
@@ -4084,3 +4084,73 @@ export const updateInternalUserSettings = async (accessToken: string, settings:
throw error;
}
};
+
+
+export const listMCPTools = async (accessToken: string) => {
+ try {
+ // Construct base URL
+ let url = proxyBaseUrl
+ ? `${proxyBaseUrl}/mcp/tools/list`
+ : `/mcp/tools/list`;
+
+ console.log("Fetching MCP tools from:", url);
+
+ const response = await fetch(url, {
+ method: "GET",
+ headers: {
+ [globalLitellmHeaderName]: `Bearer ${accessToken}`,
+ "Content-Type": "application/json",
+ },
+ });
+
+ if (!response.ok) {
+ const errorData = await response.text();
+ handleError(errorData);
+ throw new Error("Network response was not ok");
+ }
+
+ const data = await response.json();
+ console.log("Fetched MCP tools:", data);
+ return data;
+ } catch (error) {
+ console.error("Failed to fetch MCP tools:", error);
+ throw error;
+ }
+};
+
+
+export const callMCPTool = async (accessToken: string, toolName: string, toolArguments: Record<string, any>) => {
+ try {
+ // Construct base URL
+ let url = proxyBaseUrl
+ ? `${proxyBaseUrl}/mcp/tools/call`
+ : `/mcp/tools/call`;
+
+ console.log("Calling MCP tool:", toolName, "with arguments:", toolArguments);
+
+ const response = await fetch(url, {
+ method: "POST",
+ headers: {
+ [globalLitellmHeaderName]: `Bearer ${accessToken}`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ tool_name: toolName,
+ tool_arguments: toolArguments,
+ }),
+ });
+
+ if (!response.ok) {
+ const errorData = await response.text();
+ handleError(errorData);
+ throw new Error("Network response was not ok");
+ }
+
+ const data = await response.json();
+ console.log("MCP tool call response:", data);
+ return data;
+ } catch (error) {
+ console.error("Failed to call MCP tool:", error);
+ throw error;
+ }
+};
\ No newline at end of file