@@ -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 client = new Finch ( {
@@ -82,7 +82,7 @@ export function initMcpServer(params: {
8282
8383 server . setRequestHandler ( ListToolsRequestSchema , async ( ) => {
8484 if ( providedEndpoints === null ) {
85- initTools ( server . getClientVersion ( ) ) ;
85+ await initTools ( server . getClientVersion ( ) ) ;
8686 }
8787 return {
8888 tools : providedEndpoints ! . map ( ( endpoint ) => endpoint . tool ) ,
@@ -91,7 +91,7 @@ export function initMcpServer(params: {
9191
9292 server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
9393 if ( endpointMap === null ) {
94- initTools ( server . getClientVersion ( ) ) ;
94+ await initTools ( server . getClientVersion ( ) ) ;
9595 }
9696 const { name, arguments : args } = request . params ;
9797 const endpoint = endpointMap ! [ name ] ;
@@ -106,7 +106,7 @@ export function initMcpServer(params: {
106106/**
107107 * Selects the tools to include in the MCP Server based on the provided options.
108108 */
109- export function selectTools ( endpoints : Endpoint [ ] , options ?: McpOptions ) : Endpoint [ ] {
109+ export async function selectTools ( endpoints : Endpoint [ ] , options ?: McpOptions ) : Promise < Endpoint [ ] > {
110110 const filteredEndpoints = query ( options ?. filters ?? [ ] , endpoints ) ;
111111
112112 let includedTools = filteredEndpoints ;
@@ -121,7 +121,7 @@ export function selectTools(endpoints: Endpoint[], options?: McpOptions): Endpoi
121121 } else if ( options ?. includeDynamicTools ) {
122122 includedTools = dynamicTools ( endpoints ) ;
123123 } else if ( options ?. includeCodeTools ) {
124- includedTools = [ codeTool ( ) ] ;
124+ includedTools = [ await codeTool ( ) ] ;
125125 } else {
126126 includedTools = endpoints ;
127127 }
0 commit comments