@slbdn/mcp-tester 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,262 @@
1
+ import { Tool, Resource, Prompt, CallToolResult, ReadResourceResult, GetPromptResult } from '@modelcontextprotocol/sdk/types.js';
2
+ declare global {
3
+ namespace jest {
4
+ interface Matchers<R> {
5
+ toHaveTool(toolName: string): R;
6
+ toHaveResource(uri: string): R;
7
+ toHavePrompt(promptName: string): R;
8
+ toHaveToolWithSchema(toolName: string): R;
9
+ toHaveToolCount(count: number): R;
10
+ toHaveResourceCount(count: number): R;
11
+ toHavePromptCount(count: number): R;
12
+ toHaveResourceByName(name: string): R;
13
+ toHavePromptWithArgs(promptName: string): R;
14
+ toReturnText(expected?: string): R;
15
+ toReturnTextContaining(substring: string): R;
16
+ toReturnError(): R;
17
+ toReturnOk(): R;
18
+ toReturnJson(expected: unknown): R;
19
+ toReturnContentCount(count: number): R;
20
+ toReturnImage(): R;
21
+ toReturnResourceText(expected?: string): R;
22
+ toReturnResourceTextContaining(substring: string): R;
23
+ toReturnPromptTextContaining(substring: string): R;
24
+ toReturnPromptMessageCount(count: number): R;
25
+ }
26
+ }
27
+ }
28
+ /**
29
+ * Check if a tool with the given name exists in the tools array.
30
+ * Works with `.not` for negation.
31
+ *
32
+ * expect(tools).toHaveTool('echo');
33
+ * expect(tools).not.toHaveTool('deprecated_tool');
34
+ */
35
+ export declare const toHaveTool: (received: Tool[], toolName: string) => {
36
+ pass: boolean;
37
+ message: () => string;
38
+ };
39
+ /**
40
+ * Check if a resource with the given URI exists.
41
+ *
42
+ * expect(resources).toHaveResource('config://settings');
43
+ */
44
+ export declare const toHaveResource: (received: Resource[], uri: string) => {
45
+ pass: boolean;
46
+ message: () => string;
47
+ };
48
+ /**
49
+ * Check if a prompt with the given name exists.
50
+ *
51
+ * expect(prompts).toHavePrompt('greet');
52
+ */
53
+ export declare const toHavePrompt: (received: Prompt[], promptName: string) => {
54
+ pass: boolean;
55
+ message: () => string;
56
+ };
57
+ /**
58
+ * Check if a tool exists and has an input schema.
59
+ *
60
+ * expect(tools).toHaveToolWithSchema('echo');
61
+ */
62
+ export declare const toHaveToolWithSchema: (received: Tool[], toolName: string) => {
63
+ pass: boolean;
64
+ message: () => string;
65
+ };
66
+ /**
67
+ * Check that the tools array has exactly `count` items.
68
+ *
69
+ * expect(tools).toHaveToolCount(5);
70
+ */
71
+ export declare const toHaveToolCount: (received: Tool[], count: number) => {
72
+ pass: boolean;
73
+ message: () => string;
74
+ };
75
+ /**
76
+ * Check that the resources array has exactly `count` items.
77
+ *
78
+ * expect(resources).toHaveResourceCount(3);
79
+ */
80
+ export declare const toHaveResourceCount: (received: Resource[], count: number) => {
81
+ pass: boolean;
82
+ message: () => string;
83
+ };
84
+ /**
85
+ * Check that the prompts array has exactly `count` items.
86
+ *
87
+ * expect(prompts).toHavePromptCount(2);
88
+ */
89
+ export declare const toHavePromptCount: (received: Prompt[], count: number) => {
90
+ pass: boolean;
91
+ message: () => string;
92
+ };
93
+ /**
94
+ * Check if a resource with the given display name exists.
95
+ *
96
+ * expect(resources).toHaveResourceByName('Settings');
97
+ */
98
+ export declare const toHaveResourceByName: (received: Resource[], name: string) => {
99
+ pass: boolean;
100
+ message: () => string;
101
+ };
102
+ /**
103
+ * Check if a prompt exists and has defined arguments (is parameterized).
104
+ *
105
+ * expect(prompts).toHavePromptWithArgs('greet');
106
+ */
107
+ export declare const toHavePromptWithArgs: (received: Prompt[], promptName: string) => {
108
+ pass: boolean;
109
+ message: () => string;
110
+ };
111
+ /**
112
+ * Check that a tool result has text content.
113
+ * Optionally check that the text equals an exact string.
114
+ *
115
+ * expect(result).toReturnText(); // has any text
116
+ * expect(result).toReturnText('Hello World'); // text equals exactly
117
+ */
118
+ export declare const toReturnText: (received: CallToolResult, expected?: string) => {
119
+ pass: boolean;
120
+ message: () => string;
121
+ };
122
+ /**
123
+ * Check that a tool result's text contains a substring.
124
+ *
125
+ * expect(result).toReturnTextContaining('hello');
126
+ */
127
+ export declare const toReturnTextContaining: (received: CallToolResult, substring: string) => {
128
+ pass: boolean;
129
+ message: () => string;
130
+ };
131
+ /**
132
+ * Check that a tool result indicates an error (isError flag or "error" in text).
133
+ *
134
+ * expect(result).toReturnError();
135
+ */
136
+ export declare const toReturnError: (received: CallToolResult) => {
137
+ pass: boolean;
138
+ message: () => "Expected tool result to NOT be an error" | "Expected tool result to be an error, but it succeeded";
139
+ };
140
+ /**
141
+ * Check that a tool result indicates success (no error).
142
+ *
143
+ * expect(result).toReturnOk();
144
+ */
145
+ export declare const toReturnOk: (received: CallToolResult) => {
146
+ pass: boolean;
147
+ message: () => string;
148
+ };
149
+ /**
150
+ * Parse tool result text as JSON and deep-compare to expected object.
151
+ *
152
+ * expect(result).toReturnJson({ status: 'ok', count: 5 });
153
+ */
154
+ export declare const toReturnJson: (received: CallToolResult, expected: unknown) => {
155
+ pass: boolean;
156
+ message: () => string;
157
+ };
158
+ /**
159
+ * Check that a tool result has exactly `count` content items.
160
+ *
161
+ * expect(result).toReturnContentCount(2); // e.g. text + image
162
+ */
163
+ export declare const toReturnContentCount: (received: CallToolResult, count: number) => {
164
+ pass: boolean;
165
+ message: () => string;
166
+ };
167
+ /**
168
+ * Check that a tool result contains at least one image content item.
169
+ *
170
+ * expect(result).toReturnImage();
171
+ */
172
+ export declare const toReturnImage: (received: CallToolResult) => {
173
+ pass: boolean;
174
+ message: () => string;
175
+ };
176
+ /**
177
+ * Check that a resource result has text content.
178
+ * Optionally check that the text equals an exact string.
179
+ *
180
+ * expect(result).toReturnResourceText(); // has any text
181
+ * expect(result).toReturnResourceText('expected'); // text equals exactly
182
+ */
183
+ export declare const toReturnResourceText: (received: ReadResourceResult, expected?: string) => {
184
+ pass: boolean;
185
+ message: () => string;
186
+ };
187
+ /**
188
+ * Check that a resource result's text contains a substring.
189
+ *
190
+ * expect(result).toReturnResourceTextContaining('connection');
191
+ */
192
+ export declare const toReturnResourceTextContaining: (received: ReadResourceResult, substring: string) => {
193
+ pass: boolean;
194
+ message: () => string;
195
+ };
196
+ /**
197
+ * Check that a prompt result's first message text contains a substring.
198
+ *
199
+ * expect(result).toReturnPromptTextContaining('Alice');
200
+ */
201
+ export declare const toReturnPromptTextContaining: (received: GetPromptResult, substring: string) => {
202
+ pass: boolean;
203
+ message: () => string;
204
+ };
205
+ /**
206
+ * Check that a prompt result has exactly `count` messages.
207
+ *
208
+ * expect(result).toReturnPromptMessageCount(2);
209
+ */
210
+ export declare const toReturnPromptMessageCount: (received: GetPromptResult, count: number) => {
211
+ pass: boolean;
212
+ message: () => string;
213
+ };
214
+ /**
215
+ * Register all custom matchers with Jest.
216
+ * Call once in test setup:
217
+ *
218
+ * import { setupJestMatchers } from '@slbdn/mcp-tester';
219
+ * beforeAll(() => setupJestMatchers());
220
+ *
221
+ * Or add to jest.setup.js for global availability.
222
+ *
223
+ * Also works as `setupCustomMatchers()` (alias kept for backward compat).
224
+ */
225
+ export declare const setupJestMatchers: () => void;
226
+ /** @deprecated Use setupJestMatchers() instead */
227
+ export declare const setupCustomMatchers: () => void;
228
+ /**
229
+ * Register all custom matchers with Vitest.
230
+ * Call once in test setup:
231
+ *
232
+ * import { setupVitestMatchers } from '@slbdn/mcp-tester';
233
+ * import { beforeAll } from 'vitest';
234
+ * beforeAll(() => setupVitestMatchers());
235
+ */
236
+ export declare const setupVitestMatchers: () => void;
237
+ /**
238
+ * Assert that a tool result has text content (optionally matching exactly).
239
+ * Works with any test runner — throws AssertionError on failure.
240
+ */
241
+ export declare function assertToolText(result: CallToolResult, expected?: string, msg?: string): void;
242
+ /**
243
+ * Assert that a tool result text contains a substring.
244
+ * Works with any test runner — throws AssertionError on failure.
245
+ */
246
+ export declare function assertToolTextContains(result: CallToolResult, substring: string, msg?: string): void;
247
+ /**
248
+ * Assert that tools list contains a tool with the given name.
249
+ * Works with any test runner — throws AssertionError on failure.
250
+ */
251
+ export declare function assertHasTool(tools: Tool[], name: string, msg?: string): void;
252
+ /**
253
+ * Assert that resources list contains a resource with the given URI.
254
+ * Works with any test runner — throws AssertionError on failure.
255
+ */
256
+ export declare function assertHasResource(resources: Resource[], uri: string, msg?: string): void;
257
+ /**
258
+ * Assert that prompts list contains a prompt with the given name.
259
+ * Works with any test runner — throws AssertionError on failure.
260
+ */
261
+ export declare function assertHasPrompt(prompts: Prompt[], name: string, msg?: string): void;
262
+ //# sourceMappingURL=matchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,cAAc,EACd,kBAAkB,EAClB,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAK5C,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,IAAI,CAAC;QACb,UAAU,QAAQ,CAAC,CAAC;YAElB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC;YAChC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;YAC/B,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,CAAC;YACpC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC;YAC1C,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;YAClC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;YACtC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;YACpC,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;YACtC,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,CAAC;YAG5C,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;YACnC,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC;YAC7C,aAAa,IAAI,CAAC,CAAC;YACnB,UAAU,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