MCP (Master Control Program)
MCP๋ ์ธ๊ณต์ง๋ฅ ์์คํ ์ ์ค์ ์ ์ด ํ๋ก๊ทธ๋จ์ ์๋ฏธํฉ๋๋ค. ์ด๋ ์ฌ๋ฌ AI ๋ชจ๋ธ๊ณผ ์๋น์ค๋ฅผ ํตํฉํ๊ณ ๊ด๋ฆฌํ๋ ํต์ฌ ์์คํ ์ ๋๋ค.
MCP์ ์ฃผ์ ๊ธฐ๋ฅโ
-
๋ฆฌ์์ค ๊ด๋ฆฌ
- AI ๋ชจ๋ธ์ ์์ ํ ๋น ๋ฐ ๊ด๋ฆฌ
- ์ปดํจํ ํ์์ ํจ์จ์ ๋ถ๋ฐฐ
- ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ
-
์์ ์ค์ผ์ค๋ง
- AI ์์ ์ ์ฐ์ ์์ ์ค์
- ๋ณ๋ ฌ ์ฒ๋ฆฌ ๊ด๋ฆฌ
- ์์ ํ ๊ด๋ฆฌ
-
๋ชจ๋ธ ํตํฉ
- ๋ค์ํ AI ๋ชจ๋ธ์ ํตํฉ
- ๋ชจ๋ธ ๊ฐ ์ํธ์์ฉ ๊ด๋ฆฌ
- API ํตํฉ
-
๋ชจ๋ํฐ๋ง ๋ฐ ๋ก๊น
- ์์คํ ์ํ ๋ชจ๋ํฐ๋ง
- ์ฑ๋ฅ ๋ฉํธ๋ฆญ ์์ง
- ์๋ฌ ๋ก๊น ๋ฐ ์๋ฆผ
MCP์ ์ฅ์ โ
- ํจ์จ์ฑ: ๋ฆฌ์์ค๋ฅผ ์ต์ ํํ์ฌ ์ฌ์ฉ
- ํ์ฅ์ฑ: ์๋ก์ด ๋ชจ๋ธ๊ณผ ๊ธฐ๋ฅ์ ์ฝ๊ฒ ์ถ๊ฐ
- ์์ ์ฑ: ์์คํ ์ฅ์ ์ ๋ํ ๋ณต๊ตฌ ๋ฉ์ปค๋์ฆ
- ์ ์ฐ์ฑ: ๋ค์ํ AI ๋ชจ๋ธ๊ณผ ์๋น์ค ํตํฉ ๊ฐ๋ฅ
๊ฐ๋จํ MCP ์๋ฒ ์์ โ
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import asyncio
from typing import Dict, Any, Callable
import uvicorn
app = FastAPI(title="MCP Server", description="Master Control Program API")
class Task(BaseModel):
model: str
data: Any
class ModelRegistration(BaseModel):
name: str
model: Callable
class MCP:
def __init__(self):
self.models: Dict[str, Callable] = {}
self.task_queue = asyncio.Queue()
async def register_model(self, name: str, model: Callable):
self.models[name] = model
async def process_task(self, task: Task):
if task.model not in self.models:
raise HTTPException(status_code=404, detail="Model not found")
return await self.models[task.model](task.data)
mcp = MCP()
async def worker():
while True:
try:
task = await mcp.task_queue.get()
if task is None:
break
result = await mcp.process_task(task)
print(f"Task processed: {result}")
mcp.task_queue.task_done()
except Exception as e:
print(f"Error processing task: {e}")
@app.post("/task")
async def add_task(task: Task):
await mcp.task_queue.put(task)
return {"status": "Task added to queue"}
@app.post("/register")
async def register_model(registration: ModelRegistration):
await mcp.register_model(registration.name, registration.model)
return {"status": "Model registered"}
@app.on_event("startup")
async def startup_event():
# ์์ปค ํ์คํฌ ์์
for _ in range(3):
asyncio.create_task(worker())
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
์ฌ์ฉ ์์โ
import httpx
import asyncio
async def simple_model(data):
await asyncio.sleep(1) # ๋น๋๊ธฐ ์์
์๋ฎฌ๋ ์ด์
return {"result": f"Processed: {data}"}
async def main():
async with httpx.AsyncClient() as client:
# ๋ชจ๋ธ ๋ฑ๋ก
response = await client.post(
'http://localhost:8000/register',
json={"name": "simple", "model": str(simple_model)}
)
print(response.json())
# ์์
์ถ๊ฐ
response = await client.post(
'http://localhost:8000/task',
json={"model": "simple", "data": "Hello MCP"}
)
print(response.json())
if __name__ == "__main__":
asyncio.run(main())
๊ฒฐ๋ก โ
MCP๋ ํ๋ AI ์์คํ ์ ํต์ฌ ๊ตฌ์ฑ ์์๋ก, ๋ค์ํ AI ๋ชจ๋ธ๊ณผ ์๋น์ค๋ฅผ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ๊ณ ์ด์ํ ์ ์๊ฒ ํด์ค๋๋ค. ๊ฐ๋จํ ๊ตฌํ๋ถํฐ ๋ณต์กํ ์์คํ ๊น์ง, MCP์ ๊ฐ๋ ์ AI ์์คํ ์ ํ์ฅ์ฑ๊ณผ ์ ์ง๋ณด์์ฑ์ ํฌ๊ฒ ํฅ์์ํต๋๋ค.