level 13 / mcp-fundamentals

MCP Fundamentals

Understand the Model Context Protocol — how LLMs communicate with tools and external systems.

What Is MCP?

The Model Context Protocol (MCP) is an open standard that lets AI models (like Claude) communicate with external tools, data sources, and environments via a structured JSON-RPC protocol.

Think of MCP as a USB-C standard for AI integrations: instead of every AI tool building custom integrations with every service, MCP provides one universal interface.

MCP Architecture

MCP Primitives

MCP servers expose three types of primitives:

PrimitiveDescriptionExample
ToolsFunctions the LLM can callbrowser_click, run_sql, git_commit
ResourcesData the LLM can readFile contents, DB schema, API docs
PromptsReusable prompt templates”Debug this test failure”, “Generate API test”

MCP Server Structure

// Simple MCP server (TypeScript)
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server(
  { name: 'my-test-tools', version: '1.0.0' },
  { capabilities: { tools: {} } }
);

// Register a tool
server.setRequestHandler('tools/list', async () => ({
  tools: [{
    name: 'run_playwright_test',
    description: 'Run a specific Playwright test file',
    inputSchema: {
      type: 'object',
      properties: {
        testFile: { type: 'string', description: 'Path to test file' },
        grep: { type: 'string', description: 'Test name filter' },
      },
      required: ['testFile'],
    },
  }],
}));

server.setRequestHandler('tools/call', async (request) => {
  if (request.params.name === 'run_playwright_test') {
    const { testFile, grep } = request.params.arguments as any;
    const args = ['npx', 'playwright', 'test', testFile];
    if (grep) args.push('--grep', grep);

    const result = execSync(args.join(' '), { encoding: 'utf8' });
    return { content: [{ type: 'text', text: result }] };
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);

Claude Code MCP Configuration

// ~/.claude/settings.json (or project .claude/settings.json)
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {
        "PLAYWRIGHT_HEADLESS": "false"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
    }
  }
}

Transport Types

TransportHow it worksUse case
stdioServer reads/writes stdin/stdoutLocal tools (most common)
HTTP + SSEHTTP server with Server-Sent EventsRemote/web tools
WebSocketPersistent bidirectional connectionReal-time tools

MCP Security Model

  • Servers run as separate processes — LLM cannot execute arbitrary code directly
  • Tool calls require explicit user approval in interactive hosts
  • Servers define allowed operations via capability declarations
  • Network access controlled by transport configuration

Why MCP Matters for Test Automation

MCP enables AI agents to:

  1. Inspect live apps — navigate, click, read DOM via Playwright MCP
  2. Read/write test files — filesystem MCP for code generation
  3. Query databases — database MCP for test data setup
  4. Interact with CI — GitHub MCP to open PRs, read test results

Result: an AI that can autonomously write a test, run it, read the failure, fix it, and open a PR — all through standard MCP tool calls.