Skip to main content
Glama
nrwl

Nx MCP Server

Official
by nrwl
node-task.ts1.67 kB
import { getNxWorkspace } from '@nx-console/vscode-nx-workspace'; import { join } from 'path'; import { ShellExecution, Task, TaskScope } from 'vscode'; export interface NodeTaskDefinition { script: string; args?: string[]; cwd?: string; env?: Record<string, string>; } export class NodeTask extends Task { /** * Creates a task to run a Node script with the given arguments */ static async create( definition: NodeTaskDefinition, ): Promise<NodeTask | undefined> { const nxWorkspace = await getNxWorkspace(); if (!nxWorkspace) { return; } const { workspacePath } = nxWorkspace; const args = definition.args || []; const displayCommand = `node ${definition.script} ${args.join(' ')}`.trim(); // Create a direct ShellExecution rather than using getShellExecutionForConfig // since we're not running an Nx command const shellExecution = new ShellExecution( `node ${definition.script} ${args.join(' ')}`.trim(), { cwd: definition.cwd ? join(workspacePath, definition.cwd) : workspacePath, env: { ...(definition.env || {}), NX_CONSOLE: 'true', }, }, ); const task = new NodeTask( { ...definition, type: 'nx' }, TaskScope.Workspace, displayCommand, 'node', shellExecution, ); return task; } static async batchCreate( definitions: NodeTaskDefinition[], ): Promise<NodeTask[]> { const tasks = await Promise.all( definitions.map((definition) => this.create(definition)), ); return tasks.filter((task) => task !== undefined) as NodeTask[]; } }

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