|
1 | 1 | classdef tmcpHandler < HandlerBase |
2 | 2 |
|
3 | 3 | methods(Test) |
| 4 | + |
4 | 5 | function toolsList(test) |
5 | 6 | import prodserver.mcp.internal.mcpHandler |
6 | 7 | import prodserver.mcp.internal.hasField |
@@ -54,6 +55,56 @@ function notStreamable(test) |
54 | 55 | response = prodserver.mcp.internal.mcpHandler(reqT); |
55 | 56 | test.verifyEqual(response.HttpCode,405); |
56 | 57 | end |
| 58 | + |
| 59 | + function content(test) |
| 60 | + import prodserver.mcp.internal.mcpHandler |
| 61 | + import prodserver.mcp.MCPConstants |
| 62 | + import prodserver.mcp.internal.hasField |
| 63 | + |
| 64 | + % Get base request structure |
| 65 | + req = test.request; |
| 66 | + req.Headers = [req.Headers; {MCPConstants.ContentType, ... |
| 67 | + 'application/json'}]; |
| 68 | + |
| 69 | + % Make up a session ID |
| 70 | + id = matlab.lang.internal.uuid; |
| 71 | + req.Headers = [req.Headers; { MCPConstants.SessionId id} ]; |
| 72 | + |
| 73 | + % Call primeSequence requesting 13 Eisenstein primes. |
| 74 | + body = [... |
| 75 | +'{' ... |
| 76 | +' "jsonrpc": "2.0",' ... |
| 77 | +' "id": 1,'... |
| 78 | +' "method": "tools/call",'... |
| 79 | +' "params": {'... |
| 80 | +' "name": "primeSequence",'... |
| 81 | +' "arguments": {'... |
| 82 | +' "n": 13,'... |
| 83 | +' "type": "Eisenstein"'... |
| 84 | +' }'... |
| 85 | +' }'... |
| 86 | +'}' |
| 87 | +]; |
| 88 | + reqT = req; |
| 89 | + reqT.Method = "POST"; % Because there's a body |
| 90 | + reqT.Path = "http://localhost:9910/prime/mcp"; |
| 91 | + reqT.Headers = [reqT.Headers; {MCPConstants.ContentLength, numel(body)}]; |
| 92 | + reqT.Body = unicode2native(body,"UTF-8"); |
| 93 | + response = prodserver.mcp.internal.mcpHandler(reqT); |
| 94 | + response = prodserver.mcp.internal.decodeBody(response); |
| 95 | + |
| 96 | + % Expecting content and structuredContent |
| 97 | + test.verifyEqual(response.id, 1); |
| 98 | + test.verifyTrue(hasField(response, 'result.content')); |
| 99 | + test.verifyTrue(hasField(response, 'result.structuredContent')); |
| 100 | + |
| 101 | + % Result is a column vector. |
| 102 | + expected.seq = primeSequence(13,"Eisenstein")'; |
| 103 | + test.verifyEqual(response.result.structuredContent,expected); |
| 104 | + % Since HTTP interface sends all strings as char |
| 105 | + test.verifyEqual(response.result.content.text, ... |
| 106 | + char(MCPConstants.IndirectionMsg)); |
| 107 | + end |
57 | 108 | end |
58 | 109 |
|
59 | 110 | end |
0 commit comments