Skip to content

Commit 4ba9f04

Browse files
XS⚠️ ◾ Moved MCP types to shared folder (#656)
moved types to shared
1 parent f32bd09 commit 4ba9f04

File tree

4 files changed

+55
-80
lines changed

4 files changed

+55
-80
lines changed

src/backend/services/mcp/mcp-server-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class MCPServerManager {
147147
}
148148

149149
let options: CreateClientOptions | undefined;
150-
if (config.transport === "inMemory" && "inMemoryServerId" in config) {
150+
if (config.transport === "inMemory" && config.inMemoryServerId) {
151151
const transport = MCPServerManager.internalClientTransports.get(config.inMemoryServerId);
152152
if (!transport) {
153153
throw new Error(

src/backend/services/mcp/types.ts

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
1-
import type { IOType } from "node:child_process";
2-
import type Stream from "node:stream";
3-
4-
interface MCPBaseConfig {
5-
id: string;
6-
name: string;
7-
description?: string;
8-
transport: "streamableHttp" | "stdio" | "inMemory";
9-
builtin?: boolean; // True for internal/built-in servers
10-
toolWhitelist?: string[];
11-
enabled?: boolean;
12-
}
13-
14-
interface MCPHttpServerConfig extends MCPBaseConfig {
15-
transport: "streamableHttp";
16-
url: string; // For HTTP-based transports
17-
headers?: Record<string, string>;
18-
version?: string;
19-
timeoutMs?: number;
20-
}
21-
22-
interface MCPStdioServerConfig extends MCPBaseConfig {
23-
transport: "stdio";
24-
command: string; // For stdio transport
25-
args?: string[];
26-
env?: Record<string, string>;
27-
stderr?: IOType | Stream | number;
28-
cwd?: string;
29-
}
30-
31-
interface MCPInMemoryServerConfig extends MCPBaseConfig {
32-
transport: "inMemory";
33-
inMemoryServerId: string; // Identifier for the in-memory server implementation
34-
}
35-
36-
export type MCPServerConfig = MCPHttpServerConfig | MCPStdioServerConfig | MCPInMemoryServerConfig;
37-
38-
export interface MCPToolSummary {
39-
name: string;
40-
description?: string;
41-
}
1+
export type {
2+
MCPHttpServerConfig,
3+
MCPInMemoryServerConfig,
4+
MCPServerConfig,
5+
MCPStdioServerConfig,
6+
MCPToolSummary,
7+
Transport,
8+
} from "../../../shared/types/mcp";

src/shared/types/mcp.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,45 @@ export interface MCPStep {
2525
timestamp?: number;
2626
autoApproveAt?: number;
2727
}
28+
29+
export type Transport = "streamableHttp" | "stdio" | "inMemory";
30+
31+
export interface MCPBaseConfig {
32+
id: string;
33+
name: string;
34+
description?: string;
35+
transport: Transport;
36+
builtin?: boolean; // True for internal/built-in servers
37+
toolWhitelist?: string[];
38+
enabled?: boolean;
39+
}
40+
41+
export interface MCPHttpServerConfig extends MCPBaseConfig {
42+
transport: "streamableHttp";
43+
url: string; // For HTTP-based transports
44+
headers?: Record<string, string>;
45+
version?: string;
46+
timeoutMs?: number;
47+
}
48+
49+
export interface MCPStdioServerConfig extends MCPBaseConfig {
50+
transport: "stdio";
51+
command: string; // For stdio transport
52+
args?: string[];
53+
env?: Record<string, string>;
54+
stderr?: "inherit" | "ignore" | "pipe";
55+
cwd?: string;
56+
}
57+
58+
export interface MCPInMemoryServerConfig extends MCPBaseConfig {
59+
transport: "inMemory";
60+
inMemoryServerId?: string; // Identifier for the in-memory server implementation
61+
builtin?: true;
62+
}
63+
64+
export type MCPServerConfig = MCPHttpServerConfig | MCPStdioServerConfig | MCPInMemoryServerConfig;
65+
66+
export interface MCPToolSummary {
67+
name: string;
68+
description?: string;
69+
}

src/ui/src/components/settings/mcp/McpServerForm.tsx

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { zodResolver } from "@hookform/resolvers/zod";
2+
import type { MCPServerConfig, Transport } from "@shared/types/mcp";
23
import { type UseFormReturn, useForm } from "react-hook-form";
34
import { z } from "zod";
45
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "../../ui/accordion";
@@ -16,41 +17,7 @@ import { Input } from "../../ui/input";
1617
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/select";
1718
import { Textarea } from "../../ui/textarea";
1819

19-
export type Transport = "streamableHttp" | "stdio" | "inMemory";
20-
21-
type MCPBaseConfig = {
22-
id: string | null;
23-
name: string;
24-
description?: string;
25-
transport: Transport;
26-
builtin?: boolean;
27-
toolWhitelist?: string[];
28-
enabled?: boolean;
29-
};
30-
31-
type MCPHttpServerConfig = MCPBaseConfig & {
32-
transport: "streamableHttp";
33-
url: string;
34-
headers?: Record<string, string>;
35-
version?: string;
36-
timeoutMs?: number;
37-
};
38-
39-
type MCPStdioServerConfig = MCPBaseConfig & {
40-
transport: "stdio";
41-
command: string;
42-
args?: string[];
43-
env?: Record<string, string>;
44-
cwd?: string;
45-
stderr?: "inherit" | "ignore" | "pipe";
46-
};
47-
48-
type MCPInternalServerConfig = MCPBaseConfig & {
49-
transport: "inMemory";
50-
builtin: true;
51-
};
52-
53-
export type MCPServerConfig = MCPHttpServerConfig | MCPStdioServerConfig | MCPInternalServerConfig;
20+
export type { MCPServerConfig, Transport };
5421

5522
export const mcpServerSchema = z
5623
.object({
@@ -468,7 +435,7 @@ export function McpServerFormWrapper({
468435
}
469436

470437
const config: MCPServerConfig = {
471-
id: initialData?.id ?? null,
438+
id: initialData?.id ?? "",
472439
name: data.name.trim(),
473440
transport: "streamableHttp",
474441
url: data.url?.trim() ?? "",
@@ -477,7 +444,6 @@ export function McpServerFormWrapper({
477444
version: data.version?.trim() || undefined,
478445
timeoutMs: typeof data.timeoutMs === "number" ? data.timeoutMs : undefined,
479446
};
480-
481447
await onSubmit(config);
482448
return;
483449
}
@@ -546,7 +512,7 @@ export function McpServerFormWrapper({
546512
const command = sanitizeSegment(data.command ?? "");
547513

548514
const config: MCPServerConfig = {
549-
id: initialData?.id ?? null,
515+
id: initialData?.id ?? "",
550516
name: data.name.trim(),
551517
transport: "stdio",
552518
command,

0 commit comments

Comments
 (0)