C.W.K.
Stream
Lesson 05 of 05 · published

JSON-RPC 2.0 — The Wire

~20 min · json-rpc, request, notification, error-codes

Level 0호기심 많은 독자
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

모든 MCP 메시지 밑은 JSON-RPC 2.0. Spec 짧아 — 10 페이지 미만 — 한 번 읽을 가치 있어. MCP framing 의 모든 quirk 가 거기서 와.

JSON-RPC 메시지 타입 셋. Request 는 method, params, unique id; 받는 쪽이 같은 id 로 result 또는 error 답 MUST. Notification 은 같은 모양인데 id 없음; 받는 쪽 답 MUST NOT. Responseresult 또는 error 필드 — 둘 다 동시에 안 함.

에러는 first-class. 모든 JSON-RPC 에러는 numeric code, 짧은 message, optional data. 표준 코드: -32700 Parse error, -32600 Invalid request, -32601 Method not found, -32602 Invalid params, -32603 Internal error, server-defined 범위 -32099 ~ -32000 protocol-specific. MCP 가 그 마지막 코드들에 자기 의미 얹음.

새 MCP server 작가가 잡히는 부분: batch 와 concurrency. JSON-RPC 가 batched request (request object 배열) 와 같은 connection 에서 out-of-order response 허용. MCP transport 구현마다 batch 지원 엄격성 다름; 안전한 룰은 — 현재 transport 가 직렬화하더라도 — interleaved request 와 out-of-order response 처리 가능하게 server 짜는 거.

Code

JSON-RPC 메시지 모양 셋·json
// Request — id 있음; 받는 쪽 답 MUST
{"jsonrpc":"2.0","id":42,"method":"tools/call","params":{"name":"get_weather","arguments":{"location":"Seoul"}}}

// Notification — id 없음; 받는 쪽 답 MUST NOT
{"jsonrpc":"2.0","method":"notifications/cancelled","params":{"requestId":42}}

// Response (성공)
{"jsonrpc":"2.0","id":42,"result":{"content":[{"type":"text","text":"68°F"}]}}

// Response (에러)
{"jsonrpc":"2.0","id":42,"error":{"code":-32602,"message":"Invalid params","data":{"missing":["location"]}}}
볼 수 있는 표준 JSON-RPC 에러 코드·text
-32700  Parse error           — server 가 malformed JSON 받음
-32600  Invalid request       — 메시지가 JSON-RPC 모양 아님
-32601  Method not found      — server 가 모르는 method 호출
-32602  Invalid params        — params 모양/타입 틀림
-32603  Internal error        — 일반 server 실패
-32099 .. -32000              — protocol-specific (MCP 가 자기 의미 정의)

External links

Exercise

JSON-RPC 2.0 spec 끝까지 읽어 (진짜 짧음). 그 다음 MCP spec 의 base protocol section 열고 JSON-RPC 인용하는 모든 자리 찾아. 두 spec 합쳐서 진짜 contract; SDK 는 구현 디테일.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.