@@ -15,109 +15,97 @@ import (
1515 "golang.org/x/tools/internal/mcp/jsonschema"
1616)
1717
18- func TestListTools (t * testing.T ) {
19- toolA := mcp .NewTool ("apple" , "apple tool" , SayHi )
20- toolB := mcp .NewTool ("banana" , "banana tool" , SayHi )
21- toolC := mcp .NewTool ("cherry" , "cherry tool" , SayHi )
22- tools := []* mcp.ServerTool {toolA , toolB , toolC }
23-
24- wantTools := []* mcp.Tool {toolA .Tool , toolB .Tool , toolC .Tool }
18+ func TestList (t * testing.T ) {
2519 ctx := context .Background ()
2620 clientSession , serverSession , server := createSessions (ctx )
2721 defer clientSession .Close ()
2822 defer serverSession .Close ()
29- server .AddTools (tools ... )
30- t .Run ("ListTools" , func (t * testing.T ) {
31- res , err := clientSession .ListTools (ctx , nil )
32- if err != nil {
33- t .Fatal ("ListTools() failed:" , err )
34- }
35- if diff := cmp .Diff (wantTools , res .Tools , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
36- t .Fatalf ("ListTools() mismatch (-want +got):\n %s" , diff )
37- }
38- })
39- t .Run ("ToolsIterator" , func (t * testing.T ) {
40- testIterator (ctx , t , clientSession .Tools (ctx , nil ), wantTools )
41- })
42- }
4323
44- func TestListResources (t * testing.T ) {
45- resourceA := & mcp.ServerResource {Resource : & mcp.Resource {URI : "http://apple" }}
46- resourceB := & mcp.ServerResource {Resource : & mcp.Resource {URI : "http://banana" }}
47- resourceC := & mcp.ServerResource {Resource : & mcp.Resource {URI : "http://cherry" }}
48- wantResources := []* mcp.Resource {resourceA .Resource , resourceB .Resource , resourceC .Resource }
49-
50- resources := []* mcp.ServerResource {resourceA , resourceB , resourceC }
51- ctx := context .Background ()
52- clientSession , serverSession , server := createSessions (ctx )
53- defer clientSession .Close ()
54- defer serverSession .Close ()
55- server .AddResources (resources ... )
56- t .Run ("ListResources" , func (t * testing.T ) {
57- res , err := clientSession .ListResources (ctx , nil )
58- if err != nil {
59- t .Fatal ("ListResources() failed:" , err )
60- }
61- if diff := cmp .Diff (wantResources , res .Resources , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
62- t .Fatalf ("ListResources() mismatch (-want +got):\n %s" , diff )
63- }
64- })
65- t .Run ("ResourcesIterator" , func (t * testing.T ) {
66- testIterator (ctx , t , clientSession .Resources (ctx , nil ), wantResources )
24+ t .Run ("tools" , func (t * testing.T ) {
25+ toolA := mcp .NewTool ("apple" , "apple tool" , SayHi )
26+ toolB := mcp .NewTool ("banana" , "banana tool" , SayHi )
27+ toolC := mcp .NewTool ("cherry" , "cherry tool" , SayHi )
28+ tools := []* mcp.ServerTool {toolA , toolB , toolC }
29+ wantTools := []* mcp.Tool {toolA .Tool , toolB .Tool , toolC .Tool }
30+ server .AddTools (tools ... )
31+ t .Run ("list" , func (t * testing.T ) {
32+ res , err := clientSession .ListTools (ctx , nil )
33+ if err != nil {
34+ t .Fatal ("ListTools() failed:" , err )
35+ }
36+ if diff := cmp .Diff (wantTools , res .Tools , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
37+ t .Fatalf ("ListTools() mismatch (-want +got):\n %s" , diff )
38+ }
39+ })
40+ t .Run ("iterator" , func (t * testing.T ) {
41+ testIterator (ctx , t , clientSession .Tools (ctx , nil ), wantTools )
42+ })
6743 })
68- }
6944
70- func TestListResourceTemplates (t * testing.T ) {
71- resourceTmplA := & mcp.ServerResourceTemplate {ResourceTemplate : & mcp.ResourceTemplate {URITemplate : "http://apple/{x}" }}
72- resourceTmplB := & mcp.ServerResourceTemplate {ResourceTemplate : & mcp.ResourceTemplate {URITemplate : "http://banana/{x}" }}
73- resourceTmplC := & mcp.ServerResourceTemplate {ResourceTemplate : & mcp.ResourceTemplate {URITemplate : "http://cherry/{x}" }}
74- wantResourceTemplates := []* mcp.ResourceTemplate {
75- resourceTmplA .ResourceTemplate , resourceTmplB .ResourceTemplate ,
76- resourceTmplC .ResourceTemplate ,
77- }
78- resourceTemplates := []* mcp.ServerResourceTemplate {resourceTmplA , resourceTmplB , resourceTmplC }
79- ctx := context .Background ()
80- clientSession , serverSession , server := createSessions (ctx )
81- defer clientSession .Close ()
82- defer serverSession .Close ()
83- server .AddResourceTemplates (resourceTemplates ... )
84- t .Run ("ListResourceTemplates" , func (t * testing.T ) {
85- res , err := clientSession .ListResourceTemplates (ctx , nil )
86- if err != nil {
87- t .Fatal ("ListResourceTemplates() failed:" , err )
88- }
89- if diff := cmp .Diff (wantResourceTemplates , res .ResourceTemplates , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
90- t .Fatalf ("ListResourceTemplates() mismatch (-want +got):\n %s" , diff )
91- }
45+ t .Run ("resources" , func (t * testing.T ) {
46+ resourceA := & mcp.ServerResource {Resource : & mcp.Resource {URI : "http://apple" }}
47+ resourceB := & mcp.ServerResource {Resource : & mcp.Resource {URI : "http://banana" }}
48+ resourceC := & mcp.ServerResource {Resource : & mcp.Resource {URI : "http://cherry" }}
49+ wantResources := []* mcp.Resource {resourceA .Resource , resourceB .Resource , resourceC .Resource }
50+ resources := []* mcp.ServerResource {resourceA , resourceB , resourceC }
51+ server .AddResources (resources ... )
52+ t .Run ("list" , func (t * testing.T ) {
53+ res , err := clientSession .ListResources (ctx , nil )
54+ if err != nil {
55+ t .Fatal ("ListResources() failed:" , err )
56+ }
57+ if diff := cmp .Diff (wantResources , res .Resources , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
58+ t .Fatalf ("ListResources() mismatch (-want +got):\n %s" , diff )
59+ }
60+ })
61+ t .Run ("iterator" , func (t * testing.T ) {
62+ testIterator (ctx , t , clientSession .Resources (ctx , nil ), wantResources )
63+ })
9264 })
93- t .Run ("ResourceTemplatesIterator" , func (t * testing.T ) {
94- testIterator (ctx , t , clientSession .ResourceTemplates (ctx , nil ), wantResourceTemplates )
95- })
96- }
9765
98- func TestListPrompts (t * testing.T ) {
99- promptA := mcp .NewPrompt ("apple" , "apple prompt" , testPromptHandler [struct {}])
100- promptB := mcp .NewPrompt ("banana" , "banana prompt" , testPromptHandler [struct {}])
101- promptC := mcp .NewPrompt ("cherry" , "cherry prompt" , testPromptHandler [struct {}])
102- wantPrompts := []* mcp.Prompt {promptA .Prompt , promptB .Prompt , promptC .Prompt }
103-
104- prompts := []* mcp.ServerPrompt {promptA , promptB , promptC }
105- ctx := context .Background ()
106- clientSession , serverSession , server := createSessions (ctx )
107- defer clientSession .Close ()
108- defer serverSession .Close ()
109- server .AddPrompts (prompts ... )
110- t .Run ("ListPrompts" , func (t * testing.T ) {
111- res , err := clientSession .ListPrompts (ctx , nil )
112- if err != nil {
113- t .Fatal ("ListPrompts() failed:" , err )
114- }
115- if diff := cmp .Diff (wantPrompts , res .Prompts , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
116- t .Fatalf ("ListPrompts() mismatch (-want +got):\n %s" , diff )
66+ t .Run ("templates" , func (t * testing.T ) {
67+ resourceTmplA := & mcp.ServerResourceTemplate {ResourceTemplate : & mcp.ResourceTemplate {URITemplate : "http://apple/{x}" }}
68+ resourceTmplB := & mcp.ServerResourceTemplate {ResourceTemplate : & mcp.ResourceTemplate {URITemplate : "http://banana/{x}" }}
69+ resourceTmplC := & mcp.ServerResourceTemplate {ResourceTemplate : & mcp.ResourceTemplate {URITemplate : "http://cherry/{x}" }}
70+ wantResourceTemplates := []* mcp.ResourceTemplate {
71+ resourceTmplA .ResourceTemplate , resourceTmplB .ResourceTemplate ,
72+ resourceTmplC .ResourceTemplate ,
11773 }
74+ resourceTemplates := []* mcp.ServerResourceTemplate {resourceTmplA , resourceTmplB , resourceTmplC }
75+ server .AddResourceTemplates (resourceTemplates ... )
76+ t .Run ("list" , func (t * testing.T ) {
77+ res , err := clientSession .ListResourceTemplates (ctx , nil )
78+ if err != nil {
79+ t .Fatal ("ListResourceTemplates() failed:" , err )
80+ }
81+ if diff := cmp .Diff (wantResourceTemplates , res .ResourceTemplates , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
82+ t .Fatalf ("ListResourceTemplates() mismatch (-want +got):\n %s" , diff )
83+ }
84+ })
85+ t .Run ("ResourceTemplatesIterator" , func (t * testing.T ) {
86+ testIterator (ctx , t , clientSession .ResourceTemplates (ctx , nil ), wantResourceTemplates )
87+ })
11888 })
119- t .Run ("PromptsIterator" , func (t * testing.T ) {
120- testIterator (ctx , t , clientSession .Prompts (ctx , nil ), wantPrompts )
89+
90+ t .Run ("prompts" , func (t * testing.T ) {
91+ promptA := mcp .NewPrompt ("apple" , "apple prompt" , testPromptHandler [struct {}])
92+ promptB := mcp .NewPrompt ("banana" , "banana prompt" , testPromptHandler [struct {}])
93+ promptC := mcp .NewPrompt ("cherry" , "cherry prompt" , testPromptHandler [struct {}])
94+ wantPrompts := []* mcp.Prompt {promptA .Prompt , promptB .Prompt , promptC .Prompt }
95+ prompts := []* mcp.ServerPrompt {promptA , promptB , promptC }
96+ server .AddPrompts (prompts ... )
97+ t .Run ("list" , func (t * testing.T ) {
98+ res , err := clientSession .ListPrompts (ctx , nil )
99+ if err != nil {
100+ t .Fatal ("ListPrompts() failed:" , err )
101+ }
102+ if diff := cmp .Diff (wantPrompts , res .Prompts , cmpopts .IgnoreUnexported (jsonschema.Schema {})); diff != "" {
103+ t .Fatalf ("ListPrompts() mismatch (-want +got):\n %s" , diff )
104+ }
105+ })
106+ t .Run ("iterator" , func (t * testing.T ) {
107+ testIterator (ctx , t , clientSession .Prompts (ctx , nil ), wantPrompts )
108+ })
121109 })
122110}
123111
0 commit comments