Skip to main content
Glama

Nx MCP Server

Official
by nrwl
workspace_path.test.ts2.28 kB
import { cleanupNxWorkspace, createInvokeMCPInspectorCLI, defaultVersion, e2eCwd, newWorkspace, simpleReactWorkspaceOptions, uniq, } from '@nx-console/shared-e2e-utils'; import { rmSync } from 'node:fs'; import { platform } from 'node:os'; import { join } from 'node:path'; describe('workspace path', () => { let invokeMCPInspectorCLI: Awaited< ReturnType<typeof createInvokeMCPInspectorCLI> >; const workspaceName = uniq('nx-mcp-smoke-test-workspace'); const testWorkspacePath = join(e2eCwd, workspaceName); beforeAll(async () => { newWorkspace({ name: workspaceName, options: simpleReactWorkspaceOptions, }); invokeMCPInspectorCLI = await createInvokeMCPInspectorCLI( e2eCwd, workspaceName, ); }); afterAll(async () => { // Clean up Nx workspace processes before attempting to remove directory await cleanupNxWorkspace(testWorkspacePath, defaultVersion); rmSync(testWorkspacePath, { recursive: true, force: true }); }); it('should return the cwd of the workspace if workspace path is not provided', () => { const result = invokeMCPInspectorCLI( '--method tools/call', '--tool-name nx_workspace_path', ); expect(result.content[0].text).toBe(testWorkspacePath); }); it('should return the workspace path when provided as a positional', () => { const result = invokeMCPInspectorCLI( testWorkspacePath, '--method tools/call', '--tool-name nx_workspace_path', ); expect(result.content[0].text).toBe(testWorkspacePath); }); it('should return the workspace path when provided as an option', () => { const result = invokeMCPInspectorCLI( `--workspace-path ${testWorkspacePath}`, '--method tools/call', '--tool-name nx_workspace_path', ); expect(result.content[0].text).toBe(testWorkspacePath); }); it('should resolve "." to the current working directory when passed as workspace path', () => { const result = invokeMCPInspectorCLI( '.', '--method tools/call', '--tool-name nx_workspace_path', ); // Since we're running from within the test workspace, "." should resolve to the test workspace path expect(result.content[0].text).toBe(testWorkspacePath); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nrwl/nx-console'

If you have feedback or need assistance with the MCP directory API, please join our Discord server