Discover powerful developer workflows using the native Directus MCP Server with Claude Code. This episode demonstrates practical use cases including rapid data modeling, automated flow creation, sample data generation, and script writing to accelerate your development process.
Speaker 0: Alright. Alright. Welcome, devs. Brian here for Directus. And in this video, we are going to show you some developer workflows when working with the Directus native MCP and your IDE.
So no matter where you sit on the Vibe coding spectrum, love it, hate it, don't like it, cautiously optimistic. Hopefully, we're gonna get a few workflows out of here that you can try and take away for your own use. Let's dive in. First stop is just gonna be into the AI settings page of Directus to make sure that the MCP is enabled for this instance. We're gonna allow deletes, which is okay.
In our development instance, you may want to disable that in production. We've got our AI prompts collection, which is helpful for all the marketers in your life. They get reusable prompt templates they can use with things like Claude or other clients that support it, and we can change the system prompt behavior. With that enabled, what we're going to do next is just go in and create a new user here. So I'm gonna name this Claude Code, you're very right to be security concerned when it comes to LLM and prompt injection and all those bad things that we hear about, and that's why we advocate creating separate users for the MCP, so you could tightly scope those permission settings.
And, in this case, we're gonna give it admin access because I wanna show you guys some of the schema tools. But do not do this in production. Make sure you scope it down either by the access policy or by the role itself, and make sure you give it the least permissions possible for the task. Right? Alright, so we're going to create a static access token here, we're going to save this user, and now I'm just going to pull this up.
I've got a little snippet somewhere on my clipboard. I'm going to grab that token that we just created. So basically, this is the command for adding cloud code, adding the MCP server to that. I'm just gonna open up another terminal here inside cursor. I've been jamming a lot with cloud code lately, especially as part of developing this MCP.
So, that's what we'll cover today. Of course, there's other videos on how to connect it to Cursor or other clients. This is just one workflow that we're gonna show you. Alright. So our first workflow that we're gonna cover, right, is conceptual data models.
Right. Maybe I've got a new project and, you know, a a Directus makes it super easy to data model anything, really. I could go through and visually map out whatever, and then getting the instant APIs on top of that is just icing on the cake. But in this case, I I wanna move faster. Right?
So let's open up Cloud Code, and let's just talk to it, add a a con a new data model to Directus. Let's create a new data model for a CRM inside my directus instance. Keep it lightweight for now. Just standard CRM stuff. Let's brainstorm together first before you add it though.
Alright. Cool. So we will take a look at what happens. Hopefully, this should be a signal to the MCP server that it should go in and run a couple tools and just see what we have inside Directus First, but we'll see how Claude Code reacts. Right?
It is doing some thinking. We can toggle that with command o and see kind of what we what we got. Organizations, contacts, deals, activities, tasks. Okay. Questions.
Cool. Let me close this out. Let's skip the extra collections. This looks pretty good for now. Activities, let's use m two o fields versus the m two a.
Deal pipeline stages, we want those to be a separate collection. Should be a separate collection. Nothing industry specific for now. Alright. So, you know, I appreciate the back and forth here.
You know, hopefully, now that we've stressed got this planned out, let's just hit continue with the plan and see what Claude can do via the MCP. Alright. We can see it doing some thinking. And and, again, like, I could do this via the UI. We're just gonna see how much quicker it is to do it via the MCP.
It's going to ask us to call the system prompt. Basically, this just gives some more information about the role. Cool. It looks like the next one it is trying to call is the schema tool, which is good. We'll give it full access.
That way, it can see the existing schema inside our direct assistance. And I guess I could make this full screen. There we go. Zoom in even further. And I could probably even close the terminal down here.
Alright. So we could see it's trying to run the collections command. Cool. This should create the collection inside Directus for us. And, again, I'm just gonna give it full access to continue.
You know, again, be very careful when you're using these tools. Make sure you're inspecting all of the payloads first. You know, especially when it's touching the schema, you might want to export the schema. There is an API endpoint for that. Check the docs at Directus to to verify.
Alright. Now it's gonna go in and create the different relationships for us, and it looks like it's hit an error. Right? Now the MCP inside Directus, there's two validation layers. Like, we first validate, you know, a a light validation against the input schema.
And then before we actually perform the operation inside Directus, like creating a field or a relationship, goes through a a much more strict validation, which helps catch some of these errors like this. And you could see it successfully created these relationships right now. Alright. So if I do a hard refresh over here, we close this, we should start to see some of these things get populated, like our contacts and our organizations, the pipeline stages. Right?
We're still probably waiting on the deals, I would assume. Right. But now I can start entering the data for this. Right? Bryant Gillespie.
Probably shouldn't put my full email address in here. And I could create a new organization, call that direct us. Great. There we go. And we could see that it it has already got all these relationships set up for us as well, which is is super nice.
Right? We've got deals, we've got contacts, we can see the title of the deal, we've got a slider for the probability of this thing closing, we've got a link to our stage, let's call this new deal, give it a color, title, of course title is required so it's already added some validation for us. New deal, Brian's deal, Brian's new deal, sounds like a presidential thing. Alright. So that is, just one use case for the MCP.
Right? And you can see this thing is still going to town. It's adding activities, etcetera. In this case, I'm I'm just gonna go ahead and stop this, And let's start a new thread and look at another potential use case for this. Right?
So one of the other nice pieces of functionality that is in this iteration of the MCP is the ability to create direct as flows. And you're probably asking me, hey. What are direct as flows? Right? They are low code, no code automations that you can build logic in whenever things happen.
You can make requests. You can send emails. Right? As a developer, how many times have you had to put in code for a simple email notification when a certain event happens? Directus as it flows are your best friend in that scenario.
We don't have to submit a PR, wait for three days for somebody to review that change, and the email copy, we could just quickly model it inside flows. But a lot of folks in the community expressed interest in being able to create flows with LLMs. So let's do that. Right? Whenever let's plan a new direct us flow.
Whenever a contact is created, Send a notification in app to the owner of that contact. Let's plan the flow first and then create it. We confirm. Okay. Alright.
So, basically, we take a a super simple prompt, and I I could be more specific here to get better results. But using the thinking mode inside Cloud Code, the the latest Sonnet model seems to work really well. And this is kind of the the workflow that I've adopted for myself. Let's get a detailed plan. Let's pick up all the information that we need first, and then, then we send, it off on its task.
Right? So here's the flow plan. We've got a new contact notification. If the owner is null or assigned, let's add a check for no owner. Use a condition to filter that.
We don't want to send a notification if there's no owner. Alright. For the message text message text, just use the contact details. Execute the plan. Again, LLMs aren't particularly worried by typos, in some context maybe, but it should go through and then it will actually start building the flow for us.
So there's two components to flows. We have the flow itself and then the operations within the flow, and it should build both of those forming and then actually combine those together, and make sure everything is linked up properly. So we can see this happening here in real time. Directus flow, creating the operation. Not sure how long this will take.
And it looks like we're done. Right? A more complex flow would probably take a little bit longer for the LLM to map out, but let's just go in. I'm gonna refresh. We're gonna take a look.
Here's our new flow that it has created. Whenever an item is created in the contacts collection, we're gonna check the payload for the owner, and then we're going to update the user. We'll send them a notification. I do spot one issue here. Right?
The trigger dot payload dot ID is, not what we're gonna get. It's actually gonna be a trigger dot key. So, you know, this thing is not infallible, but for thirty five seconds to have this flow is pretty good. Could save me a lot of time. Right?
Scaffolding this out, and then I'll just dial it in. But let's test this out. We're just gonna send a new contact into the database. I'm gonna make sure that I set myself as the user and boom, in the notifications there we could see new contact has been assigned. I could go in and navigate directly to that contact.
Alright. Let's move on to the next workflow. So one of the other workflows that I find myself using quite a bit is just adding sample data, just small sets of sample data. MCP is a rather expensive protocol, so you you don't wanna use this to seed a database. But, you know, if we're developing a, a front end, like a a website, right, Typically, you might want to have a kitchen sink page.
You know, if we take a look at our our block based builder, right, it can be very time consuming to scaffold out a full page with all the different options so that when you are building this, right, you can visually see what's happening. Right? MCP makes that super easy. So this is another workflow. Let's go in with let's create a kitchen sink page inside Directus with all the different block combinations so we can better work on the styling and front end components.
Alright. So that's the prop we're gonna kick things off with. And it's for whatever reason, this thing is still showing what we previously had. But let's see what happens. Right?
It's gonna run the direct to schema. It will get all the existing collections that we have. And if I wanna just pull this up side by side in my browser, you know, here's kind of what we've got as far as the home page, what that kinda looks like, But let's have it create this kitchen sink page. So we're just gonna go back and okay. So it looks like it has picked up all the different block types.
We can see that here. Let's use the schema tool to understand what all of those different options are. And now it should go in and start creating this page for us. Right? Has it created the page?
It looks like it's gonna go through and create the individual blocks first. So if I show my hidden collections inside Directus, we can go through and see probably some of these different things that it's creating for us. Block hero. Right. This is a block hero.
Looks like it's doing a bunch of those. Just, block hero with the image positioned on the right side of the content. Cool. So it's gonna go through this process. I'll just speed this up for the sake of the video, and then we'll come back.
And scene. Now we're back. One of the things that I do have toggled when I'm working with Cloud Code, I I use the thinking mode quite a bit. It seems to help the output a lot. But now we've got our kitchen sink page.
All we have to do is hit refresh. We could see that it's added quite a few different blocks for us here, which is nice. Looks like it missed one of the form blocks. You missed the form block in our kitchen sink page. Alright.
So while we're doing that, let's just open this up. We can see the live preview here, which is probably not working. Maybe we just set this to publish for now. It'll be a a different issue for a different video. But let's open up this kitchen sink page, local host 3,000 kitchen sink, and see what we got.
Alright. This doesn't appear to be working. Let me just go back quickly. I'm gonna add a publish date to this. Again, we'll sort out the versioning later.
Okay. So now I could see I've got our kitchen sink page. We've got a bunch of different hero layouts. And one of the things that I noticed right away is, you know, if we've got more than two or three buttons, this kinda this design fails. Right?
It it goes off the the reservation, and this is kinda helpful for fixing that. Right? We may go in, let's just shrink this up a bit, and then we look at our button group. Cool. There's our button group.
We've got our container classes. Let's just add flex wrap here. And now we can see it's super nice to have these kitchen sink kind of components, but one of the great use cases here is just populating the sample data. Right? Is it our CRM?
We could have it populate a few sample records for us, or we could even have it generate a seed script for us, which puts us back into the next workflow for this. Alright. So one of the other workflows that is super nice with the MCP and your LLM is having it write scripts for you. This could be migrating from one CMS to another, in this case, Directus. That's a pattern that that our team has used locally with tools like Cloud Code or Cursor.
You know, there's a lot of things that need to be migrated. And MCP is is good at understanding and, you know, the context around the data, especially when you've given it the schema, but having an LLM move all the data one by one by brick by brick, token by token, is super inefficient. So, let's just have it write a script to load up a bunch of blog posts for us. Let's write a node script to use the Falso library is one that I like to generate a bunch of fake contacts and companies inside our directus instance. Alright.
So now what I'm gonna do, I'm just gonna copy the URL for Falso here or, gonna do that. Cool. And down here in the actual terminal, I'm just gonna go in and go ahead and install this library. Just get a little jump start. Cool.
Alright. So it looks like it is reading the package JSON. We should see that. It's gonna pick up our different collections. And what else?
Contacts and organizations is reading the schema for that, which is great. And we'll see if we can get it to output this script for us. Again, I this is a a more efficient way. It's more repeatable. So if you do need, like, highly deterministic output, this is, a one pattern that's worked really well for us.
Right? It looks like it's also doing a e n v example. Check if the direct Us SDK is installed. Cool. There's the seed data script.
We're probably gonna need to install the Directus SDK in the root as well. Looks like it's already taken care of that for us. Cool. We'll allow it to make those changes. We'll go ahead and run the installation script, And then we are going to need to do what?
Then we'll need to do the e and v variables. Right? PM PMI install. Let's see is what it's got for us as far as the seed data. Alright.
So different industries. We got the number of organizations, three organizations per contact. Okay. So it's actually picking this up from the directus.e n v. So we shouldn't really need to do anything other than just actually run this.
Right? Nodeseeddata.js. Created orgs is not iterable. Where is that coming from? Again, if you're gonna go straight vibe code on this, make sure that you are doing everything properly.
Let's fix the script. Yes. Alright. Looks like it is trying to make sure we're we're actually adding authentication, which is a good thing. Created orgs is not an iterable.
Okay. Just waiting on you, Claude. Just waiting on you. It is not getting the what what are we doing here? Try running it again.
There we go. Okay. So it said it has exceeded this successfully. We're gonna take a look, and boom. There's our seed data.
Right? So that was stupid quick, stupid easy to go in and add this data. And this is based on actual utility. Right? There's not a ton of crazy hype here.
These are actually just useful workflows in your day to day as you're building with Directus. You make sure you look to the community for more workflows. That is it for this video. Stay tuned for more in the MCP series.