@@ -7,29 +7,48 @@ import (
77 ghcontext "github.com/github/github-mcp-server/pkg/context"
88 "github.com/modelcontextprotocol/go-sdk/mcp"
99 "github.com/stretchr/testify/assert"
10+ "github.com/stretchr/testify/require"
1011)
1112
13+ func createMCPRequestWithCapabilities (t * testing.T , caps * mcp.ClientCapabilities ) mcp.CallToolRequest {
14+ t .Helper ()
15+ srv := mcp .NewServer (& mcp.Implementation {Name : "test" }, nil )
16+ st , _ := mcp .NewInMemoryTransports ()
17+ session , err := srv .Connect (context .Background (), st , & mcp.ServerSessionOptions {
18+ State : & mcp.ServerSessionState {
19+ InitializeParams : & mcp.InitializeParams {
20+ ClientInfo : & mcp.Implementation {Name : "test-client" },
21+ Capabilities : caps ,
22+ },
23+ },
24+ })
25+ require .NoError (t , err )
26+ t .Cleanup (func () { _ = session .Close () })
27+ return mcp.CallToolRequest {Session : session }
28+ }
29+
1230func Test_clientSupportsUI (t * testing.T ) {
1331 t .Parallel ()
1432 ctx := context .Background ()
1533
16- tests := []struct {
17- name string
18- clientName string
19- want bool
20- }{
21- {name : "VS Code Insiders" , clientName : "Visual Studio Code - Insiders" , want : true },
22- {name : "VS Code Stable" , clientName : "Visual Studio Code" , want : true },
23- {name : "unknown client" , clientName : "some-other-client" , want : false },
24- {name : "empty client name" , clientName : "" , want : false },
25- }
26-
27- for _ , tt := range tests {
28- t .Run (tt .name , func (t * testing.T ) {
29- req := createMCPRequestWithSession (t , tt .clientName , nil )
30- assert .Equal (t , tt .want , clientSupportsUI (ctx , & req ))
34+ t .Run ("client with UI extension" , func (t * testing.T ) {
35+ caps := & mcp.ClientCapabilities {}
36+ caps .AddExtension ("io.modelcontextprotocol/ui" , map [string ]any {
37+ "mimeTypes" : []string {"text/html;profile=mcp-app" },
3138 })
32- }
39+ req := createMCPRequestWithCapabilities (t , caps )
40+ assert .True (t , clientSupportsUI (ctx , & req ))
41+ })
42+
43+ t .Run ("client without UI extension" , func (t * testing.T ) {
44+ req := createMCPRequestWithCapabilities (t , & mcp.ClientCapabilities {})
45+ assert .False (t , clientSupportsUI (ctx , & req ))
46+ })
47+
48+ t .Run ("client with nil capabilities" , func (t * testing.T ) {
49+ req := createMCPRequestWithCapabilities (t , nil )
50+ assert .False (t , clientSupportsUI (ctx , & req ))
51+ })
3352
3453 t .Run ("nil request" , func (t * testing.T ) {
3554 assert .False (t , clientSupportsUI (ctx , nil ))
@@ -41,42 +60,28 @@ func Test_clientSupportsUI(t *testing.T) {
4160 })
4261}
4362
44- func Test_clientSupportsUI_nilClientInfo (t * testing.T ) {
45- t .Parallel ()
46- ctx := context .Background ()
47-
48- srv := mcp .NewServer (& mcp.Implementation {Name : "test" }, nil )
49- st , _ := mcp .NewInMemoryTransports ()
50- session , err := srv .Connect (context .Background (), st , & mcp.ServerSessionOptions {
51- State : & mcp.ServerSessionState {
52- InitializeParams : & mcp.InitializeParams {
53- ClientInfo : nil ,
54- },
55- },
56- })
57- if err != nil {
58- t .Fatal (err )
59- }
60- t .Cleanup (func () { _ = session .Close () })
61-
62- req := mcp.CallToolRequest {Session : session }
63- assert .False (t , clientSupportsUI (ctx , & req ))
64- }
65-
6663func Test_clientSupportsUI_fromContext (t * testing.T ) {
6764 t .Parallel ()
6865
69- t .Run ("supported client in context" , func (t * testing.T ) {
70- ctx := ghcontext .WithClientName (context .Background (), "Visual Studio Code - Insiders" )
66+ t .Run ("UI supported in context" , func (t * testing.T ) {
67+ ctx := ghcontext .WithUISupport (context .Background (), true )
7168 assert .True (t , clientSupportsUI (ctx , nil ))
7269 })
7370
74- t .Run ("unsupported client in context" , func (t * testing.T ) {
75- ctx := ghcontext .WithClientName (context .Background (), "some-other-client" )
71+ t .Run ("UI not supported in context" , func (t * testing.T ) {
72+ ctx := ghcontext .WithUISupport (context .Background (), false )
7673 assert .False (t , clientSupportsUI (ctx , nil ))
7774 })
7875
79- t .Run ("no client in context or session" , func (t * testing.T ) {
76+ t .Run ("context takes precedence over session" , func (t * testing.T ) {
77+ ctx := ghcontext .WithUISupport (context .Background (), false )
78+ caps := & mcp.ClientCapabilities {}
79+ caps .AddExtension ("io.modelcontextprotocol/ui" , map [string ]any {})
80+ req := createMCPRequestWithCapabilities (t , caps )
81+ assert .False (t , clientSupportsUI (ctx , & req ))
82+ })
83+
84+ t .Run ("no context or session" , func (t * testing.T ) {
8085 assert .False (t , clientSupportsUI (context .Background (), nil ))
8186 })
8287}
0 commit comments