Skip to content

Commit 72a261a

Browse files
committed
change from consent elicitation to structured error
1 parent 5ed06b5 commit 72a261a

3 files changed

Lines changed: 13 additions & 95 deletions

File tree

src/mcp_server_obp/elicitation.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/mcp_server_obp/headers.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/mcp_server_obp/server.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626

2727
from fastmcp import FastMCP, Context
2828
from fastmcp.server.dependencies import get_access_token
29-
from fastmcp.server.elicitation import AcceptedElicitation, DeclinedElicitation, CancelledElicitation
3029

3130
from src.tools.endpoint_index import get_endpoint_index
3231
from src.tools.glossary_index import get_glossary_index
3332

3433
from mcp_server_obp.lifespan import lifespan
3534
from mcp_server_obp.auth import get_auth_provider
36-
from mcp_server_obp.elicitation import elicit_consent, ApprovalConsent
3735

3836
logger = logging.getLogger(__name__)
3937

@@ -220,26 +218,19 @@ async def call_obp_api(
220218
# TODO: Elicit a simple approval here to confirm tool use?
221219
request_headers["Authorization"] = f"Bearer {access_token}"
222220
case "consent":
223-
# Elicit user consent
224-
logger.info("Eliciting user consent for OBP API call")
225-
from mcp_server_obp.elicitation import elicit_consent
226-
227-
response = await elicit_consent(ctx, endpoint)
228-
match response:
229-
case AcceptedElicitation(data=consent):
230-
# For now just assume the consent is valid, but we might want to decode the JWT in the future
231-
logger.info("User consent accepted for OBP API call")
232-
request_headers["Consent-JWT"] = consent.consent_jwt
233-
case DeclinedElicitation():
234-
logger.info("User declined consent for OBP API call")
235-
return json.dumps({
236-
"error": "User declined consent for this endpoint"
237-
}, indent=2)
238-
case CancelledElicitation():
239-
logger.info("User cancelled consent elicitation for OBP API call")
240-
return json.dumps({
241-
"error": "User cancelled operation."
242-
}, indent=2)
221+
consent_jwt = (headers or {}).get("Consent-JWT")
222+
if not consent_jwt:
223+
return json.dumps({
224+
"error": "consent_required",
225+
"endpoint_id": endpoint_id,
226+
"operation_id": endpoint.operation_id,
227+
"method": endpoint.method.value,
228+
"path": endpoint.path,
229+
"required_roles": [role.model_dump() for role in endpoint.roles],
230+
"message": f"User consent is required to call {endpoint.operation_id}. "
231+
f"Please approve and provide a Consent-JWT.",
232+
}, indent=2)
233+
request_headers["Consent-JWT"] = consent_jwt
243234
case "none":
244235
# No authorization
245236
logger.info("No authorization method used for OBP API call")

0 commit comments

Comments
 (0)