SONUB
KO English 한국어 日本語 中文 हिन्दी বাংলা اردو Español Português Français Deutsch Русский العربية Bahasa Indonesia Tiếng Việt ไทย Türkçe

알림을 켜는 방법

이 브라우저 또는 주소에서는 알림을 사용할 수 없습니다. 지원되는 브라우저로 보안 연결된 SONUB 사이트에 접속해 주세요.

알림이 차단되어 있으면 브라우저 설정에서 허용해 주세요.

  1. 주소 표시줄 옆의 사이트 설정 또는 브라우저의 사이트 설정을 열고, 이 사이트의 알림을 허용으로 바꾸세요.
  2. 기기 설정에서 브라우저 알림을 허용하고 방해 금지 또는 집중 모드를 확인하세요.
  3. SONUB으로 돌아와 페이지를 새로고침한 뒤 벨을 눌러 알림을 켜세요.

iPhone 또는 iPad에서는 SONUB을 홈 화면에 추가하고 거기에서 연 뒤 알림을 허용하세요.

로그인 로그아웃 화면 테마 기본 테마 다크 테마 핑크 테마 채팅 1:1 채팅 그룹 채팅 게시판 공지사항 뉴스 게시판 건의 게시판 메인 메뉴
를 바깥 도구에 잇는 표준

MCP(Model Context Protocol)

없이 손으로 만든 작은 와 로 메시지를 하나씩 따라가고, 에 연결해 설정이 어디에 저장되는지 봅니다.

메시지와 전송 방식

메시지는 2.0 이에요. ("무엇을 할 수 있어?"), ("이 값으로 이 일을 해 줘") 같은 작은 이에요. 메시지는 두 가지 표준 중 하나로 오가요. stdio 는 가 같은 컴퓨터에서 을 직접 켜고 표준 입력·출력으로 이야기하는 방식이고, 는 서버가 에서 돌아서 여러 사용자가 접속하는 방식이에요.

손으로 만든 서버와 클라이언트

서버(mcp-server.py)는 만 써서 자체가 그대로 보여요. 표준 입력에서 JSON-RPC 메시지를 한 줄에 하나씩 읽고, 표준 출력에 답을 한 줄에 하나씩 써요.

  • : 클라이언트가 프로토콜 을 들고 인사해요. 서버는 같은 버전으로 답하고, 가 있다고 알리고, 자기 이름을 밝혀요.
  • tools/list: 서버가 하나뿐인 도구 strange-add 를 설명과 입력 (a 와 b 는 숫자)와 함께 돌려줘요.
  • tools/call: 서버가 strange-add 를 실행하고 결과를 글자로 돌려줘요.
  • id 가 없는 메시지는 (notifications/initialized 같은 것)이라 서버가 답하지 않아요. 그 밖의 요청(ping 같은 것)에는 빈 결과로 답해요.

strange-add 는 a + b 에 1~100 사이의 무작위 수를 더해요. 은 이 값을 스스로 알아낼 수 없으니, 2 + 3 의 답이 5 가 아니면 도구가 정말 실행됐다는 증거예요. stdout 으로는 프로토콜 메시지만 오가요 — () 한 줄만 잘못 들어가도 대화가 깨지니 기록은 stderr 에 쓰세요. print(..., =True) 는 답을 바로 내보내요.

클라이언트(mcp-client.sh)는 없이 역할을 대신하는 스크립트예요. 서버를 켜고 전체(initialize, initialized 알림, tools/list, tools/call, ping)를 보낸 뒤 답을 하나씩 검사해 PASS 나 FAIL 을 찍어요. 종료 0 은 모두 통과했다는 뜻이에요. 에 연결하기 전에 서버를 이렇게 시험하세요. 실제 클라이언트에서는 모델이 이렇게 함께 돌아요.

  • 사용자의 질문과 도구 목록을 모델에 보내요.
  • 모델이 도구를 부르겠다고 하면 클라이언트가 tools/call 로 서버에서 그 도구를 불러요.
  • 결과를 모델에 돌려주면 모델이 마지막 답을 써요.

이 손으로 만든 서버는 initialize 로 시작하는 방식(프로토콜 버전 2025-06-18)으로 말하고, 같은 클라이언트는 이 방식도 받아들여요. 최신 (2026-07-28)은 initialize 대신 요청마다 버전을 실어 보내요. 실제 서비스를 만들 때는 규격을 알아서 맞춰 주는 공식 (Python 의 MCPServer, )를 쓰세요.

mcp-server.py
"""
mcp-server.py: the smallest MCP server.
One tool, plain Python (standard library only), no SDK.

Who is who
  MCP server  This program. It offers tools (functions the AI
              may use).
  Host        The app the user talks to (Claude Code, Codex).
              It runs one MCP client for each connected server.
  MCP client  The part of the host that talks to this server
              with JSON-RPC messages (here over stdio: one JSON
              message per line).
  Model       The LLM (Claude Opus, GPT, ...). It never talks to
              the server directly. It only talks to the host.

Flow
  1. Discover tools
     The client asks for the tools (tools/list). The server replies
     with each tool's name, description and input schema.
  2. Offer tools
     The host sends the user's message to the model, together
     with the tool list.
  3. Model decides
     The model answers directly, or asks for a tool call
     (tool name + arguments). It never runs the tool itself.
  4. Call the tool
     The client sends the request to the server (tools/call).
  5. Run the tool
     The server runs the function and returns the result.
  6. Model continues
     The host gives the result back to the model. The model may
     call more tools (3-6 again) or write the final answer.

  Model             Host (MCP client)            MCP server
    |                    |  1. tools/list  ------>  |
    |                    |  <------  tool list      |
    | <-- 2. message + tool list                    |
    | 3. tool call -->   |                          |
    |                    |  4. tools/call  ------>  |
    |                    |  <------  5. result      |
    | <-- 6. result      |                          |

Rule for stdio servers: stdout carries protocol messages only.
Never print() anything else there. Write logs to stderr.
"""

import json
import random
import sys

SERVER_INFO = {"name": "strange-add-mcp", "version": "1.0.0"}

# The tool. The model reads the description to decide when to use it.
STRANGE_ADD = {
    "name": "strange-add",
    "description": "Add two numbers with a strange number.",
    "inputSchema": {
        "type": "object",
        "properties": {
            "a": {"type": "number"},
            "b": {"type": "number"},
        },
        "required": ["a", "b"],
    },
}


def strange_add(a, b):
    """Add a + b and a random number from 1 to 100 (always > a + b).

    The model cannot guess the answer, so a right answer proves
    that the tool was really called.
    """
    return a + b + random.randint(1, 100)


def handle(method, params):
    """Return the result for one request. Others (like ping) get {}."""
    if method == "initialize":
        # Use the client's protocol version and say "I have tools".
        return {
            "protocolVersion": params["protocolVersion"],
            "capabilities": {"tools": {}},
            "serverInfo": SERVER_INFO,
        }
    if method == "tools/list":
        return {"tools": [STRANGE_ADD]}
    if method == "tools/call":
        args = params["arguments"]
        total = strange_add(args["a"], args["b"])
        return {"content": [{"type": "text", "text": str(total)}]}
    return {}


def main():
    # One JSON-RPC message per line comes in, one reply per line goes out.
    for line in sys.stdin:
        request = json.loads(line)
        # No id means a notification: send no reply.
        if "id" not in request:
            continue
        result = handle(request["method"], request.get("params", {}))
        reply = {"jsonrpc": "2.0", "id": request["id"], "result": result}
        # flush=True sends the reply at once.
        print(json.dumps(reply), flush=True)


if __name__ == "__main__":
    main()
mcp-client.sh
#!/bin/sh
# mcp-client.sh: the simplest MCP client, a shell script.
# It starts mcp-server.py, talks to it over stdio (one JSON-RPC
# message per line) and checks every reply.
# Exit code 0 means every check passed.

SERVER="python3 $(dirname "$0")/mcp-server.py"

# 1. Send the whole session at once and keep the replies.
#    id 1     initialize                 agree on a version
#    (no id)  notifications/initialized  "ready" (no reply)
#    id 2     tools/list                 which tools are there?
#    id 3     tools/call                 run strange-add(2, 3)
#    id 4     ping                       is the server alive?
replies=$(
  $SERVER <<'EOF'
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "shell-mcp-client", "version": "1.0.0"}}}
{"jsonrpc": "2.0", "method": "notifications/initialized"}
{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "strange-add", "arguments": {"a": 2, "b": 3}}}
{"jsonrpc": "2.0", "id": 4, "method": "ping"}
EOF
)

echo "--- Server replies ---"
echo "$replies"
echo "--- Checks ---"

failed=0

# 2. check <label> <reply id> <text the reply must contain>
check() {
  reply=$(echo "$replies" | grep -F "\"id\": $2,")
  if echo "$reply" | grep -qF "$3"; then
    echo "PASS   $1"
  else
    echo "FAIL   $1 (expected: $3)"
    failed=1
  fi
}

check "initialize: protocol version"  1 '"protocolVersion": "2025-06-18"'
check "initialize: server info"       1 '"serverInfo": {'
check "initialize: has tools"         1 '"capabilities": {"tools": {}}'
check "tools/list: strange-add"       2 '"name": "strange-add"'
check "ping: empty result"            4 '"result": {}'

# 3. strange-add adds a random 0 to 100,
#    so the answer only has to be >= 2 + 3.
total=$(echo "$replies" | grep -F '"id": 3,' |
  sed 's/.*"text": "\([0-9]*\)".*/\1/')
if [ "$total" -ge 5 ] 2>/dev/null; then
  echo "PASS   tools/call: strange-add(2, 3) >= 5 (got $total)"
else
  echo "FAIL   tools/call: strange-add(2, 3) >= 5 (got $total)"
  failed=1
fi

exit $failed
터미널에 입력할 명령
# put the two files above into one folder
mkdir -p ~/tmp/mcp && cd ~/tmp/mcp
#   mcp-server.py   mcp-client.sh

# 1) test the server without any AI
sh mcp-client.sh               # -> 6 x PASS, exit code 0

# 2) connect it to Claude Code (no --scope: the "local" scope)
claude mcp add strange-add -- python3 ~/tmp/mcp/mcp-server.py
claude mcp list                # strange-add: ... - Connected
claude mcp get strange-add     # Scope: Local config

# 3) where it was saved: NOT in this folder (no new file here)
#    ~/.claude.json -> projects -> "<this folder>" -> mcpServers
jq '.projects["'"$PWD"'"].mcpServers' ~/.claude.json

# 4) use it: start Claude Code in THIS folder
claude                         # "Use strange-add to add 2 and 3"
                               # -> not 5 (e.g. 61): the tool ran

claude mcp remove strange-add -s local

이 은 이 페이지가 아니라 나 서버의 에서 실행해요. 실행하기 전에 한 줄씩 읽어 보세요.

출처

AI 과정에서 함께 배우기

AI 과정의 MCP 챕터 — 목표 · 과제 · 진도

가이드라인

인공지능

에이전트 툴

바이브코딩

AI 활용

AI 자격증

화상 수업

IT 기초

채팅

게시판

만들기

소통

더보기

용어 사전

모르는 말을 골라 보세요. 쉬운 설명과 관련 용어를 볼 수 있어요.

찾는 용어가 아직 없어요.

용어를 고르면 설명이 보여요.