@@ -68,3 +68,133 @@ func TestMetaMarshalling(t *testing.T) {
6868 })
6969 }
7070}
71+
72+ // TestGetDisplayName tests the display name logic for all types
73+ func TestGetDisplayName (t * testing.T ) {
74+ tests := []struct {
75+ name string
76+ meta BaseMetadata
77+ expectedName string
78+ }{
79+ // Tool tests
80+ {
81+ name : "tool with direct title" ,
82+ meta : & Tool {
83+ Name : "test-tool" ,
84+ Title : "Tool Title" ,
85+ Annotations : ToolAnnotation {Title : "Annotation Title" },
86+ },
87+ expectedName : "Tool Title" ,
88+ },
89+ {
90+ name : "tool with annotation title only" ,
91+ meta : & Tool {
92+ Name : "test-tool" ,
93+ Annotations : ToolAnnotation {Title : "Annotation Title" },
94+ },
95+ expectedName : "Annotation Title" ,
96+ },
97+ {
98+ name : "tool falls back to name" ,
99+ meta : & Tool {Name : "test-tool" },
100+ expectedName : "test-tool" ,
101+ },
102+
103+ // Prompt tests
104+ {
105+ name : "prompt with title" ,
106+ meta : & Prompt {
107+ Name : "test-prompt" ,
108+ Title : "Prompt Title" ,
109+ },
110+ expectedName : "Prompt Title" ,
111+ },
112+ {
113+ name : "prompt falls back to name" ,
114+ meta : & Prompt {Name : "test-prompt" },
115+ expectedName : "test-prompt" ,
116+ },
117+
118+ // Resource tests
119+ {
120+ name : "resource with title" ,
121+ meta : & Resource {
122+ Name : "test-resource" ,
123+ Title : "Resource Title" ,
124+ },
125+ expectedName : "Resource Title" ,
126+ },
127+ {
128+ name : "resource falls back to name" ,
129+ meta : & Resource {Name : "test-resource" },
130+ expectedName : "test-resource" ,
131+ },
132+
133+ // ResourceTemplate tests
134+ {
135+ name : "resource template with title" ,
136+ meta : & ResourceTemplate {
137+ Name : "test-template" ,
138+ Title : "Template Title" ,
139+ },
140+ expectedName : "Template Title" ,
141+ },
142+ {
143+ name : "resource template falls back to name" ,
144+ meta : & ResourceTemplate {Name : "test-template" },
145+ expectedName : "test-template" ,
146+ },
147+ }
148+
149+ for _ , tt := range tests {
150+ t .Run (tt .name , func (t * testing.T ) {
151+ assert .Equal (t , tt .expectedName , GetDisplayName (tt .meta ))
152+ })
153+ }
154+ }
155+
156+ // TestToolTitleSerialization tests that Tool title field is properly serialized
157+ func TestToolTitleSerialization (t * testing.T ) {
158+ tool := Tool {
159+ Name : "test-tool" ,
160+ Title : "Test Tool Title" ,
161+ Description : "A test tool" ,
162+ InputSchema : ToolInputSchema {
163+ Type : "object" ,
164+ Properties : map [string ]any {},
165+ },
166+ Annotations : ToolAnnotation {
167+ Title : "Annotation Title" ,
168+ },
169+ }
170+
171+ // Test serialization
172+ data , err := json .Marshal (tool )
173+ require .NoError (t , err )
174+
175+ var result map [string ]any
176+ err = json .Unmarshal (data , & result )
177+ require .NoError (t , err )
178+
179+ assert .Equal (t , "test-tool" , result ["name" ])
180+ assert .Equal (t , "Test Tool Title" , result ["title" ])
181+ assert .Equal (t , "A test tool" , result ["description" ])
182+
183+ annotations , ok := result ["annotations" ].(map [string ]any )
184+ require .True (t , ok )
185+ assert .Equal (t , "Annotation Title" , annotations ["title" ])
186+
187+ // Test deserialization
188+ var deserializedTool Tool
189+ err = json .Unmarshal (data , & deserializedTool )
190+ require .NoError (t , err )
191+
192+ assert .Equal (t , "test-tool" , deserializedTool .Name )
193+ assert .Equal (t , "Test Tool Title" , deserializedTool .Title )
194+ assert .Equal (t , "A test tool" , deserializedTool .Description )
195+ assert .Equal (t , "Annotation Title" , deserializedTool .Annotations .Title )
196+
197+ // Test GetTitle method
198+ assert .Equal (t , "Test Tool Title" , deserializedTool .GetTitle ())
199+ assert .Equal (t , "Test Tool Title" , GetDisplayName (& deserializedTool ))
200+ }
0 commit comments