Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { InspectorServerJsonDraft } from "@inspector/core/mcp/types.js";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { fn } from "storybook/test";
import { ImportServerJsonPanel } from "./ImportServerJsonPanel";

const emptyDraft: InspectorServerJsonDraft = {
rawText: "",
envOverrides: {},
};

const meta: Meta<typeof ImportServerJsonPanel> = {
title: "Groups/ImportServerJsonPanel",
component: ImportServerJsonPanel,
Expand All @@ -13,10 +19,8 @@ const meta: Meta<typeof ImportServerJsonPanel> = {
onServerNameChange: fn(),
onAddServer: fn(),
onCancel: fn(),
selectedPackageIndex: 0,
envVars: [],
serverName: "",
validationResults: [],
validation: [],
},
};

Expand All @@ -25,28 +29,31 @@ type Story = StoryObj<typeof ImportServerJsonPanel>;

export const Empty: Story = {
args: {
jsonContent: "",
draft: emptyDraft,
},
};

export const ValidJson: Story = {
args: {
jsonContent: JSON.stringify(
{
name: "my-mcp-server",
version: "1.0.0",
packages: [
{
registryType: "npm",
identifier: "my-mcp-server",
runtimeHint: "node",
},
],
},
null,
2,
),
validationResults: [
draft: {
rawText: JSON.stringify(
{
name: "my-mcp-server",
version: "1.0.0",
packages: [
{
registryType: "npm",
identifier: "my-mcp-server",
runtimeHint: "node",
},
],
},
null,
2,
),
envOverrides: {},
},
validation: [
{ type: "success", message: "Valid server.json format detected" },
{ type: "success", message: "Package configuration is valid" },
{ type: "info", message: "1 package found" },
Expand All @@ -56,31 +63,38 @@ export const ValidJson: Story = {

export const MultiplePackages: Story = {
args: {
jsonContent: JSON.stringify(
{
name: "multi-server",
packages: [
{
registryType: "npm",
identifier: "@scope/server",
runtimeHint: "node",
},
{
registryType: "pip",
identifier: "server-python",
runtimeHint: "python3",
},
],
},
null,
2,
),
validationResults: [
draft: {
rawText: JSON.stringify(
{
name: "multi-server",
packages: [
{
registryType: "npm",
identifier: "@scope/server",
runtimeHint: "node",
},
{
registryType: "pip",
identifier: "server-python",
runtimeHint: "python3",
},
],
},
null,
2,
),
envOverrides: {},
},
validation: [
{ type: "success", message: "Valid server.json format detected" },
{ type: "info", message: "2 packages found - select one to install" },
],
packages: [
{ registryType: "npm", identifier: "@scope/server", runtimeHint: "node" },
{
registryType: "npm",
identifier: "@scope/server",
runtimeHint: "node",
},
{
registryType: "pip",
identifier: "server-python",
Expand All @@ -92,25 +106,28 @@ export const MultiplePackages: Story = {

export const WithEnvVars: Story = {
args: {
jsonContent: JSON.stringify(
{
name: "api-server",
packages: [
{
registryType: "npm",
identifier: "api-server",
runtimeHint: "node",
},
],
envVars: [
{ name: "API_KEY", required: true },
{ name: "API_URL", required: false },
],
},
null,
2,
),
validationResults: [
draft: {
rawText: JSON.stringify(
{
name: "api-server",
packages: [
{
registryType: "npm",
identifier: "api-server",
runtimeHint: "node",
},
],
envVars: [
{ name: "API_KEY", required: true },
{ name: "API_URL", required: false },
],
},
null,
2,
),
envOverrides: {},
},
validation: [
{ type: "success", message: "Valid server.json format detected" },
{
type: "warning",
Expand All @@ -136,31 +153,36 @@ export const WithEnvVars: Story = {

export const FullyConfigured: Story = {
args: {
jsonContent: JSON.stringify(
{
name: "full-server",
version: "2.1.0",
packages: [
{
registryType: "npm",
identifier: "@org/full-server",
runtimeHint: "node",
},
{
registryType: "docker",
identifier: "org/full-server:latest",
runtimeHint: "docker",
},
],
envVars: [
{ name: "TOKEN", required: true },
{ name: "DEBUG", required: false },
],
},
null,
2,
),
validationResults: [
draft: {
rawText: JSON.stringify(
{
name: "full-server",
version: "2.1.0",
packages: [
{
registryType: "npm",
identifier: "@org/full-server",
runtimeHint: "node",
},
{
registryType: "docker",
identifier: "org/full-server:latest",
runtimeHint: "docker",
},
],
envVars: [
{ name: "TOKEN", required: true },
{ name: "DEBUG", required: false },
],
},
null,
2,
),
selectedPackageIndex: 1,
envOverrides: { TOKEN: "sk-abc123", DEBUG: "true" },
nameOverride: "My Custom Server",
},
validation: [
{ type: "success", message: "Valid server.json format detected" },
{ type: "success", message: "All required fields present" },
{ type: "info", message: "2 packages found" },
Expand All @@ -181,7 +203,6 @@ export const FullyConfigured: Story = {
runtimeHint: "docker",
},
],
selectedPackageIndex: 1,
envVars: [
{
name: "TOKEN",
Expand All @@ -196,6 +217,5 @@ export const FullyConfigured: Story = {
value: "true",
},
],
serverName: "My Custom Server",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Textarea,
Title,
} from "@mantine/core";
import type { InspectorServerJsonDraft } from "@inspector/core/mcp/types.js";

export interface ValidationResult {
type: "success" | "warning" | "info" | "error";
Expand All @@ -29,12 +30,10 @@ export interface EnvVarInfo {
}

export interface ImportServerJsonPanelProps {
jsonContent: string;
validationResults: ValidationResult[];
draft: InspectorServerJsonDraft;
validation: ValidationResult[];
packages?: PackageInfo[];
selectedPackageIndex: number;
envVars: EnvVarInfo[];
serverName: string;
onJsonChange: (content: string) => void;
onValidate: () => void;
onSelectPackage: (index: number) => void;
Expand Down Expand Up @@ -64,12 +63,10 @@ function formatPackageLabel(pkg: PackageInfo): string {
}

export function ImportServerJsonPanel({
jsonContent,
validationResults,
draft,
validation,
packages,
selectedPackageIndex,
envVars,
serverName,
onJsonChange,
onValidate,
onSelectPackage,
Expand All @@ -85,7 +82,7 @@ export function ImportServerJsonPanel({
<HintText>Paste server.json content or drag and drop a file:</HintText>

<Textarea
value={jsonContent}
value={draft.rawText}
onChange={(e) => onJsonChange(e.currentTarget.value)}
ff="monospace"
autosize
Expand All @@ -97,7 +94,7 @@ export function ImportServerJsonPanel({

<Title order={5}>Validation Results:</Title>

{validationResults.map((result, index) => {
{validation.map((result, index) => {
const { icon, color } = validationIcons[result.type];
return (
<Group key={index} gap="xs">
Expand All @@ -112,7 +109,7 @@ export function ImportServerJsonPanel({
<Divider />
<Title order={5}>Package Selection:</Title>
<Radio.Group
value={String(selectedPackageIndex)}
value={String(draft.selectedPackageIndex ?? 0)}
onChange={(value) => onSelectPackage(Number(value))}
>
<Stack gap="xs">
Expand Down Expand Up @@ -151,7 +148,7 @@ export function ImportServerJsonPanel({

<TextInput
label="Server Name (optional override)"
value={serverName}
value={draft.nameOverride ?? ""}
onChange={(e) => onServerNameChange(e.currentTarget.value)}
/>

Expand Down
Loading