DEV Community

Andrew Lee
Andrew Lee

Posted on • Edited on

27 1

Build and use your own MCP in Cursor in 5 minutes

1. Set up your project

mkdir cursor-mcp
cd cursor-mcp
npm init -y
npm pkg set type=module
Enter fullscreen mode Exit fullscreen mode

2. Install dependencies

npm install @modelcontextprotocol/sdk
Enter fullscreen mode Exit fullscreen mode

3. Create index.js

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "Hello World",
  version: "1.0.0"
});

server.tool("add",
  { a: z.number(), b: z.number() },
  async ({ a, b }) => ({
    content: [{ type: "text", text: String(a + b) }]
  })
);

const transport = new StdioServerTransport();
await server.connect(transport);

Enter fullscreen mode Exit fullscreen mode

4. Add to Cursor

Go to Settings, MCP, and add new MCP server.

Image description

The command is node /absolute/path/to/your/index.js. For example node /Users/andyrewlee/mcp-server/index.js.

5. Trigger your MCP by asking Cursor to add 24 and 81

In Agent mode prompt 8 + 24 and watch the add tool in your MCP get triggered.

Image description

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video

Top comments (7)

Collapse
 
andyrewlee profile image
Andrew Lee
Collapse
 
danishlyy profile image
danishlyy

"cursor-mcp": {
"command": "node",
"args": [
"/Users/liyongyong/10-yingmi_application/mcp/cursor-mcp/index.js"
]
}

hello I configed above code in my cursor, but the
Image description
I donnot know where has problems

Collapse
 
andyrewlee profile image
Andrew Lee

what happens if you run that in your terminal?

Collapse
 
danishlyy profile image
danishlyy

my cursor version is 0.47.8

Collapse
 
aniketsingh98571 profile image
Aniket Singh

Image description
For me, its throwing this error

Collapse
 
andyrewlee profile image
Andrew Lee • Edited

does it show you what values were passed in for a and b values? another way to debug would be to run npx @modelcontextprotocol/inspector@latest and see if you have the same error.

Collapse
 
dbenczcappie profile image
Daniel Bencz

Are you in Composer and in Agent mode?

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay