
μ’μ΅λλ€! μ΄ μμκ³Ό μ€λͺ μλ **MCP(Model Context Protocol)**μ κΈ°λ³Έ κ°λ κ³Ό μν€ν μ²κ° λ΄κ²¨ μμ΅λλ€. μ΄μ¬μλ μ΄ν΄ν μ μλλ‘ μλμ ν΅μ¬ κ°λ λ€μ νλμ© μμΈν νμ΄ μ€λͺ λ릴κ²μ.
**Model Context Protocol (MCP)**μ λν μΈμ΄ λͺ¨λΈ(LLM)μ΄ μΈλΆμ λ°μ΄ν°λ λꡬμ μνΈμμ©ν μ μλλ‘ λμμ£Όλ **곡μμ μΈ ν΅μ κ·μ½(protocol)**μ λλ€.
MCPμ ν΅μ¬ ꡬμ±μ ν¬κ² μΈ κ°μ§λ‘ λλ μ μμ΄μ.
MCPλ₯Ό μ¬μ©νλ AI μ ν리μΌμ΄μ μ λλ€.
μμ:
μ΄ Hostλ MCPλ₯Ό ν΅ν΄ μλ‘μ΄ κΈ°λ₯(ν΄, λ°μ΄ν°, ν둬ννΈ λ±)μ βμ°κ²°β λ°μ μ μμ΄μ.
μΈλΆ κΈ°λ₯/리μμ€λ₯Ό μ€μ λ‘ μ 곡νλ μλ²μ λλ€.
μμ:
μλ²λ MCP Hostμ λꡬλ₯Ό μ 곡νλ μν .
μ¦, βAI μ±μ΄ μ¬μ©ν μ μλ λꡬλ₯Ό λ
ΈμΆνλ API μλ²β λΌκ³ μκ°νλ©΄ λ©λλ€.
MCPλ LLMμκ² μ€ μ μλ βλ§₯λ½(Context)β μ λ€μκ³Ό κ°μ΄ μ μν©λλ€:
μ¦, MCPλ λ¨μν ν΄ νΈμΆ λΏ μλλΌ λ€μν λ§₯λ½μ LLMμκ² μ λ¬νλλ° μ¬μ©λ©λλ€.
OrderFood ν΄ μ€ν β μ€μ λ‘ μ£Όλ¬Έν¨π μ΄ λͺ¨λ νλ¦μ΄ MCP νλ‘ν μ½μ μν΄ ν΅μ λ¨.
Plug & Play
LLM λ²€λ λ 립μ±
νμ₯μ±
MCP μλ²λ λ€μκ³Ό κ°μ κΈ°λ₯λ€μ ꡬνν΄μΌ MCP Hostκ° μ¬μ©ν μ μμ΄μ.
| κΈ°λ₯ μ΄λ¦ | μ€λͺ |
|---|---|
list_prompts | μ¬μ© κ°λ₯ν ν둬ννΈ λͺ©λ‘ μ 곡 |
call_tool | νΉμ ν΄ μ€ν (μ: get_weather, order_food) |
list_tools | μ 곡 κ°λ₯ν ν΄ λͺ©λ‘ μ 곡 |
list_resource_templates | μ¬μ©ν μ μλ 리μμ€ ν νλ¦Ώ μ 곡 |
progress_notification | ν΄ μ€ν μν μ€κ° λ³΄κ³ |
μ΄ν΄μ λμμ΄ λλ λ€μ΄μ΄κ·Έλ¨μ΄ νμνμ κ°μ? μνμλ©΄ μκ°μ μΌλ‘ MCP ꡬ쑰λ₯Ό κ·Έλ €λ릴κ²μ.
Understand how MCP connects clients, servers, and LLMs
The Model Context Protocol (MCP) is built on a flexible, extensible architecture that enables seamless communication between LLM applications and integrations. This document covers the core architectural components and concepts.
MCP follows a client-server architecture where:
flowchart LR
subgraph "Host"
client1[MCP Client]
client2[MCP Client]
end
subgraph "Server Process"
server1[MCP Server]
end
subgraph "Server Process"
server2[MCP Server]
end
client1 <-->|Transport Layer| server1
client2 <-->|Transport Layer| server2
The protocol layer handles message framing, request/response linking, and high-level communication patterns.
```typescript class Protocol { // Handle incoming requests setRequestHandler(schema: T, handler: (request: T, extra: RequestHandlerExtra) => Promise): void // Handle incoming notifications
setNotificationHandler<T>(schema: T, handler: (notification: T) => Promise<void>): void
// Send requests and await responses
request<T>(request: Request, schema: T, options?: RequestOptions): Promise<T>
// Send one-way notifications
notification(notification: Notification): Promise<void>
}
```
```python
class Session(BaseSession[RequestT, NotificationT, ResultT]):
async def send_request(
self,
request: RequestT,
result_type: type[Result]
) -> Result:
"""Send request and wait for response. Raises McpError if response contains error."""
# Request handling implementation
async def send_notification(
self,
notification: NotificationT
) -> None:
"""Send one-way notification that doesn't expect response."""
# Notification handling implementation
async def _received_request(
self,
responder: RequestResponder[ReceiveRequestT, ResultT]
) -> None:
"""Handle incoming request from other side."""
# Request handling implementation
async def _received_notification(
self,
notification: ReceiveNotificationT
) -> None:
"""Handle incoming notification from other side."""
# Notification handling implementation
```
Key classes include:
ProtocolClientServerThe transport layer handles the actual communication between clients and servers. MCP supports multiple transport mechanisms:
Stdio transport
HTTP with SSE transport
All transports use JSON-RPC 2.0 to exchange messages. See the specification for detailed information about the Model Context Protocol message format.
MCP has these main types of messages:
Requests expect a response from the other side:
interface Request {
method: string;
params?: { ... };
}
Results are successful responses to requests:
interface Result {
[key: string]: unknown;
}
Errors indicate that a request failed:
interface Error {
code: number;
message: string;
data?: unknown;
}
Notifications are one-way messages that don't expect a response:
interface Notification {
method: string;
params?: { ... };
}
sequenceDiagram
participant Client
participant Server
Client->>Server: initialize request
Server->>Client: initialize response
Client->>Server: initialized notification
Note over Client,Server: Connection ready for use
initialize request with protocol version and capabilitiesinitialized notification as acknowledgmentAfter initialization, the following patterns are supported:
Either party can terminate the connection:
close()MCP defines these standard error codes:
enum ErrorCode {
// Standard JSON-RPC error codes
ParseError = -32700,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603
}
SDKs and applications can define their own error codes above -32000.
Errors are propagated through:
Here's a basic example of implementing an MCP server:
```typescript import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";const server = new Server({
name: "example-server",
version: "1.0.0"
}, {
capabilities: {
resources: {}
}
});
// Handle requests
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "example://resource",
name: "Example Resource"
}
]
};
});
// Connect transport
const transport = new StdioServerTransport();
await server.connect(transport);
```
```python
import asyncio
import mcp.types as types
from mcp.server import Server
from mcp.server.stdio import stdio_server
app = Server("example-server")
@app.list_resources()
async def list_resources() -> list[types.Resource]:
return [
types.Resource(
uri="example://resource",
name="Example Resource"
)
]
async def main():
async with stdio_server() as streams:
await app.run(
streams[0],
streams[1],
app.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())
```
Local communication
Remote communication
Request processing
Progress reporting
Error management
Transport security
Message validation
Resource protection
Error handling
Logging
Diagnostics
Testing