Introduction to MCP: A Beginner's Quickstart Guide

Anis MarrouchiAI Bot
By Anis Marrouchi & AI Bot ·

Loading the Text to Speech Audio Player...

Ready to connect AI to your data? This quickstart will have you building your first MCP server in just 15 minutes. No prior MCP experience needed!

What You'll Learn

In this beginner-friendly tutorial, you will:

  • Understand what MCP is and why it matters
  • Set up a complete MCP development environment
  • Build your first MCP server from scratch
  • Connect your server to an AI application

Let's get started!


Prerequisites

Before diving in, make sure you have:

  • Node.js 18+ installed (download here)
  • npm or pnpm package manager
  • Basic TypeScript/JavaScript knowledge (variables, functions, async/await)
  • A code editor (VS Code recommended)
  • Terminal/Command line familiarity

No prior MCP experience is required. We'll explain everything step by step.


What is MCP?

The Model Context Protocol (MCP) is an open protocol developed by Anthropic that standardizes how AI applications connect to external data sources and tools.

Think of MCP as a universal adapter for AI:

  • Just like USB-C connects your devices to any compatible peripheral
  • MCP connects AI models to any compatible data source or tool

Why Use MCP?

Without MCP, connecting an AI to your data requires custom code for each integration. With MCP:

Without MCPWith MCP
Custom code for each AI providerOne standard protocol
Tight coupling between AI and toolsModular, reusable servers
Security varies by implementationBuilt-in security patterns
Hard to switch AI providersEasy provider switching

MCP Architecture Overview

MCP uses a client-server model:

[AI Application] <---> [MCP Client] <---> [MCP Server] <---> [Your Data/Tools]
  • MCP Server: Exposes tools and data to AI applications
  • MCP Client: Lives in the AI application, communicates with servers
  • Tools: Functions your AI can call (fetch data, perform actions)

For a deeper dive into MCP concepts, see our comprehensive MCP guide.


Step 1: Project Setup

Let's create your first MCP server. Open your terminal and run:

# Create project directory
mkdir mcp-hello-world
cd mcp-hello-world
 
# Initialize Node.js project
npm init -y

Install the required dependencies:

# Install MCP SDK and Zod for validation
npm install @modelcontextprotocol/sdk zod
 
# Install TypeScript development dependencies
npm install -D typescript @types/node

Step 2: Configure TypeScript

Create a tsconfig.json file in your project root:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "Node16",
    "moduleResolution": "Node16",
    "outDir": "./build",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "declaration": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

Update your package.json to include the build script and module type:

{
  "name": "mcp-hello-world",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "build": "tsc",
    "start": "node build/index.js"
  },
  "dependencies": {
    "@modelcontextprotocol/sdk": "^0.5.0",
    "zod": "^3.22.0"
  },
  "devDependencies": {
    "@types/node": "^20.0.0",
    "typescript": "^5.0.0"
  }
}

Create the source directory:

mkdir src

Step 3: Build Your First MCP Server

Create the main server file at src/index.ts:

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
  CallToolRequestSchema,
  ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
 
// Define input validation schema for our tool
const GreetingSchema = z.object({
  name: z.string().describe("The name of the person to greet"),
});
 
// Create the MCP server instance
const server = new Server(
  {
    name: "hello-world-server",
    version: "1.0.0",
  },
  {
    capabilities: {
      tools: {},
    },
  }
);
 
// Handler: List available tools
// This tells AI clients what tools are available
server.setRequestHandler(ListToolsRequestSchema, async () => {
  return {
    tools: [
      {
        name: "greet",
        description: "Generate a friendly greeting for a person",
        inputSchema: {
          type: "object",
          properties: {
            name: {
              type: "string",
              description: "The name of the person to greet",
            },
          },
          required: ["name"],
        },
      },
      {
        name: "get_current_time",
        description: "Get the current date and time",
        inputSchema: {
          type: "object",
          properties: {},
          required: [],
        },
      },
    ],
  };
});
 
// Handler: Execute tool calls
// This runs when the AI wants to use a tool
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;
 
  if (name === "greet") {
    // Validate the input
    const { name: personName } = GreetingSchema.parse(args);
 
    // Generate the greeting
    const greeting = `Hello, ${personName}! Welcome to the world of MCP. 🎉`;
 
    return {
      content: [
        {
          type: "text",
          text: greeting,
        },
      ],
    };
  }
 
  if (name === "get_current_time") {
    const now = new Date();
    const timeString = now.toLocaleString("en-US", {
      weekday: "long",
      year: "numeric",
      month: "long",
      day: "numeric",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit",
      timeZoneName: "short",
    });
 
    return {
      content: [
        {
          type: "text",
          text: `The current time is: ${timeString}`,
        },
      ],
    };
  }
 
  throw new Error(`Unknown tool: ${name}`);
});
 
