Build MCP Tools Using Project Context for Custom Cursor IDE Automation

Creating powerful and context-aware tools for Cursor IDE becomes straightforward when leveraging information directly from your current project. In this lesson, you'll learn how to build a custom MCP (Machine Command Protocol) tool that intelligently requests essential details—such as the current project path and conversation summaries—from your Cursor project.

Workflow demonstrated in this lesson:

  • Define MCP tool parameters to request specific project details.
  • Pass project path and conversation summaries into your MCP tool.
  • Automatically write or update files within your current project using these parameters.

Key benefits:

  • Automate tasks with precision based on your active project's context.
  • Simplify interactions by creating AI-driven CLI commands tailored to your needs.
  • Open endless possibilities for integrating external APIs and advanced automation.

Through this practical demonstration, you'll gain a versatile technique for enhancing your development workflow in Cursor IDE.

https://github.com/johnlindquist/mcp-cursor-tool-starter

Share with a coworker

Transcript

[00:00] I'm going to copy and paste the hello just right next to it, hit enter, and rename this to summarize. Then in my package.json file I'm going to come down to build and then start typing build summarize and it knows what I want. And we'll also add in a watch summarize and this is going to allow me to PNPM watch summarize. So anytime this file changes I'll hit save it's going to take this file and compile it into an MCP summarize file. So I was going to bring this into Composer but the tab suggestion looks good to me.

[00:32] I'll hit tab to accept that and then I actually do need the project path so I'll hit tab to accept that as well and then this can kind of see where I was going based on some other demos I was building out. Let me close this out so you can see it. We'll import path, we'll import read file, just hitting tab here and what we're building out is a tool called summarize with just a description of summarize the current conversation. And because we're going to write a file back to our project we're going to need the current project path that we're working in, And we're also going to need a conversation summary. So once these tools are called inside of Composer, it's going to essentially make a request to the AI to provide a project path, and to provide a conversation summary.

[01:12] So with the conversation summary, we can actually just write a file and hit tab to import write file and then we need to make sure we destructure conversation summary here. We'll hit tab so that the AI generated conversation summary gets passed in and is written to this summaries file. Now since this might not exist when I'm doing surgical edits like this. I don't often use Command-K, I'll use comments so that I can explain it in English in the comments and then I'm able to tweak the comment which would generate the file beneath it. So I hit tab like this rather than opening that Command-K prompt.

[01:47] That is a personal preference of mine. We'll hit tab to import that and then I'm gonna hit tab to see where it wants to jump to and this looks good. We want to send back that we updated the summaries path with the following content. So we can see that it built on the file change so we'll right-click MCP summarize, we'll copy the path, come over to a different project and go to our MCP and add a new MCP server. We'll call it MCP summarize, paste the command to run, hit add, And then based on this conversation I was having, I could say run the summarize tool.

[02:20] And I'm definitely experimenting to find the best pattern to use as far as naming tools, so that the AI will know explicitly to look for an MCP tool to always call it when requested, because it has to infer that Summarize means the tool. If you just give it a generic name like this, we'll give it a try anyway. Hit Enter. Alright it says it's going to run the Summarize tool. It hit the MCP tool and we can look and see what it generated.

[02:47] So you can see it found the project path, and then it found the conversation summary, which is a pretty long string here. And you will see it when you're calling a tool like this that requests a bunch of information, you'll see it sit on this for a while because the AI is actually generating text into here. So don't worry if it looks like it's doing some work. So then let's just check that it created a summaries file. Here's our new summaries file it created.

[03:11] And you can see that this conversation was summarized by the AI. And then in our MCP tool, you can see that it took that summary, it created a summaries file, and then it wrote the summary to the file and it returned the success message. And then you can see the success message in the tool call right here.