Skip to content

Meta Ads (Facebook/Instagram) MCP server for Claude, ChatGPT, Perplexity & Cursor — the Meta node of Pipeboard’s 5-platform family (+ Google, TikTok, Snap, Reddit). Hosted remote MCP, badged Meta Business Partner, free plan — no self-hosting required.

Enhance authentication error handling and logging for Pipeboard integration

Yves Junqueiraad3b07ab9833
diff --git a/meta_ads_mcp/core/api.py b/meta_ads_mcp/core/api.py
index 14c54d4..758dfa6 100644
--- a/meta_ads_mcp/core/api.py
+++ b/meta_ads_mcp/core/api.py
@@ -206,6 +206,9 @@ def meta_api_tool(func):
if (auth_manager.app_id == "YOUR_META_APP_ID" or not auth_manager.app_id) and not auth_manager.use_pipeboard:
logger.error("TOKEN VALIDATION FAILED: No valid app_id configured")
logger.error("Please set META_APP_ID environment variable or configure in your code")
+ elif auth_manager.use_pipeboard:
+ logger.error("TOKEN VALIDATION FAILED: Pipeboard authentication enabled but no valid token available")
+ logger.error("Complete authentication via Pipeboard service or check PIPEBOARD_API_TOKEN")
else:
logger.error("Check logs above for detailed token validation failures")
except Exception as e:
@@ -221,16 +224,21 @@ def meta_api_tool(func):
# Add more specific troubleshooting information
auth_url = auth_manager.get_auth_url()
app_id = auth_manager.app_id
+ using_pipeboard = auth_manager.use_pipeboard
logger.error("TOKEN VALIDATION SUMMARY:")
logger.error(f"- Current app_id: '{app_id}'")
logger.error(f"- Environment META_APP_ID: '{os.environ.get('META_APP_ID', 'Not set')}'")
logger.error(f"- Pipeboard API token configured: {'Yes' if os.environ.get('PIPEBOARD_API_TOKEN') else 'No'}")
+ logger.error(f"- Using Pipeboard authentication: {'Yes' if using_pipeboard else 'No'}")
- # Check for common configuration issues
- if app_id == "YOUR_META_APP_ID" or not app_id:
+ # Check for common configuration issues - but only if not using Pipeboard
+ if not using_pipeboard and (app_id == "YOUR_META_APP_ID" or not app_id):
logger.error("ISSUE DETECTED: No valid Meta App ID configured")
logger.error("ACTION REQUIRED: Set META_APP_ID environment variable with a valid App ID")
+ elif using_pipeboard:
+ logger.error("ISSUE DETECTED: Pipeboard authentication configured but no valid token available")
+ logger.error("ACTION REQUIRED: Complete authentication via Pipeboard service")
return json.dumps({
"error": {
diff --git a/meta_ads_mcp/core/authentication.py b/meta_ads_mcp/core/authentication.py
index b33dd15..bd0c640 100644
--- a/meta_ads_mcp/core/authentication.py
+++ b/meta_ads_mcp/core/authentication.py
@@ -116,7 +116,7 @@ async def get_login_link(access_token: str = None) -> str:
"authentication_method": "meta_oauth",
"token_exchange_message": f"Your authentication token will be valid for approximately {token_duration}." +
(" Long-lived token exchange is enabled." if token_exchange_supported else
- " To enable long-lived tokens (60 days), set the META_APP_SECRET environment variable."),
+ " For direct Meta authentication, long-lived tokens require META_APP_SECRET. Consider using Pipeboard authentication instead (60-day tokens by default)."),
"note": "After authenticating, the token will be automatically saved."
}
diff --git a/meta_ads_mcp/core/utils.py b/meta_ads_mcp/core/utils.py
index 855f80a..84c9083 100644
--- a/meta_ads_mcp/core/utils.py
+++ b/meta_ads_mcp/core/utils.py
@@ -24,9 +24,13 @@ using_pipeboard = bool(os.environ.get("PIPEBOARD_API_TOKEN", ""))
# Print warning if Meta app credentials are not configured and not using Pipeboard
if not using_pipeboard:
if not META_APP_ID:
- print("WARNING: META_APP_ID environment variable is not set. Authentication will not work properly.")
+ print("WARNING: META_APP_ID environment variable is not set.")
+ print("RECOMMENDED: Use Pipeboard authentication by setting PIPEBOARD_API_TOKEN instead.")
+ print("ALTERNATIVE: For direct Meta authentication, set META_APP_ID to your Meta App ID.")
if not META_APP_SECRET:
- print("WARNING: META_APP_SECRET environment variable is not set. Long-lived token exchange will not work.")
+ print("WARNING: META_APP_SECRET environment variable is not set.")
+ print("NOTE: This is only needed for direct Meta authentication. Pipeboard authentication doesn't require this.")
+ print("RECOMMENDED: Use Pipeboard authentication by setting PIPEBOARD_API_TOKEN instead.")
# Configure logging to file
def setup_logging():