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 -50% ํ• ์ธ์ฟ ํฐ: 20652-ab1f1cd4c373 buy me a coffee