mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-03-22 02:13:09 +00:00
feat: add n8n_create_data_table MCP tool and projectId for create workflow (#640)
Add new MCP tool to create n8n data tables via the REST API: - n8n_create_data_table tool definition with name + columns schema - handleCreateDataTable handler with Zod validation and N8nApiError handling - N8nApiClient.createDataTable() calling POST /data-tables - DataTable, DataTableColumn, DataTableColumnResponse types per OpenAPI spec - Column types: string | number | boolean | date | json - Input validation: .min(1) on table name and column names - Tool documentation with examples, use cases, and pitfalls Also adds projectId parameter to n8n_create_workflow for enterprise project support, and fixes stale management tool count in health check. Based on work by @djakielski in PR #646. Co-Authored-By: Dominik Jakielski <dominik.jakielski@urlaubsguru.de> Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1300,6 +1300,59 @@ describe('N8nApiClient', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('createDataTable', () => {
|
||||
beforeEach(() => {
|
||||
client = new N8nApiClient(defaultConfig);
|
||||
});
|
||||
|
||||
it('should create data table with name and columns', async () => {
|
||||
const params = {
|
||||
name: 'My Table',
|
||||
columns: [
|
||||
{ name: 'email', type: 'string' as const },
|
||||
{ name: 'count', type: 'number' as const },
|
||||
],
|
||||
};
|
||||
const createdTable = { id: 'dt-1', name: 'My Table', columns: [] };
|
||||
|
||||
mockAxiosInstance.post.mockResolvedValue({ data: createdTable });
|
||||
|
||||
const result = await client.createDataTable(params);
|
||||
|
||||
expect(mockAxiosInstance.post).toHaveBeenCalledWith('/data-tables', params);
|
||||
expect(result).toEqual(createdTable);
|
||||
});
|
||||
|
||||
it('should create data table without columns', async () => {
|
||||
const params = { name: 'Empty Table' };
|
||||
const createdTable = { id: 'dt-2', name: 'Empty Table' };
|
||||
|
||||
mockAxiosInstance.post.mockResolvedValue({ data: createdTable });
|
||||
|
||||
const result = await client.createDataTable(params);
|
||||
|
||||
expect(mockAxiosInstance.post).toHaveBeenCalledWith('/data-tables', params);
|
||||
expect(result).toEqual(createdTable);
|
||||
});
|
||||
|
||||
it('should handle 400 error', async () => {
|
||||
const error = {
|
||||
message: 'Request failed',
|
||||
response: { status: 400, data: { message: 'Invalid table name' } },
|
||||
};
|
||||
await mockAxiosInstance.simulateError('post', error);
|
||||
|
||||
try {
|
||||
await client.createDataTable({ name: '' });
|
||||
expect.fail('Should have thrown an error');
|
||||
} catch (err) {
|
||||
expect(err).toBeInstanceOf(N8nValidationError);
|
||||
expect((err as N8nValidationError).message).toBe('Invalid table name');
|
||||
expect((err as N8nValidationError).statusCode).toBe(400);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('interceptors', () => {
|
||||
let requestInterceptor: any;
|
||||
let responseInterceptor: any;
|
||||
|
||||
Reference in New Issue
Block a user