AI ToolsAI 개발 도구 마스터 · 2중급

MCP(Model Context Protocol) 입문 — AI에게 도구를 연결하는 표준

MCPModel Context ProtocolClaudeAI에이전트도구연동

MCP란 무엇인가?

MCP(Model Context Protocol)는 AI 모델이 외부 도구와 데이터에 접근하는 방식을 표준화한 오픈 프로토콜입니다. Anthropic이 2024년 말에 공개했으며, AI 에이전트 생태계의 "USB 포트"와 같은 역할을 합니다.


왜 MCP가 필요한가?

기존 방식의 문제

사용자: "우리 회사 매출 데이터 분석해줘"
AI: "죄송합니다. 저는 외부 데이터베이스에 접근할 수 없습니다.
     데이터를 복사해서 붙여넣어 주시겠어요?"

MCP 적용 후

사용자: "우리 회사 매출 데이터 분석해줘"
AI: [MCP: PostgreSQL 연결]
    [쿼리 실행: SELECT * FROM sales WHERE year = 2026]
    "2026년 1분기 매출이 전년 대비 23% 성장했습니다.
     특히 B2B 부문에서..."

MCP 핵심 개념

1. MCP 서버

외부 도구나 데이터를 Claude에 노출하는 서비스입니다.

// 간단한 MCP 서버 예시
import { MCPServer } from '@anthropic-ai/mcp';

const server = new MCPServer({
  name: 'company-data',
  version: '1.0.0',
});

// 도구 정의
server.addTool({
  name: 'get_sales_data',
  description: '회사 매출 데이터를 조회합니다',
  parameters: {
    year: { type: 'number', description: '조회 연도' },
    quarter: { type: 'number', description: '분기 (1-4)' },
  },
  handler: async ({ year, quarter }) => {
    const data = await db.query(`
      SELECT * FROM sales
      WHERE year = $1 AND quarter = $2
    `, [year, quarter]);
    return data;
  },
});

server.start();

2. MCP 클라이언트

Claude Code나 다른 AI 애플리케이션이 MCP 서버에 연결하는 방식입니다.

3. 리소스 (Resources)

AI가 참조할 수 있는 데이터입니다.

server.addResource({
  uri: 'company://docs/guidelines',
  name: '회사 코딩 가이드라인',
  mimeType: 'text/markdown',
  handler: async () => {
    return fs.readFile('./CODING_GUIDELINES.md', 'utf-8');
  },
});

4. 프롬프트 (Prompts)

재사용 가능한 프롬프트 템플릿입니다.

server.addPrompt({
  name: 'code_review',
  description: '코드 리뷰 요청',
  arguments: [
    { name: 'file_path', description: '리뷰할 파일 경로' }
  ],
  handler: async ({ file_path }) => ({
    messages: [{
      role: 'user',
      content: `다음 파일을 리뷰해주세요: ${file_path}
                회사 가이드라인을 참고해서 개선점을 제안해주세요.`
    }]
  }),
});

Claude Code에서 MCP 사용하기

1. MCP 서버 설정

~/.claude/settings.json:

{
  "mcpServers": {
    "company-db": {
      "command": "node",
      "args": ["./mcp-servers/company-db/index.js"],
      "env": {
        "DATABASE_URL": "postgresql://..."
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/mcp-server-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_..."
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/mcp-server-filesystem"],
      "args": ["--root", "/home/user/projects"]
    }
  }
}

2. 연결 확인

claude /mcp

# 출력:
# Connected MCP Servers:
# ✓ company-db (3 tools, 2 resources)
# ✓ github (5 tools)
# ✓ filesystem (4 tools)

3. 사용 예시

You: GitHub에서 최근 열린 이슈들을 확인하고,
     company-db에서 관련 고객 정보를 찾아줘

Claude: [MCP: github.list_issues]
        [MCP: company-db.search_customers]

        최근 3개 이슈를 확인했습니다:
        1. #142 결제 오류 - 고객: ABC Corp (VIP)
        2. #141 로그인 문제 - 고객: XYZ Inc (일반)
        ...

공식 MCP 서버 목록

Anthropic과 커뮤니티에서 제공하는 MCP 서버들:

서버설명설치
mcp-server-filesystem파일 시스템 접근npx @anthropic-ai/mcp-server-filesystem
mcp-server-githubGitHub API 연동npx @anthropic-ai/mcp-server-github
mcp-server-postgresPostgreSQL 쿼리npx @anthropic-ai/mcp-server-postgres
mcp-server-sqliteSQLite 데이터베이스npx @anthropic-ai/mcp-server-sqlite
mcp-server-slackSlack 메시지npx @anthropic-ai/mcp-server-slack
mcp-server-google-driveGoogle Drive 파일npx @anthropic-ai/mcp-server-gdrive
mcp-server-notionNotion 페이지npx @anthropic-ai/mcp-server-notion

커스텀 MCP 서버 만들기

프로젝트 설정

mkdir my-mcp-server && cd my-mcp-server
npm init -y
npm install @anthropic-ai/mcp zod

기본 구조

// index.ts
import { MCPServer, z } from '@anthropic-ai/mcp';

const server = new MCPServer({
  name: 'my-custom-server',
  version: '1.0.0',
});

// 날씨 정보 도구
server.addTool({
  name: 'get_weather',
  description: '특정 도시의 현재 날씨를 조회합니다',
  parameters: z.object({
    city: z.string().describe('도시 이름'),
  }),
  handler: async ({ city }) => {
    const response = await fetch(
      `https://api.weather.com/v1/current?city=${city}`
    );
    return response.json();
  },
});

// 서버 시작
server.start({ transport: 'stdio' });

테스트

# 로컬 테스트
npx @anthropic-ai/mcp-inspector ./index.ts

보안 고려사항

1. 권한 최소화

{
  "mcpServers": {
    "database": {
      "command": "...",
      "permissions": {
        "read": true,
        "write": false,
        "delete": false
      }
    }
  }
}

2. 환경 변수 관리

# .env 파일 사용 (Git 제외)
DATABASE_URL=postgresql://...
API_KEY=sk-...

# Claude 설정에서 참조
"env": {
  "DATABASE_URL": "${DATABASE_URL}"
}

3. 감사 로깅

server.use(async (ctx, next) => {
  console.log(`[${new Date().toISOString()}] Tool: ${ctx.tool}`);
  await next();
});

다음 단계

MCP를 이해했다면, 다음 편에서 Vibe Coding을 통해 AI와 자연스럽게 협업하는 워크플로우를 배워보겠습니다. 단순한 질문-응답을 넘어, AI를 진정한 페어 프로그래밍 파트너로 활용하는 방법을 알아봅니다.

궁금한 점이 있으신가요?

협업·의뢰는 아래로, 가벼운 소통은 인스타그램 @bluefox._.hi도 환영이에요.

비용이 궁금하면 외주 계산기로 먼저 확인해보세요.