golf-mcp 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of golf-mcp might be problematic. Click here for more details.
- golf/__init__.py +1 -0
- golf/auth/__init__.py +109 -0
- golf/auth/helpers.py +56 -0
- golf/auth/oauth.py +798 -0
- golf/auth/provider.py +110 -0
- golf/cli/__init__.py +1 -0
- golf/cli/main.py +223 -0
- golf/commands/__init__.py +3 -0
- golf/commands/build.py +78 -0
- golf/commands/init.py +197 -0
- golf/commands/run.py +68 -0
- golf/core/__init__.py +1 -0
- golf/core/builder.py +1169 -0
- golf/core/builder_auth.py +157 -0
- golf/core/builder_telemetry.py +208 -0
- golf/core/config.py +205 -0
- golf/core/parser.py +509 -0
- golf/core/transformer.py +168 -0
- golf/examples/__init__.py +1 -0
- golf/examples/basic/.env +3 -0
- golf/examples/basic/.env.example +3 -0
- golf/examples/basic/README.md +117 -0
- golf/examples/basic/golf.json +9 -0
- golf/examples/basic/pre_build.py +28 -0
- golf/examples/basic/prompts/welcome.py +30 -0
- golf/examples/basic/resources/current_time.py +41 -0
- golf/examples/basic/resources/info.py +27 -0
- golf/examples/basic/resources/weather/common.py +48 -0
- golf/examples/basic/resources/weather/current.py +32 -0
- golf/examples/basic/resources/weather/forecast.py +32 -0
- golf/examples/basic/tools/github_user.py +67 -0
- golf/examples/basic/tools/hello.py +29 -0
- golf/examples/basic/tools/payments/charge.py +50 -0
- golf/examples/basic/tools/payments/common.py +34 -0
- golf/examples/basic/tools/payments/refund.py +50 -0
- golf_mcp-0.1.0.dist-info/METADATA +78 -0
- golf_mcp-0.1.0.dist-info/RECORD +41 -0
- golf_mcp-0.1.0.dist-info/WHEEL +5 -0
- golf_mcp-0.1.0.dist-info/entry_points.txt +2 -0
- golf_mcp-0.1.0.dist-info/licenses/LICENSE +201 -0
- golf_mcp-0.1.0.dist-info/top_level.txt +1 -0
golf/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0" # Placeholder version
|
golf/auth/__init__.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Authentication module for GolfMCP servers.
|
|
2
|
+
|
|
3
|
+
This module provides a simple API for configuring OAuth authentication
|
|
4
|
+
for GolfMCP servers. Users can configure authentication in their pre_build.py
|
|
5
|
+
file without needing to understand the complexities of the MCP SDK.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import List, Optional, Tuple
|
|
9
|
+
|
|
10
|
+
from mcp.server.auth.settings import AuthSettings, ClientRegistrationOptions
|
|
11
|
+
|
|
12
|
+
from .provider import ProviderConfig
|
|
13
|
+
from .oauth import GolfOAuthProvider, create_callback_handler
|
|
14
|
+
from .helpers import get_access_token, get_provider_token, extract_token_from_header
|
|
15
|
+
|
|
16
|
+
class AuthConfig:
|
|
17
|
+
"""Configuration for OAuth authentication in GolfMCP."""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
provider_config: ProviderConfig,
|
|
22
|
+
required_scopes: List[str],
|
|
23
|
+
callback_path: str = "/auth/callback",
|
|
24
|
+
login_path: str = "/login",
|
|
25
|
+
error_path: str = "/auth-error"
|
|
26
|
+
):
|
|
27
|
+
"""Initialize authentication configuration.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
provider_config: Configuration for the OAuth provider
|
|
31
|
+
required_scopes: Scopes required for all authenticated requests
|
|
32
|
+
callback_path: Path for the OAuth callback
|
|
33
|
+
login_path: Path for the login redirect
|
|
34
|
+
error_path: Path for displaying authentication errors
|
|
35
|
+
"""
|
|
36
|
+
self.provider_config = provider_config
|
|
37
|
+
self.required_scopes = required_scopes
|
|
38
|
+
self.callback_path = callback_path
|
|
39
|
+
self.login_path = login_path
|
|
40
|
+
self.error_path = error_path
|
|
41
|
+
|
|
42
|
+
# Create the OAuth provider
|
|
43
|
+
self.provider = GolfOAuthProvider(provider_config)
|
|
44
|
+
|
|
45
|
+
# Create auth settings for FastMCP
|
|
46
|
+
self.auth_settings = AuthSettings(
|
|
47
|
+
issuer_url=provider_config.issuer_url or "http://localhost:3000",
|
|
48
|
+
client_registration_options=ClientRegistrationOptions(
|
|
49
|
+
enabled=True,
|
|
50
|
+
valid_scopes=provider_config.scopes,
|
|
51
|
+
default_scopes=provider_config.scopes
|
|
52
|
+
),
|
|
53
|
+
required_scopes=required_scopes or provider_config.scopes
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Global state for the build process
|
|
57
|
+
_auth_config: Optional[AuthConfig] = None
|
|
58
|
+
|
|
59
|
+
def configure_auth(
|
|
60
|
+
provider_config=None,
|
|
61
|
+
provider=None,
|
|
62
|
+
required_scopes: Optional[List[str]] = None,
|
|
63
|
+
callback_path: str = "/auth/callback",
|
|
64
|
+
) -> None:
|
|
65
|
+
"""Configure authentication for a GolfMCP server.
|
|
66
|
+
|
|
67
|
+
This function should be called in pre_build.py to set up authentication.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
provider_config: Configuration for the OAuth provider (new parameter name)
|
|
71
|
+
provider: Configuration for the OAuth provider (old parameter name, deprecated)
|
|
72
|
+
required_scopes: Scopes required for authentication
|
|
73
|
+
callback_path: Path for the OAuth callback
|
|
74
|
+
public_paths: List of paths that don't require authentication (deprecated, no longer used)
|
|
75
|
+
"""
|
|
76
|
+
global _auth_config
|
|
77
|
+
|
|
78
|
+
# Handle backward compatibility with old parameter name
|
|
79
|
+
if provider_config is None and provider is not None:
|
|
80
|
+
provider_config = provider
|
|
81
|
+
elif provider_config is None and provider is None:
|
|
82
|
+
raise ValueError("Either provider_config or provider must be provided")
|
|
83
|
+
|
|
84
|
+
_auth_config = AuthConfig(
|
|
85
|
+
provider_config=provider_config,
|
|
86
|
+
required_scopes=required_scopes or provider_config.scopes,
|
|
87
|
+
callback_path=callback_path
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def get_auth_config() -> Tuple[Optional[ProviderConfig], List[str]]:
|
|
91
|
+
"""Get the current authentication configuration.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
Tuple of (provider_config, required_scopes)
|
|
95
|
+
"""
|
|
96
|
+
if _auth_config:
|
|
97
|
+
return _auth_config.provider_config, _auth_config.required_scopes
|
|
98
|
+
return None, []
|
|
99
|
+
|
|
100
|
+
def create_auth_provider() -> Optional[GolfOAuthProvider]:
|
|
101
|
+
"""Create an OAuth provider from the configured provider settings.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
GolfOAuthProvider instance or None if not configured
|
|
105
|
+
"""
|
|
106
|
+
if not _auth_config:
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
return _auth_config.provider
|
golf/auth/helpers.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Helper functions for working with authentication in MCP context."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
# Re-export get_access_token from the MCP SDK
|
|
6
|
+
from mcp.server.auth.middleware.auth_context import get_access_token
|
|
7
|
+
|
|
8
|
+
_active_golf_oauth_provider = None
|
|
9
|
+
|
|
10
|
+
def _set_active_golf_oauth_provider(provider_instance) -> None:
|
|
11
|
+
"""
|
|
12
|
+
Sets the active GolfOAuthProvider instance.
|
|
13
|
+
Should only be called once during server startup.
|
|
14
|
+
"""
|
|
15
|
+
global _active_golf_oauth_provider
|
|
16
|
+
_active_golf_oauth_provider = provider_instance
|
|
17
|
+
|
|
18
|
+
def get_provider_token() -> Optional[str]:
|
|
19
|
+
"""
|
|
20
|
+
Get a provider token (e.g., GitHub token) associated with the current
|
|
21
|
+
MCP session's access token.
|
|
22
|
+
|
|
23
|
+
This relies on _set_active_golf_oauth_provider being called at server startup.
|
|
24
|
+
"""
|
|
25
|
+
mcp_access_token = get_access_token() # From MCP SDK, uses its own ContextVar
|
|
26
|
+
if not mcp_access_token:
|
|
27
|
+
# No active MCP session token.
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
provider = _active_golf_oauth_provider
|
|
31
|
+
if not provider:
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
if not hasattr(provider, "get_provider_token"):
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
# Call the get_provider_token method on the actual GolfOAuthProvider instance
|
|
38
|
+
return provider.get_provider_token(mcp_access_token.token)
|
|
39
|
+
|
|
40
|
+
def extract_token_from_header(auth_header: str) -> Optional[str]:
|
|
41
|
+
"""Extract bearer token from Authorization header.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
auth_header: Authorization header value
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
Bearer token or None if not present/valid
|
|
48
|
+
"""
|
|
49
|
+
if not auth_header:
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
parts = auth_header.split()
|
|
53
|
+
if len(parts) != 2 or parts[0].lower() != 'bearer':
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
return parts[1]
|