1. Learn
  2. /
  3. คอร์ส
  4. /
  5. Model Context Protocol: Advanced Topics

Connected

แบบฝึกหัด

Build a request and a notification

Time to hand-write two MCP messages. One asks the server to run the add tool and expects a result back; the other is a one-way notification telling the server the client is ready. On the wire, the difference is a single field: a request carries an id so its reply can be matched to it, while a notification has no id at all.

No imports or setup are needed — you'll work with plain Python dictionaries.

คำแนะนำ

100 XP
  • Give call_request an id of 1, so the server's reply can be matched back to it.
  • Set the initialized notification's method to "notifications/initialized" (notice it has no id).
  • Complete expects_reply() so it returns True only when a message carries an "id" key.