fix: resolve all TypeScript and lint errors in integration tests

- Fixed InMemoryTransport destructuring (object → array)
- Updated all callTool calls to new object syntax
- Changed getServerInfo() to getServerVersion()
- Added type assertions for response objects
- Fixed import paths and missing imports
- Corrected template and performance test type issues
- All 56 TypeScript errors resolved

Both 'npm run lint' and 'npm run typecheck' now pass successfully
This commit is contained in:
czlonkowski
2025-07-29 18:09:03 +02:00
parent c5e012f601
commit e405346b3e
12 changed files with 435 additions and 394 deletions

View File

@@ -12,7 +12,7 @@ describe('MCP Protocol Compliance', () => {
mcpServer = new TestableN8NMCPServer();
await mcpServer.initialize();
const { serverTransport, clientTransport } = InMemoryTransport.createLinkedPair();
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
transport = serverTransport;
// Connect MCP server to transport
@@ -36,18 +36,18 @@ describe('MCP Protocol Compliance', () => {
describe('JSON-RPC 2.0 Compliance', () => {
it('should return proper JSON-RPC 2.0 response format', async () => {
const response = await client.request({
const response = await (client as any).request({
method: 'tools/list',
params: {}
});
// Response should have tools array
expect(response).toHaveProperty('tools');
expect(Array.isArray(response.tools)).toBe(true);
expect(Array.isArray((response as any).tools)).toBe(true);
});
it('should handle request with id correctly', async () => {
const response = await client.request({
const response = await (client as any).request({
method: 'tools/list',
params: {}
});
@@ -59,9 +59,9 @@ describe('MCP Protocol Compliance', () => {
it('should handle batch requests', async () => {
// Send multiple requests concurrently
const promises = [
client.request({ method: 'tools/list', params: {} }),
client.request({ method: 'tools/list', params: {} }),
client.request({ method: 'tools/list', params: {} })
(client as any).request({ method: 'tools/list', params: {} }),
(client as any).request({ method: 'tools/list', params: {} }),
(client as any).request({ method: 'tools/list', params: {} })
];
const responses = await Promise.all(promises);
@@ -80,7 +80,7 @@ describe('MCP Protocol Compliance', () => {
for (let i = 0; i < 5; i++) {
expectedOrder.push(i);
requests.push(
client.callTool('get_database_statistics', {})
client.callTool({ name: 'get_database_statistics', arguments: {} })
.then(() => i)
);
}
@@ -92,18 +92,18 @@ describe('MCP Protocol Compliance', () => {
describe('Protocol Version Negotiation', () => {
it('should negotiate protocol capabilities', async () => {
const serverInfo = await client.getServerInfo();
const serverInfo = await client.getServerVersion();
expect(serverInfo).toHaveProperty('name');
expect(serverInfo).toHaveProperty('version');
expect(serverInfo.name).toBe('n8n-documentation-mcp');
expect(serverInfo!.name).toBe('n8n-documentation-mcp');
});
it('should expose supported capabilities', async () => {
const serverInfo = await client.getServerInfo();
const serverInfo = await client.getServerVersion();
expect(serverInfo).toHaveProperty('capabilities');
const capabilities = serverInfo.capabilities || {};
const capabilities = serverInfo!.capabilities || {};
// Should support tools
expect(capabilities).toHaveProperty('tools');
@@ -121,7 +121,7 @@ describe('MCP Protocol Compliance', () => {
try {
// This should fail as MCP SDK validates method
await testClient.request({ method: '', params: {} });
await (testClient as any).request({ method: '', params: {} });
expect.fail('Should have thrown an error');
} catch (error) {
expect(error).toBeDefined();
@@ -132,16 +132,16 @@ describe('MCP Protocol Compliance', () => {
it('should handle missing params gracefully', async () => {
// Most tools should work without params
const response = await client.callTool('list_nodes', {});
const response = await client.callTool({ name: 'list_nodes', arguments: {} });
expect(response).toBeDefined();
});
it('should validate params schema', async () => {
try {
// Invalid nodeType format (missing prefix)
await client.callTool('get_node_info', {
await client.callTool({ name: 'get_node_info', arguments: {
nodeType: 'httpRequest' // Should be 'nodes-base.httpRequest'
});
} });
expect.fail('Should have thrown an error');
} catch (error: any) {
expect(error.message).toContain('not found');
@@ -151,32 +151,32 @@ describe('MCP Protocol Compliance', () => {
describe('Content Types', () => {
it('should handle text content in tool responses', async () => {
const response = await client.callTool('get_database_statistics', {});
const response = await client.callTool({ name: 'get_database_statistics', arguments: {} });
expect(response).toHaveLength(1);
expect(response[0]).toHaveProperty('type', 'text');
expect(response[0]).toHaveProperty('text');
expect(typeof response[0].text).toBe('string');
expect(typeof (response[0] as any).text).toBe('string');
});
it('should handle large text responses', async () => {
// Get a large node info response
const response = await client.callTool('get_node_info', {
const response = await client.callTool({ name: 'get_node_info', arguments: {
nodeType: 'nodes-base.httpRequest'
});
} });
expect(response).toHaveLength(1);
expect(response[0].type).toBe('text');
expect(response[0].text.length).toBeGreaterThan(1000);
expect((response[0] as any).type).toBe('text');
expect((response[0] as any).text.length).toBeGreaterThan(1000);
});
it('should handle JSON content properly', async () => {
const response = await client.callTool('list_nodes', {
const response = await client.callTool({ name: 'list_nodes', arguments: {
limit: 5
});
} });
expect(response).toHaveLength(1);
const content = JSON.parse(response[0].text);
const content = JSON.parse((response[0] as any).text);
expect(Array.isArray(content)).toBe(true);
});
});
@@ -184,29 +184,29 @@ describe('MCP Protocol Compliance', () => {
describe('Request/Response Correlation', () => {
it('should correlate concurrent requests correctly', async () => {
const requests = [
client.callTool('get_node_essentials', { nodeType: 'nodes-base.httpRequest' }),
client.callTool('get_node_essentials', { nodeType: 'nodes-base.webhook' }),
client.callTool('get_node_essentials', { nodeType: 'nodes-base.slack' })
client.callTool({ name: 'get_node_essentials', arguments: { nodeType: 'nodes-base.httpRequest' } }),
client.callTool({ name: 'get_node_essentials', arguments: { nodeType: 'nodes-base.webhook' } }),
client.callTool({ name: 'get_node_essentials', arguments: { nodeType: 'nodes-base.slack' } })
];
const responses = await Promise.all(requests);
expect(responses[0][0].text).toContain('httpRequest');
expect(responses[1][0].text).toContain('webhook');
expect(responses[2][0].text).toContain('slack');
expect((responses[0][0] as any).text).toContain('httpRequest');
expect((responses[1][0] as any).text).toContain('webhook');
expect((responses[2][0] as any).text).toContain('slack');
});
it('should handle interleaved requests', async () => {
const results: string[] = [];
// Start multiple requests with different delays
const p1 = client.callTool('get_database_statistics', {})
const p1 = client.callTool({ name: 'get_database_statistics', arguments: {} })
.then(() => { results.push('stats'); return 'stats'; });
const p2 = client.callTool('list_nodes', { limit: 1 })
const p2 = client.callTool({ name: 'list_nodes', arguments: { limit: 1 } })
.then(() => { results.push('nodes'); return 'nodes'; });
const p3 = client.callTool('search_nodes', { query: 'http' })
const p3 = client.callTool({ name: 'search_nodes', arguments: { query: 'http' } })
.then(() => { results.push('search'); return 'search'; });
const resolved = await Promise.all([p1, p2, p3]);
@@ -220,29 +220,29 @@ describe('MCP Protocol Compliance', () => {
describe('Protocol Extensions', () => {
it('should handle tool-specific extensions', async () => {
// Test tool with complex params
const response = await client.callTool('validate_node_operation', {
const response = await client.callTool({ name: 'validate_node_operation', arguments: {
nodeType: 'nodes-base.httpRequest',
config: {
method: 'GET',
url: 'https://api.example.com'
},
profile: 'runtime'
});
} });
expect(response).toHaveLength(1);
expect(response[0].type).toBe('text');
expect((response[0] as any).type).toBe('text');
});
it('should support optional parameters', async () => {
// Call with minimal params
const response1 = await client.callTool('list_nodes', {});
const response1 = await client.callTool({ name: 'list_nodes', arguments: {} });
// Call with all params
const response2 = await client.callTool('list_nodes', {
const response2 = await client.callTool({ name: 'list_nodes', arguments: {
limit: 10,
category: 'trigger',
package: 'n8n-nodes-base'
});
} });
expect(response1).toBeDefined();
expect(response2).toBeDefined();
@@ -258,7 +258,7 @@ describe('MCP Protocol Compliance', () => {
await testClient.connect(clientTransport);
// Make a request
const response = await testClient.callTool('get_database_statistics', {});
const response = await testClient.callTool({ name: 'get_database_statistics', arguments: {} });
expect(response).toBeDefined();
// Close client
@@ -266,7 +266,7 @@ describe('MCP Protocol Compliance', () => {
// Further requests should fail
try {
await testClient.callTool('get_database_statistics', {});
await testClient.callTool({ name: 'get_database_statistics', arguments: {} });
expect.fail('Should have thrown an error');
} catch (error) {
expect(error).toBeDefined();
@@ -284,12 +284,12 @@ describe('MCP Protocol Compliance', () => {
await engine.initialize();
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
await engine.connect(serverTransport);
await engine.connectToTransport(serverTransport);
const testClient = new Client({ name: 'test', version: '1.0.0' }, {});
await testClient.connect(clientTransport);
const response = await testClient.callTool('get_database_statistics', {});
const response = await testClient.callTool({ name: 'get_database_statistics', arguments: {} });
expect(response).toBeDefined();
await testClient.close();