@1mcp/agent 0.7.0 → 0.8.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.
- package/README.md +55 -0
- package/build/capabilities/capabilityManager.d.ts +34 -0
- package/build/capabilities/capabilityManager.d.ts.map +1 -0
- package/build/capabilities/capabilityManager.js +1 -0
- package/build/capabilities/capabilityManager.js.map +1 -0
- package/build/client.d.ts +25 -0
- package/build/client.d.ts.map +1 -0
- package/build/client.js +3 -10
- package/build/client.js.map +1 -0
- package/build/clients/clientManager.d.ts +40 -0
- package/build/clients/clientManager.d.ts.map +1 -0
- package/build/clients/clientManager.js +1 -0
- package/build/clients/clientManager.js.map +1 -0
- package/build/config/configManager.d.ts +54 -0
- package/build/config/configManager.d.ts.map +1 -0
- package/build/config/configManager.js +1 -0
- package/build/config/configManager.js.map +1 -0
- package/build/config/transportConfig.d.ts +7 -0
- package/build/config/transportConfig.d.ts.map +1 -0
- package/build/config/transportConfig.js +1 -0
- package/build/config/transportConfig.js.map +1 -0
- package/build/constants.d.ts +43 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +19 -4
- package/build/constants.js.map +1 -0
- package/build/handlers/notificationHandlers.d.ts +14 -0
- package/build/handlers/notificationHandlers.d.ts.map +1 -0
- package/build/handlers/notificationHandlers.js +1 -0
- package/build/handlers/notificationHandlers.js.map +1 -0
- package/build/handlers/requestHandlers.d.ts +10 -0
- package/build/handlers/requestHandlers.d.ts.map +1 -0
- package/build/handlers/requestHandlers.js +1 -0
- package/build/handlers/requestHandlers.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +6 -1
- package/build/index.js.map +1 -0
- package/build/logger/logger.d.ts +13 -0
- package/build/logger/logger.d.ts.map +1 -0
- package/build/logger/logger.js +5 -35
- package/build/logger/logger.js.map +1 -0
- package/build/middleware/loggingMiddleware.d.ts +6 -0
- package/build/middleware/loggingMiddleware.d.ts.map +1 -0
- package/build/middleware/loggingMiddleware.js +1 -0
- package/build/middleware/loggingMiddleware.js.map +1 -0
- package/build/server/expressServer.d.ts +10 -0
- package/build/server/expressServer.d.ts.map +1 -0
- package/build/server/expressServer.js +2 -11
- package/build/server/expressServer.js.map +1 -0
- package/build/server.d.ts +7 -0
- package/build/server.d.ts.map +1 -0
- package/build/server.js +1 -0
- package/build/server.js.map +1 -0
- package/build/serverManager.d.ts +25 -0
- package/build/serverManager.d.ts.map +1 -0
- package/build/serverManager.js +4 -2
- package/build/serverManager.js.map +1 -0
- package/build/services/configReloadService.d.ts +37 -0
- package/build/services/configReloadService.d.ts.map +1 -0
- package/build/services/configReloadService.js +1 -0
- package/build/services/configReloadService.js.map +1 -0
- package/build/types.d.ts +129 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +1 -0
- package/build/types.js.map +1 -0
- package/build/utils/clientFiltering.d.ts +37 -0
- package/build/utils/clientFiltering.d.ts.map +1 -0
- package/build/utils/clientFiltering.js +1 -0
- package/build/utils/clientFiltering.js.map +1 -0
- package/build/utils/errorHandling.d.ts +62 -0
- package/build/utils/errorHandling.d.ts.map +1 -0
- package/build/utils/errorHandling.js +1 -0
- package/build/utils/errorHandling.js.map +1 -0
- package/build/utils/errorTypes.d.ts +25 -0
- package/build/utils/errorTypes.d.ts.map +1 -0
- package/build/utils/errorTypes.js +1 -0
- package/build/utils/errorTypes.js.map +1 -0
- package/package.json +8 -9
- package/build/clients/clientManager.test.js +0 -172
- package/build/config/configManager.test.js +0 -92
- package/build/logger/mcpTransport.js +0 -150
- package/build/serverManager.test.js +0 -158
- package/build/test-utils/fixtures/commonFixtures.js +0 -44
- package/build/test-utils/helpers/testHelpers.js +0 -23
- package/build/test-utils/mocks/commonMocks.js +0 -65
- package/build/utils/clientFiltering.test.js +0 -124
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Helper to clear all mocks in a test
|
|
2
|
-
export const clearAllMocks = () => {
|
|
3
|
-
jest.clearAllMocks();
|
|
4
|
-
jest.useRealTimers();
|
|
5
|
-
};
|
|
6
|
-
// Helper to setup fake timers
|
|
7
|
-
export const setupFakeTimers = () => {
|
|
8
|
-
jest.useFakeTimers();
|
|
9
|
-
};
|
|
10
|
-
// Helper to advance timers by time
|
|
11
|
-
export const advanceTimersByTime = async (ms) => {
|
|
12
|
-
await jest.advanceTimersByTimeAsync(ms);
|
|
13
|
-
};
|
|
14
|
-
// Helper to run all timers
|
|
15
|
-
export const runAllTimers = async () => {
|
|
16
|
-
await jest.runAllTimersAsync();
|
|
17
|
-
};
|
|
18
|
-
// Helper to create a mock event emitter spy
|
|
19
|
-
export const createEventEmitterSpy = (instance) => {
|
|
20
|
-
return jest.spyOn(instance, 'emit');
|
|
21
|
-
};
|
|
22
|
-
// Helper to wait for next tick
|
|
23
|
-
export const waitForNextTick = () => new Promise((resolve) => process.nextTick(resolve));
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Mock Logger
|
|
2
|
-
export const mockLogger = {
|
|
3
|
-
info: jest.fn(),
|
|
4
|
-
error: jest.fn(),
|
|
5
|
-
warn: jest.fn(),
|
|
6
|
-
debug: jest.fn(),
|
|
7
|
-
level: 'info',
|
|
8
|
-
transports: [],
|
|
9
|
-
};
|
|
10
|
-
// Mock Transport
|
|
11
|
-
export const createMockTransport = () => ({
|
|
12
|
-
start: jest.fn(),
|
|
13
|
-
send: jest.fn(),
|
|
14
|
-
close: jest.fn(),
|
|
15
|
-
});
|
|
16
|
-
// Mock Server
|
|
17
|
-
export const createMockServer = (overrides = {}) => ({
|
|
18
|
-
connect: jest.fn().mockResolvedValue(undefined),
|
|
19
|
-
transport: createMockTransport(),
|
|
20
|
-
...overrides,
|
|
21
|
-
});
|
|
22
|
-
// Mock Client
|
|
23
|
-
export const createMockClient = (overrides = {}) => ({
|
|
24
|
-
connect: jest.fn(),
|
|
25
|
-
getServerVersion: jest.fn(),
|
|
26
|
-
...overrides,
|
|
27
|
-
});
|
|
28
|
-
// Mock File System
|
|
29
|
-
export const createMockFs = () => ({
|
|
30
|
-
existsSync: jest.fn(),
|
|
31
|
-
mkdirSync: jest.fn(),
|
|
32
|
-
writeFileSync: jest.fn(),
|
|
33
|
-
readFileSync: jest.fn(),
|
|
34
|
-
watch: jest.fn(() => ({ close: jest.fn() })),
|
|
35
|
-
});
|
|
36
|
-
// Mock Config
|
|
37
|
-
export const createMockConfig = (overrides = {}) => ({
|
|
38
|
-
name: 'test-server',
|
|
39
|
-
version: '1.0.0',
|
|
40
|
-
...overrides,
|
|
41
|
-
});
|
|
42
|
-
// Mock Capabilities
|
|
43
|
-
export const createMockCapabilities = (overrides = {}) => ({
|
|
44
|
-
capabilities: {
|
|
45
|
-
resources: {},
|
|
46
|
-
tools: {},
|
|
47
|
-
...overrides,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
// Jest module mocks setup helper
|
|
51
|
-
export const setupCommonJestMocks = () => {
|
|
52
|
-
jest.mock('@modelcontextprotocol/sdk/server/index.js', () => ({
|
|
53
|
-
Server: jest.fn(),
|
|
54
|
-
}));
|
|
55
|
-
jest.mock('@modelcontextprotocol/sdk/client/index.js', () => ({
|
|
56
|
-
Client: jest.fn(),
|
|
57
|
-
}));
|
|
58
|
-
jest.mock('@modelcontextprotocol/sdk/shared/transport.js', () => ({
|
|
59
|
-
Transport: jest.fn(),
|
|
60
|
-
}));
|
|
61
|
-
jest.mock('../../logger/logger.js', () => ({
|
|
62
|
-
__esModule: true,
|
|
63
|
-
default: mockLogger,
|
|
64
|
-
}));
|
|
65
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { filterClients, byCapabilities, byTags, filterClientsByCapabilities, filterClientsByTags, } from './clientFiltering.js';
|
|
2
|
-
describe('Client Filtering Utils', () => {
|
|
3
|
-
const mockClients = {
|
|
4
|
-
client1: {
|
|
5
|
-
capabilities: {
|
|
6
|
-
resources: {},
|
|
7
|
-
tools: {},
|
|
8
|
-
},
|
|
9
|
-
transport: {
|
|
10
|
-
tags: ['tag1', 'tag2'],
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
client2: {
|
|
14
|
-
capabilities: {
|
|
15
|
-
resources: {},
|
|
16
|
-
},
|
|
17
|
-
transport: {
|
|
18
|
-
tags: ['tag1'],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
client3: {
|
|
22
|
-
capabilities: {
|
|
23
|
-
tools: {},
|
|
24
|
-
},
|
|
25
|
-
transport: {
|
|
26
|
-
tags: ['tag3'],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
clientNoCapabilities: {
|
|
30
|
-
transport: {
|
|
31
|
-
tags: ['tag1'],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
clientNoTags: {
|
|
35
|
-
capabilities: {
|
|
36
|
-
resources: {},
|
|
37
|
-
},
|
|
38
|
-
transport: {},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
describe('filterClientsByCapabilities', () => {
|
|
42
|
-
it('should filter clients by single capability', () => {
|
|
43
|
-
const filtered = filterClientsByCapabilities(mockClients, { resources: {} });
|
|
44
|
-
expect(Object.keys(filtered)).toEqual(['client1', 'client2', 'clientNoTags']);
|
|
45
|
-
});
|
|
46
|
-
it('should filter clients by multiple capabilities', () => {
|
|
47
|
-
const filtered = filterClientsByCapabilities(mockClients, { resources: {}, tools: {} });
|
|
48
|
-
expect(Object.keys(filtered)).toEqual(['client1']);
|
|
49
|
-
});
|
|
50
|
-
it('should handle clients with no capabilities', () => {
|
|
51
|
-
const filtered = filterClientsByCapabilities(mockClients, { resources: {} });
|
|
52
|
-
expect(filtered).not.toHaveProperty('clientNoCapabilities');
|
|
53
|
-
});
|
|
54
|
-
it('should return empty object when no matches found', () => {
|
|
55
|
-
const filtered = filterClientsByCapabilities(mockClients, { nonexistent: {} });
|
|
56
|
-
expect(Object.keys(filtered)).toHaveLength(0);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe('filterClientsByTags', () => {
|
|
60
|
-
it('should return all clients when no tags provided', () => {
|
|
61
|
-
const filtered = filterClientsByTags(mockClients, undefined);
|
|
62
|
-
expect(Object.keys(filtered)).toEqual(Object.keys(mockClients));
|
|
63
|
-
});
|
|
64
|
-
it('should filter clients by single tag', () => {
|
|
65
|
-
const filtered = filterClientsByTags(mockClients, ['tag1']);
|
|
66
|
-
expect(Object.keys(filtered)).toEqual(['client1', 'client2', 'clientNoCapabilities']);
|
|
67
|
-
});
|
|
68
|
-
it('should filter clients by multiple tags', () => {
|
|
69
|
-
const filtered = filterClientsByTags(mockClients, ['tag1', 'tag2']);
|
|
70
|
-
expect(Object.keys(filtered)).toEqual(['client1']);
|
|
71
|
-
});
|
|
72
|
-
it('should handle clients with no tags', () => {
|
|
73
|
-
const filtered = filterClientsByTags(mockClients, ['tag1']);
|
|
74
|
-
expect(filtered).not.toHaveProperty('clientNoTags');
|
|
75
|
-
});
|
|
76
|
-
it('should return empty object when no matches found', () => {
|
|
77
|
-
const filtered = filterClientsByTags(mockClients, ['nonexistent']);
|
|
78
|
-
expect(Object.keys(filtered)).toHaveLength(0);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('filterClients (composed filters)', () => {
|
|
82
|
-
it('should chain multiple filters together', () => {
|
|
83
|
-
const filtered = filterClients(byCapabilities({ resources: {} }), byTags(['tag1']))(mockClients);
|
|
84
|
-
expect(Object.keys(filtered)).toEqual(['client1', 'client2']);
|
|
85
|
-
});
|
|
86
|
-
it('should handle empty filters array', () => {
|
|
87
|
-
const filtered = filterClients()(mockClients);
|
|
88
|
-
expect(Object.keys(filtered)).toEqual(Object.keys(mockClients));
|
|
89
|
-
});
|
|
90
|
-
it('should handle no matching results', () => {
|
|
91
|
-
const filtered = filterClients(byCapabilities({ resources: {} }), byTags(['tag3']))(mockClients);
|
|
92
|
-
expect(Object.keys(filtered)).toHaveLength(0);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('byCapabilities', () => {
|
|
96
|
-
it('should create a filter function for capabilities', () => {
|
|
97
|
-
const filter = byCapabilities({ resources: {} });
|
|
98
|
-
const filtered = filter(mockClients);
|
|
99
|
-
expect(Object.keys(filtered)).toEqual(['client1', 'client2', 'clientNoTags']);
|
|
100
|
-
});
|
|
101
|
-
it('should handle undefined capabilities safely', () => {
|
|
102
|
-
const filter = byCapabilities({ resources: {} });
|
|
103
|
-
const filtered = filter({ ...mockClients, unsafeClient: { transport: {} } });
|
|
104
|
-
expect(filtered).not.toHaveProperty('unsafeClient');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('byTags', () => {
|
|
108
|
-
it('should create a filter function for tags', () => {
|
|
109
|
-
const filter = byTags(['tag1']);
|
|
110
|
-
const filtered = filter(mockClients);
|
|
111
|
-
expect(Object.keys(filtered)).toEqual(['client1', 'client2', 'clientNoCapabilities']);
|
|
112
|
-
});
|
|
113
|
-
it('should handle undefined tags array', () => {
|
|
114
|
-
const filter = byTags(undefined);
|
|
115
|
-
const filtered = filter(mockClients);
|
|
116
|
-
expect(Object.keys(filtered)).toEqual(Object.keys(mockClients));
|
|
117
|
-
});
|
|
118
|
-
it('should handle empty tags array', () => {
|
|
119
|
-
const filter = byTags([]);
|
|
120
|
-
const filtered = filter(mockClients);
|
|
121
|
-
expect(Object.keys(filtered)).toEqual(Object.keys(mockClients));
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|