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.

Refactor authentication module to conditionally register get_login_link tool

Yves Junqueira1df41cfa954c
diff --git a/meta_ads_mcp/__init__.py b/meta_ads_mcp/__init__.py
index 09f0b1a..e2efded 100644
--- a/meta_ads_mcp/__init__.py
+++ b/meta_ads_mcp/__init__.py
@@ -24,7 +24,7 @@ __all__ = [
'get_ad_image',
'update_ad',
'get_insights',
- 'get_login_link',
+ # 'get_login_link' is conditionally exported via core.__all__
'login_cli',
'main',
'search_interests',
@@ -51,7 +51,6 @@ from .core import (
get_ad_image,
update_ad,
get_insights,
- get_login_link,
login_cli,
main,
search_interests,
diff --git a/meta_ads_mcp/core/__init__.py b/meta_ads_mcp/core/__init__.py
index ea27552..7538b23 100644
--- a/meta_ads_mcp/core/__init__.py
+++ b/meta_ads_mcp/core/__init__.py
@@ -6,7 +6,7 @@ from .campaigns import get_campaigns, get_campaign_details, create_campaign
from .adsets import get_adsets, get_adset_details, update_adset
from .ads import get_ads, get_ad_details, get_ad_creatives, get_ad_image, update_ad
from .insights import get_insights
-from .authentication import get_login_link
+from . import authentication # Import module to register conditional auth tools
from .server import login_cli, main
from .auth import login
from . import ads_library # Import module to register conditional tools
@@ -32,7 +32,7 @@ __all__ = [
'get_ad_image',
'update_ad',
'get_insights',
- 'get_login_link',
+ # Note: 'get_login_link' is registered conditionally by the authentication module
'login_cli',
'login',
'main',
diff --git a/meta_ads_mcp/core/authentication.py b/meta_ads_mcp/core/authentication.py
index 9b09b63..ae8ba1d 100644
--- a/meta_ads_mcp/core/authentication.py
+++ b/meta_ads_mcp/core/authentication.py
@@ -21,6 +21,7 @@ Environment Variables:
- PIPEBOARD_API_TOKEN: Enables mode 2 (token-based auth)
- META_ADS_DISABLE_CALLBACK_SERVER: Disables local server, enables mode 3
- META_ACCESS_TOKEN: Direct Meta token (fallback)
+- META_ADS_DISABLE_LOGIN_LINK: Hard-disables the get_login_link tool; returns a disabled message
"""
import json
@@ -32,8 +33,10 @@ from .server import mcp_server
from .utils import logger, META_APP_SECRET
from .pipeboard_auth import pipeboard_auth_manager
+# Only register the login link tool if not explicitly disabled
+ENABLE_LOGIN_LINK = not bool(os.environ.get("META_ADS_DISABLE_LOGIN_LINK", ""))
+
-@mcp_server.tool()
async def get_login_link(access_token: str = None) -> str:
"""
Get a clickable login link for Meta Ads authentication.
@@ -195,4 +198,8 @@ async def get_login_link(access_token: str = None) -> str:
# Wait a moment to ensure the server is fully started
await asyncio.sleep(1)
- return json.dumps(response, indent=2)
\ No newline at end of file
+ return json.dumps(response, indent=2)
+
+# Conditionally register as MCP tool only when enabled
+if ENABLE_LOGIN_LINK:
+ get_login_link = mcp_server.tool()(get_login_link)
\ No newline at end of file