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:
| Primitive | Description | Example |
|---|---|---|
| Tools | Functions the LLM can call | browser_click, run_sql, git_commit |
| Resources | Data the LLM can read | File contents, DB schema, API docs |
| Prompts | Reusable 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
| Transport | How it works | Use case |
|---|---|---|
| stdio | Server reads/writes stdin/stdout | Local tools (most common) |
| HTTP + SSE | HTTP server with Server-Sent Events | Remote/web tools |
| WebSocket | Persistent bidirectional connection | Real-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:
- Inspect live apps — navigate, click, read DOM via Playwright MCP
- Read/write test files — filesystem MCP for code generation
- Query databases — database MCP for test data setup
- 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.