Skip to main content
Glama
nrwl

Nx MCP Server

Official
by nrwl
create-project-graph.ts1.48 kB
import { getNxExecutionCommand } from '@nx-console/shared-npm'; import { execSync } from 'child_process'; import { getProjectGraphOutput } from './get-project-graph-output'; import { nxWorkspace } from '@nx-console/shared-nx-workspace-info'; import { lspLogger } from '@nx-console/language-server-utils'; export async function createProjectGraph( workspacePath: string, showAffected: boolean, ): Promise<string | undefined> { const { isEncapsulatedNx } = await nxWorkspace(workspacePath, lspLogger); const projectGraphOutput = await getProjectGraphOutput(workspacePath); return getNxExecutionCommand({ cwd: workspacePath, displayCommand: `nx graph ${showAffected ? '--affected' : ''} --file ` + projectGraphOutput.relativePath, encapsulatedNx: isEncapsulatedNx, }).then((command) => { lspLogger.log(`Generating graph with command: \`${command}\``); try { execSync(command, { cwd: workspacePath, windowsHide: true, // Since this is going to be used within nxls, we need to make sure that stdio is set to ignore // The lsp is set up to write to the host on stdio, so if we pollute the stdio with data that is not // standard lsp, the connection will close because of malformed data. stdio: 'ignore', }); return undefined; } catch (e) { const errorMessage = `${e.output[1] || e}`; throw 'Unable to create project graph: ' + errorMessage; } }); }

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