| 1 | import context |
| 2 | import mcp |
| 3 | import x.async as xasync |
| 4 | |
| 5 | struct TestEchoArgs { |
| 6 | pub: |
| 7 | text string |
| 8 | } |
| 9 | |
| 10 | fn test_mcp_task_dispatches_in_memory_request() { |
| 11 | request := mcp.new_request(1, 'tools/call', TestEchoArgs{ |
| 12 | text: 'hello' |
| 13 | }) |
| 14 | mut task := xasync.run[mcp.Response](fn [request] (mut ctx context.Context) !mcp.Response { |
| 15 | _ = ctx |
| 16 | req := mcp.decode_request(request.encode())! |
| 17 | if req.method != 'tools/call' { |
| 18 | return error('unexpected MCP method') |
| 19 | } |
| 20 | args := req.decode_params[TestEchoArgs]()! |
| 21 | result := mcp.tool_text_result(args.text) |
| 22 | return mcp.new_response(1, result, mcp.ResponseError{}) |
| 23 | })! |
| 24 | |
| 25 | response := task.wait()! |
| 26 | result := response.decode_result[mcp.ToolResult]()! |
| 27 | assert result.content.contains('hello') |
| 28 | } |
| 29 | |