Phase 2: Refactor Sampling/Elicitation cluster to MCP SDK types

Replace ad hoc local types with SDK schema types across the Sampling
and Elicitation group components.

- SamplingRequestPanel: accept `request: CreateMessageRequestParams` +
  `draftResult: CreateMessageResult` instead of 16 flat props; derive
  messages, model preferences, and parameters from the request object;
  drop `tools`/`toolChoice` (not in MCP 2025-11-25 CreateMessageRequest)
- InlineSamplingRequest: accept `request: CreateMessageRequestParams`;
  derive messagePreview and modelHints from the request
- ElicitationFormPanel: accept `request: ElicitRequest['params']` +
  `serverName`; pass requestedSchema directly to SchemaForm
- ElicitationUrlPanel: rename `elicitationId` to `requestId`
- InlineElicitationRequest: accept `request: ElicitRequest['params']`;
  discriminate form vs URL mode on request shape instead of `mode` prop
- PendingClientRequests: unchanged (children-based wrapper)
- Delete local `SamplingTool` type
- Update all stories with real SDK type fixtures

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cliffhall 2026-04-20 19:57:58 -04:00
commit c1a63cb37d
11 changed files with 326 additions and 299 deletions

View file

@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react-vite"; import type { Meta, StoryObj } from "@storybook/react-vite";
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test"; import { fn } from "storybook/test";
import { ElicitationFormPanel } from "./ElicitationFormPanel"; import { ElicitationFormPanel } from "./ElicitationFormPanel";
@ -10,7 +11,6 @@ const meta: Meta<typeof ElicitationFormPanel> = {
onSubmit: fn(), onSubmit: fn(),
onCancel: fn(), onCancel: fn(),
serverName: "postgres-server", serverName: "postgres-server",
message: "Please provide database connection details.",
values: {}, values: {},
}, },
}; };
@ -18,49 +18,55 @@ const meta: Meta<typeof ElicitationFormPanel> = {
export default meta; export default meta;
type Story = StoryObj<typeof ElicitationFormPanel>; type Story = StoryObj<typeof ElicitationFormPanel>;
export const SimpleForm: Story = { const dbRequest = {
args: { message: "Please provide database connection details.",
schema: { requestedSchema: {
type: "object", type: "object" as const,
properties: { properties: {
host: { type: "string", title: "Host" }, host: { type: "string" as const, title: "Host" },
port: { type: "integer", title: "Port" }, port: { type: "string" as const, title: "Port" },
database: { type: "string", title: "Database" }, database: { type: "string" as const, title: "Database" },
},
required: ["host", "port"],
}, },
}, },
} satisfies ElicitRequest["params"];
const sslRequest = {
message: "Please select your SSL mode preference.",
requestedSchema: {
type: "object" as const,
properties: {
sslMode: {
type: "string" as const,
title: "SSL Mode",
enum: ["disable", "require", "verify-full"],
},
},
},
} satisfies ElicitRequest["params"];
const deployRequest = {
message: "Please confirm the deployment.",
requestedSchema: {
type: "object" as const,
properties: {
environment: {
type: "string" as const,
title: "Environment",
enum: ["staging", "production"],
},
confirm: { type: "boolean" as const, title: "Confirm deployment" },
},
},
} satisfies ElicitRequest["params"];
export const SimpleForm: Story = {
args: { request: dbRequest },
}; };
export const WithEnums: Story = { export const WithEnums: Story = {
args: { args: { request: sslRequest },
schema: {
type: "object",
properties: {
sslMode: {
type: "string",
title: "SSL Mode",
oneOf: [
{ const: "disable", title: "Disable" },
{ const: "require", title: "Require" },
{ const: "verify-full", title: "Verify Full" },
],
},
},
},
},
}; };
export const AllRequired: Story = { export const BooleanField: Story = {
args: { args: { request: deployRequest },
schema: {
type: "object",
properties: {
host: { type: "string", title: "Host" },
port: { type: "integer", title: "Port" },
database: { type: "string", title: "Database" },
},
required: ["host", "port", "database"],
},
},
}; };

View file

@ -1,12 +1,12 @@
import { Alert, Button, Divider, Group, Stack, Text } from "@mantine/core"; import { Alert, Button, Divider, Group, Stack, Text } from "@mantine/core";
import type { JsonSchema } from "../SchemaForm/SchemaForm"; import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
import { SchemaForm } from "../SchemaForm/SchemaForm"; import { SchemaForm } from "../SchemaForm/SchemaForm";
import type { JsonSchema } from "../SchemaForm/SchemaForm";
export interface ElicitationFormPanelProps { export interface ElicitationFormPanelProps {
message: string; request: ElicitRequest["params"];
schema: JsonSchema;
values: Record<string, unknown>;
serverName: string; serverName: string;
values: Record<string, unknown>;
onChange: (values: Record<string, unknown>) => void; onChange: (values: Record<string, unknown>) => void;
onSubmit: () => void; onSubmit: () => void;
onCancel: () => void; onCancel: () => void;
@ -26,19 +26,27 @@ function formatWarning(serverName: string): string {
} }
export function ElicitationFormPanel({ export function ElicitationFormPanel({
message, request,
schema,
values,
serverName, serverName,
values,
onChange, onChange,
onSubmit, onSubmit,
onCancel, onCancel,
}: ElicitationFormPanelProps) { }: ElicitationFormPanelProps) {
const schema =
"requestedSchema" in request ? request.requestedSchema : undefined;
return ( return (
<Stack gap="md"> <Stack gap="md">
<QuotedMessage>{formatQuoted(message)}</QuotedMessage> <QuotedMessage>{formatQuoted(request.message)}</QuotedMessage>
<Divider /> <Divider />
<SchemaForm schema={schema} values={values} onChange={onChange} /> {schema && (
<SchemaForm
schema={schema as JsonSchema}
values={values}
onChange={onChange}
/>
)}
<Alert color="yellow" title="Warning"> <Alert color="yellow" title="Warning">
{formatWarning(serverName)} {formatWarning(serverName)}
</Alert> </Alert>

View file

@ -10,7 +10,7 @@ const meta: Meta<typeof ElicitationUrlPanel> = {
onOpenInBrowser: fn(), onOpenInBrowser: fn(),
onCancel: fn(), onCancel: fn(),
message: "Please authenticate with the external service.", message: "Please authenticate with the external service.",
elicitationId: "elicit-abc-123", requestId: "elicit-abc-123",
}, },
}; };

View file

@ -12,7 +12,7 @@ import {
export interface ElicitationUrlPanelProps { export interface ElicitationUrlPanelProps {
message: string; message: string;
url: string; url: string;
elicitationId: string; requestId: string;
isWaiting: boolean; isWaiting: boolean;
onCopyUrl: () => void; onCopyUrl: () => void;
onOpenInBrowser: () => void; onOpenInBrowser: () => void;
@ -39,14 +39,14 @@ const MetaText = Text.withProps({
c: "dimmed", c: "dimmed",
}); });
function formatElicitationId(id: string): string { function formatRequestId(id: string): string {
return `Elicitation ID: ${id}`; return `Request ID: ${id}`;
} }
export function ElicitationUrlPanel({ export function ElicitationUrlPanel({
message, message,
url, url,
elicitationId, requestId,
isWaiting, isWaiting,
onCopyUrl, onCopyUrl,
onOpenInBrowser, onOpenInBrowser,
@ -73,7 +73,7 @@ export function ElicitationUrlPanel({
<HintText>Waiting for completion...</HintText> <HintText>Waiting for completion...</HintText>
</Group> </Group>
)} )}
<MetaText>{formatElicitationId(elicitationId)}</MetaText> <MetaText>{formatRequestId(requestId)}</MetaText>
<Alert color="yellow" title="Warning"> <Alert color="yellow" title="Warning">
This will open an external URL. Verify the domain before proceeding. This will open an external URL. Verify the domain before proceeding.
</Alert> </Alert>

View file

@ -1,12 +1,31 @@
import type { Meta, StoryObj } from "@storybook/react-vite"; import type { Meta, StoryObj } from "@storybook/react-vite";
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test"; import { fn } from "storybook/test";
import { InlineElicitationRequest } from "./InlineElicitationRequest"; import { InlineElicitationRequest } from "./InlineElicitationRequest";
const formRequest = {
message: "Please provide your database connection details.",
requestedSchema: {
type: "object" as const,
properties: {
host: { type: "string" as const, title: "Host" },
port: { type: "string" as const, title: "Port" },
database: { type: "string" as const, title: "Database" },
},
},
} satisfies ElicitRequest["params"];
const urlRequest: ElicitRequest["params"] = {
mode: "url",
message: "Please authenticate via the external URL.",
url: "https://example.com/auth/callback?session=abc123",
elicitationId: "elicit-abc-123",
};
const meta: Meta<typeof InlineElicitationRequest> = { const meta: Meta<typeof InlineElicitationRequest> = {
title: "Groups/InlineElicitationRequest", title: "Groups/InlineElicitationRequest",
component: InlineElicitationRequest, component: InlineElicitationRequest,
args: { args: {
message: "Please provide your database connection details.",
queuePosition: "1 of 1", queuePosition: "1 of 1",
onChange: fn(), onChange: fn(),
onSubmit: fn(), onSubmit: fn(),
@ -19,32 +38,21 @@ type Story = StoryObj<typeof InlineElicitationRequest>;
export const FormMode: Story = { export const FormMode: Story = {
args: { args: {
mode: "form", request: formRequest,
schema: {
type: "object",
properties: {
host: { type: "string", title: "Host" },
port: { type: "integer", title: "Port" },
database: { type: "string", title: "Database" },
},
required: ["host", "port"],
},
values: {}, values: {},
}, },
}; };
export const UrlMode: Story = { export const UrlMode: Story = {
args: { args: {
mode: "url", request: urlRequest,
url: "https://example.com/auth/callback?session=abc123",
isWaiting: false, isWaiting: false,
}, },
}; };
export const UrlWaiting: Story = { export const UrlWaiting: Story = {
args: { args: {
mode: "url", request: urlRequest,
url: "https://example.com/auth/callback?session=abc123",
isWaiting: true, isWaiting: true,
}, },
}; };

View file

@ -8,16 +8,14 @@ import {
Stack, Stack,
Text, Text,
} from "@mantine/core"; } from "@mantine/core";
import type { JsonSchema } from "../SchemaForm/SchemaForm"; import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
import { SchemaForm } from "../SchemaForm/SchemaForm"; import { SchemaForm } from "../SchemaForm/SchemaForm";
import type { JsonSchema } from "../SchemaForm/SchemaForm";
export interface InlineElicitationRequestProps { export interface InlineElicitationRequestProps {
mode: "form" | "url"; request: ElicitRequest["params"];
message: string;
queuePosition: string; queuePosition: string;
schema?: JsonSchema;
values?: Record<string, unknown>; values?: Record<string, unknown>;
url?: string;
isWaiting?: boolean; isWaiting?: boolean;
onChange: (values: Record<string, unknown>) => void; onChange: (values: Record<string, unknown>) => void;
onSubmit: () => void; onSubmit: () => void;
@ -49,45 +47,52 @@ const CompactButton = Button.withProps({
variant: "light", variant: "light",
}); });
function getBadgeLabel(mode: "form" | "url"): string { function isFormMode(
return mode === "form" request: ElicitRequest["params"],
): request is ElicitRequest["params"] & {
requestedSchema: Record<string, unknown>;
} {
return "requestedSchema" in request;
}
function getBadgeLabel(request: ElicitRequest["params"]): string {
return isFormMode(request)
? "elicitation/create (form)" ? "elicitation/create (form)"
: "elicitation/create (url)"; : "elicitation/create (url)";
} }
export function InlineElicitationRequest({ export function InlineElicitationRequest({
mode, request,
message,
queuePosition, queuePosition,
schema,
values, values,
url,
isWaiting, isWaiting,
onChange, onChange,
onSubmit, onSubmit,
onCancel, onCancel,
}: InlineElicitationRequestProps) { }: InlineElicitationRequestProps) {
const formMode = isFormMode(request);
return ( return (
<RequestContainer> <RequestContainer>
<Stack gap="sm"> <Stack gap="sm">
<Group justify="space-between"> <Group justify="space-between">
<Badge color="violet">{getBadgeLabel(mode)}</Badge> <Badge color="violet">{getBadgeLabel(request)}</Badge>
<QueueLabel>{queuePosition}</QueueLabel> <QueueLabel>{queuePosition}</QueueLabel>
</Group> </Group>
<ItalicMessage>{message}</ItalicMessage> <ItalicMessage>{request.message}</ItalicMessage>
{mode === "form" && schema && ( {formMode && (
<SchemaForm <SchemaForm
schema={schema} schema={request.requestedSchema as JsonSchema}
values={values ?? {}} values={values ?? {}}
onChange={onChange} onChange={onChange}
/> />
)} )}
{mode === "url" && url && ( {!formMode && "url" in request && (
<> <>
<Code block>{url}</Code> <Code block>{(request as { url: string }).url}</Code>
{isWaiting && ( {isWaiting && (
<Group> <Group>
<Loader size="xs" /> <Loader size="xs" />
@ -99,7 +104,7 @@ export function InlineElicitationRequest({
<ActionsRow> <ActionsRow>
<CompactButton onClick={onCancel}>Cancel</CompactButton> <CompactButton onClick={onCancel}>Cancel</CompactButton>
{mode === "form" && ( {formMode && (
<Button size="xs" onClick={onSubmit}> <Button size="xs" onClick={onSubmit}>
Submit Submit
</Button> </Button>

View file

@ -1,14 +1,27 @@
import type { Meta, StoryObj } from "@storybook/react-vite"; import type { Meta, StoryObj } from "@storybook/react-vite";
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test"; import { fn } from "storybook/test";
import { InlineSamplingRequest } from "./InlineSamplingRequest"; import { InlineSamplingRequest } from "./InlineSamplingRequest";
const defaultRequest: CreateMessageRequestParams = {
messages: [
{
role: "user",
content: {
type: "text",
text: "Please analyze the following code and suggest improvements for performance and readability.",
},
},
],
maxTokens: 1024,
};
const meta: Meta<typeof InlineSamplingRequest> = { const meta: Meta<typeof InlineSamplingRequest> = {
title: "Groups/InlineSamplingRequest", title: "Groups/InlineSamplingRequest",
component: InlineSamplingRequest, component: InlineSamplingRequest,
args: { args: {
request: defaultRequest,
queuePosition: "1 of 1", queuePosition: "1 of 1",
messagePreview:
"Please analyze the following code and suggest improvements for performance and readability.",
responseText: "", responseText: "",
onAutoRespond: fn(), onAutoRespond: fn(),
onEditAndSend: fn(), onEditAndSend: fn(),
@ -24,7 +37,15 @@ export const Default: Story = {};
export const WithModelHints: Story = { export const WithModelHints: Story = {
args: { args: {
modelHints: ["claude-3-opus", "claude-3-sonnet"], request: {
...defaultRequest,
modelPreferences: {
hints: [
{ name: "claude-opus-4-20250514" },
{ name: "claude-sonnet-4-20250514" },
],
},
},
}, },
}; };

View file

@ -7,11 +7,11 @@ import {
Text, Text,
Textarea, Textarea,
} from "@mantine/core"; } from "@mantine/core";
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
export interface InlineSamplingRequestProps { export interface InlineSamplingRequestProps {
request: CreateMessageRequestParams;
queuePosition: string; queuePosition: string;
modelHints?: string[];
messagePreview: string;
responseText: string; responseText: string;
onAutoRespond: () => void; onAutoRespond: () => void;
onEditAndSend: () => void; onEditAndSend: () => void;
@ -56,20 +56,41 @@ const RejectButton = Button.withProps({
color: "red", color: "red",
}); });
function extractPreview(request: CreateMessageRequestParams): string {
const lastMessage = request.messages[request.messages.length - 1];
if (!lastMessage) return "";
const content = lastMessage.content;
if (Array.isArray(content)) {
const textBlock = content.find((b) => b.type === "text");
return textBlock && "text" in textBlock ? textBlock.text : "";
}
return content.type === "text" ? content.text : `[${content.type}]`;
}
function extractModelHints(
request: CreateMessageRequestParams,
): string[] | undefined {
const hints = request.modelPreferences?.hints;
if (!hints || hints.length === 0) return undefined;
return hints.map((h) => h.name).filter(Boolean) as string[];
}
function formatModelHints(hints: string[]): string { function formatModelHints(hints: string[]): string {
return `Model hints: ${hints.join(", ")}`; return `Model hints: ${hints.join(", ")}`;
} }
export function InlineSamplingRequest({ export function InlineSamplingRequest({
request,
queuePosition, queuePosition,
modelHints,
messagePreview,
responseText, responseText,
onAutoRespond, onAutoRespond,
onEditAndSend, onEditAndSend,
onReject, onReject,
onViewDetails, onViewDetails,
}: InlineSamplingRequestProps) { }: InlineSamplingRequestProps) {
const modelHints = extractModelHints(request);
const messagePreview = extractPreview(request);
return ( return (
<RequestContainer> <RequestContainer>
<Stack gap="sm"> <Stack gap="sm">

View file

@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react-vite"; import type { Meta, StoryObj } from "@storybook/react-vite";
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test"; import { fn } from "storybook/test";
import { PendingClientRequests } from "./PendingClientRequests"; import { PendingClientRequests } from "./PendingClientRequests";
import { InlineSamplingRequest } from "../InlineSamplingRequest/InlineSamplingRequest"; import { InlineSamplingRequest } from "../InlineSamplingRequest/InlineSamplingRequest";
@ -12,13 +13,50 @@ const meta: Meta<typeof PendingClientRequests> = {
export default meta; export default meta;
type Story = StoryObj<typeof PendingClientRequests>; type Story = StoryObj<typeof PendingClientRequests>;
const elicitFormRequest = {
message: "Please provide your database connection details.",
requestedSchema: {
type: "object" as const,
properties: {
host: { type: "string" as const, title: "Host" },
port: { type: "string" as const, title: "Port" },
},
},
} satisfies ElicitRequest["params"];
const elicitDeployRequest = {
message: "Please confirm the deployment target.",
requestedSchema: {
type: "object" as const,
properties: {
environment: {
type: "string" as const,
title: "Environment",
enum: ["staging", "production"],
},
confirm: { type: "boolean" as const, title: "Confirm deployment" },
},
},
} satisfies ElicitRequest["params"];
export const SingleSampling: Story = { export const SingleSampling: Story = {
args: { args: {
count: 1, count: 1,
children: ( children: (
<InlineSamplingRequest <InlineSamplingRequest
request={{
messages: [
{
role: "user",
content: {
type: "text",
text: "Please analyze the following code and suggest improvements.",
},
},
],
maxTokens: 1024,
}}
queuePosition="1 of 1" queuePosition="1 of 1"
messagePreview="Please analyze the following code and suggest improvements."
responseText="" responseText=""
onAutoRespond={fn()} onAutoRespond={fn()}
onEditAndSend={fn()} onEditAndSend={fn()}
@ -34,17 +72,8 @@ export const SingleElicitation: Story = {
count: 1, count: 1,
children: ( children: (
<InlineElicitationRequest <InlineElicitationRequest
mode="form" request={elicitFormRequest}
message="Please provide your database connection details."
queuePosition="1 of 1" queuePosition="1 of 1"
schema={{
type: "object",
properties: {
host: { type: "string", title: "Host" },
port: { type: "integer", title: "Port" },
},
required: ["host"],
}}
values={{}} values={{}}
onChange={fn()} onChange={fn()}
onSubmit={fn()} onSubmit={fn()}
@ -60,8 +89,19 @@ export const MultipleMixed: Story = {
children: ( children: (
<> <>
<InlineSamplingRequest <InlineSamplingRequest
request={{
messages: [
{
role: "user",
content: {
type: "text",
text: "Please analyze the following code and suggest improvements.",
},
},
],
maxTokens: 1024,
}}
queuePosition="1 of 2" queuePosition="1 of 2"
messagePreview="Please analyze the following code and suggest improvements."
responseText="" responseText=""
onAutoRespond={fn()} onAutoRespond={fn()}
onEditAndSend={fn()} onEditAndSend={fn()}
@ -69,21 +109,8 @@ export const MultipleMixed: Story = {
onViewDetails={fn()} onViewDetails={fn()}
/> />
<InlineElicitationRequest <InlineElicitationRequest
mode="form" request={elicitDeployRequest}
message="Please confirm the deployment target."
queuePosition="2 of 2" queuePosition="2 of 2"
schema={{
type: "object",
properties: {
environment: {
type: "string",
title: "Environment",
enum: ["staging", "production"],
},
confirm: { type: "boolean", title: "Confirm deployment" },
},
required: ["environment", "confirm"],
}}
values={{}} values={{}}
onChange={fn()} onChange={fn()}
onSubmit={fn()} onSubmit={fn()}

View file

@ -1,17 +1,23 @@
import type { Meta, StoryObj } from "@storybook/react-vite"; import type { Meta, StoryObj } from "@storybook/react-vite";
import type {
CreateMessageRequestParams,
CreateMessageResult,
} from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test"; import { fn } from "storybook/test";
import { SamplingRequestPanel } from "./SamplingRequestPanel"; import { SamplingRequestPanel } from "./SamplingRequestPanel";
const defaultDraftResult: CreateMessageResult = {
role: "assistant",
content: { type: "text", text: "" },
model: "claude-sonnet-4-20250514",
};
const meta: Meta<typeof SamplingRequestPanel> = { const meta: Meta<typeof SamplingRequestPanel> = {
title: "Groups/SamplingRequestPanel", title: "Groups/SamplingRequestPanel",
component: SamplingRequestPanel, component: SamplingRequestPanel,
args: { args: {
responseText: "", draftResult: defaultDraftResult,
modelUsed: "claude-3-sonnet", onResultChange: fn(),
stopReason: "end_turn",
onResponseChange: fn(),
onModelChange: fn(),
onStopReasonChange: fn(),
onAutoRespond: fn(), onAutoRespond: fn(),
onSend: fn(), onSend: fn(),
onReject: fn(), onReject: fn(),
@ -21,115 +27,69 @@ const meta: Meta<typeof SamplingRequestPanel> = {
export default meta; export default meta;
type Story = StoryObj<typeof SamplingRequestPanel>; type Story = StoryObj<typeof SamplingRequestPanel>;
export const SimpleRequest: Story = { const simpleRequest: CreateMessageRequestParams = {
args: { messages: [
messages: [ {
{ role: "user",
role: "user", content: { type: "text", text: "What is the capital of France?" },
content: { },
type: "text", ],
text: "What is the capital of France?", maxTokens: 1024,
},
},
],
},
}; };
export const WithModelHints: Story = { const withPreferencesRequest: CreateMessageRequestParams = {
args: { messages: [
messages: [ {
{ role: "user",
role: "user", content: { type: "text", text: "Summarize this document for me." },
content: { type: "text", text: "Summarize this document for me." }, },
}, ],
], maxTokens: 2048,
modelHints: ["claude-3-sonnet", "gpt-4"], modelPreferences: {
}, hints: [{ name: "claude-sonnet-4-20250514" }, { name: "gpt-4" }],
};
export const WithPriorities: Story = {
args: {
messages: [
{
role: "user",
content: { type: "text", text: "Translate this text to Spanish." },
},
],
modelHints: ["claude-3-sonnet"],
costPriority: 0.3, costPriority: 0.3,
speedPriority: 0.5, speedPriority: 0.5,
intelligencePriority: 0.9, intelligencePriority: 0.9,
}, },
}; };
export const WithAllParams: Story = { const fullRequest: CreateMessageRequestParams = {
args: { messages: [
messages: [ {
{ role: "user",
role: "user", content: { type: "text", text: "Write a haiku about programming." },
content: { type: "text", text: "Write a haiku about programming." }, },
}, {
{ role: "assistant",
role: "assistant", content: { type: "text", text: "Here is a haiku:" },
content: { type: "text", text: "Here is a haiku:" }, },
}, ],
], maxTokens: 1024,
maxTokens: 1024, stopSequences: ["\n\n", "END"],
stopSequences: ["\n\n", "END"], temperature: 0.7,
temperature: 0.7, includeContext: "thisServer",
includeContext: "thisServer",
},
}; };
export const WithTools: Story = { export const SimpleRequest: Story = {
args: { args: { request: simpleRequest },
messages: [ };
{
role: "user", export const WithModelHints: Story = {
content: { args: { request: withPreferencesRequest },
type: "text", };
text: "Look up the weather in San Francisco.",
}, export const WithAllParams: Story = {
}, args: { request: fullRequest },
],
tools: [
{
name: "get_weather",
description: "Get the current weather for a given location.",
inputSchema: {
type: "object",
properties: {
location: { type: "string", description: "City name" },
},
required: ["location"],
},
},
{
name: "search_web",
description: "Search the web for information.",
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "Search query" },
},
required: ["query"],
},
},
],
toolChoice: "auto",
},
}; };
export const PrefilledResponse: Story = { export const PrefilledResponse: Story = {
args: { args: {
messages: [ request: simpleRequest,
{ draftResult: {
role: "user", role: "assistant",
content: { type: "text", text: "What is 2 + 2?" }, content: { type: "text", text: "The capital of France is Paris." },
}, model: "claude-haiku-4-5-20251001",
], stopReason: "endTurn",
responseText: "The answer is 4.", },
modelUsed: "claude-3-haiku",
stopReason: "end_turn",
}, },
}; };

View file

@ -11,33 +11,16 @@ import {
Textarea, Textarea,
Title, Title,
} from "@mantine/core"; } from "@mantine/core";
import type { SamplingMessage } from "@modelcontextprotocol/sdk/types.js"; import type {
CreateMessageRequestParams,
CreateMessageResult,
} from "@modelcontextprotocol/sdk/types.js";
import { MessageBubble } from "../../elements/MessageBubble/MessageBubble"; import { MessageBubble } from "../../elements/MessageBubble/MessageBubble";
export interface SamplingTool {
name: string;
description?: string;
inputSchema: Record<string, unknown>;
}
export interface SamplingRequestPanelProps { export interface SamplingRequestPanelProps {
messages: SamplingMessage[]; request: CreateMessageRequestParams;
modelHints?: string[]; draftResult: CreateMessageResult;
costPriority?: number; onResultChange: (result: CreateMessageResult) => void;
speedPriority?: number;
intelligencePriority?: number;
maxTokens?: number;
stopSequences?: string[];
temperature?: number;
includeContext?: string;
tools?: SamplingTool[];
toolChoice?: string;
responseText: string;
modelUsed: string;
stopReason: string;
onResponseChange: (text: string) => void;
onModelChange: (model: string) => void;
onStopReasonChange: (reason: string) => void;
onAutoRespond: () => void; onAutoRespond: () => void;
onSend: () => void; onSend: () => void;
onReject: () => void; onReject: () => void;
@ -67,43 +50,30 @@ const PreferencesContainer = Paper.withProps({
withBorder: true, withBorder: true,
}); });
const ToolCard = Paper.withProps({
p: "xs",
withBorder: true,
});
const ToolName = Text.withProps({
size: "sm",
fw: 600,
});
const RejectButton = Button.withProps({ const RejectButton = Button.withProps({
variant: "light", variant: "light",
color: "red", color: "red",
}); });
export function SamplingRequestPanel({ export function SamplingRequestPanel({
messages, request,
modelHints, draftResult,
costPriority, onResultChange,
speedPriority,
intelligencePriority,
maxTokens,
stopSequences,
temperature,
includeContext,
tools,
toolChoice,
responseText,
modelUsed,
stopReason,
onResponseChange,
onModelChange,
onStopReasonChange,
onAutoRespond, onAutoRespond,
onSend, onSend,
onReject, onReject,
}: SamplingRequestPanelProps) { }: SamplingRequestPanelProps) {
const {
messages,
modelPreferences,
maxTokens,
stopSequences,
temperature,
includeContext,
} = request;
const hints = modelPreferences?.hints?.map((h) => h.name) ?? [];
return ( return (
<Stack gap="md"> <Stack gap="md">
<HintText>The server is requesting an LLM completion.</HintText> <HintText>The server is requesting an LLM completion.</HintText>
@ -113,29 +83,30 @@ export function SamplingRequestPanel({
<MessageBubble key={index} index={index} message={message} /> <MessageBubble key={index} index={index} message={message} />
))} ))}
{modelHints && modelHints.length > 0 && ( {hints.length > 0 && (
<PreferencesContainer> <PreferencesContainer>
<Stack gap="xs"> <Stack gap="xs">
<Title order={5}>Model Preferences:</Title> <Title order={5}>Model Preferences:</Title>
<Group gap="xs"> <Group gap="xs">
<Text size="sm">Hints:</Text> <Text size="sm">Hints:</Text>
{modelHints.map((hint) => ( {hints.map((hint) => (
<Badge key={hint}>{hint}</Badge> <Badge key={hint}>{hint}</Badge>
))} ))}
</Group> </Group>
{costPriority !== undefined && ( {modelPreferences?.costPriority !== undefined && (
<Text size="sm"> <Text size="sm">
Cost Priority: {formatPriority(costPriority)} Cost Priority: {formatPriority(modelPreferences.costPriority)}
</Text> </Text>
)} )}
{speedPriority !== undefined && ( {modelPreferences?.speedPriority !== undefined && (
<Text size="sm"> <Text size="sm">
Speed Priority: {formatPriority(speedPriority)} Speed Priority: {formatPriority(modelPreferences.speedPriority)}
</Text> </Text>
)} )}
{intelligencePriority !== undefined && ( {modelPreferences?.intelligencePriority !== undefined && (
<Text size="sm"> <Text size="sm">
Intelligence Priority: {formatPriority(intelligencePriority)} Intelligence Priority:{" "}
{formatPriority(modelPreferences.intelligencePriority)}
</Text> </Text>
)} )}
</Stack> </Stack>
@ -161,40 +132,40 @@ export function SamplingRequestPanel({
</Group> </Group>
)} )}
{tools && tools.length > 0 && (
<>
<Title order={5}>Available Tools:</Title>
{tools.map((tool) => (
<ToolCard key={tool.name}>
<ToolName>{tool.name}</ToolName>
{tool.description && <Text size="sm">{tool.description}</Text>}
</ToolCard>
))}
</>
)}
{toolChoice && <Text size="sm">Tool Choice: {toolChoice}</Text>}
<Divider /> <Divider />
<Title order={5}>Response:</Title> <Title order={5}>Response:</Title>
<Textarea <Textarea
value={responseText} value={
onChange={(event) => onResponseChange(event.currentTarget.value)} draftResult.content.type === "text" ? draftResult.content.text : ""
}
onChange={(event) =>
onResultChange({
...draftResult,
content: { type: "text", text: event.currentTarget.value },
})
}
autosize autosize
minRows={3} minRows={3}
/> />
<Group> <Group>
<TextInput <TextInput
label="Model Used" label="Model Used"
value={modelUsed} value={draftResult.model}
onChange={(event) => onModelChange(event.currentTarget.value)} onChange={(event) =>
onResultChange({ ...draftResult, model: event.currentTarget.value })
}
/> />
<Select <Select
label="Stop Reason" label="Stop Reason"
data={["end_turn", "max_tokens", "stop_sequence", "toolUse"]} data={["endTurn", "maxTokens", "stopSequence"]}
value={stopReason} value={draftResult.stopReason ?? null}
onChange={(value) => onStopReasonChange(value ?? "")} onChange={(value) =>
onResultChange({
...draftResult,
stopReason: value ?? undefined,
})
}
/> />
</Group> </Group>
<Group justify="flex-end"> <Group justify="flex-end">