Skip to content

Commit 1d878d4

Browse files
authored
fix: correct the version lookup and add fallback (#24)
1 parent 7e46608 commit 1d878d4

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

analytics_mcp/tools/utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@
2222
import google.auth
2323
import proto
2424

25+
26+
def _get_package_version_with_fallback():
27+
"""Returns the version of the package.
28+
29+
Falls back to 'unknown' if the version can't be resolved.
30+
"""
31+
try:
32+
return metadata.version("google-analytics-mcp")
33+
except:
34+
return "unknown"
35+
36+
2537
# Client information that adds a custom user agent to all API requests.
26-
_CLIENT_INFO = ClientInfo(
27-
user_agent=f"analytics-mcp/{metadata.version('analytics-mcp')}"
28-
)
38+
_CLIENT_INFO = ClientInfo(user_agent=f"analytics-mcp/{_get_package_version_with_fallback()}")
2939

3040
# Read-only scope for Analytics Admin API and Analytics Data API.
3141
_READ_ONLY_ANALYTICS_SCOPE = (

0 commit comments

Comments
 (0)