From 3786c88960899551b3f46ddcc2f3fa59a59db549 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Wed, 2 Oct 2024 14:17:31 +0100 Subject: [PATCH] Combine types into one file --- src/client/index.ts | 2 +- src/client/sse.ts | 2 +- src/client/stdio.test.ts | 2 +- src/client/stdio.ts | 2 +- src/client/websocket.ts | 2 +- src/server/index.ts | 2 +- src/server/sse.ts | 2 +- src/server/stdio.test.ts | 2 +- src/server/stdio.ts | 2 +- src/shared/message.ts | 2 +- src/shared/protocol.ts | 2 +- src/shared/stdio.test.ts | 2 +- src/shared/stdio.ts | 2 +- src/shared/transport.ts | 2 +- src/{types/schema.ts => types.ts} | 21 +++++++++++++++++++++ src/types/index.ts | 25 ------------------------- 16 files changed, 35 insertions(+), 39 deletions(-) rename src/{types/schema.ts => types.ts} (97%) delete mode 100644 src/types/index.ts diff --git a/src/client/index.ts b/src/client/index.ts index b40fd838..61cd6ea6 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -11,7 +11,7 @@ import { ServerNotification, ServerRequest, ServerResult, -} from "../types/index.js"; +} from "../types.js"; /** * An MCP client on top of a pluggable transport. diff --git a/src/client/sse.ts b/src/client/sse.ts index a82229a5..7b3a128a 100644 --- a/src/client/sse.ts +++ b/src/client/sse.ts @@ -1,6 +1,6 @@ import { validateMessage } from "../shared/message.js"; import { Transport } from "../shared/transport.js"; -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; /** * Client transport for SSE: this will connect to a server using Server-Sent Events for receiving diff --git a/src/client/stdio.test.ts b/src/client/stdio.test.ts index 0b6ed513..32dced90 100644 --- a/src/client/stdio.test.ts +++ b/src/client/stdio.test.ts @@ -1,4 +1,4 @@ -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import { StdioClientTransport, StdioServerParameters } from "./stdio.js"; const serverParameters: StdioServerParameters = { diff --git a/src/client/stdio.ts b/src/client/stdio.ts index c3e044d4..30da0799 100644 --- a/src/client/stdio.ts +++ b/src/client/stdio.ts @@ -1,6 +1,6 @@ import { ChildProcess, spawn } from "node:child_process"; import { ReadBuffer, serializeMessage } from "../shared/stdio.js"; -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import { Transport } from "../shared/transport.js"; export type StdioServerParameters = { diff --git a/src/client/websocket.ts b/src/client/websocket.ts index 179b917d..bd6039b4 100644 --- a/src/client/websocket.ts +++ b/src/client/websocket.ts @@ -1,6 +1,6 @@ import { validateMessage } from "../shared/message.js"; import { Transport } from "../shared/transport.js"; -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; const SUBPROTOCOL = "mcp"; diff --git a/src/server/index.ts b/src/server/index.ts index e5f82368..a17de0c2 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -11,7 +11,7 @@ import { ServerNotification, ServerRequest, ServerResult, -} from "../types/index.js"; +} from "../types.js"; /** * An MCP server on top of a pluggable transport. diff --git a/src/server/sse.ts b/src/server/sse.ts index 69cf4c5b..e4c08a2c 100644 --- a/src/server/sse.ts +++ b/src/server/sse.ts @@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto"; import { IncomingMessage, ServerResponse } from "node:http"; import { validateMessage } from "../shared/message.js"; import { Transport } from "../shared/transport.js"; -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import getRawBody from "raw-body"; import contentType from "content-type"; diff --git a/src/server/stdio.test.ts b/src/server/stdio.test.ts index 9a35a14e..5243268d 100644 --- a/src/server/stdio.test.ts +++ b/src/server/stdio.test.ts @@ -1,6 +1,6 @@ import { Readable, Writable } from "node:stream"; import { ReadBuffer, serializeMessage } from "../shared/stdio.js"; -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import { StdioServerTransport } from "./stdio.js"; let input: Readable; diff --git a/src/server/stdio.ts b/src/server/stdio.ts index 16020da1..d5f3eee4 100644 --- a/src/server/stdio.ts +++ b/src/server/stdio.ts @@ -1,7 +1,7 @@ import process from "node:process"; import { Readable, Writable } from "node:stream"; import { ReadBuffer, serializeMessage } from "../shared/stdio.js"; -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import { Transport } from "../shared/transport.js"; /** diff --git a/src/shared/message.ts b/src/shared/message.ts index 5ec3d8e5..25162b1e 100644 --- a/src/shared/message.ts +++ b/src/shared/message.ts @@ -1,4 +1,4 @@ -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; // Throws an exception if the message is invalid or unsupported. export function validateMessage(message: JSONRPCMessage): void { diff --git a/src/shared/protocol.ts b/src/shared/protocol.ts index 00b4b19c..0171a1e5 100644 --- a/src/shared/protocol.ts +++ b/src/shared/protocol.ts @@ -14,7 +14,7 @@ import { ProgressNotification, Request, Result, -} from "../types/index.js"; +} from "../types.js"; import { Transport } from "./transport.js"; /** diff --git a/src/shared/stdio.test.ts b/src/shared/stdio.test.ts index dda421e5..b1227966 100644 --- a/src/shared/stdio.test.ts +++ b/src/shared/stdio.test.ts @@ -1,4 +1,4 @@ -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import { ReadBuffer } from "./stdio.js"; const testMessage: JSONRPCMessage = { diff --git a/src/shared/stdio.ts b/src/shared/stdio.ts index 0a19e72c..c9a51d40 100644 --- a/src/shared/stdio.ts +++ b/src/shared/stdio.ts @@ -1,4 +1,4 @@ -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; import { validateMessage } from "./message.js"; /** diff --git a/src/shared/transport.ts b/src/shared/transport.ts index 3c0ce5df..b0eabe05 100644 --- a/src/shared/transport.ts +++ b/src/shared/transport.ts @@ -1,4 +1,4 @@ -import { JSONRPCMessage } from "../types/index.js"; +import { JSONRPCMessage } from "../types.js"; /** * Describes the minimal contract for a MCP transport that a client or server can communicate over. diff --git a/src/types/schema.ts b/src/types.ts similarity index 97% rename from src/types/schema.ts rename to src/types.ts index bc85a3b7..e6dcda20 100644 --- a/src/types/schema.ts +++ b/src/types.ts @@ -783,3 +783,24 @@ export type ServerResult = | ReadResourceResult | CallToolResult | ListToolsResult; + + export const CONNECTION_CLOSED_ERROR = -1; + + export class McpError extends Error { + constructor( + public readonly code: number, + message: string, + public readonly data?: unknown, + ) { + super(`MCP error ${code}: ${message}`); + } + } + + export type Progress = Pick< + ProgressNotification["params"], + "progress" | "total" + >; + + export const PROGRESS_NOTIFICATION_METHOD: ProgressNotification["method"] = + "notifications/progress"; + export const PING_REQUEST_METHOD: PingRequest["method"] = "ping"; diff --git a/src/types/index.ts b/src/types/index.ts deleted file mode 100644 index 47982dde..00000000 --- a/src/types/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ProgressNotification, PingRequest } from "./schema.js"; -export * from "./schema.js"; - -export const CONNECTION_CLOSED_ERROR = -1; - -export class McpError extends Error { - constructor( - public readonly code: number, - message: string, - public readonly data?: unknown, - ) { - super(`MCP error ${code}: ${message}`); - } -} - -export type Progress = Pick< - ProgressNotification["params"], - "progress" | "total" ->; - -export const PROGRESS_NOTIFICATION_METHOD: ProgressNotification["method"] = - "notifications/progress"; -export const PING_REQUEST_METHOD: PingRequest["method"] = "ping"; - -export type RequestId = string | number;