Skip to main content
Glama
nrwl

Nx MCP Server

Official
by nrwl
project-link.ts1.3 kB
import { isStringNode, lspLogger } from '@nx-console/language-server-utils'; import { nxWorkspace } from '@nx-console/shared-nx-workspace-info'; import { fileExists } from '@nx-console/shared-file-system'; import { join } from 'path'; import { ASTNode } from 'vscode-json-languageservice'; import { URI } from 'vscode-uri'; export async function projectLink( workingPath: string, node: ASTNode, ): Promise<string | undefined> { if (!isStringNode(node)) { return; } let projectName = node.value; if (projectName.startsWith('!')) { projectName = projectName.slice(1); } const { projectGraph } = await nxWorkspace(workingPath, lspLogger); const workspaceProject = projectGraph.nodes[projectName]; if (!workspaceProject) { return; } const projectRoot = join(workingPath, workspaceProject.data.root); const projectJsonPath = join(projectRoot, 'project.json'); if (await fileExists(projectJsonPath)) { return URI.from({ scheme: 'file', path: projectJsonPath, fragment: '1', }).toString(); } const packageJsonPath = join(projectRoot, 'package.json'); if (await fileExists(packageJsonPath)) { return URI.from({ scheme: 'file', path: packageJsonPath, fragment: '1', }).toString(); } return; }

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