@@ -55,7 +55,7 @@ export function initMcpServer(params: {
5555 let providedEndpoints : Endpoint [ ] | null = null ;
5656 let endpointMap : Record < string , Endpoint > | null = null ;
5757
58- const initTools = ( implementation ?: Implementation ) => {
58+ const initTools = async ( implementation ?: Implementation ) => {
5959 if ( implementation && ( ! mcpOptions . client || mcpOptions . client === 'infer' ) ) {
6060 mcpOptions . client =
6161 implementation . name . toLowerCase ( ) . includes ( 'claude' ) ? 'claude'
@@ -66,8 +66,8 @@ export function initMcpServer(params: {
6666 ...mcpOptions . capabilities ,
6767 } ;
6868 }
69- providedEndpoints = selectTools ( endpoints , mcpOptions ) ;
70- endpointMap = Object . fromEntries ( providedEndpoints . map ( ( endpoint ) => [ endpoint . tool . name , endpoint ] ) ) ;
69+ providedEndpoints ??= await selectTools ( endpoints , mcpOptions ) ;
70+ endpointMap ?? = Object . fromEntries ( providedEndpoints . map ( ( endpoint ) => [ endpoint . tool . name , endpoint ] ) ) ;
7171 } ;
7272
7373 const logAtLevel =
@@ -96,7 +96,7 @@ export function initMcpServer(params: {
9696
9797 server . setRequestHandler ( ListToolsRequestSchema , async ( ) => {
9898 if ( providedEndpoints === null ) {
99- initTools ( server . getClientVersion ( ) ) ;
99+ await initTools ( server . getClientVersion ( ) ) ;
100100 }
101101 return {
102102 tools : providedEndpoints ! . map ( ( endpoint ) => endpoint . tool ) ,
@@ -105,7 +105,7 @@ export function initMcpServer(params: {
105105
106106 server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
107107 if ( endpointMap === null ) {
108- initTools ( server . getClientVersion ( ) ) ;
108+ await initTools ( server . getClientVersion ( ) ) ;
109109 }
110110 const { name, arguments : args } = request . params ;
111111 const endpoint = endpointMap ! [ name ] ;
@@ -120,7 +120,7 @@ export function initMcpServer(params: {
120120/**
121121 * Selects the tools to include in the MCP Server based on the provided options.
122122 */
123- export function selectTools ( endpoints : Endpoint [ ] , options ?: McpOptions ) : Endpoint [ ] {
123+ export async function selectTools ( endpoints : Endpoint [ ] , options ?: McpOptions ) : Promise < Endpoint [ ] > {
124124 const filteredEndpoints = query ( options ?. filters ?? [ ] , endpoints ) ;
125125
126126 let includedTools = filteredEndpoints ;
@@ -135,7 +135,7 @@ export function selectTools(endpoints: Endpoint[], options?: McpOptions): Endpoi
135135 } else if ( options ?. includeDynamicTools ) {
136136 includedTools = dynamicTools ( endpoints ) ;
137137 } else if ( options ?. includeCodeTools ) {
138- includedTools = [ codeTool ( ) ] ;
138+ includedTools = [ await codeTool ( ) ] ;
139139 } else {
140140 includedTools = endpoints ;
141141 }
0 commit comments