3333use crate :: common:: types:: { GeneratedCode , GeneratedFile } ;
3434use crate :: common:: typescript:: { extract_properties, to_camel_case} ;
3535use crate :: progressive:: types:: {
36- BridgeContext , CategoryInfo , IndexContext , PropertyInfo , ToolContext , ToolSummary ,
36+ BridgeContext , CategoryInfo , IndexContext , PropertyInfo , ToolCategorization , ToolContext ,
37+ ToolSummary ,
3738} ;
3839use crate :: template_engine:: TemplateEngine ;
3940use mcp_core:: { Error , Result } ;
@@ -191,20 +192,20 @@ impl<'a> ProgressiveGenerator<'a> {
191192 Ok ( code)
192193 }
193194
194- /// Generates progressive loading files with category metadata.
195+ /// Generates progressive loading files with categorization metadata.
195196 ///
196- /// Like `generate`, but includes category information from Claude's
197- /// categorization . Categories are displayed in the index file and
198- /// included in individual tool file headers.
197+ /// Like `generate`, but includes full categorization information from Claude's
198+ /// analysis . Categories, keywords, and short descriptions are displayed in
199+ /// the index file and included in individual tool file headers.
199200 ///
200201 /// # Arguments
201202 ///
202203 /// * `server_info` - MCP server introspection data
203- /// * `categories ` - Map of tool name to category name
204+ /// * `categorizations ` - Map of tool name to categorization metadata
204205 ///
205206 /// # Returns
206207 ///
207- /// Generated code with category metadata included.
208+ /// Generated code with categorization metadata included.
208209 ///
209210 /// # Errors
210211 ///
@@ -213,7 +214,7 @@ impl<'a> ProgressiveGenerator<'a> {
213214 /// # Examples
214215 ///
215216 /// ```no_run
216- /// use mcp_codegen::progressive::ProgressiveGenerator;
217+ /// use mcp_codegen::progressive::{ ProgressiveGenerator, ToolCategorization} ;
217218 /// use mcp_introspector::{ServerInfo, ServerCapabilities};
218219 /// use mcp_core::ServerId;
219220 /// use std::collections::HashMap;
@@ -233,33 +234,35 @@ impl<'a> ProgressiveGenerator<'a> {
233234 /// },
234235 /// };
235236 ///
236- /// let mut categories = HashMap::new();
237- /// categories.insert("create_issue".to_string(), "issues".to_string());
238- /// categories.insert("list_issues".to_string(), "issues".to_string());
239- /// categories.insert("create_pr".to_string(), "pull-requests".to_string());
237+ /// let mut categorizations = HashMap::new();
238+ /// categorizations.insert("create_issue".to_string(), ToolCategorization {
239+ /// category: "issues".to_string(),
240+ /// keywords: "create,issue,new,bug".to_string(),
241+ /// short_description: "Create a new issue".to_string(),
242+ /// });
240243 ///
241- /// let code = generator.generate_with_categories(&info, &categories )?;
244+ /// let code = generator.generate_with_categories(&info, &categorizations )?;
242245 /// # Ok(())
243246 /// # }
244247 /// ```
245248 pub fn generate_with_categories (
246249 & self ,
247250 server_info : & ServerInfo ,
248- categories : & HashMap < String , String > ,
251+ categorizations : & HashMap < String , ToolCategorization > ,
249252 ) -> Result < GeneratedCode > {
250253 tracing:: info!(
251- "Generating progressive loading code with categories for server: {}" ,
254+ "Generating progressive loading code with categorizations for server: {}" ,
252255 server_info. name
253256 ) ;
254257
255258 let mut code = GeneratedCode :: new ( ) ;
256259 let server_id = server_info. id . as_str ( ) ;
257260
258- // Generate tool files (one per tool) with category metadata
261+ // Generate tool files (one per tool) with categorization metadata
259262 for tool in & server_info. tools {
260263 let tool_name = tool. name . as_str ( ) ;
261- let category = categories . get ( tool_name) . map ( String :: as_str ) ;
262- let tool_context = self . create_tool_context ( server_id, tool, category ) ?;
264+ let categorization = categorizations . get ( tool_name) ;
265+ let tool_context = self . create_tool_context ( server_id, tool, categorization ) ?;
263266 let tool_code = self . engine . render ( "progressive/tool" , & tool_context) ?;
264267
265268 code. add_file ( GeneratedFile {
@@ -270,20 +273,23 @@ impl<'a> ProgressiveGenerator<'a> {
270273 tracing:: debug!(
271274 "Generated tool file: {}.ts (category: {:?})" ,
272275 tool_context. typescript_name,
273- category
276+ categorization . map ( |c| & c . category)
274277 ) ;
275278 }
276279
277280 // Generate index.ts with category grouping
278- let index_context = self . create_index_context ( server_info, Some ( categories ) ) ?;
281+ let index_context = self . create_index_context ( server_info, Some ( categorizations ) ) ?;
279282 let index_code = self . engine . render ( "progressive/index" , & index_context) ?;
280283
281284 code. add_file ( GeneratedFile {
282285 path : "index.ts" . to_string ( ) ,
283286 content : index_code,
284287 } ) ;
285288
286- tracing:: debug!( "Generated index.ts with {} categories" , categories. len( ) ) ;
289+ tracing:: debug!(
290+ "Generated index.ts with {} categorizations" ,
291+ categorizations. len( )
292+ ) ;
287293
288294 // Generate runtime bridge (same as non-categorized)
289295 let bridge_context = BridgeContext :: default ( ) ;
@@ -299,7 +305,7 @@ impl<'a> ProgressiveGenerator<'a> {
299305 tracing:: debug!( "Generated _runtime/mcp-bridge.ts" ) ;
300306
301307 tracing:: info!(
302- "Successfully generated {} files for {} with categories (progressive loading)" ,
308+ "Successfully generated {} files for {} with categorizations (progressive loading)" ,
303309 code. file_count( ) ,
304310 server_info. name
305311 ) ;
@@ -318,7 +324,7 @@ impl<'a> ProgressiveGenerator<'a> {
318324 & self ,
319325 server_id : & str ,
320326 tool : & mcp_introspector:: ToolInfo ,
321- category : Option < & str > ,
327+ categorization : Option < & ToolCategorization > ,
322328 ) -> Result < ToolContext > {
323329 let typescript_name = to_camel_case ( tool. name . as_str ( ) ) ;
324330
@@ -332,32 +338,36 @@ impl<'a> ProgressiveGenerator<'a> {
332338 description : tool. description . clone ( ) ,
333339 input_schema : tool. input_schema . clone ( ) ,
334340 properties,
335- category : category. map ( String :: from) ,
341+ category : categorization. map ( |c| c. category . clone ( ) ) ,
342+ keywords : categorization. map ( |c| c. keywords . clone ( ) ) ,
343+ short_description : categorization. map ( |c| c. short_description . clone ( ) ) ,
336344 } )
337345 }
338346
339347 /// Creates index context from server information.
340348 fn create_index_context (
341349 & self ,
342350 server_info : & ServerInfo ,
343- categories : Option < & HashMap < String , String > > ,
351+ categorizations : Option < & HashMap < String , ToolCategorization > > ,
344352 ) -> Result < IndexContext > {
345353 let tools: Vec < ToolSummary > = server_info
346354 . tools
347355 . iter ( )
348356 . map ( |tool| {
349357 let tool_name = tool. name . as_str ( ) ;
350- let category = categories . and_then ( |c| c. get ( tool_name) ) . cloned ( ) ;
358+ let cat = categorizations . and_then ( |c| c. get ( tool_name) ) ;
351359 ToolSummary {
352360 typescript_name : to_camel_case ( tool_name) ,
353361 description : tool. description . clone ( ) ,
354- category,
362+ category : cat. map ( |c| c. category . clone ( ) ) ,
363+ keywords : cat. map ( |c| c. keywords . clone ( ) ) ,
364+ short_description : cat. map ( |c| c. short_description . clone ( ) ) ,
355365 }
356366 } )
357367 . collect ( ) ;
358368
359- // Build category groups if categories are provided
360- let category_groups = categories . map ( |_| {
369+ // Build category groups if categorizations are provided
370+ let category_groups = categorizations . map ( |_| {
361371 let mut groups: HashMap < String , Vec < ToolSummary > > = HashMap :: new ( ) ;
362372
363373 for tool in & tools {
@@ -551,8 +561,13 @@ mod tests {
551561 output_schema : None ,
552562 } ;
553563
564+ let categorization = ToolCategorization {
565+ category : "messaging" . to_string ( ) ,
566+ keywords : "send,message,chat" . to_string ( ) ,
567+ short_description : "Send a message" . to_string ( ) ,
568+ } ;
554569 let context = generator
555- . create_tool_context ( "test-server" , & tool, Some ( "messaging" ) )
570+ . create_tool_context ( "test-server" , & tool, Some ( & categorization ) )
556571 . unwrap ( ) ;
557572
558573 assert_eq ! ( context. server_id, "test-server" ) ;
@@ -562,6 +577,11 @@ mod tests {
562577 assert_eq ! ( context. properties. len( ) , 1 ) ;
563578 assert_eq ! ( context. properties[ 0 ] . name, "text" ) ;
564579 assert_eq ! ( context. category, Some ( "messaging" . to_string( ) ) ) ;
580+ assert_eq ! ( context. keywords, Some ( "send,message,chat" . to_string( ) ) ) ;
581+ assert_eq ! (
582+ context. short_description,
583+ Some ( "Send a message" . to_string( ) )
584+ ) ;
565585 }
566586
567587 #[ test]
0 commit comments