Skip to content

Commit dd310c7

Browse files
committed
Separating version_to_call and version_of_interest
1 parent d6bfee4 commit dd310c7

10 files changed

Lines changed: 62 additions & 37 deletions

File tree

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# OBP API Configuration
22
OBP_BASE_URL="http://localhost:8080"
3-
OBP_API_VERSION="v7.0.0"
3+
# Version of the OBP meta-endpoint to call (resource-docs, glossary, /root)
4+
OBP_VERSION_TO_CALL="v7.0.0"
5+
# Which API version's endpoint catalog to request (requestedApiVersion)
6+
API_VERSION_OF_INTEREST="v7.0.0"
47

58
# Basic Server Config
69
FASTMCP_PORT=9101

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ ENV PATH="/app/.venv/bin:$PATH"
2222
ENV FASTMCP_HOST=0.0.0.0
2323
ENV FASTMCP_PORT=9100
2424
ENV OBP_BASE_URL=https://apisandbox.openbankproject.com
25-
ENV OBP_API_VERSION=v7.0.0
25+
ENV OBP_VERSION_TO_CALL=v7.0.0
26+
ENV API_VERSION_OF_INTEREST=v7.0.0
2627

2728
EXPOSE 9100
2829

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
1818

1919
```bash
2020
OBP_BASE_URL=https://apisandbox.openbankproject.com
21-
OBP_API_VERSION=v7.0.0
21+
OBP_VERSION_TO_CALL=v7.0.0
22+
API_VERSION_OF_INTEREST=v7.0.0
2223
FASTMCP_HOST=127.0.0.1
2324
FASTMCP_PORT=9100
2425
```

database/data_hash_manager.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from pathlib import Path
1717
import requests
1818

19+
from .obp_utils import DEFAULT_API_VERSION
20+
1921
logger = logging.getLogger(__name__)
2022

2123

@@ -35,10 +37,11 @@ def __init__(self, hash_storage_path: Optional[str] = None):
3537

3638
self.hash_storage_path = Path(hash_storage_path)
3739
self.base_url = os.getenv("OBP_BASE_URL")
38-
self.api_version = os.getenv("OBP_API_VERSION")
39-
40-
if not self.base_url or not self.api_version:
41-
raise ValueError("OBP_BASE_URL and OBP_API_VERSION must be set in environment")
40+
self.version_to_call = os.getenv("OBP_VERSION_TO_CALL", DEFAULT_API_VERSION)
41+
self.version_of_interest = os.getenv("API_VERSION_OF_INTEREST", DEFAULT_API_VERSION)
42+
43+
if not self.base_url:
44+
raise ValueError("OBP_BASE_URL must be set in environment")
4245

4346
def check_obp_health(self) -> bool:
4447
"""
@@ -47,7 +50,7 @@ def check_obp_health(self) -> bool:
4750
Returns:
4851
True if OBP is healthy, False otherwise
4952
"""
50-
root_url = f"{self.base_url}/obp/{self.api_version}/root"
53+
root_url = f"{self.base_url}/obp/{self.version_to_call}/root"
5154
try:
5255
response = requests.get(root_url, timeout=10)
5356
response.raise_for_status()
@@ -116,8 +119,8 @@ def fetch_current_data_hashes(self, endpoint_type: str = "all") -> Dict[str, str
116119
Returns:
117120
Dictionary with 'glossary' and 'endpoints' hashes
118121
"""
119-
glossary_url = f"{self.base_url}/obp/{self.api_version}/api/glossary"
120-
swagger_url = f"{self.base_url}/obp/{self.api_version}/resource-docs/{self.api_version}/swagger?content={endpoint_type}"
122+
glossary_url = f"{self.base_url}/obp/{self.version_to_call}/api/glossary"
123+
swagger_url = f"{self.base_url}/obp/{self.version_to_call}/resource-docs/{self.version_of_interest}/swagger?content={endpoint_type}"
121124

122125
try:
123126
# Fetch data

database/obp_utils.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import requests
66
from typing import Dict, Any
77

8+
DEFAULT_API_VERSION = "v7.0.0"
9+
810

911
def get_obp_config(endpoint_type: str = "static", use_resource_docs: bool = True) -> Dict[str, str]:
1012
"""
@@ -19,17 +21,21 @@ def get_obp_config(endpoint_type: str = "static", use_resource_docs: bool = True
1921
Dictionary with configuration including URLs for data fetching
2022
"""
2123
base_url = os.getenv("OBP_BASE_URL")
22-
api_version = os.getenv("OBP_API_VERSION")
23-
24-
if not all([base_url, api_version]):
25-
raise ValueError("Missing required environment variables: OBP_BASE_URL, OBP_API_VERSION")
26-
24+
# Two distinct version axes: the version of the meta-endpoint we hit, and
25+
# the requestedApiVersion that selects which endpoint catalog comes back.
26+
version_to_call = os.getenv("OBP_VERSION_TO_CALL", DEFAULT_API_VERSION)
27+
version_of_interest = os.getenv("API_VERSION_OF_INTEREST", DEFAULT_API_VERSION)
28+
29+
if not base_url:
30+
raise ValueError("Missing required environment variable: OBP_BASE_URL")
31+
2732
config = {
2833
"base_url": base_url,
29-
"api_version": api_version,
30-
"glossary_url": f"{base_url}/obp/{api_version}/api/glossary",
31-
"swagger_url": f"{base_url}/obp/{api_version}/resource-docs/{api_version}/swagger?content={endpoint_type}",
32-
"resource_docs_url": f"{base_url}/obp/{api_version}/resource-docs/{api_version}/obp?content={endpoint_type}",
34+
"version_to_call": version_to_call,
35+
"version_of_interest": version_of_interest,
36+
"glossary_url": f"{base_url}/obp/{version_to_call}/api/glossary",
37+
"swagger_url": f"{base_url}/obp/{version_to_call}/resource-docs/{version_of_interest}/swagger?content={endpoint_type}",
38+
"resource_docs_url": f"{base_url}/obp/{version_to_call}/resource-docs/{version_of_interest}/obp?content={endpoint_type}",
3339
}
3440

3541
# Set the primary data URL based on preference

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ services:
1515

1616
# OBP API Configuration
1717
OBP_BASE_URL: ${OBP_BASE_URL:-https://apisandbox.openbankproject.com}
18-
OBP_API_VERSION: ${OBP_API_VERSION:-v7.0.0}
18+
OBP_VERSION_TO_CALL: ${OBP_VERSION_TO_CALL:-v7.0.0}
19+
API_VERSION_OF_INTEREST: ${API_VERSION_OF_INTEREST:-v7.0.0}
1920

2021
# Authentication Configuration (optional)
2122
ENABLE_OAUTH: ${ENABLE_OAUTH:-false}

docs/HYBRID_ROUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ python scripts/generate_endpoint_index.py --output /path/to/custom_index.json
221221

222222
**Requirements:**
223223
- `OBP_BASE_URL` environment variable (e.g., `https://apisandbox.openbankproject.com`)
224-
- `OBP_API_VERSION` environment variable (e.g., `v7.0.0`)
224+
- `OBP_VERSION_TO_CALL` environment variable — version of the OBP meta-endpoint to call (e.g., `v7.0.0`)
225+
- `API_VERSION_OF_INTEREST` environment variable — `requestedApiVersion` for the endpoint catalog (e.g., `v7.0.0`)
225226

226227
## Deprecated: RAG-Based Tools
227228

run_server.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ fi
1616
export FASTMCP_HOST=${FASTMCP_HOST:-0.0.0.0}
1717
export FASTMCP_PORT=${FASTMCP_PORT:-9100}
1818
export OBP_BASE_URL=${OBP_BASE_URL:-https://apisandbox.openbankproject.com}
19-
export OBP_API_VERSION=${OBP_API_VERSION:-v7.0.0}
19+
export OBP_VERSION_TO_CALL=${OBP_VERSION_TO_CALL:-v7.0.0}
20+
export API_VERSION_OF_INTEREST=${API_VERSION_OF_INTEREST:-v7.0.0}
2021

2122
# Parse command line arguments
2223
WATCH_MODE=false
@@ -41,7 +42,8 @@ echo "=========================================="
4142
echo "Host: $FASTMCP_HOST"
4243
echo "Port: $FASTMCP_PORT"
4344
echo "OBP Base URL: $OBP_BASE_URL"
44-
echo "OBP API Version: $OBP_API_VERSION"
45+
echo "OBP Version To Call: $OBP_VERSION_TO_CALL"
46+
echo "API Version Of Interest: $API_VERSION_OF_INTEREST"
4547
if [ "$WATCH_MODE" = true ]; then
4648
echo "Watch Mode: ENABLED (auto-reload on changes)"
4749
fi

src/mcp_server_obp/server.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
from src.tools.endpoint_index import get_endpoint_index
3434
from src.tools.glossary_index import get_glossary_index
3535

36+
from database.obp_utils import DEFAULT_API_VERSION
37+
3638
from mcp_server_obp.lifespan import lifespan
3739
from mcp_server_obp.auth import get_auth_provider
3840
from mcp_server_obp.status import health_endpoint, ready_endpoint, status_endpoint
@@ -250,7 +252,7 @@ async def call_obp_api(
250252
Execute an OBP API request to a specific endpoint.
251253
252254
Uses the lightweight endpoint index to construct and execute the API call.
253-
Requires OBP_BASE_URL and OBP_API_VERSION environment variables to be set.
255+
Requires the OBP_BASE_URL environment variable to be set.
254256
You may also need authentication headers depending on the endpoint.
255257
256258
Args:
@@ -279,11 +281,11 @@ async def call_obp_api(
279281

280282
# Build the request URL
281283
base_url = os.getenv("OBP_BASE_URL")
282-
api_version = os.getenv("OBP_API_VERSION")
283-
284-
if not base_url or not api_version:
284+
version_to_call = os.getenv("OBP_VERSION_TO_CALL", DEFAULT_API_VERSION)
285+
286+
if not base_url:
285287
return json.dumps({
286-
"error": "OBP_BASE_URL and OBP_API_VERSION environment variables must be set"
288+
"error": "OBP_BASE_URL environment variable must be set"
287289
}, indent=2)
288290

289291
# Construct the path with parameters
@@ -296,7 +298,7 @@ async def call_obp_api(
296298
path = path.replace(key, str(value))
297299

298300
# Replace VERSION placeholder
299-
path = path.replace("VERSION", api_version)
301+
path = path.replace("VERSION", version_to_call)
300302

301303
# Build full URL
302304
url = f"{base_url}{path}"

src/mcp_server_obp/status.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from starlette.requests import Request
2323
from starlette.responses import HTMLResponse, JSONResponse, Response
2424

25+
from database.obp_utils import DEFAULT_API_VERSION
26+
2527
logger = logging.getLogger(__name__)
2628

2729
_START_TIME = time.time()
@@ -66,7 +68,8 @@ async def build_status() -> dict[str, Any]:
6668
from src.tools.glossary_index import get_glossary_index
6769

6870
obp_base_url = os.getenv("OBP_BASE_URL", "").rstrip("/")
69-
obp_api_version = os.getenv("OBP_API_VERSION", "")
71+
obp_version_to_call = os.getenv("OBP_VERSION_TO_CALL", DEFAULT_API_VERSION)
72+
obp_version_of_interest = os.getenv("API_VERSION_OF_INTEREST", DEFAULT_API_VERSION)
7073
auth_enabled = os.getenv("ENABLE_OAUTH", "false").lower() == "true"
7174
auth_provider = os.getenv("AUTH_PROVIDER", "none") if auth_enabled else "none"
7275
outbound_auth_via = os.getenv("OBP_AUTHORIZATION_VIA", "").lower() or None
@@ -95,8 +98,8 @@ async def build_status() -> dict[str, Any]:
9598
obp_check: dict[str, Any] | None = None
9699
if obp_base_url:
97100
root_url = (
98-
f"{obp_base_url}/obp/{obp_api_version}/root"
99-
if obp_api_version
101+
f"{obp_base_url}/obp/{obp_version_to_call}/root"
102+
if obp_version_to_call
100103
else obp_base_url
101104
)
102105
obp_check = {"url": root_url, **(await _check_http(root_url))}
@@ -125,7 +128,8 @@ async def build_status() -> dict[str, Any]:
125128
},
126129
"obp_api": {
127130
"base_url": obp_base_url or None,
128-
"api_version": obp_api_version or None,
131+
"version_to_call": obp_version_to_call or None,
132+
"version_of_interest": obp_version_of_interest or None,
129133
"check": obp_check,
130134
},
131135
"auth": {
@@ -196,7 +200,8 @@ def row(label: str, value: Any) -> str:
196200
obp_check = obp.get("check") or {}
197201
obp_rows = "".join([
198202
row("Base URL", obp.get("base_url")),
199-
row("API version", obp.get("api_version")),
203+
row("Version to call", obp.get("version_to_call")),
204+
row("API version of interest", obp.get("version_of_interest")),
200205
row("Probe URL", obp_check.get("url")),
201206
row("Reachable", obp_check.get("reachable")),
202207
row("HTTP status", obp_check.get("status_code")),
@@ -333,11 +338,11 @@ async def ready_endpoint(request: Request) -> Response:
333338
ok = False
334339

335340
obp_base_url = os.getenv("OBP_BASE_URL", "").rstrip("/")
336-
obp_api_version = os.getenv("OBP_API_VERSION", "")
341+
obp_version_to_call = os.getenv("OBP_VERSION_TO_CALL", DEFAULT_API_VERSION)
337342
if obp_base_url:
338343
url = (
339-
f"{obp_base_url}/obp/{obp_api_version}/root"
340-
if obp_api_version
344+
f"{obp_base_url}/obp/{obp_version_to_call}/root"
345+
if obp_version_to_call
341346
else obp_base_url
342347
)
343348
result = await _check_http(url, timeout=2.0)

0 commit comments

Comments
 (0)