AIMCPLLMAI AgentClaudeAPI

MCP (Model Context Protocol) 가이드 — 개념부터 실전 사용법까지

Model Context Protocol(MCP)이 무엇인지, 왜 등장했는지, 그리고 실제 프로젝트에서 어떻게 활용하는지 코드와 함께 설명합니다.

VWV2026-04-015분 읽기

MCP란 무엇인가?

Model Context Protocol(MCP) 은 Anthropic이 2024년 공개한 오픈 표준으로, AI 모델(LLM)과 외부 도구·데이터 소스 사이의 표준화된 통신 인터페이스를 정의합니다. USB-C가 다양한 장치를 하나의 규격으로 연결하듯, MCP는 Claude·GPT 등 다양한 LLM이 동일한 방식으로 외부 시스템과 대화할 수 있게 해줍니다.

등장 배경

기존에는 LLM에 외부 도구를 연결하려면 모델마다 다른 형식의 Function Calling / Tool Use API를 직접 구현해야 했습니다. 이로 인해 다음 문제가 발생했습니다.

문제 내용
파편화 모델마다 다른 도구 연결 방식
재사용 불가 같은 기능을 모델별로 중복 구현
보안 불일치 인증·권한 처리 방식이 제각각
유지보수 부담 API 변경 시 연결된 모든 코드 수정 필요

MCP는 이를 하나의 표준으로 해결합니다.


MCP 핵심 구조

MCP는 클라이언트-서버 아키텍처를 따릅니다.

┌─────────────────┐        MCP 프로토콜        ┌─────────────────┐
│   MCP Client    │ ◄─────────────────────────► │   MCP Server    │
│  (Claude, IDE)  │   JSON-RPC 2.0 over stdio   │ (DB, API, Tool) │
└─────────────────┘                              └─────────────────┘

주요 개념 3가지

개념 역할 예시
Tools LLM이 호출할 수 있는 함수 파일 읽기, DB 쿼리, API 호출
Resources LLM이 참조할 수 있는 데이터 문서, 이미지, 로그
Prompts 재사용 가능한 프롬프트 템플릿 코드 리뷰 지시문

MCP 서버 직접 만들기 (Python)

1. 설치

pip install mcp

2. 간단한 MCP 서버 — 파일 읽기 도구

# file_server.py
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, TextContent
import asyncio, pathlib

app = Server("file-reader")

@app.list_tools()
async def list_tools() -> list[Tool]:
    return [
        Tool(
            name="read_file",
            description="로컬 파일의 내용을 읽어 반환합니다.",
            inputSchema={
                "type": "object",
                "properties": {
                    "path": {"type": "string", "description": "읽을 파일 경로"}
                },
                "required": ["path"]
            }
        )
    ]

@app.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
    if name == "read_file":
        content = pathlib.Path(arguments["path"]).read_text(encoding="utf-8")
        return [TextContent(type="text", text=content)]
    raise ValueError(f"Unknown tool: {name}")

async def main():
    async with stdio_server() as streams:
        await app.run(*streams, app.create_initialization_options())

if __name__ == "__main__":
    asyncio.run(main())

3. Claude Desktop에 등록

~/Library/Application Support/Claude/claude_desktop_config.json (macOS 기준):

{
  "mcpServers": {
    "file-reader": {
      "command": "python",
      "args": ["/path/to/file_server.py"]
    }
  }
}

등록 후 Claude Desktop을 재시작하면 Claude가 read_file 도구를 사용할 수 있게 됩니다.


MCP 클라이언트에서 서버 연결하기 (TypeScript)

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const transport = new StdioClientTransport({
  command: "python",
  args: ["file_server.py"],
});

const client = new Client({ name: "my-app", version: "1.0.0" }, {});
await client.connect(transport);

// 사용 가능한 도구 목록 조회
const { tools } = await client.listTools();
console.log(tools.map(t => t.name)); // ["read_file"]

// 도구 호출
const result = await client.callTool({
  name: "read_file",
  arguments: { path: "./README.md" },
});
console.log(result.content[0].text);

실전 활용 사례

사례 MCP 서버 역할
코드 리뷰 자동화 GitHub API 연결 → PR diff 읽기
보안 취약점 분석 CVE DB 쿼리 → 실시간 취약점 조회
문서 Q&A 사내 위키/Confluence 연결
데이터 분석 PostgreSQL/BigQuery 연결
모니터링 알림 Slack API + Grafana 연결

MCP vs Function Calling 비교

항목 Function Calling MCP
표준화 모델별 상이 단일 표준
서버 재사용 불가 가능 (어떤 클라이언트든)
트랜스포트 HTTP만 stdio, HTTP, WebSocket
생태계 모델 종속 오픈 생태계
보안 직접 구현 프로토콜 레벨 지원

정리

MCP는 AI 에이전트 시대의 핵심 인프라 표준으로 자리잡고 있습니다. 2026년 현재 주요 IDE, Claude, Cursor 등이 MCP를 기본 지원하며 서드파티 MCP 서버 생태계도 빠르게 성장 중입니다. 자신만의 MCP 서버를 만들어 반복 작업을 자동화하거나, 기존 API를 LLM과 손쉽게 연결해보세요.