@@ -22,28 +22,27 @@ export async function createArktsMcpServer(options: ArktsMcpServerOptions = {}):
2222 // Lazy or eager load the tools
2323 if ( import . meta. env . BUILD_TYPE === 'BIN' ) {
2424 const mods = Object . entries ( import . meta. glob < ToolModule > ( './tools/**/*.tool.{ts,md}' , { eager : true } ) )
25- for ( const [ path , mod ] of mods ) {
26- installTools ( path , mod , mods )
27- }
25+ await Promise . all ( mods . map ( async ( [ path , mod ] ) => /* @__PURE__ */ await installTools ( path , mod , mods ) ) )
2826 }
2927 else {
3028 const mods = Object . entries ( import . meta. glob < ToolModule > ( './tools/**/*.tool.{ts,md}' ) )
31- for ( const [ path , mod ] of mods ) {
32- if ( path . endsWith ( '.md' ) ) continue
33- installTools ( path , await mod ( ) , mods )
34- }
29+ await Promise . all ( mods . map ( async ( [ path , mod ] ) => /* @__PURE__ */ await installTools ( path , await mod ( ) , mods ) ) )
3530 }
3631
3732 return server
3833
3934 async function installTools ( path : string , module : ToolModule , mods : [ string , ( ( ) => Promise < ToolModule > ) | ToolModule ] [ ] ) : Promise < void > {
4035 if ( typeof module . default === 'object' && module . default !== null ) {
36+ const description = await findDescription ( path , mods )
37+ const title = await findTitle ( description ?? '' )
38+
4139 server . registerTool ( module . default . name , {
42- description : await findDescription ( path , mods ) ,
40+ title,
41+ description,
4342 ...module . default ,
4443 } , module . default . execute )
4544 }
46- module . install ?.( server )
45+ await module . install ?.( server )
4746 }
4847
4948 async function findDescription ( path : string , mods : [ string , ( ( ) => Promise < ToolModule | MarkdownModule > ) | ToolModule | MarkdownModule ] [ ] ) : Promise < string | undefined > {
@@ -54,4 +53,10 @@ export async function createArktsMcpServer(options: ArktsMcpServerOptions = {}):
5453 return loadedMod . default as string
5554 }
5655 }
56+
57+ async function findTitle ( description : string ) : Promise < string | undefined > {
58+ const maybeTitle = description . trim ( ) . split ( '\n' ) ?. [ 0 ]
59+ if ( maybeTitle ?. startsWith ( '# ' ) ) return maybeTitle . slice ( 2 )
60+ return undefined
61+ }
5762}
0 commit comments