MCP

개요

주요 특징

작동 방식

MCP 주요 구성 요소:

  1. MCP 서버: 외부 도구와 서비스를 호스팅하고 관리하는 서버
  2. MCP 클라이언트: AI 모델이 MCP 서버와 통신하기 위한 인터페이스
  3. 도구 정의: 각 도구의 기능, 파라미터, 반환 값 등을 정의하는 스키마
AI 모델 <-> MCP 클라이언트 <-> MCP 서버 <-> 외부 도구/서비스

사용 사례

구현 예시

기본 MCP 서버 구현 (Node.js)

const express = require('express');
const app = express();
app.use(express.json());

// 도구 정의
const tools = {
  calculator: {
    add: (a, b) => a + b,
    subtract: (a, b) => a - b,
    multiply: (a, b) => a * b,
    divide: (a, b) => a / b
  },
  weather: {
    getTemperature: (city) => {
      // 실제 구현에서는 날씨 API 호출
      return `${city}의 현재 온도는 22°C입니다.`;
    }
  }
};

// MCP 엔드포인트
app.post('/mcp', (req, res) => {
  const { tool, method, params } = req.body;
  
  if (!tools[tool] || !tools[tool][method]) {
    return res.status(400).json({ error: '유효하지 않은 도구 또는 메서드' });
  }
  
  try {
    const result = tools[tool][method](...params);
    res.json({ result });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000, () => {
  console.log('MCP 서버가 포트 3000에서 실행 중입니다.');
});

Python에서의 MCP 클라이언트 예시

import requests
import json

class MCPClient:
    def __init__(self, server_url):
        self.server_url = server_url
        
    def call_tool(self, tool, method, params):
        payload = {
            "tool": tool,
            "method": method,
            "params": params
        }
        
        response = requests.post(
            f"{self.server_url}/mcp", 
            json=payload
        )
        
        if response.status_code == 200:
            return response.json()["result"]
        else:
            error = response.json().get("error", "알 수 없는 오류")
            raise Exception(f"MCP 호출 실패: {error}")

# 사용 예시
client = MCPClient("http://localhost:3000")
result = client.call_tool("calculator", "add", [5, 3])
print(f"5 + 3 = {result}")  # 출력: 5 + 3 = 8

weather = client.call_tool("weather", "getTemperature", ["서울"])
print(weather)  # 출력: 서울의 현재 온도는 22°C입니다.

MCP 다이어그램 예시

graph TD
    A[Claude Desktop] <--> |MCP Protocol: Query and Result| B[SQLite MCP Server]
    B <--> |Local Access: SQL Operation| C[SQLite Database ~/test.db]
    
    style A fill:#e6e6ff,stroke:#9999ff
    style B fill:#e6e6ff,stroke:#9999ff
    style C fill:#e6f0ff,stroke:#99c2ff,stroke-width:2px
    
    subgraph Your Computer
    A
    B
    C
    end

주요 특징

MCP와 Claude, GPT 통합

최신 AI 모델들은 MCP를 통해 외부 도구와 통합:

보안 고려사항

MCP를 구현할 때 고려해야 할 주요 보안 사항:

MCP 서버 목록

브라우저 및 웹 자동화

데이터 및 분석

클라우드 및 개발 도구

검색 및 정보 검색

언어 및 번역

자동화 및 통합

금융 및 결제

기타 특수 서버

참고 자료

What Else?
inflearn react api server buy me a coffee