-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.test.js
More file actions
84 lines (71 loc) · 2.64 KB
/
Copy pathserver.test.js
File metadata and controls
84 lines (71 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { handleJsonRpcMessage, toMcpTool } = require('./server');
describe('OpenSign MCP server', () => {
const integration = {
getTools: jest.fn(() => [
{
name: 'get_user',
description: 'Get your account details from OpenSign',
input_schema: { type: 'object', properties: {} }
}
]),
executeTool: jest.fn()
};
beforeEach(() => {
jest.clearAllMocks();
});
test('converts Claude tool schema to MCP tool schema', () => {
expect(toMcpTool(integration.getTools()[0])).toEqual({
name: 'get_user',
description: 'Get your account details from OpenSign',
inputSchema: { type: 'object', properties: {} }
});
});
test('responds to initialize', async () => {
const response = await handleJsonRpcMessage({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: { protocolVersion: '2024-11-05' }
}, integration);
expect(response.result.serverInfo.name).toBe('opensign');
expect(response.result.capabilities.tools).toEqual({});
});
test('lists OpenSign tools', async () => {
const response = await handleJsonRpcMessage({
jsonrpc: '2.0',
id: 2,
method: 'tools/list'
}, integration);
expect(response.result.tools).toHaveLength(1);
expect(response.result.tools[0].name).toBe('get_user');
});
test('calls OpenSign tools', async () => {
integration.executeTool.mockResolvedValue({ email: 'user@example.com' });
const response = await handleJsonRpcMessage({
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'get_user',
arguments: {}
}
}, integration);
expect(integration.executeTool).toHaveBeenCalledWith('get_user', {});
expect(response.result.content[0].type).toBe('text');
expect(JSON.parse(response.result.content[0].text)).toEqual({ email: 'user@example.com' });
});
test('returns MCP errors for failed tool calls', async () => {
integration.executeTool.mockRejectedValue(new Error('OpenSign API Error'));
const response = await handleJsonRpcMessage({
jsonrpc: '2.0',
id: 4,
method: 'tools/call',
params: {
name: 'get_user',
arguments: {}
}
}, integration);
expect(response.error.code).toBe(-32000);
expect(response.error.message).toBe('OpenSign API Error');
});
});