Give Cursor monorepo awareness with the Nx MCP

This lesson demonstrates how AI assistants struggle with complex monorepo structures and how to dramatically improve their understanding using the Nx MCP extension in Cursor.

Workflow demonstrated in this lesson:

  • Observe how AI initially attempts to understand monorepo structure by scanning package.json files and analyzing folder hierarchies
  • Install the Nx Console extension and configure the Nx MCP server in your project
  • Enable the Nx MCP integration in Cursor's settings to access 15 powerful workspace tools
  • Ask the AI assistant questions about your workspace structure and dependencies
  • Watch as the AI leverages Nx's knowledge to accurately identify project relationships
  • Visualize dependencies through an interactive graph generated by the Nx tools

Key benefits:

  • Enhanced Workspace Understanding: AI assistants gain direct access to Nx's comprehensive workspace knowledge
  • Accurate Dependency Mapping: Precisely identify connections between libraries and applications
  • More efficient parsing of your workspace structure for your AI assistant
Share with a coworker

Transcript

[00:00] So even though AI models get better and better, they still kind of struggle at the moment when it comes to monorepo setups. Monorepos are great from one perspective because you have all these projects in one place. And so here, this is actually a relatively small one. There's a shop React-based application, bunch of packages down here that basically are being linked into that shop application to kind of modularize the setup. So here in cursor, I can ask and say something like, what are the current projects of this npm workspace?

[00:30] And it is probably going to check on the package.json files and try to figure out what the relationships are. And you can see how it kind of scans through the repository. And then based on the folder structure, you can kind of already reason what this structure might look like. So one thing that we can do to improve this further is to install the NX MCP. Now this product here already uses NX which is quite a popular monorepo management tool.

[00:55] It helps you run tasks in a monorepo in an efficient way and provides some other facilities to improve the DX overall. When you have multiple products in one Git repo. And one thing that they have is NX console. So if we go and install that extension you will see that they have integrated a new MCP feature into the NX console extension which basically exposes some of the intelligence that NX has about the workspace to your AI assistant. So once you have installed it you should get such a notification which you can click and it will automatically configure the MCP for you or you can also hit here MCP configuration, and then you see here an entry that says configure NX MCP server, which is basically the same.

[01:41] What it will do is basically set up here the MCP in your MCP.json, such that you don't have to do it by hand on your own. So with this, we can now make sure to enable that in cursor. And so if you go to cursor settings, should make sure here in MCP tools, we have the NX MCP enabled and installed, and you can see it has here 15 different tools by now, which is a bunch of different things like the workspace analytics here, it also gets access to NX docs, sees your running tasks and some more interesting things. But basically when we have this enabled we can have the same question again. Can you look at this workspace and list me the projects that are in this workspace?

[02:23] And so instead of now parsing the entire MonoEBOOT workspace, which can be a lot of projects, it will actually invoke now the NXMTP tool And so if I run this tool, it can leverage the knowledge that NX has about these different products. For instance, we could say, list me all the connections that the feed product detail library has. And so it goes again, looks at different product details for that tool and so now you can see NX has the knowledge about the dependencies of each library and so similarly now it exposed that to our AI assistant and so you can see here now it knows that there's a dependency to the data access project, there is a dependency to UI product detail and obviously the shop application. It also has information about the owners and it can also visualize these. Yes, can you please visualize these dependencies?

[03:23] So we can run this tool as well and now you can see it opens up the graph visualization where it exactly shows this dependency between these different products.