@@ -1399,6 +1399,148 @@ func TestServerSessionHandle_RejectsInitializeOnNewProtocol(t *testing.T) {
13991399 })
14001400}
14011401
1402+ func TestServerSessionHandle_SetsResultTypeOnNewProtocol (t * testing.T ) {
1403+ server := NewServer (testImpl , & ServerOptions {
1404+ CompletionHandler : func (context.Context , * CompleteRequest ) (* CompleteResult , error ) {
1405+ return & CompleteResult {
1406+ Completion : CompletionResultDetails {
1407+ Values : []string {"go" },
1408+ },
1409+ }, nil
1410+ },
1411+ })
1412+ AddTool (server , & Tool {Name : "tool" }, func (context.Context , * CallToolRequest , struct {}) (* CallToolResult , any , error ) {
1413+ return & CallToolResult {
1414+ InputRequests : InputRequestMap {"confirm" : & ElicitParams {Message : "Continue?" }},
1415+ }, nil , nil
1416+ })
1417+ server .AddPrompt (& Prompt {Name : "prompt" }, func (context.Context , * GetPromptRequest ) (* GetPromptResult , error ) {
1418+ return & GetPromptResult {
1419+ InputRequests : InputRequestMap {"confirm" : & ElicitParams {Message : "Continue?" }},
1420+ }, nil
1421+ })
1422+ server .AddResource (& Resource {URI : "test://resource" , Name : "resource" }, func (context.Context , * ReadResourceRequest ) (* ReadResourceResult , error ) {
1423+ return & ReadResourceResult {
1424+ InputRequests : InputRequestMap {"confirm" : & ElicitParams {Message : "Continue?" }},
1425+ }, nil
1426+ })
1427+ newProtocolParams := func (fields map [string ]any ) map [string ]any {
1428+ params := map [string ]any {
1429+ "_meta" : map [string ]any {
1430+ MetaKeyProtocolVersion : protocolVersion20260728 ,
1431+ MetaKeyClientInfo : map [string ]any {"name" : "c" , "version" : "1" },
1432+ MetaKeyClientCapabilities : map [string ]any {},
1433+ },
1434+ }
1435+ for k , v := range fields {
1436+ params [k ] = v
1437+ }
1438+ return params
1439+ }
1440+
1441+ tests := []struct {
1442+ name string
1443+ method string
1444+ params map [string ]any
1445+ want resultType
1446+ }{
1447+ {
1448+ name : "discover" ,
1449+ method : methodDiscover ,
1450+ params : newProtocolParams (nil ),
1451+ want : resultTypeComplete ,
1452+ },
1453+ {
1454+ name : "tools list" ,
1455+ method : methodListTools ,
1456+ params : newProtocolParams (nil ),
1457+ want : resultTypeComplete ,
1458+ },
1459+ {
1460+ name : "prompts list" ,
1461+ method : methodListPrompts ,
1462+ params : newProtocolParams (nil ),
1463+ want : resultTypeComplete ,
1464+ },
1465+ {
1466+ name : "resources list" ,
1467+ method : methodListResources ,
1468+ params : newProtocolParams (nil ),
1469+ want : resultTypeComplete ,
1470+ },
1471+ {
1472+ name : "resource templates list" ,
1473+ method : methodListResourceTemplates ,
1474+ params : newProtocolParams (nil ),
1475+ want : resultTypeComplete ,
1476+ },
1477+ {
1478+ name : "complete" ,
1479+ method : methodComplete ,
1480+ params : newProtocolParams (map [string ]any {
1481+ "argument" : map [string ]any {
1482+ "name" : "language" ,
1483+ "value" : "g" ,
1484+ },
1485+ "ref" : map [string ]any {
1486+ "type" : "ref/prompt" ,
1487+ "name" : "code_review" ,
1488+ },
1489+ }),
1490+ want : resultTypeComplete ,
1491+ },
1492+ {
1493+ name : "tool input required" ,
1494+ method : methodCallTool ,
1495+ params : newProtocolParams (map [string ]any {"name" : "tool" , "arguments" : map [string ]any {}}),
1496+ want : resultTypeInputRequired ,
1497+ },
1498+ {
1499+ name : "prompt input required" ,
1500+ method : methodGetPrompt ,
1501+ params : newProtocolParams (map [string ]any {"name" : "prompt" }),
1502+ want : resultTypeInputRequired ,
1503+ },
1504+ {
1505+ name : "resource input required" ,
1506+ method : methodReadResource ,
1507+ params : newProtocolParams (map [string ]any {"uri" : "test://resource" }),
1508+ want : resultTypeInputRequired ,
1509+ },
1510+ }
1511+
1512+ for _ , tc := range tests {
1513+ t .Run (tc .name , func (t * testing.T ) {
1514+ ss := & ServerSession {server : server }
1515+ id , err := jsonrpc .MakeID ("test" )
1516+ if err != nil {
1517+ t .Fatal (err )
1518+ }
1519+ result , err := ss .handle (context .Background (), & jsonrpc.Request {
1520+ ID : id ,
1521+ Method : tc .method ,
1522+ Params : mustMarshal (tc .params ),
1523+ })
1524+ if err != nil {
1525+ t .Fatal (err )
1526+ }
1527+ data , err := json .Marshal (result )
1528+ if err != nil {
1529+ t .Fatal (err )
1530+ }
1531+ var got struct {
1532+ ResultType string `json:"resultType"`
1533+ }
1534+ if err := json .Unmarshal (data , & got ); err != nil {
1535+ t .Fatal (err )
1536+ }
1537+ if got .ResultType != string (tc .want ) {
1538+ t .Fatalf ("resultType = %q, want %q; response = %s" , got .ResultType , tc .want , data )
1539+ }
1540+ })
1541+ }
1542+ }
1543+
14021544// TestServerSessionHandle_RejectsRemovedMethodsOnNewProtocol verifies that
14031545// the methods removed by SEP-2575 (`initialize`, `notifications/initialized`,
14041546// `ping`) all return Method not found when the request opts into the new
0 commit comments