DEV Community

Cover image for Building MCP Tools and Running Them in Cursor Editor
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on

24 5 5 5 5

Building MCP Tools and Running Them in Cursor Editor

Ever wanted to build a tool you could test and run directly in Cursor, with zero frontend, just TypeScript, and a sprinkle of MCP magic?

Let’s go from zero to “Hey, this runs inside Cursor!” in a few minutes using Model Context Protocol (MCP) and the official SDK.

Setup

Start with a fresh project (or clone an existing one). The setup uses:

package.json overview:

{
  "name": "mcp-tools",
  "type": "module",
  "dependencies": {
    "@modelcontextprotocol/sdk": "^1.4.0",
    "zod": "^3.24.1"
  },
  "scripts": {
    "build": "pnpm build:all",
    "build:hello": "mkdir -p bin && bun build src/hello.ts --compile --minify --sourcemap --outfile bin/mcp-hello",
    "build:weather": "mkdir -p bin && bun build src/weather.ts --compile --minify --sourcemap --outfile bin/mcp-weather"
  }
}
Enter fullscreen mode Exit fullscreen mode

Install dependencies:

pnpm install
Enter fullscreen mode Exit fullscreen mode

Example Tool: Weather Alerts

Create your first tool in src/weather.ts:

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

// Create an MCP server instance
const server = new McpServer({
    name: "weather-tool",
    version: "1.0.0",
});

// Register a weather alerts tool
server.tool(
    "get_alerts",
    "Get weather alerts for a state",
    {
        state: z.string().min(2).max(2).describe("Two-letter state code (e.g. CA, NY)"),
    },
    async ({ state }) => {
        // In a real implementation, this would call a weather API
        // For this example, we'll just return mock data
        const mockAlerts = {
            "CA": ["Wildfire warning in Northern California", "Heat advisory in Southern California"],
            "NY": ["Flood warning in Western New York", "Thunderstorm watch in NYC metro area"],
            "FL": ["Hurricane watch along the coast", "Flood warning in South Florida"],
        };

        const alerts = (mockAlerts as Record<string, string[]>)[state] || ["No current alerts for this state"];

        return {
            content: [
                {
                    type: "text",
                    text: `Weather Alerts for ${state}:\n${alerts.map(alert => `- ${alert}`).join('\n')}`,
                },
            ],
        };
    }
);

// Start the server using stdio transport
async function main() {
    const transport = new StdioServerTransport();
    await server.connect(transport);
    console.error("Weather MCP Tool running on stdio");
}

main().catch((error) => {
    console.error("Fatal error:", error);
    process.exit(1);
}); 
Enter fullscreen mode Exit fullscreen mode

This exmaple has hardcoded data mockAlerts. You can use your API here.

Build It

To compile the tool into a native executable using Bun:

pnpm build:weather
Enter fullscreen mode Exit fullscreen mode

Check the output:

./bin/mcp-weather
Enter fullscreen mode Exit fullscreen mode

You should see logs like:

Weather MCP Tool running on stdio
Enter fullscreen mode Exit fullscreen mode

Image description

Setup for cursor

  1. Open Cursor Settings (Ctrl+Shift+j)
  2. Select Features
  3. Click on Add new MCP server
  4. Give the full path of the binary Ex: /home/lovestaco/pers/mcp-example-weather-hello-blog/bin/mcp-weather

Image description

How to run your MCP tool in Cursor:

  1. Go to Cursor's chat panel.
  2. Ask your query

Image description

Image description

Hot Reload (Optional)

For faster dev loops:

pnpm watch:weather
Enter fullscreen mode Exit fullscreen mode

Now any change to src/weather.ts will rebuild the binary automatically.

TL;DR Commands

pnpm build         # build all tools
pnpm build:weather # build weather tool

# Run the binary
./bin/mcp-weather

# Watch mode (auto-rebuild)
pnpm watch:weather
Enter fullscreen mode Exit fullscreen mode

Wrapping Up

With just a bit of TypeScript and MCP SDK, you can turn any script or tool into something Cursor can interact with directly.

It’s like CLI meets LLM tooling — with schema validation, zero boilerplate, and instant feedback inside your editor.

Want to build more tools? Just add new .ts files, register new server.tool() calls, and compile.

Cursor will treat them like first-class AI copilots.

Full source code available here: lovestaco/mcp-example-weather-hello-blog

I picked this up while exploring courses on Egghead. Checkout egghead's other courses on MCP [ 1, 2, 3]


I’ve been actively working on a super-convenient tool called LiveAPI.

LiveAPI helps you get all your backend APIs documented in a few minutes

With LiveAPI, you can quickly generate interactive API documentation that allows users to execute APIs directly from the browser.

image

If you’re tired of manually creating docs for your APIs, this tool might just make your life easier.

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (7)

Collapse
 
anmolbaranwal profile image
Anmol Baranwal

Super useful. Cursor recently updated the method and it's now using npx command. I believe it's much better in terms of configuration.

Collapse
 
lovestaco profile image
Athreya aka Maneshwar • Edited

Thanks @anmolbaranwal
Got it, will look into it.

Collapse
 
nevodavid profile image
Nevo David

Amazing overview of building tools with MCP! Which aspects of MCP do you find most versatile for developers?

Collapse
 
lovestaco profile image
Athreya aka Maneshwar

Appreciate it @nevodavid !

Honestly, the best part is how chill it is to spin up tools, just TypeScript + Zod and you're good.

No crazy setup, and plugging them into Cursor is basically drop and go.
I felt it was super easy to experiment.

Are you thinking of building something with it?

Collapse
 
serhiyandryeyev profile image
Serhiy

thanks!

Collapse
 
danedens profile image
Dan Edens

I'm going to write an mcp server that pastes into the cursor question bar, and I'm going to have it ask itself the question as the 25. lol call it sonnet-2.7-MIN

Collapse
 
lovestaco profile image
Athreya aka Maneshwar

LOL I’d pay to see that in action, sonnet-2.7-MIN, the existential AI loop.

Like an echo-chamber as a feature xD

Jetbrains Survey

Calling all developers!

Participate in the Developer Ecosystem Survey 2025 and get the chance to win a MacBook Pro, an iPhone 16, or other exciting prizes. Contribute to our research on the development landscape.

Take the survey

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay