|
26 | 26 |
|
27 | 27 | from fastmcp import FastMCP, Context |
28 | 28 | from fastmcp.server.dependencies import get_access_token |
29 | | -from fastmcp.server.elicitation import AcceptedElicitation, DeclinedElicitation, CancelledElicitation |
30 | 29 |
|
31 | 30 | from src.tools.endpoint_index import get_endpoint_index |
32 | 31 | from src.tools.glossary_index import get_glossary_index |
33 | 32 |
|
34 | 33 | from mcp_server_obp.lifespan import lifespan |
35 | 34 | from mcp_server_obp.auth import get_auth_provider |
36 | | -from mcp_server_obp.elicitation import elicit_consent, ApprovalConsent |
37 | 35 |
|
38 | 36 | logger = logging.getLogger(__name__) |
39 | 37 |
|
@@ -220,26 +218,19 @@ async def call_obp_api( |
220 | 218 | # TODO: Elicit a simple approval here to confirm tool use? |
221 | 219 | request_headers["Authorization"] = f"Bearer {access_token}" |
222 | 220 | 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 |
243 | 234 | case "none": |
244 | 235 | # No authorization |
245 | 236 | logger.info("No authorization method used for OBP API call") |
|
0 commit comments