|
| 1 | +import { |
| 2 | + cleanupNxWorkspace, |
| 3 | + createInvokeMCPInspectorCLI, |
| 4 | + defaultVersion, |
| 5 | + e2eCwd, |
| 6 | + newWorkspace, |
| 7 | + simpleReactWorkspaceOptions, |
| 8 | + uniq, |
| 9 | +} from '@nx-console/shared-e2e-utils'; |
| 10 | +import { rmSync } from 'node:fs'; |
| 11 | +import { join } from 'node:path'; |
| 12 | + |
| 13 | +describe('tool-filter', () => { |
| 14 | + let invokeMCPInspectorCLI: Awaited< |
| 15 | + ReturnType<typeof createInvokeMCPInspectorCLI> |
| 16 | + >; |
| 17 | + const workspaceName = uniq('nx-mcp-tool-filter'); |
| 18 | + const testWorkspacePath = join(e2eCwd, workspaceName); |
| 19 | + |
| 20 | + beforeAll(async () => { |
| 21 | + newWorkspace({ |
| 22 | + name: workspaceName, |
| 23 | + options: simpleReactWorkspaceOptions, |
| 24 | + }); |
| 25 | + invokeMCPInspectorCLI = await createInvokeMCPInspectorCLI( |
| 26 | + e2eCwd, |
| 27 | + workspaceName, |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + afterAll(async () => { |
| 32 | + await cleanupNxWorkspace(testWorkspacePath, defaultVersion); |
| 33 | + rmSync(testWorkspacePath, { recursive: true, force: true }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should filter to a single tool when --tools specifies one tool', () => { |
| 37 | + const result = invokeMCPInspectorCLI( |
| 38 | + testWorkspacePath, |
| 39 | + '--tools', |
| 40 | + 'nx_docs', |
| 41 | + '--method', |
| 42 | + 'tools/list', |
| 43 | + ); |
| 44 | + const toolNames = result.tools.map((tool: any) => tool.name); |
| 45 | + expect(toolNames).toEqual(['nx_docs']); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should allow multiple tools with multiple --tools args', () => { |
| 49 | + const result = invokeMCPInspectorCLI( |
| 50 | + testWorkspacePath, |
| 51 | + '--tools', |
| 52 | + 'nx_docs', |
| 53 | + 'nx_workspace', |
| 54 | + '--method', |
| 55 | + 'tools/list', |
| 56 | + ); |
| 57 | + const toolNames = result.tools.map((tool: any) => tool.name); |
| 58 | + expect(toolNames).toEqual(['nx_docs', 'nx_workspace']); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should support glob patterns for tool filtering', () => { |
| 62 | + const result = invokeMCPInspectorCLI( |
| 63 | + testWorkspacePath, |
| 64 | + '--tools', |
| 65 | + 'nx_*', |
| 66 | + '--method', |
| 67 | + 'tools/list', |
| 68 | + ); |
| 69 | + const toolNames = result.tools.map((tool: any) => tool.name); |
| 70 | + expect(toolNames).toEqual([ |
| 71 | + 'nx_docs', |
| 72 | + 'nx_available_plugins', |
| 73 | + 'nx_workspace', |
| 74 | + 'nx_workspace_path', |
| 75 | + 'nx_project_details', |
| 76 | + 'nx_generators', |
| 77 | + 'nx_generator_schema', |
| 78 | + ]); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should exclude tools matching negation patterns', () => { |
| 82 | + const result = invokeMCPInspectorCLI( |
| 83 | + testWorkspacePath, |
| 84 | + '--tools', |
| 85 | + 'nx_*', |
| 86 | + '!nx_docs', |
| 87 | + '--method', |
| 88 | + 'tools/list', |
| 89 | + ); |
| 90 | + const toolNames = result.tools.map((tool: any) => tool.name); |
| 91 | + expect(toolNames).not.toContain('nx_docs'); |
| 92 | + expect(toolNames).toContain('nx_workspace'); |
| 93 | + expect(toolNames).toContain('nx_generators'); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should combine positive and negative patterns correctly', () => { |
| 97 | + const result = invokeMCPInspectorCLI( |
| 98 | + testWorkspacePath, |
| 99 | + '--tools', |
| 100 | + 'nx_*', |
| 101 | + '!nx_generators', |
| 102 | + '!nx_generator_schema', |
| 103 | + '--method', |
| 104 | + 'tools/list', |
| 105 | + ); |
| 106 | + const toolNames = result.tools.map((tool: any) => tool.name); |
| 107 | + expect(toolNames).toEqual([ |
| 108 | + 'nx_docs', |
| 109 | + 'nx_available_plugins', |
| 110 | + 'nx_workspace', |
| 111 | + 'nx_workspace_path', |
| 112 | + 'nx_project_details', |
| 113 | + ]); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should support negative glob patterns', () => { |
| 117 | + const result = invokeMCPInspectorCLI( |
| 118 | + testWorkspacePath, |
| 119 | + '--tools', |
| 120 | + 'nx_*', |
| 121 | + '!nx_generator*', |
| 122 | + '--method', |
| 123 | + 'tools/list', |
| 124 | + ); |
| 125 | + const toolNames = result.tools.map((tool: any) => tool.name); |
| 126 | + expect(toolNames).toEqual([ |
| 127 | + 'nx_docs', |
| 128 | + 'nx_available_plugins', |
| 129 | + 'nx_workspace', |
| 130 | + 'nx_workspace_path', |
| 131 | + 'nx_project_details', |
| 132 | + ]); |
| 133 | + }); |
| 134 | +}); |
0 commit comments