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

Athreya aka Maneshwar @lovestaco

About: Technical Writer | 200k+ Reads | i3 x Mint | Learning, building, improving, writing :)

Joined:
Jan 5, 2023

Building MCP Tools and Running Them in Cursor Editor

Publish Date: Apr 10
44 7

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.

Comments 7 total

  • Anmol Baranwal
    Anmol BaranwalApr 10, 2025

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

  • Serhiy
    SerhiyApr 13, 2025

    thanks!

  • Dan Edens
    Dan EdensApr 13, 2025

    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

    • Athreya aka Maneshwar
      Athreya aka ManeshwarApr 14, 2025

      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

  • Nevo David
    Nevo DavidApr 13, 2025

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

    • Athreya aka Maneshwar
      Athreya aka ManeshwarApr 14, 2025

      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?

Add comment