1010# Load environment variables from .env file before anything else
1111load_dotenv ()
1212
13- # Configure logging
13+ # Configure logging (allow override via LOG_LEVEL env)
14+ _log_level = os .getenv ("LOG_LEVEL" , "INFO" ).upper ()
1415logging .basicConfig (
15- level = logging .INFO ,
16+ level = getattr ( logging , _log_level , logging .INFO ) ,
1617 format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ,
1718)
19+ # Ensure our package logger honors the chosen level (basicConfig locks in handlers)
20+ logging .getLogger ("mcp_server_obp" ).setLevel (getattr (logging , _log_level , logging .INFO ))
1821
1922# Add the src and project root directories to the Python path when running as a script
2023_src_dir = Path (__file__ ).parent .parent
@@ -204,7 +207,7 @@ async def call_obp_api(
204207 url = f"{ base_url } { path } "
205208
206209 # Prepare request
207- method = endpoint .method . value # HttpMethod enum value
210+ method = endpoint .method # HttpMethod enum value
208211 request_headers = headers or {}
209212
210213 auth_method = os .getenv ("OBP_AUTHORIZATION_VIA" , "none" ).lower ()
@@ -224,7 +227,7 @@ async def call_obp_api(
224227 "error" : "consent_required" ,
225228 "endpoint_id" : endpoint_id ,
226229 "operation_id" : endpoint .operation_id ,
227- "method" : endpoint .method . value ,
230+ "method" : endpoint .method ,
228231 "path" : endpoint .path ,
229232 "required_roles" : [role .model_dump () for role in endpoint .roles ],
230233 "message" : f"User consent is required to call { endpoint .operation_id } . "
@@ -263,8 +266,12 @@ async def call_obp_api(
263266
264267 try :
265268 result ["response" ] = response .json ()
269+ logging .info (f"OBP API call successful: { method } { url } - Status: { response .status_code } " )
270+ logging .info (f"Response: { json .dumps (result ['response' ], indent = 2 )[:500 ]} ..." ) # Log first 500 chars of response
266271 except :
267272 result ["response" ] = response .text
273+ logging .info (f"OBP API call with non-JSON response: { method } { url } - Status: { response .status_code } " )
274+ logging .info (f"Response: { result ['response' ][:500 ]} ..." ) # Log first 500 chars of response
268275
269276 return json .dumps (result , indent = 2 )
270277
0 commit comments