โ Model Context Protocol/M-047Build Your First MCP Message Handler๐ Guide๐
Rank 05ยท The Artificer
๐งชTDD Challengeยทbeginnerยทโฑ๏ธ 15โ30mยทโญ 100 XP
M-047Build Your First MCP Message Handler
Description
Nebula Corp is adopting the Model Context Protocol to let AI assistants access internal tools. Before building a full server, they need a message handler that can parse MCP JSON-RPC requests, validate them, and route to the correct handler. Build the protocol layer that processes initialize, tools/list, and tools/call messages.
Test Cases (4)
Parses valid message
Should parse valid JSON-RPC message
Input:parseMessage('{"jsonrpc":"2.0","id":1,"method":"initialize"}')
Expected:CONTAINS_ALL:initialize,id
Handles initialize
Should return protocol version and capabilities
Input:handleMessage('{"jsonrpc":"2.0","id":1,"method":"initialize"}')
Expected:CONTAINS_ALL:2024-11-05,capabilities
Handles tool call
Should echo the input text
Input:handleMessage('{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"echo","arguments":{"text":"hello"}}}')
Expected:CONTAINS:hello
Rejects invalid JSON
Should return error for invalid JSON
Input:handleMessage('not json')
Expected:CONTAINS:error
Related Lessons
Click Run / Check to validate your solution