MCP ์ฃผ์ ๊ตฌ์ฑ ์์:
AI ๋ชจ๋ธ <-> MCP ํด๋ผ์ด์ธํธ <-> MCP ์๋ฒ <-> ์ธ๋ถ ๋๊ตฌ/์๋น์ค
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์์ ์คํ ์ค์
๋๋ค.');
});
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์
๋๋ค.
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
์ต์ AI ๋ชจ๋ธ๋ค์ MCP๋ฅผ ํตํด ์ธ๋ถ ๋๊ตฌ์ ํตํฉ:
MCP๋ฅผ ๊ตฌํํ ๋ ๊ณ ๋ คํด์ผ ํ ์ฃผ์ ๋ณด์ ์ฌํญ: