clean up tests - remove mockRequestInfo
This commit is contained in:
parent
166da76b00
commit
606c278668
10 changed files with 47 additions and 73 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
@ -50,7 +43,7 @@ test("should initialize with matching protocol version", async () => {
|
|||
},
|
||||
instructions: "test instructions",
|
||||
},
|
||||
}, { requestInfo: mockRequestInfo });
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
|
|
@ -108,7 +101,7 @@ test("should initialize with supported older protocol version", async () => {
|
|||
version: "1.0",
|
||||
},
|
||||
},
|
||||
}, { requestInfo: mockRequestInfo });
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
|
|
@ -158,7 +151,7 @@ test("should reject unsupported protocol version", async () => {
|
|||
version: "1.0",
|
||||
},
|
||||
},
|
||||
}, { requestInfo: mockRequestInfo });
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -86,7 +78,7 @@ test("should accept latest protocol version", async () => {
|
|||
version: "1.0",
|
||||
},
|
||||
},
|
||||
}, { requestInfo: mockRequestInfo });
|
||||
});
|
||||
|
||||
await expect(sendPromise).resolves.toBeUndefined();
|
||||
});
|
||||
|
|
@ -147,7 +139,7 @@ test("should accept supported older protocol version", async () => {
|
|||
version: "1.0",
|
||||
},
|
||||
},
|
||||
}, { requestInfo: mockRequestInfo });
|
||||
});
|
||||
|
||||
await expect(sendPromise).resolves.toBeUndefined();
|
||||
});
|
||||
|
|
@ -207,7 +199,7 @@ test("should handle unsupported protocol version", async () => {
|
|||
version: "1.0",
|
||||
},
|
||||
},
|
||||
}, { requestInfo: mockRequestInfo });
|
||||
});
|
||||
|
||||
await expect(sendPromise).resolves.toBeUndefined();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ describe('SSEServerTransport', () => {
|
|||
);
|
||||
});
|
||||
|
||||
/***
|
||||
/**
|
||||
* Test: Tool With Request Info
|
||||
*/
|
||||
it("should pass request info to tool callback", async () => {
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
import { AuthInfo } from "../auth/types.js";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
31
src/types.ts
31
src/types.ts
|
|
@ -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";
|
||||
|
|
@ -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>;
|
||||
|
|
|
|||
Loading…
Reference in a new issue