// Main function to start the server
async function main() {
  // Create a stdio transport (communicates via stdin/stdout)
  const transport = new StdioServerTransport();
 
  // Connect the server to the transport
  await server.connect(transport);
 
  // Log startup (to stderr so it doesn't interfere with protocol)
  console.error("MCP Hello World Server is running!");
}
 
// Start the server
main().catch((error) => {
  console.error("Fatal error:", error);
  process.exit(1);
});

Understanding the Code

Let's break down what each part does:

  1. Server Creation: We create a new MCP server with a name and version
  2. ListToolsRequestSchema: Tells AI clients what tools are available
  3. CallToolRequestSchema: Handles actual tool execution when AI calls them
  4. StdioServerTransport: Communication layer using stdin/stdout

Step 4: Build and Test

Compile your TypeScript code:

npm run build

You should see a build/index.js file created. Your server is ready!

Quick Test

To verify it works, you can run it directly (it will wait for MCP protocol messages):

# Run the server (press Ctrl+C to exit)
npm start

You should see: MCP Hello World Server is running!


Step 5: Connect to an AI Application

Now let's connect your server to an AI application. The most common way is through Claude Desktop.

Option A: Claude Desktop Configuration

  1. Open Claude Desktop settings
  2. Navigate to the MCP servers configuration
  3. Add your server:
{
  "mcpServers": {
    "hello-world": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-hello-world/build/index.js"]
    }
  }
}
  1. Restart Claude Desktop
  2. Ask Claude to "greet John" or "what time is it"

Option B: Programmatic Client

Create a simple test client in src/client.ts:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { spawn } from "child_process";
 
async function testServer() {
  // Spawn the server process
  const serverProcess = spawn("node", ["build/index.js"], {
    stdio: ["pipe", "pipe", "inherit"],
  });
 
  // Create client transport
  const transport = new StdioClientTransport({
    reader: serverProcess.stdout!,
    writer: serverProcess.stdin!,
  });
 
  // Create and connect client
  const client = new Client({
    name: "test-client",
    version: "1.0.0",
  }, {
    capabilities: {},
  });
 
  await client.connect(transport);
 
  // List available tools
  console.log("Available tools:");
  const tools = await client.listTools();
  tools.tools.forEach((tool) => {
    console.log(`  - ${tool.name}: ${tool.description}`);
  });
 
  // Call the greet tool
  console.log("\nCalling greet tool:");
  const greetResult = await client.callTool({
    name: "greet",
    arguments: { name: "Developer" },
  });
  console.log("  Result:", greetResult.content[0].text);
 
  // Call the time tool
  console.log("\nCalling get_current_time tool:");
  const timeResult = await client.callTool({
    name: "get_current_time",
    arguments: {},
  });
  console.log("  Result:", timeResult.content[0].text);
 
  // Cleanup
  await client.close();
  serverProcess.kill();
}
 
testServer().catch(console.error);

Run the test:

# Add client script to package.json first
npm run build
npx tsx src/client.ts

What's Next?

Congratulations! You've built your first MCP server. Here are some next steps:

Expand Your Server

Add more useful tools:

  • File system access
  • API integrations
  • Database queries
  • Custom business logic

Learn More

Explore the Ecosystem


Quick Reference

Project Structure

mcp-hello-world/
├── src/
│   └── index.ts      # Server code
├── build/
│   └── index.js      # Compiled output
├── package.json
└── tsconfig.json

Key Concepts

ConceptDescription
ServerExposes tools and data to AI
ToolA function the AI can call
TransportCommunication layer (stdio, HTTP)
SchemaDefines tool inputs and outputs

Common Commands

# Build the project
npm run build
 
# Run the server
npm start
 
# Watch mode (requires tsx)
npx tsx --watch src/index.ts

Troubleshooting

Build errors? Make sure you're using Node.js 18+ and have installed all dependencies.

Server not responding? Check that the path in your AI client configuration is absolute and correct.

Tools not showing? Restart your AI application after updating the server configuration.


Summary

In this quickstart, you learned:

  1. What MCP is - A universal protocol for connecting AI to tools and data
  2. How to set up - Project structure, TypeScript configuration, dependencies
  3. How to build - Creating a server with tools that AI can call
  4. How to connect - Integrating with Claude Desktop or programmatic clients

You now have the foundation to build powerful AI integrations using MCP. Start experimenting and see what you can create!


Reference: This tutorial follows the official Model Context Protocol documentation. For more advanced patterns and real-world examples, explore our MCP content hub.


Want to read more tutorials? Check out our latest tutorial on Building a Custom Code Interpreter for LLM Agents.

Discuss Your Project with Us

We're here to help with your web development needs. Schedule a call to discuss your project and how we can assist you.

Let's find the best solutions for your needs.