Skip to content

Commit 1b4669d

Browse files
committed
fix: add error handling for collection creation in QdrantStore and update MCP server run method to use environment variables for host and port
1 parent 2df074a commit 1b4669d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

app/mcp_server.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,25 @@ def compile_and_fix(code: str, description: str, max_attempts: int = 3) -> Dict[
114114
# Initialize components
115115
llm_client = LlamaEdgeClient(api_key=api_key)
116116
vector_store = QdrantStore(embedding_size=llm_embed_size)
117-
vector_store.create_collection("project_examples")
118-
vector_store.create_collection("error_examples")
117+
118+
# Create collections with error handling
119+
try:
120+
vector_store.create_collection("project_examples")
121+
print("Created collection: project_examples")
122+
except Exception as e:
123+
if "already exists" in str(e):
124+
print("Collection project_examples already exists")
125+
else:
126+
raise
127+
128+
try:
129+
vector_store.create_collection("error_examples")
130+
print("Created collection: error_examples")
131+
except Exception as e:
132+
if "already exists" in str(e):
133+
print("Collection error_examples already exists")
134+
else:
135+
raise
119136

120137
# Initialize MCP service
121138
mcp_service = RustCompilerMCP(vector_store=vector_store, llm_client=llm_client)
@@ -132,4 +149,6 @@ def compile_and_fix(code: str, description: str, max_attempts: int = 3) -> Dict[
132149
host = os.getenv("MCP_HOST", "0.0.0.0")
133150
port = int(os.getenv("MCP_PORT", "3001"))
134151
print(f"Starting MCP server on {host}:{port}")
135-
mcp.run(host=host, port=port)
152+
os.environ["MCP_HOST"] = host
153+
os.environ["MCP_PORT"] = str(port)
154+
mcp.run() # No parameters

0 commit comments

Comments
 (0)