Skip to content
Merged
Prev Previous commit
Next Next commit
clean up tests - remove mockRequestInfo
  • Loading branch information
KKonstantinov committed Jun 25, 2025
commit 606c278668c4328b2592da73f59d1b98b2ccf062
15 changes: 4 additions & 11 deletions src/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ import {
import { Transport } from "../shared/transport.js";
import { Server } from "../server/index.js";
import { InMemoryTransport } from "../inMemory.js";
import { RequestInfo } from "../server/types/types.js";

const mockRequestInfo: RequestInfo = {
headers: {
'content-type': 'application/json',
'accept': 'application/json',
},
};

/***
* Test: Initialize with Matching Protocol Version
*/
Expand All @@ -50,7 +43,7 @@ test("should initialize with matching protocol version", async () => {
},
instructions: "test instructions",
},
}, { requestInfo: mockRequestInfo });
});
}
return Promise.resolve();
}),
Expand Down Expand Up @@ -108,7 +101,7 @@ test("should initialize with supported older protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});
}
return Promise.resolve();
}),
Expand Down Expand Up @@ -158,7 +151,7 @@ test("should reject unsupported protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});
}
return Promise.resolve();
}),
Expand Down
16 changes: 4 additions & 12 deletions src/server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ import {
ListResourcesRequestSchema,
ListToolsRequestSchema,
SetLevelRequestSchema,
ErrorCode,
ErrorCode
} from "../types.js";
import { Transport } from "../shared/transport.js";
import { InMemoryTransport } from "../inMemory.js";
import { Client } from "../client/index.js";
import { RequestInfo } from "./types/types.js";

const mockRequestInfo: RequestInfo = {
headers: {
'content-type': 'application/json',
'traceparent': '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',
},
};

test("should accept latest protocol version", async () => {
let sendPromiseResolve: (value: unknown) => void;
Expand Down Expand Up @@ -86,7 +78,7 @@ test("should accept latest protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});

await expect(sendPromise).resolves.toBeUndefined();
});
Expand Down Expand Up @@ -147,7 +139,7 @@ test("should accept supported older protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});

await expect(sendPromise).resolves.toBeUndefined();
});
Expand Down Expand Up @@ -207,7 +199,7 @@ test("should handle unsupported protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});

await expect(sendPromise).resolves.toBeUndefined();
});
Expand Down
13 changes: 2 additions & 11 deletions src/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ import {
LoggingMessageNotificationSchema,
Notification,
TextContent,
ElicitRequestSchema,
ElicitRequestSchema
} from "../types.js";
import { ResourceTemplate } from "./mcp.js";
import { completable } from "./completable.js";
import { UriTemplate } from "../shared/uriTemplate.js";
import { RequestInfo } from "./types/types.js";
import { getDisplayName } from "../shared/metadataUtils.js";

const mockRequestInfo: RequestInfo = {
headers: {
'content-type': 'application/json',
'accept': 'application/json',
},
};

describe("McpServer", () => {
/***
* Test: Basic Server Instance
Expand Down Expand Up @@ -222,8 +214,7 @@ describe("ResourceTemplate", () => {
signal: abortController.signal,
requestId: 'not-implemented',
sendRequest: () => { throw new Error("Not implemented") },
sendNotification: () => { throw new Error("Not implemented") },
requestInfo: mockRequestInfo
sendNotification: () => { throw new Error("Not implemented") }
});
expect(result?.resources).toHaveLength(1);
expect(list).toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion src/server/sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('SSEServerTransport', () => {
);
});

/***
/**
* Test: Tool With Request Info
*/
it("should pass request info to tool callback", async () => {
Expand Down
3 changes: 1 addition & 2 deletions src/server/sse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { randomUUID } from "node:crypto";
import { IncomingMessage, ServerResponse } from "node:http";
import { Transport } from "../shared/transport.js";
import { JSONRPCMessage, JSONRPCMessageSchema } from "../types.js";
import { JSONRPCMessage, JSONRPCMessageSchema, MessageExtraInfo, RequestInfo } from "../types.js";
import getRawBody from "raw-body";
import contentType from "content-type";
import { AuthInfo } from "./auth/types.js";
import { MessageExtraInfo, RequestInfo } from "./types/types.js";
import { URL } from 'url';

const MAXIMUM_MESSAGE_SIZE = "4mb";
Expand Down
3 changes: 1 addition & 2 deletions src/server/streamableHttp.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { IncomingMessage, ServerResponse } from "node:http";
import { Transport } from "../shared/transport.js";
import { isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessage, JSONRPCMessageSchema, RequestId, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js";
import { MessageExtraInfo, RequestInfo, isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessage, JSONRPCMessageSchema, RequestId, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js";
import getRawBody from "raw-body";
import contentType from "content-type";
import { randomUUID } from "node:crypto";
import { AuthInfo } from "./auth/types.js";
import { MessageExtraInfo, RequestInfo } from "./types/types.js";

const MAXIMUM_MESSAGE_SIZE = "4mb";

Expand Down
31 changes: 0 additions & 31 deletions src/server/types/types.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import {
Result,
ServerCapabilities,
RequestMeta,
MessageExtraInfo,
RequestInfo,
} from "../types.js";
import { Transport, TransportSendOptions } from "./transport.js";
import { AuthInfo } from "../server/auth/types.js";
import { MessageExtraInfo, RequestInfo } from "../server/types/types.js";

/**
* Callback for progress notifications.
Expand Down
3 changes: 1 addition & 2 deletions src/shared/transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MessageExtraInfo } from "../server/types/types.js";
import { JSONRPCMessage, RequestId } from "../types.js";
import { JSONRPCMessage, MessageExtraInfo, RequestId } from "../types.js";

/**
* Options for sending a JSON-RPC message.
Expand Down
31 changes: 31 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z, ZodTypeAny } from "zod";
import { AuthInfo } from "./server/auth/types.js";

export const LATEST_PROTOCOL_VERSION = "2025-06-18";
export const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
Expand Down Expand Up @@ -1463,6 +1464,36 @@ type Flatten<T> = T extends Primitive

type Infer<Schema extends ZodTypeAny> = Flatten<z.infer<Schema>>;

/**
* Headers that are compatible with both Node.js and the browser.
*/
export type IsomorphicHeaders = Record<string, string | string[] | undefined>;

/**
* Information about the incoming request.
*/
export interface RequestInfo {
/**
* The headers of the request.
*/
headers: IsomorphicHeaders;
}

/**
* Extra information about a message.
*/
export interface MessageExtraInfo {
/**
* The request information.
*/
requestInfo?: RequestInfo;

/**
* The authentication information.
*/
authInfo?: AuthInfo;
}

/* JSON-RPC types */
export type ProgressToken = Infer<typeof ProgressTokenSchema>;
export type Cursor = Infer<typeof CursorSchema>;
Expand Down