run prettier

This commit is contained in:
Ashwin Bhat
2025-01-09 11:01:35 -08:00
parent d973f58bef
commit 715936d747
8 changed files with 120 additions and 61 deletions

View File

@@ -1,2 +1,4 @@
packages packages
server/build server/build
CODE_OF_CONDUCT.md
SECURITY.md

View File

@@ -16,7 +16,7 @@ import {
ResourceTemplate, ResourceTemplate,
Root, Root,
ServerNotification, ServerNotification,
Tool Tool,
} from "@modelcontextprotocol/sdk/types.js"; } from "@modelcontextprotocol/sdk/types.js";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
@@ -124,10 +124,7 @@ const App = () => {
const [nextToolCursor, setNextToolCursor] = useState<string | undefined>(); const [nextToolCursor, setNextToolCursor] = useState<string | undefined>();
const progressTokenRef = useRef(0); const progressTokenRef = useRef(0);
const { const { height: historyPaneHeight, handleDragStart } = useDraggablePane(300);
height: historyPaneHeight,
handleDragStart
} = useDraggablePane(300);
const { const {
connectionStatus, connectionStatus,
@@ -136,7 +133,7 @@ const App = () => {
requestHistory, requestHistory,
makeRequest: makeConnectionRequest, makeRequest: makeConnectionRequest,
sendNotification, sendNotification,
connect: connectMcpServer connect: connectMcpServer,
} = useConnection({ } = useConnection({
transportType, transportType,
command, command,
@@ -145,18 +142,21 @@ const App = () => {
env, env,
proxyServerUrl: PROXY_SERVER_URL, proxyServerUrl: PROXY_SERVER_URL,
onNotification: (notification) => { onNotification: (notification) => {
setNotifications(prev => [...prev, notification as ServerNotification]); setNotifications((prev) => [...prev, notification as ServerNotification]);
}, },
onStdErrNotification: (notification) => { onStdErrNotification: (notification) => {
setStdErrNotifications(prev => [...prev, notification as StdErrNotification]); setStdErrNotifications((prev) => [
},
onPendingRequest: (request, resolve, reject) => {
setPendingSampleRequests(prev => [
...prev, ...prev,
{ id: nextRequestId.current++, request, resolve, reject } notification as StdErrNotification,
]); ]);
}, },
getRoots: () => rootsRef.current onPendingRequest: (request, resolve, reject) => {
setPendingSampleRequests((prev) => [
...prev,
{ id: nextRequestId.current++, request, resolve, reject },
]);
},
getRoots: () => rootsRef.current,
}); });
const makeRequest = async <T extends z.ZodType>( const makeRequest = async <T extends z.ZodType>(
@@ -345,26 +345,40 @@ const App = () => {
{mcpClient ? ( {mcpClient ? (
<Tabs <Tabs
defaultValue={ defaultValue={
Object.keys(serverCapabilities ?? {}).includes(window.location.hash.slice(1)) ? Object.keys(serverCapabilities ?? {}).includes(
window.location.hash.slice(1) : window.location.hash.slice(1),
serverCapabilities?.resources ? "resources" : )
serverCapabilities?.prompts ? "prompts" : ? window.location.hash.slice(1)
serverCapabilities?.tools ? "tools" : : serverCapabilities?.resources
"ping" ? "resources"
: serverCapabilities?.prompts
? "prompts"
: serverCapabilities?.tools
? "tools"
: "ping"
} }
className="w-full p-4" className="w-full p-4"
onValueChange={(value) => (window.location.hash = value)} onValueChange={(value) => (window.location.hash = value)}
> >
<TabsList className="mb-4 p-0"> <TabsList className="mb-4 p-0">
<TabsTrigger value="resources" disabled={!serverCapabilities?.resources}> <TabsTrigger
value="resources"
disabled={!serverCapabilities?.resources}
>
<Files className="w-4 h-4 mr-2" /> <Files className="w-4 h-4 mr-2" />
Resources Resources
</TabsTrigger> </TabsTrigger>
<TabsTrigger value="prompts" disabled={!serverCapabilities?.prompts}> <TabsTrigger
value="prompts"
disabled={!serverCapabilities?.prompts}
>
<MessageSquare className="w-4 h-4 mr-2" /> <MessageSquare className="w-4 h-4 mr-2" />
Prompts Prompts
</TabsTrigger> </TabsTrigger>
<TabsTrigger value="tools" disabled={!serverCapabilities?.tools}> <TabsTrigger
value="tools"
disabled={!serverCapabilities?.tools}
>
<Hammer className="w-4 h-4 mr-2" /> <Hammer className="w-4 h-4 mr-2" />
Tools Tools
</TabsTrigger> </TabsTrigger>
@@ -388,7 +402,9 @@ const App = () => {
</TabsList> </TabsList>
<div className="w-full"> <div className="w-full">
{!serverCapabilities?.resources && !serverCapabilities?.prompts && !serverCapabilities?.tools ? ( {!serverCapabilities?.resources &&
!serverCapabilities?.prompts &&
!serverCapabilities?.tools ? (
<div className="flex items-center justify-center p-4"> <div className="flex items-center justify-center p-4">
<p className="text-lg text-gray-500"> <p className="text-lg text-gray-500">
The connected server does not support any MCP capabilities The connected server does not support any MCP capabilities

View File

@@ -1,5 +1,12 @@
import { useState } from "react"; import { useState } from "react";
import { Play, ChevronDown, ChevronRight, CircleHelp, Bug, Github } from "lucide-react"; import {
Play,
ChevronDown,
ChevronRight,
CircleHelp,
Bug,
Github,
} from "lucide-react";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { import {
@@ -243,18 +250,33 @@ const Sidebar = ({
</Select> </Select>
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
<a href="https://modelcontextprotocol.io/docs/tools/inspector" target="_blank" rel="noopener noreferrer"> <a
href="https://modelcontextprotocol.io/docs/tools/inspector"
target="_blank"
rel="noopener noreferrer"
>
<Button variant="ghost" title="Inspector Documentation"> <Button variant="ghost" title="Inspector Documentation">
<CircleHelp className="w-4 h-4 text-gray-800" /> <CircleHelp className="w-4 h-4 text-gray-800" />
</Button> </Button>
</a> </a>
<a href="https://modelcontextprotocol.io/docs/tools/debugging" target="_blank" rel="noopener noreferrer"> <a
href="https://modelcontextprotocol.io/docs/tools/debugging"
target="_blank"
rel="noopener noreferrer"
>
<Button variant="ghost" title="Debugging Guide"> <Button variant="ghost" title="Debugging Guide">
<Bug className="w-4 h-4 text-gray-800" /> <Bug className="w-4 h-4 text-gray-800" />
</Button> </Button>
</a> </a>
<a href="https://github.com/modelcontextprotocol/inspector" target="_blank" rel="noopener noreferrer"> <a
<Button variant="ghost" title="Report bugs or contribute on GitHub"> href="https://github.com/modelcontextprotocol/inspector"
target="_blank"
rel="noopener noreferrer"
>
<Button
variant="ghost"
title="Report bugs or contribute on GitHub"
>
<Github className="w-4 h-4 text-gray-800" /> <Github className="w-4 h-4 text-gray-800" />
</Button> </Button>
</a> </a>

View File

@@ -174,8 +174,7 @@ const ToolsTab = ({
} }
className="mt-1" className="mt-1"
/> />
) : ) : /* @ts-expect-error value type is currently unknown */
/* @ts-expect-error value type is currently unknown */
value.type === "object" ? ( value.type === "object" ? (
<Textarea <Textarea
id={key} id={key}

View File

@@ -44,10 +44,15 @@ export function useConnection({
onPendingRequest, onPendingRequest,
getRoots, getRoots,
}: UseConnectionOptions) { }: UseConnectionOptions) {
const [connectionStatus, setConnectionStatus] = useState<"disconnected" | "connected" | "error">("disconnected"); const [connectionStatus, setConnectionStatus] = useState<
const [serverCapabilities, setServerCapabilities] = useState<ServerCapabilities | null>(null); "disconnected" | "connected" | "error"
>("disconnected");
const [serverCapabilities, setServerCapabilities] =
useState<ServerCapabilities | null>(null);
const [mcpClient, setMcpClient] = useState<Client | null>(null); const [mcpClient, setMcpClient] = useState<Client | null>(null);
const [requestHistory, setRequestHistory] = useState<{ request: string; response?: string }[]>([]); const [requestHistory, setRequestHistory] = useState<
{ request: string; response?: string }[]
>([]);
const pushHistory = (request: object, response?: object) => { const pushHistory = (request: object, response?: object) => {
setRequestHistory((prev) => [ setRequestHistory((prev) => [
@@ -61,7 +66,7 @@ export function useConnection({
const makeRequest = async <T extends z.ZodType>( const makeRequest = async <T extends z.ZodType>(
request: ClientRequest, request: ClientRequest,
schema: T schema: T,
) => { ) => {
if (!mcpClient) { if (!mcpClient) {
throw new Error("MCP client not connected"); throw new Error("MCP client not connected");
@@ -80,14 +85,14 @@ export function useConnection({
}); });
pushHistory(request, response); pushHistory(request, response);
} catch (error) { } catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error); const errorMessage =
error instanceof Error ? error.message : String(error);
pushHistory(request, { error: errorMessage }); pushHistory(request, { error: errorMessage });
throw error; throw error;
} finally { } finally {
clearTimeout(timeoutId); clearTimeout(timeoutId);
} }
return response; return response;
} catch (e: unknown) { } catch (e: unknown) {
const errorString = (e as Error).message ?? String(e); const errorString = (e as Error).message ?? String(e);
@@ -140,13 +145,19 @@ export function useConnection({
} }
const clientTransport = new SSEClientTransport(backendUrl); const clientTransport = new SSEClientTransport(backendUrl);
if (onNotification) { if (onNotification) {
client.setNotificationHandler(ProgressNotificationSchema, onNotification); client.setNotificationHandler(
ProgressNotificationSchema,
onNotification,
);
} }
if (onStdErrNotification) { if (onStdErrNotification) {
client.setNotificationHandler(StdErrNotificationSchema, onStdErrNotification); client.setNotificationHandler(
StdErrNotificationSchema,
onStdErrNotification,
);
} }
await client.connect(clientTransport); await client.connect(clientTransport);
@@ -183,6 +194,6 @@ export function useConnection({
requestHistory, requestHistory,
makeRequest, makeRequest,
sendNotification, sendNotification,
connect connect,
}; };
} }

View File

@@ -6,19 +6,28 @@ export function useDraggablePane(initialHeight: number) {
const dragStartY = useRef<number>(0); const dragStartY = useRef<number>(0);
const dragStartHeight = useRef<number>(0); const dragStartHeight = useRef<number>(0);
const handleDragStart = useCallback((e: React.MouseEvent) => { const handleDragStart = useCallback(
setIsDragging(true); (e: React.MouseEvent) => {
dragStartY.current = e.clientY; setIsDragging(true);
dragStartHeight.current = height; dragStartY.current = e.clientY;
document.body.style.userSelect = "none"; dragStartHeight.current = height;
}, [height]); document.body.style.userSelect = "none";
},
[height],
);
const handleDragMove = useCallback((e: MouseEvent) => { const handleDragMove = useCallback(
if (!isDragging) return; (e: MouseEvent) => {
const deltaY = dragStartY.current - e.clientY; if (!isDragging) return;
const newHeight = Math.max(100, Math.min(800, dragStartHeight.current + deltaY)); const deltaY = dragStartY.current - e.clientY;
setHeight(newHeight); const newHeight = Math.max(
}, [isDragging]); 100,
Math.min(800, dragStartHeight.current + deltaY),
);
setHeight(newHeight);
},
[isDragging],
);
const handleDragEnd = useCallback(() => { const handleDragEnd = useCallback(() => {
setIsDragging(false); setIsDragging(false);
@@ -39,6 +48,6 @@ export function useDraggablePane(initialHeight: number) {
return { return {
height, height,
isDragging, isDragging,
handleDragStart handleDragStart,
}; };
} }

View File

@@ -1,7 +1,7 @@
import { StrictMode } from "react"; import { StrictMode } from "react";
import { createRoot } from "react-dom/client"; import { createRoot } from "react-dom/client";
import { ToastContainer } from 'react-toastify'; import { ToastContainer } from "react-toastify";
import 'react-toastify/dist/ReactToastify.css'; import "react-toastify/dist/ReactToastify.css";
import App from "./App.tsx"; import App from "./App.tsx";
import "./index.css"; import "./index.css";

View File

@@ -14,8 +14,8 @@ export default defineConfig({
minify: false, minify: false,
rollupOptions: { rollupOptions: {
output: { output: {
manualChunks: undefined manualChunks: undefined,
} },
} },
} },
}); });