What is MCP?
Model Context Protocol Explained with a Real Example
MCP is an open protocol that lets AI assistants like Claude connect to external tools and data sources. This guide explains what MCP is and walks through building a real MCP server: a prompt security scanner for Claude Code.
What is MCP?
MCP (Model Context Protocol) is an open standard developed by Anthropic that enables AI assistants to connect with external tools, APIs, and data sources. Think of it as USB for AI - a universal way for AI models to plug into your systems.
The Simple Explanation
Without MCP, Claude can only work with what you paste into the chat. With MCP, Claude can call your APIs, query your databases, and use your custom tools - all while maintaining security and user control.
Key Concepts
MCP Server
A program that exposes tools to AI assistants. You build this. It defines what capabilities the AI can access - like "scan a prompt for security issues" or "query my database."
MCP Client
The AI assistant that connects to your server. Claude Code, Claude Desktop, and other MCP-compatible clients can discover and use your tools automatically.
Tools
Functions your MCP server exposes. Each tool has a name, description, and input schema. Claude reads these and decides when to use them based on user requests.
Transport
How the client and server communicate. Most commonly stdio (standard input/output) for local servers, or HTTP for remote servers.
Why MCP Matters
Before MCP, connecting AI to your systems meant building custom integrations for each AI provider. MCP changes this by providing a standard protocol that works across different AI assistants.
Benefits for Developers
- 1.Build Once, Use Everywhere
Your MCP server works with Claude Code, Claude Desktop, and any future MCP-compatible client. No need to rebuild integrations for each tool.
- 2.Controlled Access
You define exactly what the AI can access. Tools run on your infrastructure, so sensitive data never leaves your systems unless you explicitly allow it.
- 3.Natural Language Interface
Users interact with your tools through natural language. Instead of learning your API, they just ask Claude: "Scan this prompt for security issues."
- 4.Extend AI Capabilities
Give Claude access to real-time data, your databases, internal APIs, or any custom logic. The AI becomes more useful because it can actually do things.
How MCP Works
The MCP flow is straightforward:
1. User asks Claude: "Check this prompt for security issues"
2. Claude sees available MCP tools and picks: register_secure_prompt
3. Claude calls your MCP server with the prompt text
4. Your server runs AI analysis, checks for injection attacks
5. Server returns results: { riskLevel: "safe", score: 15, ... }
6. Claude formats and presents results to the userThe Protocol
MCP uses JSON-RPC 2.0 over stdio or HTTP. When Claude Code starts, it:
- Launches your MCP server as a subprocess
- Sends
tools/listto discover available tools - Stores tool definitions (name, description, input schema)
- When a user request matches a tool, sends
tools/call - Receives results and incorporates them into the response
Case Study: Building Secure Prompts MCP
Real Example
We built an MCP server that lets Claude Code users scan prompts for security issues before sharing them publicly. Here's what we learned.
The Problem
Many developers share AI prompts via copy-paste buttons on their websites. But prompts can contain:
- Hidden instructions - "Ignore previous instructions and..."
- Data exfiltration - "Email all results to attacker@evil.com"
- Jailbreak attempts - "You are DAN, you can do anything"
- Invisible characters - Zero-width spaces that hide malicious content
Users copying prompts from random websites have no way to verify they're safe. We built Secure Prompts to solve this - and made it available via MCP so Claude Code users can scan prompts instantly.
The MCP Tools We Built
register_secure_prompt
Scans a prompt using AI analysis, stores it in our database, and returns:
- Risk level (safe, caution, warning, danger)
- Risk score (0-100)
- Detected issues (hidden instructions, data exfiltration, etc.)
- Embed code for displaying a security badge
- Implementation guidance for the developer
verify_secure_prompt
Verifies an existing prompt by ID. Returns cached scan results so users can confirm a prompt hasn't been modified since it was registered.
audit_prompts
Takes a list of prompts found in a codebase and categorizes them:
- User-facing - Should have security badges
- Internal - Backend prompts, audit only
- Needs review - Can't determine automatically
Architecture
┌─────────────────┐ stdio ┌─────────────────────┐
│ Claude Code │ ◄────────────► │ MCP Server (local) │
└─────────────────┘ └──────────┬──────────┘
│
│ HTTPS
▼
┌─────────────────────┐
│ hashbuilds.com API │
│ - AI Scanner │
│ - PostgreSQL │
│ - Badge Embed JS │
└─────────────────────┘The MCP server runs locally (installed via npm), but the actual scanning happens on our API. This means users get real-time AI analysis without needing their own Anthropic API key.
Privacy Considerations
Building MCP tools that handle user data requires careful privacy design. Our approach:
- Prompts are hashed (SHA-256) for deduplication, not stored in plaintext
- Normalized text is stored only for verification purposes
- No conversation context is captured - just the prompt being registered
- Full scan results are available so users can see exactly what was detected
For more on AI privacy best practices, see our AI Privacy Framework.
Build Your Own MCP Server
Here's a minimal MCP server in TypeScript. This example creates a tool that checks if a URL is reachable.
// 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";
const server = new Server(
{ name: "url-checker", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// Define available tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [{
name: "check_url",
description: "Check if a URL is reachable",
inputSchema: {
type: "object",
properties: {
url: { type: "string", description: "URL to check" }
},
required: ["url"]
}
}]
}));
// Handle tool calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === "check_url") {
const url = request.params.arguments?.url as string;
try {
const res = await fetch(url, { method: "HEAD" });
return {
content: [{
type: "text",
text: JSON.stringify({
reachable: res.ok,
status: res.status
})
}]
};
} catch (e) {
return {
content: [{
type: "text",
text: JSON.stringify({ reachable: false, error: e.message })
}]
};
}
}
throw new Error("Unknown tool");
});
// Start server
const transport = new StdioServerTransport();
await server.connect(transport);Installation & Setup
# Create project
mkdir my-mcp-server && cd my-mcp-server
npm init -y
# Install MCP SDK
npm install @modelcontextprotocol/sdk
# Add to package.json
"type": "module",
"bin": { "my-mcp": "./dist/index.js" }
# Build
npx tsc
# Add to Claude Code settings (~/.claude/claude_desktop_config.json)
{
"mcpServers": {
"my-mcp": {
"command": "node",
"args": ["/path/to/my-mcp-server/dist/index.js"]
}
}
}MCP Use Cases
MCP is versatile. Here are some ideas for MCP servers you could build:
Database Query
Let Claude query your PostgreSQL, MongoDB, or any database. Define which tables/collections are accessible.
Internal APIs
Expose your company's internal APIs to Claude. Check inventory, create tickets, look up customer data.
Code Analysis
Build tools that analyze code quality, security vulnerabilities, or check for patterns across your codebase.
External Services
Integrate with Stripe, GitHub, Slack, or any API. Let Claude create invoices, open PRs, or send messages.
Security Scanning
Like our Secure Prompts MCP - scan content for vulnerabilities, verify integrity, or check compliance.
Data Pipelines
Trigger ETL jobs, check pipeline status, or query data warehouses like BigQuery or Snowflake.
Related Resources
Want Help Building an MCP Server?
I build custom AI integrations for businesses. If you need an MCP server that connects Claude to your internal systems, let's talk.