Skip to content

Commit c4fc052

Browse files
committed
bootstrap consent creation
1 parent 2b3aa45 commit c4fc052

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/mcp_server_obp/server.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,31 @@ async def call_obp_api(
264264
consent_jwt = (headers or {}).get("Consent-JWT")
265265
if not consent_jwt:
266266
bank_id = (path_params or {}).get("BANK_ID") or (path_params or {}).get("bank_id")
267+
268+
# Start with the endpoint's own required roles
269+
required_roles = [role.model_dump() for role in endpoint.roles]
270+
271+
# Merge roles from request body entitlements (e.g., for consent-creation
272+
# endpoints where the body specifies roles to grant). Without this, the
273+
# consent elicited for the endpoint would lack the roles needed to
274+
# actually perform the action (chicken-and-egg problem).
275+
if body and isinstance(body, dict):
276+
for entitlement in body.get("entitlements", []):
277+
if isinstance(entitlement, dict) and "role_name" in entitlement:
278+
body_role = {
279+
"role": entitlement["role_name"],
280+
"requires_bank_id": bool(entitlement.get("bank_id"))
281+
}
282+
if body_role not in required_roles:
283+
required_roles.append(body_role)
284+
267285
return json.dumps({
268286
"error": "consent_required",
269287
"endpoint_id": endpoint_id,
270288
"operation_id": endpoint.operation_id,
271289
"method": endpoint.method,
272290
"path": endpoint.path,
273-
"required_roles": [role.model_dump() for role in endpoint.roles],
291+
"required_roles": required_roles,
274292
"bank_id": bank_id,
275293
"message": f"User consent is required to call {endpoint.operation_id}. "
276294
f"Please approve and provide a Consent-JWT.",

0 commit comments

Comments
 (0)