Skip to content

Commit 4952f27

Browse files
committed
fix: mcp test
1 parent 7e4fb30 commit 4952f27

File tree

1 file changed

+54
-35
lines changed

1 file changed

+54
-35
lines changed

src/server/mcp.test.ts

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
1-
import { Ajv } from 'ajv';
21
import { z } from 'zod';
32
import { Client } from '../client/index.js';
43
import { InMemoryTransport } from '../inMemory.js';
5-
import { UriTemplate } from '../shared/uriTemplate.js';
64
import { getDisplayName } from '../shared/metadataUtils.js';
5+
import { UriTemplate } from '../shared/uriTemplate.js';
76
import {
87
CallToolResultSchema,
98
CompleteResultSchema,
109
ElicitRequestSchema,
1110
GetPromptResultSchema,
1211
ListPromptsResultSchema,
13-
ListResourceTemplatesResultSchema,
1412
ListResourcesResultSchema,
13+
ListResourceTemplatesResultSchema,
1514
ListToolsResultSchema,
1615
LoggingMessageNotificationSchema,
17-
Notification,
16+
type Notification,
1817
ReadResourceResultSchema,
19-
TextContent
18+
type TextContent
2019
} from '../types.js';
21-
import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js';
2220
import { completable } from './completable.js';
2321
import { McpServer, ResourceTemplate } from './mcp.js';
2422

25-
// Set up AJV validator for tests
26-
const ajv = new Ajv({
27-
strict: false,
28-
validateFormats: false,
29-
validateSchema: false
30-
});
31-
const ajvValidator = new AjvJsonSchemaValidator(ajv);
32-
3323
describe('McpServer', () => {
3424
/***
3525
* Test: Basic Server Instance
@@ -121,11 +111,22 @@ describe('McpServer', () => {
121111
}
122112
}
123113

124-
return { content: [{ type: 'text' as const, text: `Operation completed with ${steps} steps` }] };
114+
return {
115+
content: [
116+
{
117+
type: 'text' as const,
118+
text: `Operation completed with ${steps} steps`
119+
}
120+
]
121+
};
125122
}
126123
);
127124

128-
const progressUpdates: Array<{ progress: number; total?: number; message?: string }> = [];
125+
const progressUpdates: Array<{
126+
progress: number;
127+
total?: number;
128+
message?: string;
129+
}> = [];
129130

130131
const client = new Client({
131132
name: 'test client',
@@ -686,9 +687,15 @@ describe('tool()', () => {
686687

687688
expect(result.tools).toHaveLength(2);
688689
expect(result.tools[0].name).toBe('test');
689-
expect(result.tools[0].annotations).toEqual({ title: 'Test Tool', readOnlyHint: true });
690+
expect(result.tools[0].annotations).toEqual({
691+
title: 'Test Tool',
692+
readOnlyHint: true
693+
});
690694
expect(result.tools[1].name).toBe('test (new api)');
691-
expect(result.tools[1].annotations).toEqual({ title: 'Test Tool', readOnlyHint: true });
695+
expect(result.tools[1].annotations).toEqual({
696+
title: 'Test Tool',
697+
readOnlyHint: true
698+
});
692699
});
693700

694701
/***
@@ -731,7 +738,10 @@ describe('tool()', () => {
731738
type: 'object',
732739
properties: { name: { type: 'string' } }
733740
});
734-
expect(result.tools[0].annotations).toEqual({ title: 'Test Tool', readOnlyHint: true });
741+
expect(result.tools[0].annotations).toEqual({
742+
title: 'Test Tool',
743+
readOnlyHint: true
744+
});
735745
expect(result.tools[1].name).toBe('test (new api)');
736746
expect(result.tools[1].inputSchema).toEqual(result.tools[0].inputSchema);
737747
expect(result.tools[1].annotations).toEqual(result.tools[0].annotations);
@@ -765,7 +775,11 @@ describe('tool()', () => {
765775
{
766776
description: 'A tool with everything',
767777
inputSchema: { name: z.string() },
768-
annotations: { title: 'Complete Test Tool', readOnlyHint: true, openWorldHint: false }
778+
annotations: {
779+
title: 'Complete Test Tool',
780+
readOnlyHint: true,
781+
openWorldHint: false
782+
}
769783
},
770784
async ({ name }) => ({
771785
content: [{ type: 'text', text: `Hello, ${name}!` }]
@@ -813,7 +827,11 @@ describe('tool()', () => {
813827
'test',
814828
'A tool with everything but empty params',
815829
{},
816-
{ title: 'Complete Test Tool with empty params', readOnlyHint: true, openWorldHint: false },
830+
{
831+
title: 'Complete Test Tool with empty params',
832+
readOnlyHint: true,
833+
openWorldHint: false
834+
},
817835
async () => ({
818836
content: [{ type: 'text', text: 'Test response' }]
819837
})
@@ -824,7 +842,11 @@ describe('tool()', () => {
824842
{
825843
description: 'A tool with everything but empty params',
826844
inputSchema: {},
827-
annotations: { title: 'Complete Test Tool with empty params', readOnlyHint: true, openWorldHint: false }
845+
annotations: {
846+
title: 'Complete Test Tool with empty params',
847+
readOnlyHint: true,
848+
openWorldHint: false
849+
}
828850
},
829851
async () => ({
830852
content: [{ type: 'text' as const, text: 'Test response' }]
@@ -1351,7 +1373,7 @@ describe('tool()', () => {
13511373

13521374
expect(receivedRequestId).toBeDefined();
13531375
expect(typeof receivedRequestId === 'string' || typeof receivedRequestId === 'number').toBe(true);
1354-
expect(result.content && result.content[0].text).toContain('Received request ID:');
1376+
expect(result.content?.[0].text).toContain('Received request ID:');
13551377
});
13561378

13571379
/***
@@ -1379,7 +1401,10 @@ describe('tool()', () => {
13791401
});
13801402

13811403
mcpServer.tool('test-tool', async ({ sendNotification }) => {
1382-
await sendNotification({ method: 'notifications/message', params: { level: 'debug', data: loggingMessage } });
1404+
await sendNotification({
1405+
method: 'notifications/message',
1406+
params: { level: 'debug', data: loggingMessage }
1407+
});
13831408
return {
13841409
content: [
13851410
{
@@ -3892,15 +3917,10 @@ describe('elicitInput()', () => {
38923917
jest.clearAllMocks();
38933918

38943919
// Create server with restaurant booking tool
3895-
mcpServer = new McpServer(
3896-
{
3897-
name: 'restaurant-booking-server',
3898-
version: '1.0.0'
3899-
},
3900-
{
3901-
jsonSchemaValidator: ajvValidator
3902-
}
3903-
);
3920+
mcpServer = new McpServer({
3921+
name: 'restaurant-booking-server',
3922+
version: '1.0.0'
3923+
});
39043924

39053925
// Register the restaurant booking tool from README example
39063926
mcpServer.tool(
@@ -3981,8 +4001,7 @@ describe('elicitInput()', () => {
39814001
{
39824002
capabilities: {
39834003
elicitation: {}
3984-
},
3985-
jsonSchemaValidator: ajvValidator
4004+
}
39864005
}
39874006
);
39884007
});

0 commit comments

Comments
 (0)