11import asyncio
2+ import logging
23import os
34import sys
45from pathlib import Path
2930from vectorcode .subcommands .prompt import prompt_strings
3031from vectorcode .subcommands .query import get_query_result_files
3132
33+ logger = logging .getLogger (name = __name__ )
3234mcp = FastMCP ("VectorCode" , instructions = "\n " .join (prompt_strings ))
3335
3436
@@ -47,6 +49,7 @@ async def list_collections() -> list[str]:
4749 async for col in get_collections (client ):
4850 if col .metadata is not None :
4951 names .append (str (col .metadata .get ("path" )))
52+ logger .info ("Retrieved the following collections: %s" , names )
5053 return names
5154
5255
@@ -58,7 +61,11 @@ async def query_tool(
5861 query_messages: keywords to query.
5962 collection_path: Directory to the repository;
6063 """
64+ logger .info (
65+ f"query tool called with the following args: { n_query = } , { query_messages = } , { project_root = } "
66+ )
6167 if not os .path .isdir (project_root ):
68+ logger .error ("Invalid project root: %s" , project_root )
6269 raise McpError (
6370 ErrorData (
6471 code = 1 ,
@@ -71,6 +78,7 @@ async def query_tool(
7178 client = await get_client (config )
7279 collection = await get_collection (client , config , False )
7380 except Exception :
81+ logger .error ("Failed to access collection at %s" , project_root )
7482 raise McpError (
7583 ErrorData (
7684 code = 1 ,
@@ -87,6 +95,7 @@ async def query_tool(
8795 query_config = await config .merge_from (
8896 Config (n_result = n_query , query = query_messages )
8997 )
98+ logger .info ("Built the final config: %s" , query_config )
9099 result_paths = await get_query_result_files (
91100 collection = collection ,
92101 configs = query_config ,
@@ -99,7 +108,7 @@ async def query_tool(
99108 results .append (
100109 f"<path>{ rel_path } </path>\n <content>{ fin .read ()} </content>" ,
101110 )
102-
111+ logger . info ( "Retrieved the following files: %s" , result_paths )
103112 return results
104113
105114
@@ -108,6 +117,7 @@ async def mcp_server():
108117 local_config_dir = await find_project_config_dir ("." )
109118
110119 if local_config_dir is not None :
120+ logger .info ("Found project config: %s" , local_config_dir )
111121 project_root = str (Path (local_config_dir ).parent .resolve ())
112122
113123 default_config = await load_config_file (
@@ -117,6 +127,7 @@ async def mcp_server():
117127 default_client = await get_client (default_config )
118128 try :
119129 default_collection = await get_collection (default_client , default_config )
130+ logger .info ("Collection initialised for %s." , project_root )
120131 except InvalidCollectionException :
121132 default_collection = None
122133
0 commit comments