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:
parent
7b74598f83
commit
c1a63cb37d
2 changed files with 326 additions and 299 deletions
|
|
@ -1,14 +1,27 @@
|
|||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
|
||||
import { fn } from "storybook/test";
|
||||
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> = {
|
||||
title: "Groups/InlineSamplingRequest",
|
||||
component: InlineSamplingRequest,
|
||||
args: {
|
||||
request: defaultRequest,
|
||||
queuePosition: "1 of 1",
|
||||
messagePreview:
|
||||
"Please analyze the following code and suggest improvements for performance and readability.",
|
||||
responseText: "",
|
||||
onAutoRespond: fn(),
|
||||
onEditAndSend: fn(),
|
||||
|
|
@ -24,7 +37,15 @@ export const Default: Story = {};
|
|||
|
||||
export const WithModelHints: Story = {
|
||||
args: {
|
||||
modelHints: ["claude-3-opus", "claude-3-sonnet"],
|
||||
request: {
|
||||
...defaultRequest,
|
||||
modelPreferences: {
|
||||
hints: [
|
||||
{ name: "claude-opus-4-20250514" },
|
||||
{ name: "claude-sonnet-4-20250514" },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import {
|
|||
Text,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
export interface InlineSamplingRequestProps {
|
||||
request: CreateMessageRequestParams;
|
||||
queuePosition: string;
|
||||
modelHints?: string[];
|
||||
messagePreview: string;
|
||||
responseText: string;
|
||||
onAutoRespond: () => void;
|
||||
onEditAndSend: () => void;
|
||||
|
|
@ -56,20 +56,41 @@ const RejectButton = Button.withProps({
|
|||
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 {
|
||||
return `Model hints: ${hints.join(", ")}`;
|
||||
}
|
||||
|
||||
export function InlineSamplingRequest({
|
||||
request,
|
||||
queuePosition,
|
||||
modelHints,
|
||||
messagePreview,
|
||||
responseText,
|
||||
onAutoRespond,
|
||||
onEditAndSend,
|
||||
onReject,
|
||||
onViewDetails,
|
||||
}: InlineSamplingRequestProps) {
|
||||
const modelHints = extractModelHints(request);
|
||||
const messagePreview = extractPreview(request);
|
||||
|
||||
return (
|
||||
<RequestContainer>
|
||||
<Stack gap="sm">
|
||||
|
|
|
|||
Loading…
Reference in a new issue