Phase 2: Refactor Resources cluster to MCP SDK types

Replace ad hoc local types with MCP SDK schema types across the Resources
group components and ResourcesScreen, per the v2 UX interfaces plan.

- ResourceListItem: accept `resource: Resource | ResourceTemplate` instead
  of flat `name`/`uri`; render `title ?? name`; delete local
  `ResourceAnnotations` type
- ResourceControls: accept `Resource[]`, `ResourceTemplate[]`,
  `InspectorResourceSubscription[]` + `selectedUri`/`selectedTemplate`
  instead of `ResourceItem[]`/`TemplateListItem[]`/`SubscriptionItem[]`;
  no-op on re-selecting
- ResourcePreviewPanel: accept `resource: Resource` +
  `contents: (TextResourceContents | BlobResourceContents)[]` instead of
  flat `content: string`; use SDK `Annotations` (audience as Role[]);
  `lastUpdated` as `Date` not `string`
- ResourceTemplatePanel: accept `template: ResourceTemplate` instead of
  flat props; use SDK `Annotations`
- ResourceSubscribedItem: accept `subscription: InspectorResourceSubscription`
  instead of flat `name`/`lastUpdated`; `lastUpdated` as `Date`
- ResourcesScreen: accept `Resource[]`, `ResourceTemplate[]`,
  `InspectorResourceSubscription[]` + `selectedResourceUri`/
  `selectedTemplateUri` + `ReadResourceState`; derive selections via
  `find()`; add loading/error states
- Delete local `ResourceItem`, `TemplateListItem`, `SubscriptionItem`,
  `SelectedResource`, `SelectedTemplate`, `ResourceAnnotations` types
- Update all stories with real SDK fixtures
- Update ConnectedView ResourcesActive story

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cliffhall 2026-04-18 18:34:32 -04:00
commit d817c46911
2 changed files with 465 additions and 616 deletions

View file

@ -15,13 +15,23 @@ type Story = StoryObj<typeof ResourceSubscribedItem>;
export const WithTimestamp: Story = {
args: {
name: "config.json",
lastUpdated: "2026-03-17T10:30:00Z",
subscription: {
resource: {
name: "config.json",
uri: "file:///config.json",
},
lastUpdated: new Date("2026-03-17T10:30:00Z"),
},
},
};
export const WithoutTimestamp: Story = {
args: {
name: "schema.sql",
subscription: {
resource: {
name: "schema.sql",
uri: "file:///schema.sql",
},
},
},
};

View file

@ -1,8 +1,8 @@
import { Button, Group, Stack, Text } from "@mantine/core";
import type { InspectorResourceSubscription } from "../../../../../../core/mcp/types.js";
export interface ResourceSubscribedItemProps {
name: string;
lastUpdated?: string;
subscription: InspectorResourceSubscription;
onUnsubscribe: () => void;
}
@ -26,16 +26,22 @@ const ItemRow = Group.withProps({
wrap: "nowrap",
});
function formatLastUpdated(date: Date): string {
return date.toLocaleString();
}
export function ResourceSubscribedItem({
name,
lastUpdated,
subscription,
onUnsubscribe,
}: ResourceSubscribedItemProps) {
const { resource, lastUpdated } = subscription;
return (
<ItemRow>
<Stack gap={2}>
<NameText>{name}</NameText>
{lastUpdated && <TimestampText>{lastUpdated}</TimestampText>}
<NameText>{resource.title ?? resource.name}</NameText>
{lastUpdated && (
<TimestampText>{formatLastUpdated(lastUpdated)}</TimestampText>
)}
</Stack>
<SubtleButton onClick={onUnsubscribe}>Unsubscribe</SubtleButton>
</ItemRow>