golf-mcp 0.1.20__py3-none-any.whl → 0.2.1__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 +9 -1
- golf/_endpoints.py +6 -0
- golf/_endpoints_fallback.py +10 -0
- golf/auth/__init__.py +235 -83
- golf/auth/api_key.py +6 -14
- golf/auth/factory.py +358 -0
- golf/auth/helpers.py +12 -42
- golf/auth/providers.py +446 -0
- golf/auth/registry.py +256 -0
- golf/cli/branding.py +192 -0
- golf/cli/main.py +28 -69
- golf/commands/__init__.py +2 -0
- golf/commands/build.py +4 -7
- golf/commands/init.py +30 -53
- golf/commands/run.py +50 -20
- golf/core/builder.py +355 -414
- golf/core/builder_auth.py +63 -144
- golf/core/builder_telemetry.py +26 -3
- golf/core/config.py +38 -59
- golf/core/parser.py +132 -139
- golf/core/platform.py +12 -10
- golf/core/telemetry.py +11 -19
- golf/core/transformer.py +38 -15
- golf/examples/__pycache__/__init__.cpython-311.pyc +0 -0
- golf/examples/basic/.coverage +0 -0
- golf/examples/basic/.env.example +8 -4
- golf/examples/basic/README.md +117 -45
- golf/examples/basic/__pycache__/auth.cpython-311.pyc +0 -0
- golf/examples/basic/auth.py +76 -0
- golf/examples/basic/golf.json +2 -5
- golf/examples/basic/htmlcov/.gitignore +2 -0
- golf/examples/basic/htmlcov/class_index.html +547 -0
- golf/examples/basic/htmlcov/coverage_html_cb_6fb7b396.js +733 -0
- golf/examples/basic/htmlcov/favicon_32_cb_58284776.png +0 -0
- golf/examples/basic/htmlcov/function_index.html +2091 -0
- golf/examples/basic/htmlcov/index.html +349 -0
- golf/examples/basic/htmlcov/keybd_closed_cb_ce680311.png +0 -0
- golf/examples/basic/htmlcov/status.json +1 -0
- golf/examples/basic/htmlcov/style_cb_8e611ae1.css +337 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496___init___py.html +323 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_api_key_py.html +170 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_factory_py.html +430 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_helpers_py.html +288 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_providers_py.html +493 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_registry_py.html +353 -0
- golf/examples/basic/htmlcov/z_3ec3b3f490dc0950___init___py.html +120 -0
- golf/examples/basic/htmlcov/z_3ec3b3f490dc0950_instrumentation_py.html +1535 -0
- golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db___init___py.html +98 -0
- golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db_branding_py.html +289 -0
- golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db_main_py.html +476 -0
- golf/examples/basic/htmlcov/z_5a6c4e6bcc86fb2f___init___py.html +97 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d___init___py.html +102 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d_build_py.html +178 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d_init_py.html +387 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d_run_py.html +222 -0
- golf/examples/basic/htmlcov/z_6fcdee0582ba84e4___init___py.html +106 -0
- golf/examples/basic/htmlcov/z_6fcdee0582ba84e4__endpoints_fallback_py.html +107 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217___init___py.html +98 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_auth_py.html +306 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_metrics_py.html +329 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_py.html +1471 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_telemetry_py.html +186 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_config_py.html +315 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_parser_py.html +1149 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_platform_py.html +279 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_telemetry_py.html +589 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_transformer_py.html +286 -0
- golf/examples/basic/htmlcov/z_7d7da37693a43688___init___py.html +107 -0
- golf/examples/basic/htmlcov/z_7d7da37693a43688_collector_py.html +417 -0
- golf/examples/basic/htmlcov/z_7d7da37693a43688_registry_py.html +109 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e___init___py.html +109 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e_context_py.html +150 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e_elicitation_py.html +267 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e_sampling_py.html +318 -0
- golf/examples/basic/prompts/__pycache__/welcome.cpython-311.pyc +0 -0
- golf/examples/basic/prompts/welcome.py +3 -5
- golf/examples/basic/resources/__pycache__/current_time.cpython-311.pyc +0 -0
- golf/examples/basic/resources/__pycache__/info.cpython-311.pyc +0 -0
- golf/examples/basic/resources/current_time.py +5 -13
- golf/examples/basic/resources/weather/__pycache__/common.cpython-311.pyc +0 -0
- golf/examples/basic/resources/weather/__pycache__/current.cpython-311.pyc +0 -0
- golf/examples/basic/resources/weather/__pycache__/forecast.cpython-311.pyc +0 -0
- golf/examples/basic/resources/weather/city.py +46 -0
- golf/examples/basic/resources/weather/common.py +4 -11
- golf/examples/basic/resources/weather/current.py +5 -5
- golf/examples/basic/resources/weather/forecast.py +5 -5
- golf/examples/basic/tools/__pycache__/calculator.cpython-311.pyc +0 -0
- golf/examples/basic/tools/calculator.py +94 -0
- golf/examples/basic/tools/say/__pycache__/hello.cpython-311.pyc +0 -0
- golf/examples/basic/tools/say/hello.py +65 -0
- golf/metrics/collector.py +100 -19
- golf/telemetry/__init__.py +4 -0
- golf/telemetry/instrumentation.py +484 -178
- golf/utilities/__init__.py +12 -0
- golf/utilities/context.py +53 -0
- golf/utilities/elicitation.py +170 -0
- golf/utilities/sampling.py +221 -0
- {golf_mcp-0.1.20.dist-info → golf_mcp-0.2.1.dist-info}/METADATA +51 -104
- golf_mcp-0.2.1.dist-info/RECORD +110 -0
- golf/auth/oauth.py +0 -861
- golf/auth/provider.py +0 -115
- golf/examples/api_key/.env +0 -2
- golf/examples/api_key/.env.example +0 -1
- golf/examples/api_key/README.md +0 -84
- golf/examples/api_key/golf.json +0 -8
- golf/examples/api_key/pre_build.py +0 -11
- golf/examples/api_key/tools/issues/create.py +0 -93
- golf/examples/api_key/tools/issues/list.py +0 -92
- golf/examples/api_key/tools/repos/list.py +0 -111
- golf/examples/api_key/tools/search/code.py +0 -106
- golf/examples/api_key/tools/users/get.py +0 -82
- golf/examples/basic/.env +0 -5
- golf/examples/basic/pre_build.py +0 -28
- golf/examples/basic/tools/github_user.py +0 -65
- golf/examples/basic/tools/hello.py +0 -34
- golf/examples/basic/tools/payments/charge.py +0 -70
- golf/examples/basic/tools/payments/common.py +0 -36
- golf/examples/basic/tools/payments/refund.py +0 -61
- golf_mcp-0.1.20.dist-info/RECORD +0 -60
- {golf_mcp-0.1.20.dist-info → golf_mcp-0.2.1.dist-info}/WHEEL +0 -0
- {golf_mcp-0.1.20.dist-info → golf_mcp-0.2.1.dist-info}/entry_points.txt +0 -0
- {golf_mcp-0.1.20.dist-info → golf_mcp-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {golf_mcp-0.1.20.dist-info → golf_mcp-0.2.1.dist-info}/top_level.txt +0 -0
golf/__init__.py
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
__version__ = "0.1
|
|
1
|
+
__version__ = "0.2.1"
|
|
2
|
+
|
|
3
|
+
# Import endpoints with fallback for dev mode
|
|
4
|
+
try:
|
|
5
|
+
# In built wheels, this exists (generated from _endpoints.py.in)
|
|
6
|
+
from . import _endpoints
|
|
7
|
+
except ImportError:
|
|
8
|
+
# In editable/dev installs, fall back to env-based values
|
|
9
|
+
from . import _endpoints_fallback as _endpoints
|
golf/_endpoints.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Fallback endpoints for development/editable installs."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
# These are used when the generated _endpoints.py doesn't exist (dev mode)
|
|
6
|
+
# or when environment variables override the built-in values
|
|
7
|
+
|
|
8
|
+
PLATFORM_API_URL = os.getenv("GOLF_PLATFORM_API_URL", "http://localhost:8000/api/resources")
|
|
9
|
+
|
|
10
|
+
OTEL_ENDPOINT = os.getenv("GOLF_OTEL_ENDPOINT", "http://localhost:4318/v1/traces")
|
golf/auth/__init__.py
CHANGED
|
@@ -1,122 +1,274 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Modern authentication for Golf MCP servers using FastMCP 2.11+ providers.
|
|
2
2
|
|
|
3
|
-
This module provides
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
This module provides authentication configuration and utilities for Golf servers,
|
|
4
|
+
leveraging FastMCP's built-in authentication system with JWT verification,
|
|
5
|
+
OAuth providers, and token management.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
# Modern auth provider configurations and factory functions
|
|
11
|
+
from .providers import (
|
|
12
|
+
AuthConfig,
|
|
13
|
+
JWTAuthConfig,
|
|
14
|
+
StaticTokenConfig,
|
|
15
|
+
OAuthServerConfig,
|
|
16
|
+
RemoteAuthConfig,
|
|
17
|
+
OAuthProxyConfig,
|
|
18
|
+
)
|
|
19
|
+
from .factory import (
|
|
20
|
+
create_auth_provider,
|
|
21
|
+
create_simple_jwt_provider,
|
|
22
|
+
create_dev_token_provider,
|
|
23
|
+
)
|
|
24
|
+
from .registry import (
|
|
25
|
+
BaseProviderPlugin,
|
|
26
|
+
AuthProviderFactory,
|
|
27
|
+
get_provider_registry,
|
|
28
|
+
register_provider_factory,
|
|
29
|
+
register_provider_plugin,
|
|
30
|
+
)
|
|
11
31
|
|
|
32
|
+
# Re-export for backward compatibility
|
|
12
33
|
from .api_key import configure_api_key, get_api_key_config, is_api_key_configured
|
|
13
34
|
from .helpers import (
|
|
14
35
|
debug_api_key_context,
|
|
15
36
|
extract_token_from_header,
|
|
16
|
-
get_access_token,
|
|
17
37
|
get_api_key,
|
|
18
38
|
get_provider_token,
|
|
19
39
|
set_api_key,
|
|
20
40
|
)
|
|
21
|
-
from .oauth import GolfOAuthProvider, create_callback_handler
|
|
22
|
-
from .provider import ProviderConfig
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class AuthConfig:
|
|
26
|
-
"""Configuration for OAuth authentication in GolfMCP."""
|
|
27
|
-
|
|
28
|
-
def __init__(
|
|
29
|
-
self,
|
|
30
|
-
provider_config: ProviderConfig,
|
|
31
|
-
required_scopes: list[str],
|
|
32
|
-
callback_path: str = "/auth/callback",
|
|
33
|
-
login_path: str = "/login",
|
|
34
|
-
error_path: str = "/auth-error",
|
|
35
|
-
) -> None:
|
|
36
|
-
"""Initialize authentication configuration.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
provider_config: Configuration for the OAuth provider
|
|
40
|
-
required_scopes: Scopes required for all authenticated requests
|
|
41
|
-
callback_path: Path for the OAuth callback
|
|
42
|
-
login_path: Path for the login redirect
|
|
43
|
-
error_path: Path for displaying authentication errors
|
|
44
|
-
"""
|
|
45
|
-
self.provider_config = provider_config
|
|
46
|
-
self.required_scopes = required_scopes
|
|
47
|
-
self.callback_path = callback_path
|
|
48
|
-
self.login_path = login_path
|
|
49
|
-
self.error_path = error_path
|
|
50
|
-
|
|
51
|
-
# Create the OAuth provider
|
|
52
|
-
self.provider = GolfOAuthProvider(provider_config)
|
|
53
|
-
|
|
54
|
-
# Create auth settings for FastMCP
|
|
55
|
-
self.auth_settings = AuthSettings(
|
|
56
|
-
issuer_url=provider_config.issuer_url or "http://localhost:3000",
|
|
57
|
-
client_registration_options=ClientRegistrationOptions(
|
|
58
|
-
enabled=True,
|
|
59
|
-
valid_scopes=provider_config.scopes,
|
|
60
|
-
default_scopes=provider_config.scopes,
|
|
61
|
-
),
|
|
62
|
-
required_scopes=required_scopes or provider_config.scopes,
|
|
63
|
-
)
|
|
64
41
|
|
|
42
|
+
# Public API
|
|
43
|
+
__all__ = [
|
|
44
|
+
# Main configuration functions
|
|
45
|
+
"configure_auth",
|
|
46
|
+
"configure_jwt_auth",
|
|
47
|
+
"configure_dev_auth",
|
|
48
|
+
"configure_oauth_proxy",
|
|
49
|
+
"get_auth_config",
|
|
50
|
+
# Provider configurations
|
|
51
|
+
"AuthConfig",
|
|
52
|
+
"JWTAuthConfig",
|
|
53
|
+
"StaticTokenConfig",
|
|
54
|
+
"OAuthServerConfig",
|
|
55
|
+
"RemoteAuthConfig",
|
|
56
|
+
"OAuthProxyConfig",
|
|
57
|
+
# Factory functions
|
|
58
|
+
"create_auth_provider",
|
|
59
|
+
"create_simple_jwt_provider",
|
|
60
|
+
"create_dev_token_provider",
|
|
61
|
+
# Provider registry and plugins
|
|
62
|
+
"BaseProviderPlugin",
|
|
63
|
+
"AuthProviderFactory",
|
|
64
|
+
"get_provider_registry",
|
|
65
|
+
"register_provider_factory",
|
|
66
|
+
"register_provider_plugin",
|
|
67
|
+
# API key functions (backward compatibility)
|
|
68
|
+
"configure_api_key",
|
|
69
|
+
"get_api_key_config",
|
|
70
|
+
"is_api_key_configured",
|
|
71
|
+
# Helper functions
|
|
72
|
+
"debug_api_key_context",
|
|
73
|
+
"extract_token_from_header",
|
|
74
|
+
"get_api_key",
|
|
75
|
+
"get_provider_token",
|
|
76
|
+
"set_api_key",
|
|
77
|
+
]
|
|
65
78
|
|
|
66
|
-
# Global
|
|
79
|
+
# Global storage for auth configuration
|
|
67
80
|
_auth_config: AuthConfig | None = None
|
|
68
81
|
|
|
69
82
|
|
|
70
|
-
def configure_auth(
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
def configure_auth(config: AuthConfig) -> None:
|
|
84
|
+
"""Configure authentication for the Golf server.
|
|
85
|
+
|
|
86
|
+
This function should be called in auth.py to set up authentication
|
|
87
|
+
using FastMCP's modern auth providers.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
config: Authentication configuration (JWT, OAuth, Static, or Remote)
|
|
91
|
+
The required_scopes should be specified in the config itself.
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
# JWT authentication with Auth0
|
|
95
|
+
from golf.auth import configure_auth, JWTAuthConfig
|
|
96
|
+
|
|
97
|
+
configure_auth(
|
|
98
|
+
JWTAuthConfig(
|
|
99
|
+
jwks_uri="https://your-domain.auth0.com/.well-known/jwks.json",
|
|
100
|
+
issuer="https://your-domain.auth0.com/",
|
|
101
|
+
audience="https://your-api.example.com",
|
|
102
|
+
required_scopes=["read:data"],
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Development with static tokens
|
|
107
|
+
from golf.auth import configure_auth, StaticTokenConfig
|
|
108
|
+
|
|
109
|
+
configure_auth(
|
|
110
|
+
StaticTokenConfig(
|
|
111
|
+
tokens={
|
|
112
|
+
"dev-token-123": {
|
|
113
|
+
"client_id": "dev-client",
|
|
114
|
+
"scopes": ["read", "write"],
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
required_scopes=["read"],
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# Full OAuth server
|
|
122
|
+
from golf.auth import configure_auth, OAuthServerConfig
|
|
123
|
+
|
|
124
|
+
configure_auth(
|
|
125
|
+
OAuthServerConfig(
|
|
126
|
+
base_url="https://your-server.example.com",
|
|
127
|
+
valid_scopes=["read", "write", "admin"],
|
|
128
|
+
default_scopes=["read"],
|
|
129
|
+
required_scopes=["read"],
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
"""
|
|
133
|
+
global _auth_config
|
|
134
|
+
_auth_config = config
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def configure_jwt_auth(
|
|
138
|
+
*,
|
|
139
|
+
jwks_uri: str | None = None,
|
|
140
|
+
public_key: str | None = None,
|
|
141
|
+
issuer: str | None = None,
|
|
142
|
+
audience: str | list[str] | None = None,
|
|
73
143
|
required_scopes: list[str] | None = None,
|
|
74
|
-
|
|
144
|
+
**env_vars: str,
|
|
75
145
|
) -> None:
|
|
76
|
-
"""
|
|
146
|
+
"""Convenience function to configure JWT authentication.
|
|
77
147
|
|
|
78
|
-
|
|
148
|
+
Args:
|
|
149
|
+
jwks_uri: JWKS URI for key fetching
|
|
150
|
+
public_key: Static public key (PEM format)
|
|
151
|
+
issuer: Expected issuer claim
|
|
152
|
+
audience: Expected audience claim(s)
|
|
153
|
+
required_scopes: Required scopes for all requests
|
|
154
|
+
**env_vars: Environment variable names (public_key_env_var,
|
|
155
|
+
jwks_uri_env_var, etc.)
|
|
156
|
+
"""
|
|
157
|
+
config = JWTAuthConfig(
|
|
158
|
+
jwks_uri=jwks_uri,
|
|
159
|
+
public_key=public_key,
|
|
160
|
+
issuer=issuer,
|
|
161
|
+
audience=audience,
|
|
162
|
+
required_scopes=required_scopes or [],
|
|
163
|
+
**env_vars,
|
|
164
|
+
)
|
|
165
|
+
configure_auth(config)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def configure_dev_auth(
|
|
169
|
+
tokens: dict[str, Any] | None = None,
|
|
170
|
+
required_scopes: list[str] | None = None,
|
|
171
|
+
) -> None:
|
|
172
|
+
"""Convenience function to configure development authentication.
|
|
79
173
|
|
|
80
174
|
Args:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
required_scopes: Scopes required for authentication
|
|
84
|
-
callback_path: Path for the OAuth callback
|
|
85
|
-
public_paths: List of paths that don't require authentication (deprecated, no longer used)
|
|
175
|
+
tokens: Token dictionary or None for defaults
|
|
176
|
+
required_scopes: Required scopes for all requests
|
|
86
177
|
"""
|
|
87
|
-
|
|
178
|
+
if tokens is None:
|
|
179
|
+
tokens = {
|
|
180
|
+
"dev-token-123": {
|
|
181
|
+
"client_id": "dev-client",
|
|
182
|
+
"scopes": ["read", "write"],
|
|
183
|
+
},
|
|
184
|
+
"admin-token-456": {
|
|
185
|
+
"client_id": "admin-client",
|
|
186
|
+
"scopes": ["read", "write", "admin"],
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
config = StaticTokenConfig(
|
|
191
|
+
tokens=tokens,
|
|
192
|
+
required_scopes=required_scopes or [],
|
|
193
|
+
)
|
|
194
|
+
configure_auth(config)
|
|
88
195
|
|
|
89
|
-
# Handle backward compatibility with old parameter name
|
|
90
|
-
if provider_config is None and provider is not None:
|
|
91
|
-
provider_config = provider
|
|
92
|
-
elif provider_config is None and provider is None:
|
|
93
|
-
raise ValueError("Either provider_config or provider must be provided")
|
|
94
196
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
197
|
+
def configure_oauth_proxy(
|
|
198
|
+
upstream_authorization_endpoint: str,
|
|
199
|
+
upstream_token_endpoint: str,
|
|
200
|
+
upstream_client_id: str,
|
|
201
|
+
upstream_client_secret: str,
|
|
202
|
+
base_url: str,
|
|
203
|
+
token_verifier_config: JWTAuthConfig | StaticTokenConfig,
|
|
204
|
+
scopes_supported: list[str] | None = None,
|
|
205
|
+
upstream_revocation_endpoint: str | None = None,
|
|
206
|
+
redirect_path: str = "/oauth/callback",
|
|
207
|
+
) -> None:
|
|
208
|
+
"""Configure OAuth proxy authentication for non-DCR providers.
|
|
209
|
+
|
|
210
|
+
This sets up an OAuth proxy that bridges MCP clients (expecting DCR) with
|
|
211
|
+
traditional OAuth providers like GitHub, Google, Okta Web Apps that use
|
|
212
|
+
fixed client credentials.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
upstream_authorization_endpoint: Provider's authorization URL
|
|
216
|
+
upstream_token_endpoint: Provider's token endpoint URL
|
|
217
|
+
upstream_client_id: Your client ID registered with the provider
|
|
218
|
+
upstream_client_secret: Your client secret from the provider
|
|
219
|
+
base_url: This proxy server's public URL
|
|
220
|
+
token_verifier_config: JWT or static token config for token verification
|
|
221
|
+
scopes_supported: Scopes to advertise to MCP clients
|
|
222
|
+
upstream_revocation_endpoint: Optional token revocation endpoint
|
|
223
|
+
redirect_path: OAuth callback path (default: /oauth/callback)
|
|
224
|
+
|
|
225
|
+
Note:
|
|
226
|
+
Requires golf-mcp-enterprise package for implementation.
|
|
227
|
+
"""
|
|
228
|
+
config = OAuthProxyConfig(
|
|
229
|
+
upstream_authorization_endpoint=upstream_authorization_endpoint,
|
|
230
|
+
upstream_token_endpoint=upstream_token_endpoint,
|
|
231
|
+
upstream_client_id=upstream_client_id,
|
|
232
|
+
upstream_client_secret=upstream_client_secret,
|
|
233
|
+
upstream_revocation_endpoint=upstream_revocation_endpoint,
|
|
234
|
+
base_url=base_url,
|
|
235
|
+
redirect_path=redirect_path,
|
|
236
|
+
scopes_supported=scopes_supported or [],
|
|
237
|
+
token_verifier_config=token_verifier_config,
|
|
99
238
|
)
|
|
239
|
+
configure_auth(config)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def get_auth_config() -> AuthConfig | None:
|
|
243
|
+
"""Get the current auth configuration.
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
AuthConfig if configured, None otherwise
|
|
247
|
+
"""
|
|
248
|
+
return _auth_config
|
|
100
249
|
|
|
101
250
|
|
|
102
|
-
def
|
|
103
|
-
"""
|
|
251
|
+
def is_auth_configured() -> bool:
|
|
252
|
+
"""Check if authentication is configured.
|
|
104
253
|
|
|
105
254
|
Returns:
|
|
106
|
-
|
|
255
|
+
True if authentication is configured, False otherwise
|
|
107
256
|
"""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
257
|
+
return _auth_config is not None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
# Breaking change in Golf 0.2.x: Legacy auth system removed
|
|
261
|
+
# Users must migrate to modern auth configurations
|
|
111
262
|
|
|
112
263
|
|
|
113
|
-
def
|
|
114
|
-
"""Create an
|
|
264
|
+
def create_auth_provider_from_config() -> object | None:
|
|
265
|
+
"""Create an auth provider from the current configuration.
|
|
115
266
|
|
|
116
267
|
Returns:
|
|
117
|
-
|
|
268
|
+
FastMCP AuthProvider instance or None if not configured
|
|
118
269
|
"""
|
|
119
|
-
|
|
270
|
+
config = get_auth_config()
|
|
271
|
+
if not config:
|
|
120
272
|
return None
|
|
121
273
|
|
|
122
|
-
return
|
|
274
|
+
return create_auth_provider(config)
|
golf/auth/api_key.py
CHANGED
|
@@ -11,28 +11,22 @@ from pydantic import BaseModel, Field
|
|
|
11
11
|
class ApiKeyConfig(BaseModel):
|
|
12
12
|
"""Configuration for API key authentication."""
|
|
13
13
|
|
|
14
|
-
header_name: str = Field(
|
|
15
|
-
"X-API-Key", description="Name of the header containing the API key"
|
|
16
|
-
)
|
|
14
|
+
header_name: str = Field("X-API-Key", description="Name of the header containing the API key")
|
|
17
15
|
header_prefix: str = Field(
|
|
18
16
|
"",
|
|
19
17
|
description="Optional prefix to strip from the header value (e.g., 'Bearer ')",
|
|
20
18
|
)
|
|
21
|
-
required: bool = Field(
|
|
22
|
-
True, description="Whether API key is required for all requests"
|
|
23
|
-
)
|
|
19
|
+
required: bool = Field(True, description="Whether API key is required for all requests")
|
|
24
20
|
|
|
25
21
|
|
|
26
22
|
# Global configuration storage
|
|
27
23
|
_api_key_config: ApiKeyConfig | None = None
|
|
28
24
|
|
|
29
25
|
|
|
30
|
-
def configure_api_key(
|
|
31
|
-
header_name: str = "X-API-Key", header_prefix: str = "", required: bool = True
|
|
32
|
-
) -> None:
|
|
26
|
+
def configure_api_key(header_name: str = "X-API-Key", header_prefix: str = "", required: bool = True) -> None:
|
|
33
27
|
"""Configure API key extraction from request headers.
|
|
34
28
|
|
|
35
|
-
This function should be called in
|
|
29
|
+
This function should be called in auth.py to set up API key handling.
|
|
36
30
|
|
|
37
31
|
Args:
|
|
38
32
|
header_name: Name of the header containing the API key (default: "X-API-Key")
|
|
@@ -40,7 +34,7 @@ def configure_api_key(
|
|
|
40
34
|
required: Whether API key is required for all requests (default: True)
|
|
41
35
|
|
|
42
36
|
Example:
|
|
43
|
-
# In
|
|
37
|
+
# In auth.py
|
|
44
38
|
from golf.auth.api_key import configure_api_key
|
|
45
39
|
|
|
46
40
|
# Require API key for all requests
|
|
@@ -58,9 +52,7 @@ def configure_api_key(
|
|
|
58
52
|
)
|
|
59
53
|
"""
|
|
60
54
|
global _api_key_config
|
|
61
|
-
_api_key_config = ApiKeyConfig(
|
|
62
|
-
header_name=header_name, header_prefix=header_prefix, required=required
|
|
63
|
-
)
|
|
55
|
+
_api_key_config = ApiKeyConfig(header_name=header_name, header_prefix=header_prefix, required=required)
|
|
64
56
|
|
|
65
57
|
|
|
66
58
|
def get_api_key_config() -> ApiKeyConfig | None:
|