← Back to Guides
GuideIntermediate

Model Context Protocol: The Universal AI Integration Layer

MCP is becoming the standard for connecting AI assistants to tools, databases, and APIs. This guide explains the protocol from first principles and walks through building your first MCP server.

Apr 25, 2026 20 min
MCPTypeScriptintermediate

Model Context Protocol: The Universal AI Integration Layer

Model Context Protocol (MCP) is an open standard that defines how AI assistants connect to external tools, data sources, and APIs. Think of it as USB-C for AI — a single standard that works everywhere.

Why MCP Matters

Before MCP, every AI tool had its own bespoke plugin system. Claude had plugins, ChatGPT had plugins, Cursor had extensions. Each was incompatible with the others, and every developer had to integrate the same tools multiple times.

MCP solves this with a universal client-server protocol:

  • MCP Server — a process that exposes tools, resources, and prompts
  • MCP Client — an AI assistant that can discover and call those tools
  • Transport — stdio (local) or HTTP/SSE (remote)
  • Core Concepts

    Tools

    Functions the AI can call. They have a name, description, and JSON Schema input definition.

    Resources

    Data the AI can read — files, database rows, API responses. Identified by URI.

    Prompts

    Pre-defined prompt templates that users can invoke.

    Your First MCP Server

    Install the SDK:

    npm install @modelcontextprotocol/sdk

    Create server.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';

    const server = new Server(

    { name: 'my-server', version: '1.0.0' },

    { capabilities: { tools: {} } }

    );

    // List available tools

    server.setRequestHandler(ListToolsRequestSchema, async () => ({

    tools: [{

    name: 'get_weather',

    description: 'Get current weather for a city',

    inputSchema: {

    type: 'object',

    properties: {

    city: { type: 'string', description: 'City name' }

    },

    required: ['city']

    }

    }]

    }));

    // Handle tool calls

    server.setRequestHandler(CallToolRequestSchema, async (request) => {

    if (request.params.name === 'get_weather') {

    const { city } = request.params.arguments as { city: string };

    // Call your weather API here

    const weather = await fetchWeather(city);

    return { content: [{ type: 'text', text: JSON.stringify(weather) }] };

    }

    throw new Error('Tool not found');

    });

    // Start server

    const transport = new StdioServerTransport();

    await server.connect(transport);

    Connect to Claude Desktop

    Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

    {

    "mcpServers": {

    "my-server": {

    "command": "node",

    "args": ["/path/to/dist/server.js"]

    }

    }

    }

    Restart Claude Desktop. Your tools are now available.

    Real-World Use Cases

  • Database MCP — let Claude query your PostgreSQL directly
  • Git MCP — let Claude read commits, diffs, and PRs
  • Slack MCP — Claude reads and sends messages in your workspace
  • Filesystem MCP — Claude reads and writes files with explicit permissions
  • Security Considerations

    MCP servers execute with real permissions. Always:

  • Scope permissions to minimum required
  • Validate and sanitize all inputs
  • Log all tool calls
  • Never expose credentials in tool responses
  • Next Steps

  • Browse the MCP server registry
  • Read the full MCP specification
  • Explore CoAgent Studio for visual MCP workflow design