Skip to main content

Danielle Hoopes11 pieces · 11 min

MCP Tutorial: Build AI Agents That Actually Do Things (2026 Guide)

Tags: ai, mcp, model-context-protocol, ai-agents, tutorial

If you've been following AI news, you've heard about MCP (Model Context Protocol) - the open standard that lets AI models connect to external tools, databases, and APIs.

Anthropic created it. OpenAI adopted it. Microsoft embraced it. It was just donated to the Linux Foundation's new Agentic AI Foundation.

MCP is being called "USB-C for AI" - a universal way for AI agents to plug into anything.

This tutorial shows you how to use it.

01 / 11 · 1 min

What is MCP?

Before MCP, connecting an AI to external tools was a mess:

  • Every AI provider had different APIs
  • Every tool needed custom integration code
  • Agents couldn't easily share capabilities

MCP standardizes this. One protocol, universal compatibility.

Think of it like this:

  • Before MCP: Every phone needed a different charger
  • After MCP: USB-C works with everything
Keep reading → Why Should You Care?

02 / 11 · 1 min

Why Should You Care?

MCP unlocks agentic AI - AI that doesn't just chat, but takes actions:

  • Query your database and generate reports
  • Create GitHub issues from bug descriptions
  • Send Slack messages based on events
  • Control smart home devices
  • Execute code and return results

This is the difference between a chatbot and an AI assistant that actually does things.

Keep reading → Prerequisites

03 / 11 · 1 min

Prerequisites

You'll need:

  • Node.js 18+ installed
  • An Anthropic API key (get one here)
  • Basic JavaScript/TypeScript knowledge
Keep reading → Step 1: Install the MCP SDK

04 / 11 · 1 min

Step 1: Install the MCP SDK

mkdir my-mcp-agent
cd my-mcp-agent
npm init -y
npm install @anthropic-ai/sdk @modelcontextprotocol/sdk
Keep reading → Step 2: Create a Simple MCP Server

05 / 11 · 1 min

Step 2: Create a Simple MCP Server

MCP servers expose "tools" that AI can use. Let's create one that checks the weather:

// weather-server.js
import { MCPServer } from '@modelcontextprotocol/sdk';
 
const server = new MCPServer({
  name: 'weather-server',
  version: '1.0.0'
});
 
// Define a tool the AI can use
server.addTool({
  name: 'get_weather',
  description: 'Get current weather for a city',
  parameters: {
    type: 'object',
    properties: {
      city: { type: 'string', description: 'City name' }
    },
    required: ['city']
  },
  handler: async ({ city }) => {
    // In production, call a real weather API
    const weather = {
      city,
      temp: Math.floor(Math.random() * 30) + 40,
      condition: ['sunny', 'cloudy', 'rainy'][Math.floor(Math.random() * 3)]
    };
    return JSON.stringify(weather);
  }
});
 
server.start();
console.log('Weather MCP server running...');
Keep reading → Step 3: Connect Claude to Your Server

06 / 11 · 1 min

Step 3: Connect Claude to Your Server

// agent.js
import Anthropic from '@anthropic-ai/sdk';
 
const client = new Anthropic();
 
async function runAgent(userMessage) {
  const response = await client.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    tools: [
      {
        name: 'get_weather',
        description: 'Get current weather for a city',
        input_schema: {
          type: 'object',
          properties: {
            city: { type: 'string', description: 'City name' }
          },
          required: ['city']
        }
      }
    ],
    messages: [{ role: 'user', content: userMessage }]
  });
 
  // Handle tool calls
  for (const block of response.content) {
    if (block.type === 'tool_use') {
      console.log(`AI wants to use: ${block.name}`);
      console.log(`With input: ${JSON.stringify(block.input)}`);
      // Call your MCP server here and return results
    }
  }
 
  return response;
}
 
// Test it
runAgent("What's the weather like in Denver?");
Keep reading → Security Considerations

07 / 11 · 1 min

Security Considerations

MCP gives AI real power. With that comes risk:

  1. Validate All Inputs - Don't trust AI-generated queries blindly
  2. Use Read-Only Where Possible - Don't give AI write access unless necessary
  3. Rate Limit Everything - Prevent runaway costs and abuse
  4. Log All Tool Calls - Maintain an audit trail
Keep reading → Real-World MCP Servers

08 / 11 · 1 min

Real-World MCP Servers

The community is building MCP servers for everything:

Server What It Does
mcp-server-sqlite Query SQLite databases
mcp-server-github Full GitHub integration
mcp-server-slack Send/read Slack messages
mcp-server-filesystem Read/write files
mcp-server-puppeteer Browser automation
Keep reading → Hosting Your MCP Agent

09 / 11 · 1 min

Hosting Your MCP Agent

For production, a $6/month DigitalOcean droplet handles most MCP workloads:

git clone https://github.com/you/my-mcp-agent
cd my-mcp-agent
npm install
pm2 start agent.js --name mcp-agent
Keep reading → What's Next?

10 / 11 · 1 min

What's Next?

MCP is still early but moving fast. The AI agents of 2026 won't just answer questions - they'll do your work. MCP is how they connect to everything.

Keep reading → Resources

11 / 11 · 1 min

Resources