Documentation
/

Introduction

Introduction

Create your first MCP server in minutes with ModelFetch's CLI tools. This guide will walk you through setting up a new project, understanding the structure, and running your server locally.

Step 1: Create Your MCP Server

Use the create-modelfetch CLI to scaffold a new MCP server project:

npx create-modelfetch my-mcp-server

This command will create a new directory with your project name, scaffold the project structure, and install all necessary dependencies automatically.

What happens during creation:

Step 2: Navigate to Your Project

cd my-mcp-server

Step 3: Understanding the Project Structure

Your new MCP server project will have this structure:

my-mcp-server/
├── src/
│   ├── index.ts          # Your MCP server implementation
│   └── env.d.ts          # TypeScript environment declarations
├── package.json          # Dependencies and scripts
├── tsconfig.json         # TypeScript configuration
└── .gitignore           # Git ignore patterns

Key files explained:

Step 4: Examine the Example Code

The generated src/index.ts file contains a complete example MCP server:

The src/index.ts file:

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

export default function createMcpServer({ implementation }: Options) {
  const mcpServer = new McpServer(implementation);

  // Example tool: roll a dice
  mcpServer.tool(
    "roll_dice",
    "Rolls an N-sided dice",
    { sides: z.number().int().min(2) },
    ({ sides }) => {
      const value = 1 + Math.floor(Math.random() * sides);
      return {
        content: [{
          type: "text",
          text: `🎲 You rolled a ${value}!`
        }]
      };
    },
  );

  return mcpServer;
}

The src/env.d.ts file:

/// <reference types="@modelfetch/node" />

declare namespace NodeJS {
  interface ProcessEnv {
    readonly PORT?: string;
  }
}

Step 5: Start Development Server

Start the development server to test your MCP server locally:

npm run dev

What happens in development mode:

Step 6: Test Your MCP Server

Once your development server is running, you can test your MCP server by connecting it to AI clients. Your server is available at http://localhost:33333/mcp and ready for connections.

Here are some popular ways to test your MCP server:

MCP Inspector (recommended)

A dedicated testing tool with an intuitive graphical interface:

npx -y @modelcontextprotocol/inspector@latest

AI Editors (Cursor, VS Code, etc.)

Add to your MCP configuration file:

{
  "mcpServers": {
    "my-mcp-server": {
      "url": "http://localhost:33333/mcp"
    }
  }
}

Next Steps

Congratulations! You now have a working MCP server. Here's what you can do next: