Komunikacja Client - Server

Z MCP Wiki

Przebieg rozmowy między klientem a serwerem MCP

1. Klient: „Hej, zaczynamy!”

{
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-06-18",
    "capabilities": {
      "roots": {}
    },
    "clientInfo": {
      "name": "claude-code",
      "version": "1.0.38"
    }
  },
  "jsonrpc": "2.0",
  "id": 0
}

Opis: Klient mówi: „Siema serwer, chcę pogadać w wersji 2025-06-18. Oto, co potrafię – dasz znać, co u Ciebie?”

2. Serwer: „No hej, oto co umiem”

<syntaxhighlight lang="json"> {

 "jsonrpc": "2.0",
 "id": 0,
 "result": {
   "protocolVersion": "2025-06-18",
   "capabilities": {
     "experimental": {},
     "prompts": {
       "listChanged": false
     },
     "resources": {
       "subscribe": false,
       "listChanged": false
     },
     "tools": {
       "listChanged": false
     }
   },
   "serverInfo": {
     "name": "simple-server",
     "version": "1.10.1"
   }
 }

} </syntaxhighlight>

Opis: Serwer odpowiada: „Spoko, też działam na wersji 2025-06-18. Lista narzędzi, zasobów i promptów jest stała – nie będzie tu niespodzianek. No i nie obsługuję subskrypcji zmian w plikach.”

3. Klient: „Dobra, gotowy do pracy”

<syntaxhighlight lang="json"> {

 "method": "notifications/initialized",
 "jsonrpc": "2.0"

} </syntaxhighlight>

Opis: Klient mówi: „Jestem gotów, lecimy z tematem.”

4. Klient: „Pokaż, co masz za narzędzia”

<syntaxhighlight lang="json"> {

 "method": "tools/list",
 "jsonrpc": "2.0",
 "id": 1

} </syntaxhighlight>

Opis: Klient zagląda do skrzynki z narzędziami: „Masz jakieś młotki albo inne zabawki?”

5. Klient: „A jakie masz zasoby?”

<syntaxhighlight lang="json"> {

 "method": "resources/list",
 "jsonrpc": "2.0",
 "id": 3

} </syntaxhighlight>

Opis: „Masz może jakieś pliki, URI, coś do pobrania?”

6. Klient: „A gotowe prompty też dajesz?”

<syntaxhighlight lang="json"> {

 "method": "prompts/list",
 "jsonrpc": "2.0",
 "id": 2

} </syntaxhighlight>

Opis: „Może masz gotowe teksty, które mógłbym wykorzystać?”

7. Serwer: „Zasoby? Pusto.”

<syntaxhighlight lang="json"> {

 "jsonrpc": "2.0",
 "id": 3,
 "result": {
   "resources": []
 }

} </syntaxhighlight>

Opis: „Sorry, nie mam żadnych zasobów na tę chwilę.”

8. Serwer: „Mam tylko jedno narzędzie – zegarek”

<syntaxhighlight lang="json"> {

 "jsonrpc": "2.0",
 "id": 1,
 "result": {
   "tools": [
     {
       "name": "get_current_date",
       "description": "Get current date and time.",
       "inputSchema": {
         "properties": {},
         "title": "get_current_dateArguments",
         "type": "object"
       },
       "outputSchema": {
         "properties": {
           "result": {
             "title": "Result",
             "type": "string"
           }
         },
         "required": ["result"],
         "title": "get_current_dateOutput",
         "type": "object"
       }
     }
   ]
 }

} </syntaxhighlight>

Opis: „Mam tylko jedno narzędzie: takie, które mówi, która jest godzina.”

9. Serwer: „Promptów też nie mam.”

<syntaxhighlight lang="json"> {

 "jsonrpc": "2.0",
 "id": 2,
 "result": {
   "prompts": []
 }

} </syntaxhighlight>

Opis: „Niestety, żadnych gotowych tekstów na dziś nie mam.”