Merge branch 'main' of https://github.com/modelcontextprotocol/inspector
This commit is contained in:
commit
fef37483ba
26 changed files with 3224 additions and 475 deletions
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
|
|
@ -26,6 +26,10 @@ jobs:
|
||||||
# - run: npm ci
|
# - run: npm ci
|
||||||
- run: npm install --no-package-lock
|
- run: npm install --no-package-lock
|
||||||
|
|
||||||
|
- name: Check linting
|
||||||
|
working-directory: ./client
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
- name: Run client tests
|
- name: Run client tests
|
||||||
working-directory: ./client
|
working-directory: ./client
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|
@ -54,8 +58,6 @@ jobs:
|
||||||
# - run: npm ci
|
# - run: npm ci
|
||||||
- run: npm install --no-package-lock
|
- run: npm install --no-package-lock
|
||||||
|
|
||||||
- run: npm run build
|
|
||||||
|
|
||||||
# TODO: Add --provenance once the repo is public
|
# TODO: Add --provenance once the repo is public
|
||||||
- run: npm run publish-all
|
- run: npm run publish-all
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@modelcontextprotocol/inspector-cli",
|
"name": "@modelcontextprotocol/inspector-cli",
|
||||||
"version": "0.10.2",
|
"version": "0.11.0",
|
||||||
"description": "CLI for the Model Context Protocol inspector",
|
"description": "CLI for the Model Context Protocol inspector",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Anthropic, PBC (https://anthropic.com)",
|
"author": "Anthropic, PBC (https://anthropic.com)",
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.10.0",
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
"commander": "^13.1.0",
|
"commander": "^13.1.0",
|
||||||
"spawn-rx": "^5.1.2"
|
"spawn-rx": "^5.1.2"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,34 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const distPath = join(__dirname, "../dist");
|
const distPath = join(__dirname, "../dist");
|
||||||
|
|
||||||
const server = http.createServer((request, response) => {
|
const server = http.createServer((request, response) => {
|
||||||
return handler(request, response, {
|
const handlerOptions = {
|
||||||
public: distPath,
|
public: distPath,
|
||||||
rewrites: [{ source: "/**", destination: "/index.html" }],
|
rewrites: [{ source: "/**", destination: "/index.html" }],
|
||||||
});
|
headers: [
|
||||||
|
{
|
||||||
|
// Ensure index.html is never cached
|
||||||
|
source: "index.html",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "no-cache, no-store, max-age=0",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Allow long-term caching for hashed assets
|
||||||
|
source: "assets/**",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "public, max-age=31536000, immutable",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
return handler(request, response, handlerOptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
const port = process.env.PORT || 6274;
|
const port = process.env.PORT || 6274;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
preset: "ts-jest",
|
preset: "ts-jest",
|
||||||
testEnvironment: "jsdom",
|
testEnvironment: "jest-fixed-jsdom",
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
"^@/(.*)$": "<rootDir>/src/$1",
|
"^@/(.*)$": "<rootDir>/src/$1",
|
||||||
"\\.css$": "<rootDir>/src/__mocks__/styleMock.js",
|
"\\.css$": "<rootDir>/src/__mocks__/styleMock.js",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@modelcontextprotocol/inspector-client",
|
"name": "@modelcontextprotocol/inspector-client",
|
||||||
"version": "0.10.2",
|
"version": "0.11.0",
|
||||||
"description": "Client-side application for the Model Context Protocol inspector",
|
"description": "Client-side application for the Model Context Protocol inspector",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Anthropic, PBC (https://anthropic.com)",
|
"author": "Anthropic, PBC (https://anthropic.com)",
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
"test:watch": "jest --config jest.config.cjs --watch"
|
"test:watch": "jest --config jest.config.cjs --watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.10.0",
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
"@radix-ui/react-checkbox": "^1.1.4",
|
"@radix-ui/react-checkbox": "^1.1.4",
|
||||||
"@radix-ui/react-dialog": "^1.1.3",
|
"@radix-ui/react-dialog": "^1.1.3",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,14 @@ const App = () => {
|
||||||
const [sseUrl, setSseUrl] = useState<string>(() => {
|
const [sseUrl, setSseUrl] = useState<string>(() => {
|
||||||
return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse";
|
return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse";
|
||||||
});
|
});
|
||||||
const [transportType, setTransportType] = useState<"stdio" | "sse">(() => {
|
const [transportType, setTransportType] = useState<
|
||||||
|
"stdio" | "sse" | "streamable-http"
|
||||||
|
>(() => {
|
||||||
return (
|
return (
|
||||||
(localStorage.getItem("lastTransportType") as "stdio" | "sse") || "stdio"
|
(localStorage.getItem("lastTransportType") as
|
||||||
|
| "stdio"
|
||||||
|
| "sse"
|
||||||
|
| "streamable-http") || "stdio"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
const [logLevel, setLogLevel] = useState<LoggingLevel>("debug");
|
const [logLevel, setLogLevel] = useState<LoggingLevel>("debug");
|
||||||
|
|
@ -642,6 +647,7 @@ const App = () => {
|
||||||
setSelectedPrompt={(prompt) => {
|
setSelectedPrompt={(prompt) => {
|
||||||
clearError("prompts");
|
clearError("prompts");
|
||||||
setSelectedPrompt(prompt);
|
setSelectedPrompt(prompt);
|
||||||
|
setPromptContent("");
|
||||||
}}
|
}}
|
||||||
handleCompletion={handleCompletion}
|
handleCompletion={handleCompletion}
|
||||||
completionsSupported={completionsSupported}
|
completionsSupported={completionsSupported}
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,12 @@ const DynamicJsonForm = ({
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-end space-x-2">
|
<div className="flex justify-end space-x-2">
|
||||||
{isJsonMode && (
|
{isJsonMode && (
|
||||||
<Button variant="outline" size="sm" onClick={formatJson}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={formatJson}
|
||||||
|
>
|
||||||
Format JSON
|
Format JSON
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import type { JsonValue } from "@/utils/jsonUtils";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { Copy, CheckCheck } from "lucide-react";
|
import { Copy, CheckCheck } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
import { getDataType, tryParseJson } from "@/utils/jsonUtils";
|
import { getDataType, tryParseJson } from "@/utils/jsonUtils";
|
||||||
|
|
||||||
interface JsonViewProps {
|
interface JsonViewProps {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { useEffect, useRef } from "react";
|
||||||
import { InspectorOAuthClientProvider } from "../lib/auth";
|
import { InspectorOAuthClientProvider } from "../lib/auth";
|
||||||
import { SESSION_KEYS } from "../lib/constants";
|
import { SESSION_KEYS } from "../lib/constants";
|
||||||
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
||||||
import { useToast } from "@/hooks/use-toast.ts";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
import {
|
import {
|
||||||
generateOAuthErrorDescription,
|
generateOAuthErrorDescription,
|
||||||
parseOAuthCallbackParams,
|
parseOAuthCallbackParams,
|
||||||
|
|
|
||||||
167
client/src/components/SamplingRequest.tsx
Normal file
167
client/src/components/SamplingRequest.tsx
Normal file
|
|
@ -0,0 +1,167 @@
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import JsonView from "./JsonView";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import {
|
||||||
|
CreateMessageResult,
|
||||||
|
CreateMessageResultSchema,
|
||||||
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { PendingRequest } from "./SamplingTab";
|
||||||
|
import DynamicJsonForm from "./DynamicJsonForm";
|
||||||
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
|
import { JsonSchemaType, JsonValue } from "@/utils/jsonUtils";
|
||||||
|
|
||||||
|
export type SamplingRequestProps = {
|
||||||
|
request: PendingRequest;
|
||||||
|
onApprove: (id: number, result: CreateMessageResult) => void;
|
||||||
|
onReject: (id: number) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SamplingRequest = ({
|
||||||
|
onApprove,
|
||||||
|
request,
|
||||||
|
onReject,
|
||||||
|
}: SamplingRequestProps) => {
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const [messageResult, setMessageResult] = useState<JsonValue>({
|
||||||
|
model: "stub-model",
|
||||||
|
stopReason: "endTurn",
|
||||||
|
role: "assistant",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const contentType = (
|
||||||
|
(messageResult as { [key: string]: JsonValue })?.content as {
|
||||||
|
[key: string]: JsonValue;
|
||||||
|
}
|
||||||
|
)?.type;
|
||||||
|
|
||||||
|
const schema = useMemo(() => {
|
||||||
|
const s: JsonSchemaType = {
|
||||||
|
type: "object",
|
||||||
|
description: "Message result",
|
||||||
|
properties: {
|
||||||
|
model: {
|
||||||
|
type: "string",
|
||||||
|
default: "stub-model",
|
||||||
|
description: "model name",
|
||||||
|
},
|
||||||
|
stopReason: {
|
||||||
|
type: "string",
|
||||||
|
default: "endTurn",
|
||||||
|
description: "Stop reason",
|
||||||
|
},
|
||||||
|
role: {
|
||||||
|
type: "string",
|
||||||
|
default: "endTurn",
|
||||||
|
description: "Role of the model",
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
type: {
|
||||||
|
type: "string",
|
||||||
|
default: "text",
|
||||||
|
description: "Type of content",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (contentType === "text" && s.properties) {
|
||||||
|
s.properties.content.properties = {
|
||||||
|
...s.properties.content.properties,
|
||||||
|
text: {
|
||||||
|
type: "string",
|
||||||
|
default: "",
|
||||||
|
description: "text content",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
setMessageResult((prev) => ({
|
||||||
|
...(prev as { [key: string]: JsonValue }),
|
||||||
|
content: {
|
||||||
|
type: contentType,
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
} else if (contentType === "image" && s.properties) {
|
||||||
|
s.properties.content.properties = {
|
||||||
|
...s.properties.content.properties,
|
||||||
|
data: {
|
||||||
|
type: "string",
|
||||||
|
default: "",
|
||||||
|
description: "Base64 encoded image data",
|
||||||
|
},
|
||||||
|
mimeType: {
|
||||||
|
type: "string",
|
||||||
|
default: "",
|
||||||
|
description: "Mime type of the image",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
setMessageResult((prev) => ({
|
||||||
|
...(prev as { [key: string]: JsonValue }),
|
||||||
|
content: {
|
||||||
|
type: contentType,
|
||||||
|
data: "",
|
||||||
|
mimeType: "",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}, [contentType]);
|
||||||
|
|
||||||
|
const handleApprove = (id: number) => {
|
||||||
|
const validationResult = CreateMessageResultSchema.safeParse(messageResult);
|
||||||
|
if (!validationResult.success) {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: `There was an error validating the message result: ${validationResult.error.message}`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onApprove(id, validationResult.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-testid="sampling-request"
|
||||||
|
className="flex gap-4 p-4 border rounded-lg space-y-4"
|
||||||
|
>
|
||||||
|
<div className="flex-1 bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-2 rounded">
|
||||||
|
<JsonView data={JSON.stringify(request.request)} />
|
||||||
|
</div>
|
||||||
|
<form className="flex-1 space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<DynamicJsonForm
|
||||||
|
schema={schema}
|
||||||
|
value={messageResult}
|
||||||
|
onChange={(newValue: JsonValue) => {
|
||||||
|
setMessageResult(newValue);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex space-x-2 mt-1">
|
||||||
|
<Button type="button" onClick={() => handleApprove(request.id)}>
|
||||||
|
Approve
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onReject(request.id)}
|
||||||
|
>
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SamplingRequest;
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { TabsContent } from "@/components/ui/tabs";
|
import { TabsContent } from "@/components/ui/tabs";
|
||||||
import {
|
import {
|
||||||
CreateMessageRequest,
|
CreateMessageRequest,
|
||||||
CreateMessageResult,
|
CreateMessageResult,
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
import JsonView from "./JsonView";
|
import SamplingRequest from "./SamplingRequest";
|
||||||
|
|
||||||
export type PendingRequest = {
|
export type PendingRequest = {
|
||||||
id: number;
|
id: number;
|
||||||
|
|
@ -19,19 +18,6 @@ export type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const SamplingTab = ({ pendingRequests, onApprove, onReject }: Props) => {
|
const SamplingTab = ({ pendingRequests, onApprove, onReject }: Props) => {
|
||||||
const handleApprove = (id: number) => {
|
|
||||||
// For now, just return a stub response
|
|
||||||
onApprove(id, {
|
|
||||||
model: "stub-model",
|
|
||||||
stopReason: "endTurn",
|
|
||||||
role: "assistant",
|
|
||||||
content: {
|
|
||||||
type: "text",
|
|
||||||
text: "This is a stub response.",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="sampling">
|
<TabsContent value="sampling">
|
||||||
<div className="h-96">
|
<div className="h-96">
|
||||||
|
|
@ -44,21 +30,12 @@ const SamplingTab = ({ pendingRequests, onApprove, onReject }: Props) => {
|
||||||
<div className="mt-4 space-y-4">
|
<div className="mt-4 space-y-4">
|
||||||
<h3 className="text-lg font-semibold">Recent Requests</h3>
|
<h3 className="text-lg font-semibold">Recent Requests</h3>
|
||||||
{pendingRequests.map((request) => (
|
{pendingRequests.map((request) => (
|
||||||
<div key={request.id} className="p-4 border rounded-lg space-y-4">
|
<SamplingRequest
|
||||||
<JsonView
|
key={request.id}
|
||||||
className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 rounded"
|
request={request}
|
||||||
data={JSON.stringify(request.request)}
|
onApprove={onApprove}
|
||||||
/>
|
onReject={onReject}
|
||||||
|
/>
|
||||||
<div className="flex space-x-2">
|
|
||||||
<Button onClick={() => handleApprove(request.id)}>
|
|
||||||
Approve
|
|
||||||
</Button>
|
|
||||||
<Button variant="outline" onClick={() => onReject(request.id)}>
|
|
||||||
Reject
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
{pendingRequests.length === 0 && (
|
{pendingRequests.length === 0 && (
|
||||||
<p className="text-gray-500">No pending requests</p>
|
<p className="text-gray-500">No pending requests</p>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import {
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { InspectorConfig } from "@/lib/configurationTypes";
|
import { InspectorConfig } from "@/lib/configurationTypes";
|
||||||
import { ConnectionStatus } from "@/lib/constants";
|
import { ConnectionStatus } from "@/lib/constants";
|
||||||
import useTheme from "../lib/useTheme";
|
import useTheme from "../lib/hooks/useTheme";
|
||||||
import { version } from "../../../package.json";
|
import { version } from "../../../package.json";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
|
|
@ -42,8 +42,8 @@ import { useToast } from "@/hooks/use-toast";
|
||||||
|
|
||||||
interface SidebarProps {
|
interface SidebarProps {
|
||||||
connectionStatus: ConnectionStatus;
|
connectionStatus: ConnectionStatus;
|
||||||
transportType: "stdio" | "sse";
|
transportType: "stdio" | "sse" | "streamable-http";
|
||||||
setTransportType: (type: "stdio" | "sse") => void;
|
setTransportType: (type: "stdio" | "sse" | "streamable-http") => void;
|
||||||
command: string;
|
command: string;
|
||||||
setCommand: (command: string) => void;
|
setCommand: (command: string) => void;
|
||||||
args: string;
|
args: string;
|
||||||
|
|
@ -229,7 +229,7 @@ const Sidebar = ({
|
||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={transportType}
|
value={transportType}
|
||||||
onValueChange={(value: "stdio" | "sse") =>
|
onValueChange={(value: "stdio" | "sse" | "streamable-http") =>
|
||||||
setTransportType(value)
|
setTransportType(value)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|
@ -239,6 +239,7 @@ const Sidebar = ({
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="stdio">STDIO</SelectItem>
|
<SelectItem value="stdio">STDIO</SelectItem>
|
||||||
<SelectItem value="sse">SSE</SelectItem>
|
<SelectItem value="sse">SSE</SelectItem>
|
||||||
|
<SelectItem value="streamable-http">Streamable HTTP</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { InspectorConfig } from "@/lib/configurationTypes";
|
||||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
// Mock theme hook
|
// Mock theme hook
|
||||||
jest.mock("../../lib/useTheme", () => ({
|
jest.mock("../../lib/hooks/useTheme", () => ({
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
default: () => ["light", jest.fn()],
|
default: () => ["light", jest.fn()],
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
73
client/src/components/__tests__/samplingRequest.test.tsx
Normal file
73
client/src/components/__tests__/samplingRequest.test.tsx
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
import { render, screen, fireEvent } from "@testing-library/react";
|
||||||
|
import SamplingRequest from "../SamplingRequest";
|
||||||
|
import { PendingRequest } from "../SamplingTab";
|
||||||
|
|
||||||
|
const mockRequest: PendingRequest = {
|
||||||
|
id: 1,
|
||||||
|
request: {
|
||||||
|
method: "sampling/createMessage",
|
||||||
|
params: {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "What files are in the current directory?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
systemPrompt: "You are a helpful file system assistant.",
|
||||||
|
includeContext: "thisServer",
|
||||||
|
maxTokens: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Form to handle sampling response", () => {
|
||||||
|
const mockOnApprove = jest.fn();
|
||||||
|
const mockOnReject = jest.fn();
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onApprove with correct text content when Approve button is clicked", () => {
|
||||||
|
render(
|
||||||
|
<SamplingRequest
|
||||||
|
request={mockRequest}
|
||||||
|
onApprove={mockOnApprove}
|
||||||
|
onReject={mockOnReject}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click the Approve button
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /approve/i }));
|
||||||
|
|
||||||
|
// Assert that onApprove is called with the correct arguments
|
||||||
|
expect(mockOnApprove).toHaveBeenCalledWith(mockRequest.id, {
|
||||||
|
model: "stub-model",
|
||||||
|
stopReason: "endTurn",
|
||||||
|
role: "assistant",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onReject with correct request id when Reject button is clicked", () => {
|
||||||
|
render(
|
||||||
|
<SamplingRequest
|
||||||
|
request={mockRequest}
|
||||||
|
onApprove={mockOnApprove}
|
||||||
|
onReject={mockOnReject}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click the Approve button
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /Reject/i }));
|
||||||
|
|
||||||
|
// Assert that onApprove is called with the correct arguments
|
||||||
|
expect(mockOnReject).toHaveBeenCalledWith(mockRequest.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
55
client/src/components/__tests__/samplingTab.test.tsx
Normal file
55
client/src/components/__tests__/samplingTab.test.tsx
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import { Tabs } from "@/components/ui/tabs";
|
||||||
|
import SamplingTab, { PendingRequest } from "../SamplingTab";
|
||||||
|
|
||||||
|
describe("Sampling tab", () => {
|
||||||
|
const mockOnApprove = jest.fn();
|
||||||
|
const mockOnReject = jest.fn();
|
||||||
|
|
||||||
|
const renderSamplingTab = (pendingRequests: PendingRequest[]) =>
|
||||||
|
render(
|
||||||
|
<Tabs defaultValue="sampling">
|
||||||
|
<SamplingTab
|
||||||
|
pendingRequests={pendingRequests}
|
||||||
|
onApprove={mockOnApprove}
|
||||||
|
onReject={mockOnReject}
|
||||||
|
/>
|
||||||
|
</Tabs>,
|
||||||
|
);
|
||||||
|
|
||||||
|
it("should render 'No pending requests' when there are no pending requests", () => {
|
||||||
|
renderSamplingTab([]);
|
||||||
|
expect(
|
||||||
|
screen.getByText(
|
||||||
|
"When the server requests LLM sampling, requests will appear here for approval.",
|
||||||
|
),
|
||||||
|
).toBeTruthy();
|
||||||
|
expect(screen.findByText("No pending requests")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render the correct number of requests", () => {
|
||||||
|
renderSamplingTab(
|
||||||
|
Array.from({ length: 5 }, (_, i) => ({
|
||||||
|
id: i,
|
||||||
|
request: {
|
||||||
|
method: "sampling/createMessage",
|
||||||
|
params: {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "What files are in the current directory?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
systemPrompt: "You are a helpful file system assistant.",
|
||||||
|
includeContext: "thisServer",
|
||||||
|
maxTokens: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
expect(screen.getAllByTestId("sampling-request").length).toBe(5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
import {
|
import {
|
||||||
Toast,
|
Toast,
|
||||||
ToastClose,
|
ToastClose,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock the toast hook
|
// Mock the toast hook
|
||||||
jest.mock("@/hooks/use-toast", () => ({
|
jest.mock("@/lib/hooks/useToast", () => ({
|
||||||
useToast: () => ({
|
useToast: () => ({
|
||||||
toast: jest.fn(),
|
toast: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {
|
||||||
SSEClientTransport,
|
SSEClientTransport,
|
||||||
SseError,
|
SseError,
|
||||||
} from "@modelcontextprotocol/sdk/client/sse.js";
|
} from "@modelcontextprotocol/sdk/client/sse.js";
|
||||||
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||||
import {
|
import {
|
||||||
ClientNotification,
|
ClientNotification,
|
||||||
ClientRequest,
|
ClientRequest,
|
||||||
|
|
@ -26,7 +27,7 @@ import {
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ConnectionStatus } from "../constants";
|
import { ConnectionStatus } from "../constants";
|
||||||
import { Notification, StdErrNotificationSchema } from "../notificationTypes";
|
import { Notification, StdErrNotificationSchema } from "../notificationTypes";
|
||||||
|
|
@ -42,7 +43,7 @@ import { getMCPServerRequestTimeout } from "@/utils/configUtils";
|
||||||
import { InspectorConfig } from "../configurationTypes";
|
import { InspectorConfig } from "../configurationTypes";
|
||||||
|
|
||||||
interface UseConnectionOptions {
|
interface UseConnectionOptions {
|
||||||
transportType: "stdio" | "sse";
|
transportType: "stdio" | "sse" | "streamable-http";
|
||||||
command: string;
|
command: string;
|
||||||
args: string;
|
args: string;
|
||||||
sseUrl: string;
|
sseUrl: string;
|
||||||
|
|
@ -278,15 +279,29 @@ export function useConnection({
|
||||||
setConnectionStatus("error-connecting-to-proxy");
|
setConnectionStatus("error-connecting-to-proxy");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
|
let mcpProxyServerUrl;
|
||||||
mcpProxyServerUrl.searchParams.append("transportType", transportType);
|
switch (transportType) {
|
||||||
if (transportType === "stdio") {
|
case "stdio":
|
||||||
mcpProxyServerUrl.searchParams.append("command", command);
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
|
||||||
mcpProxyServerUrl.searchParams.append("args", args);
|
mcpProxyServerUrl.searchParams.append("command", command);
|
||||||
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
|
mcpProxyServerUrl.searchParams.append("args", args);
|
||||||
} else {
|
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
|
||||||
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
break;
|
||||||
|
|
||||||
|
case "sse":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "streamable-http":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
(mcpProxyServerUrl as URL).searchParams.append(
|
||||||
|
"transportType",
|
||||||
|
transportType,
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Inject auth manually instead of using SSEClientTransport, because we're
|
// Inject auth manually instead of using SSEClientTransport, because we're
|
||||||
|
|
@ -304,14 +319,24 @@ export function useConnection({
|
||||||
headers[authHeaderName] = `Bearer ${token}`;
|
headers[authHeaderName] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientTransport = new SSEClientTransport(mcpProxyServerUrl, {
|
// Create appropriate transport
|
||||||
|
const transportOptions = {
|
||||||
eventSourceInit: {
|
eventSourceInit: {
|
||||||
fetch: (url, init) => fetch(url, { ...init, headers }),
|
fetch: (
|
||||||
|
url: string | URL | globalThis.Request,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
) => fetch(url, { ...init, headers }),
|
||||||
},
|
},
|
||||||
requestInit: {
|
requestInit: {
|
||||||
headers,
|
headers,
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
const clientTransport =
|
||||||
|
transportType === "streamable-http"
|
||||||
|
? new StreamableHTTPClientTransport(mcpProxyServerUrl as URL, {
|
||||||
|
sessionId: undefined,
|
||||||
|
})
|
||||||
|
: new SSEClientTransport(mcpProxyServerUrl as URL, transportOptions);
|
||||||
|
|
||||||
if (onNotification) {
|
if (onNotification) {
|
||||||
[
|
[
|
||||||
|
|
|
||||||
52
client/src/lib/hooks/useTheme.ts
Normal file
52
client/src/lib/hooks/useTheme.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
|
type Theme = "light" | "dark" | "system";
|
||||||
|
|
||||||
|
const useTheme = (): [Theme, (mode: Theme) => void] => {
|
||||||
|
const [theme, setTheme] = useState<Theme>(() => {
|
||||||
|
const savedTheme = localStorage.getItem("theme") as Theme;
|
||||||
|
return savedTheme || "system";
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const darkModeMediaQuery = window.matchMedia(
|
||||||
|
"(prefers-color-scheme: dark)",
|
||||||
|
);
|
||||||
|
const handleDarkModeChange = (e: MediaQueryListEvent) => {
|
||||||
|
if (theme === "system") {
|
||||||
|
updateDocumentTheme(e.matches ? "dark" : "light");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateDocumentTheme = (newTheme: "light" | "dark") => {
|
||||||
|
document.documentElement.classList.toggle("dark", newTheme === "dark");
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set initial theme based on current mode
|
||||||
|
if (theme === "system") {
|
||||||
|
updateDocumentTheme(darkModeMediaQuery.matches ? "dark" : "light");
|
||||||
|
} else {
|
||||||
|
updateDocumentTheme(theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
darkModeMediaQuery.addEventListener("change", handleDarkModeChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
darkModeMediaQuery.removeEventListener("change", handleDarkModeChange);
|
||||||
|
};
|
||||||
|
}, [theme]);
|
||||||
|
|
||||||
|
const setThemeWithSideEffect = useCallback((newTheme: Theme) => {
|
||||||
|
setTheme(newTheme);
|
||||||
|
localStorage.setItem("theme", newTheme);
|
||||||
|
if (newTheme !== "system") {
|
||||||
|
document.documentElement.classList.toggle("dark", newTheme === "dark");
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
return useMemo(
|
||||||
|
() => [theme, setThemeWithSideEffect],
|
||||||
|
[theme, setThemeWithSideEffect],
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useTheme;
|
||||||
191
client/src/lib/hooks/useToast.ts
Normal file
191
client/src/lib/hooks/useToast.ts
Normal file
|
|
@ -0,0 +1,191 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
// Inspired by react-hot-toast library
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
import type { ToastActionElement, ToastProps } from "@/components/ui/toast";
|
||||||
|
|
||||||
|
const TOAST_LIMIT = 1;
|
||||||
|
const TOAST_REMOVE_DELAY = 1000000;
|
||||||
|
|
||||||
|
type ToasterToast = ToastProps & {
|
||||||
|
id: string;
|
||||||
|
title?: React.ReactNode;
|
||||||
|
description?: React.ReactNode;
|
||||||
|
action?: ToastActionElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
function genId() {
|
||||||
|
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
||||||
|
return count.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum ActionType {
|
||||||
|
ADD_TOAST = "ADD_TOAST",
|
||||||
|
UPDATE_TOAST = "UPDATE_TOAST",
|
||||||
|
DISMISS_TOAST = "DISMISS_TOAST",
|
||||||
|
REMOVE_TOAST = "REMOVE_TOAST",
|
||||||
|
}
|
||||||
|
|
||||||
|
type Action =
|
||||||
|
| {
|
||||||
|
type: ActionType.ADD_TOAST;
|
||||||
|
toast: ToasterToast;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: ActionType.UPDATE_TOAST;
|
||||||
|
toast: Partial<ToasterToast>;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: ActionType.DISMISS_TOAST;
|
||||||
|
toastId?: ToasterToast["id"];
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: ActionType.REMOVE_TOAST;
|
||||||
|
toastId?: ToasterToast["id"];
|
||||||
|
};
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
toasts: ToasterToast[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
||||||
|
|
||||||
|
const addToRemoveQueue = (toastId: string) => {
|
||||||
|
if (toastTimeouts.has(toastId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
toastTimeouts.delete(toastId);
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.REMOVE_TOAST,
|
||||||
|
toastId: toastId,
|
||||||
|
});
|
||||||
|
}, TOAST_REMOVE_DELAY);
|
||||||
|
|
||||||
|
toastTimeouts.set(toastId, timeout);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const reducer = (state: State, action: Action): State => {
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionType.ADD_TOAST:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
||||||
|
};
|
||||||
|
|
||||||
|
case ActionType.UPDATE_TOAST:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.map((t) =>
|
||||||
|
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
case ActionType.DISMISS_TOAST: {
|
||||||
|
const { toastId } = action;
|
||||||
|
|
||||||
|
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
||||||
|
// but I'll keep it here for simplicity
|
||||||
|
if (toastId) {
|
||||||
|
addToRemoveQueue(toastId);
|
||||||
|
} else {
|
||||||
|
state.toasts.forEach((toast) => {
|
||||||
|
addToRemoveQueue(toast.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.map((t) =>
|
||||||
|
t.id === toastId || toastId === undefined
|
||||||
|
? {
|
||||||
|
...t,
|
||||||
|
open: false,
|
||||||
|
}
|
||||||
|
: t,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case ActionType.REMOVE_TOAST:
|
||||||
|
if (action.toastId === undefined) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const listeners: Array<(state: State) => void> = [];
|
||||||
|
|
||||||
|
let memoryState: State = { toasts: [] };
|
||||||
|
|
||||||
|
function dispatch(action: Action) {
|
||||||
|
memoryState = reducer(memoryState, action);
|
||||||
|
listeners.forEach((listener) => {
|
||||||
|
listener(memoryState);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
type Toast = Omit<ToasterToast, "id">;
|
||||||
|
|
||||||
|
function toast({ ...props }: Toast) {
|
||||||
|
const id = genId();
|
||||||
|
|
||||||
|
const update = (props: ToasterToast) =>
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.UPDATE_TOAST,
|
||||||
|
toast: { ...props, id },
|
||||||
|
});
|
||||||
|
const dismiss = () =>
|
||||||
|
dispatch({ type: ActionType.DISMISS_TOAST, toastId: id });
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.ADD_TOAST,
|
||||||
|
toast: {
|
||||||
|
...props,
|
||||||
|
id,
|
||||||
|
open: true,
|
||||||
|
onOpenChange: (open) => {
|
||||||
|
if (!open) dismiss();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: id,
|
||||||
|
dismiss,
|
||||||
|
update,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function useToast() {
|
||||||
|
const [state, setState] = React.useState<State>(memoryState);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
listeners.push(setState);
|
||||||
|
return () => {
|
||||||
|
const index = listeners.indexOf(setState);
|
||||||
|
if (index > -1) {
|
||||||
|
listeners.splice(index, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toast,
|
||||||
|
dismiss: (toastId?: string) =>
|
||||||
|
dispatch({ type: ActionType.DISMISS_TOAST, toastId }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useToast, toast };
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue