Skip to content

Commit 46ba92a

Browse files
committed
feat(api): add centralized API version config for MCP server
- Create mcp-server/config.py as single source of truth - API_VERSION = 'v1', API_PREFIX = '/api/v1' - server.py: import API_PREFIX, construct BACKEND_API_URL with version - Remove hardcoded /api/ from all 6 API calls: - /search - /repos - /repos/{id}/dependencies - /repos/{id}/style-analysis - /repos/{id}/impact - /repos/{id}/insights Mirrors backend/config/api.py and frontend/config/api.ts pattern. Part of #55
1 parent 3756938 commit 46ba92a

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

mcp-server/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
API Configuration - Single Source of Truth for API Versioning
3+
4+
Change API_VERSION here to update all API calls across the MCP server.
5+
Example: "v1" -> "v2" will change /api/v1/* to /api/v2/*
6+
"""
7+
8+
# =============================================================================
9+
# API VERSION CONFIGURATION
10+
# =============================================================================
11+
12+
API_VERSION = "v1"
13+
14+
# =============================================================================
15+
# DERIVED PREFIXES (auto-calculated from version)
16+
# =============================================================================
17+
18+
# Current versioned API prefix: /api/v1
19+
API_PREFIX = f"/api/{API_VERSION}"

mcp-server/server.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
import mcp.types as types
1515
from dotenv import load_dotenv
1616

17+
# Import API config (single source of truth for versioning)
18+
from config import API_PREFIX
19+
1720
# Load environment variables
1821
load_dotenv()
1922

2023
# Configuration
21-
BACKEND_API_URL = os.getenv("BACKEND_API_URL", "http://localhost:8000")
24+
BACKEND_BASE_URL = os.getenv("BACKEND_API_URL", "http://localhost:8000")
25+
BACKEND_API_URL = f"{BACKEND_BASE_URL}{API_PREFIX}" # Full versioned URL
2226
API_KEY = os.getenv("API_KEY", "dev-secret-key")
2327

2428
# Create MCP server instance
@@ -138,7 +142,7 @@ async def handle_call_tool(
138142

139143
if name == "search_code":
140144
response = await client.post(
141-
f"{BACKEND_API_URL}/api/search",
145+
f"{BACKEND_API_URL}/search",
142146
json=arguments,
143147
headers=headers
144148
)
@@ -167,7 +171,7 @@ async def handle_call_tool(
167171

168172
elif name == "list_repositories":
169173
response = await client.get(
170-
f"{BACKEND_API_URL}/api/repos",
174+
f"{BACKEND_API_URL}/repos",
171175
headers=headers
172176
)
173177
response.raise_for_status()
@@ -188,7 +192,7 @@ async def handle_call_tool(
188192

189193
elif name == "get_dependency_graph":
190194
response = await client.get(
191-
f"{BACKEND_API_URL}/api/repos/{arguments['repo_id']}/dependencies",
195+
f"{BACKEND_API_URL}/repos/{arguments['repo_id']}/dependencies",
192196
headers=headers
193197
)
194198
response.raise_for_status()
@@ -214,7 +218,7 @@ async def handle_call_tool(
214218

215219
elif name == "analyze_code_style":
216220
response = await client.get(
217-
f"{BACKEND_API_URL}/api/repos/{arguments['repo_id']}/style",
221+
f"{BACKEND_API_URL}/repos/{arguments['repo_id']}/style-analysis",
218222
headers=headers
219223
)
220224
response.raise_for_status()
@@ -245,7 +249,7 @@ async def handle_call_tool(
245249

246250
elif name == "analyze_impact":
247251
response = await client.post(
248-
f"{BACKEND_API_URL}/api/repos/{arguments['repo_id']}/impact",
252+
f"{BACKEND_API_URL}/repos/{arguments['repo_id']}/impact",
249253
json={"repo_id": arguments['repo_id'], "file_path": arguments['file_path']},
250254
headers=headers
251255
)
@@ -276,7 +280,7 @@ async def handle_call_tool(
276280

277281
elif name == "get_repository_insights":
278282
response = await client.get(
279-
f"{BACKEND_API_URL}/api/repos/{arguments['repo_id']}/insights",
283+
f"{BACKEND_API_URL}/repos/{arguments['repo_id']}/insights",
280284
headers=headers
281285
)
282286
response.raise_for_status()

0 commit comments

Comments
 (0)