golf-mcp 0.1.19__py3-none-any.whl → 0.2.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.

Files changed (123) hide show
  1. golf/__init__.py +9 -1
  2. golf/_endpoints.py +6 -0
  3. golf/_endpoints_fallback.py +10 -0
  4. golf/auth/__init__.py +188 -84
  5. golf/auth/api_key.py +6 -14
  6. golf/auth/factory.py +333 -0
  7. golf/auth/helpers.py +12 -42
  8. golf/auth/providers.py +396 -0
  9. golf/auth/registry.py +256 -0
  10. golf/cli/branding.py +192 -0
  11. golf/cli/main.py +28 -69
  12. golf/commands/__init__.py +2 -0
  13. golf/commands/build.py +4 -7
  14. golf/commands/init.py +30 -53
  15. golf/commands/run.py +50 -20
  16. golf/core/builder.py +356 -412
  17. golf/core/builder_auth.py +63 -144
  18. golf/core/builder_telemetry.py +26 -3
  19. golf/core/config.py +38 -59
  20. golf/core/parser.py +132 -139
  21. golf/core/platform.py +12 -10
  22. golf/core/telemetry.py +11 -19
  23. golf/core/transformer.py +38 -15
  24. golf/examples/__pycache__/__init__.cpython-311.pyc +0 -0
  25. golf/examples/basic/.coverage +0 -0
  26. golf/examples/basic/.env.example +8 -4
  27. golf/examples/basic/README.md +117 -45
  28. golf/examples/basic/__pycache__/auth.cpython-311.pyc +0 -0
  29. golf/examples/basic/auth.py +76 -0
  30. golf/examples/basic/golf.json +2 -5
  31. golf/examples/basic/htmlcov/.gitignore +2 -0
  32. golf/examples/basic/htmlcov/class_index.html +547 -0
  33. golf/examples/basic/htmlcov/coverage_html_cb_6fb7b396.js +733 -0
  34. golf/examples/basic/htmlcov/favicon_32_cb_58284776.png +0 -0
  35. golf/examples/basic/htmlcov/function_index.html +2091 -0
  36. golf/examples/basic/htmlcov/index.html +349 -0
  37. golf/examples/basic/htmlcov/keybd_closed_cb_ce680311.png +0 -0
  38. golf/examples/basic/htmlcov/status.json +1 -0
  39. golf/examples/basic/htmlcov/style_cb_8e611ae1.css +337 -0
  40. golf/examples/basic/htmlcov/z_1c9a91c0e91c8496___init___py.html +323 -0
  41. golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_api_key_py.html +170 -0
  42. golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_factory_py.html +430 -0
  43. golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_helpers_py.html +288 -0
  44. golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_providers_py.html +493 -0
  45. golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_registry_py.html +353 -0
  46. golf/examples/basic/htmlcov/z_3ec3b3f490dc0950___init___py.html +120 -0
  47. golf/examples/basic/htmlcov/z_3ec3b3f490dc0950_instrumentation_py.html +1535 -0
  48. golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db___init___py.html +98 -0
  49. golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db_branding_py.html +289 -0
  50. golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db_main_py.html +476 -0
  51. golf/examples/basic/htmlcov/z_5a6c4e6bcc86fb2f___init___py.html +97 -0
  52. golf/examples/basic/htmlcov/z_6cadab9ec0df475d___init___py.html +102 -0
  53. golf/examples/basic/htmlcov/z_6cadab9ec0df475d_build_py.html +178 -0
  54. golf/examples/basic/htmlcov/z_6cadab9ec0df475d_init_py.html +387 -0
  55. golf/examples/basic/htmlcov/z_6cadab9ec0df475d_run_py.html +222 -0
  56. golf/examples/basic/htmlcov/z_6fcdee0582ba84e4___init___py.html +106 -0
  57. golf/examples/basic/htmlcov/z_6fcdee0582ba84e4__endpoints_fallback_py.html +107 -0
  58. golf/examples/basic/htmlcov/z_7ba499ed22986217___init___py.html +98 -0
  59. golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_auth_py.html +306 -0
  60. golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_metrics_py.html +329 -0
  61. golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_py.html +1471 -0
  62. golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_telemetry_py.html +186 -0
  63. golf/examples/basic/htmlcov/z_7ba499ed22986217_config_py.html +315 -0
  64. golf/examples/basic/htmlcov/z_7ba499ed22986217_parser_py.html +1149 -0
  65. golf/examples/basic/htmlcov/z_7ba499ed22986217_platform_py.html +279 -0
  66. golf/examples/basic/htmlcov/z_7ba499ed22986217_telemetry_py.html +589 -0
  67. golf/examples/basic/htmlcov/z_7ba499ed22986217_transformer_py.html +286 -0
  68. golf/examples/basic/htmlcov/z_7d7da37693a43688___init___py.html +107 -0
  69. golf/examples/basic/htmlcov/z_7d7da37693a43688_collector_py.html +417 -0
  70. golf/examples/basic/htmlcov/z_7d7da37693a43688_registry_py.html +109 -0
  71. golf/examples/basic/htmlcov/z_abe733142b40ad4e___init___py.html +109 -0
  72. golf/examples/basic/htmlcov/z_abe733142b40ad4e_context_py.html +150 -0
  73. golf/examples/basic/htmlcov/z_abe733142b40ad4e_elicitation_py.html +267 -0
  74. golf/examples/basic/htmlcov/z_abe733142b40ad4e_sampling_py.html +318 -0
  75. golf/examples/basic/prompts/__pycache__/welcome.cpython-311.pyc +0 -0
  76. golf/examples/basic/prompts/welcome.py +3 -5
  77. golf/examples/basic/resources/__pycache__/current_time.cpython-311.pyc +0 -0
  78. golf/examples/basic/resources/__pycache__/info.cpython-311.pyc +0 -0
  79. golf/examples/basic/resources/current_time.py +5 -13
  80. golf/examples/basic/resources/weather/__pycache__/common.cpython-311.pyc +0 -0
  81. golf/examples/basic/resources/weather/__pycache__/current.cpython-311.pyc +0 -0
  82. golf/examples/basic/resources/weather/__pycache__/forecast.cpython-311.pyc +0 -0
  83. golf/examples/basic/resources/weather/city.py +46 -0
  84. golf/examples/basic/resources/weather/common.py +4 -11
  85. golf/examples/basic/resources/weather/current.py +5 -5
  86. golf/examples/basic/resources/weather/forecast.py +5 -5
  87. golf/examples/basic/tools/__pycache__/calculator.cpython-311.pyc +0 -0
  88. golf/examples/basic/tools/calculator.py +94 -0
  89. golf/examples/basic/tools/say/__pycache__/hello.cpython-311.pyc +0 -0
  90. golf/examples/basic/tools/say/hello.py +65 -0
  91. golf/metrics/collector.py +100 -19
  92. golf/telemetry/__init__.py +4 -0
  93. golf/telemetry/instrumentation.py +496 -174
  94. golf/utilities/__init__.py +12 -0
  95. golf/utilities/context.py +53 -0
  96. golf/utilities/elicitation.py +170 -0
  97. golf/utilities/sampling.py +221 -0
  98. {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/METADATA +56 -110
  99. golf_mcp-0.2.0.dist-info/RECORD +110 -0
  100. golf/auth/oauth.py +0 -861
  101. golf/auth/provider.py +0 -115
  102. golf/examples/api_key/.env +0 -2
  103. golf/examples/api_key/.env.example +0 -1
  104. golf/examples/api_key/README.md +0 -84
  105. golf/examples/api_key/golf.json +0 -8
  106. golf/examples/api_key/pre_build.py +0 -11
  107. golf/examples/api_key/tools/issues/create.py +0 -93
  108. golf/examples/api_key/tools/issues/list.py +0 -92
  109. golf/examples/api_key/tools/repos/list.py +0 -111
  110. golf/examples/api_key/tools/search/code.py +0 -106
  111. golf/examples/api_key/tools/users/get.py +0 -82
  112. golf/examples/basic/.env +0 -5
  113. golf/examples/basic/pre_build.py +0 -28
  114. golf/examples/basic/tools/github_user.py +0 -65
  115. golf/examples/basic/tools/hello.py +0 -34
  116. golf/examples/basic/tools/payments/charge.py +0 -70
  117. golf/examples/basic/tools/payments/common.py +0 -36
  118. golf/examples/basic/tools/payments/refund.py +0 -61
  119. golf_mcp-0.1.19.dist-info/RECORD +0 -60
  120. {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/WHEEL +0 -0
  121. {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/entry_points.txt +0 -0
  122. {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/licenses/LICENSE +0 -0
  123. {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/top_level.txt +0 -0
golf/__init__.py CHANGED
@@ -1 +1,9 @@
1
- __version__ = "0.1.19"
1
+ __version__ = "0.2.0"
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,6 @@
1
+ # Auto-generated at build time by setup.py:build_py
2
+ # This template contains placeholders that are replaced during build
3
+
4
+ # Platform endpoints
5
+ PLATFORM_API_URL = "https://golf-backend.golf-auth-1.authed-qukc4.ryvn.run/api/resources"
6
+ OTEL_ENDPOINT = "https://golf-backend.golf-auth-1.authed-qukc4.ryvn.run/api/v1/otel"
@@ -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,226 @@
1
- """Authentication module for GolfMCP servers.
1
+ """Modern authentication for Golf MCP servers using FastMCP 2.11+ providers.
2
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.
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 List, Optional, Tuple
8
+ from typing import Any
9
9
 
10
- from mcp.server.auth.settings import AuthSettings, ClientRegistrationOptions
10
+ # Modern auth provider configurations and factory functions
11
+ from .providers import (
12
+ AuthConfig,
13
+ JWTAuthConfig,
14
+ StaticTokenConfig,
15
+ OAuthServerConfig,
16
+ RemoteAuthConfig,
17
+ )
18
+ from .factory import (
19
+ create_auth_provider,
20
+ create_simple_jwt_provider,
21
+ create_dev_token_provider,
22
+ )
23
+ from .registry import (
24
+ BaseProviderPlugin,
25
+ AuthProviderFactory,
26
+ get_provider_registry,
27
+ register_provider_factory,
28
+ register_provider_plugin,
29
+ )
11
30
 
31
+ # Re-export for backward compatibility
12
32
  from .api_key import configure_api_key, get_api_key_config, is_api_key_configured
13
33
  from .helpers import (
14
34
  debug_api_key_context,
15
35
  extract_token_from_header,
16
- get_access_token,
17
36
  get_api_key,
18
37
  get_provider_token,
19
38
  set_api_key,
20
39
  )
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,
40
+
41
+ # Public API
42
+ __all__ = [
43
+ # Main configuration functions
44
+ "configure_auth",
45
+ "configure_jwt_auth",
46
+ "configure_dev_auth",
47
+ "get_auth_config",
48
+ # Provider configurations
49
+ "AuthConfig",
50
+ "JWTAuthConfig",
51
+ "StaticTokenConfig",
52
+ "OAuthServerConfig",
53
+ "RemoteAuthConfig",
54
+ # Factory functions
55
+ "create_auth_provider",
56
+ "create_simple_jwt_provider",
57
+ "create_dev_token_provider",
58
+ # Provider registry and plugins
59
+ "BaseProviderPlugin",
60
+ "AuthProviderFactory",
61
+ "get_provider_registry",
62
+ "register_provider_factory",
63
+ "register_provider_plugin",
64
+ # API key functions (backward compatibility)
65
+ "configure_api_key",
66
+ "get_api_key_config",
67
+ "is_api_key_configured",
68
+ # Helper functions
69
+ "debug_api_key_context",
70
+ "extract_token_from_header",
71
+ "get_api_key",
72
+ "get_provider_token",
73
+ "set_api_key",
74
+ ]
75
+
76
+ # Global storage for auth configuration
77
+ _auth_config: AuthConfig | None = None
78
+
79
+
80
+ def configure_auth(config: AuthConfig) -> None:
81
+ """Configure authentication for the Golf server.
82
+
83
+ This function should be called in auth.py to set up authentication
84
+ using FastMCP's modern auth providers.
85
+
86
+ Args:
87
+ config: Authentication configuration (JWT, OAuth, Static, or Remote)
88
+ The required_scopes should be specified in the config itself.
89
+
90
+ Examples:
91
+ # JWT authentication with Auth0
92
+ from golf.auth import configure_auth, JWTAuthConfig
93
+
94
+ configure_auth(
95
+ JWTAuthConfig(
96
+ jwks_uri="https://your-domain.auth0.com/.well-known/jwks.json",
97
+ issuer="https://your-domain.auth0.com/",
98
+ audience="https://your-api.example.com",
99
+ required_scopes=["read:data"],
100
+ )
63
101
  )
64
102
 
103
+ # Development with static tokens
104
+ from golf.auth import configure_auth, StaticTokenConfig
105
+
106
+ configure_auth(
107
+ StaticTokenConfig(
108
+ tokens={
109
+ "dev-token-123": {
110
+ "client_id": "dev-client",
111
+ "scopes": ["read", "write"],
112
+ }
113
+ },
114
+ required_scopes=["read"],
115
+ )
116
+ )
65
117
 
66
- # Global state for the build process
67
- _auth_config: AuthConfig | None = None
118
+ # Full OAuth server
119
+ from golf.auth import configure_auth, OAuthServerConfig
120
+
121
+ configure_auth(
122
+ OAuthServerConfig(
123
+ base_url="https://your-server.example.com",
124
+ valid_scopes=["read", "write", "admin"],
125
+ default_scopes=["read"],
126
+ required_scopes=["read"],
127
+ )
128
+ )
129
+ """
130
+ global _auth_config
131
+ _auth_config = config
68
132
 
69
133
 
70
- def configure_auth(
71
- provider_config=None,
72
- provider=None,
134
+ def configure_jwt_auth(
135
+ *,
136
+ jwks_uri: str | None = None,
137
+ public_key: str | None = None,
138
+ issuer: str | None = None,
139
+ audience: str | list[str] | None = None,
73
140
  required_scopes: list[str] | None = None,
74
- callback_path: str = "/auth/callback",
141
+ **env_vars: str,
75
142
  ) -> None:
76
- """Configure authentication for a GolfMCP server.
77
-
78
- This function should be called in pre_build.py to set up authentication.
143
+ """Convenience function to configure JWT authentication.
79
144
 
80
145
  Args:
81
- provider_config: Configuration for the OAuth provider (new parameter name)
82
- provider: Configuration for the OAuth provider (old parameter name, deprecated)
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)
146
+ jwks_uri: JWKS URI for key fetching
147
+ public_key: Static public key (PEM format)
148
+ issuer: Expected issuer claim
149
+ audience: Expected audience claim(s)
150
+ required_scopes: Required scopes for all requests
151
+ **env_vars: Environment variable names (public_key_env_var,
152
+ jwks_uri_env_var, etc.)
86
153
  """
87
- global _auth_config
154
+ config = JWTAuthConfig(
155
+ jwks_uri=jwks_uri,
156
+ public_key=public_key,
157
+ issuer=issuer,
158
+ audience=audience,
159
+ required_scopes=required_scopes or [],
160
+ **env_vars,
161
+ )
162
+ configure_auth(config)
163
+
88
164
 
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")
165
+ def configure_dev_auth(
166
+ tokens: dict[str, Any] | None = None,
167
+ required_scopes: list[str] | None = None,
168
+ ) -> None:
169
+ """Convenience function to configure development authentication.
94
170
 
95
- _auth_config = AuthConfig(
96
- provider_config=provider_config,
97
- required_scopes=required_scopes or provider_config.scopes,
98
- callback_path=callback_path,
171
+ Args:
172
+ tokens: Token dictionary or None for defaults
173
+ required_scopes: Required scopes for all requests
174
+ """
175
+ if tokens is None:
176
+ tokens = {
177
+ "dev-token-123": {
178
+ "client_id": "dev-client",
179
+ "scopes": ["read", "write"],
180
+ },
181
+ "admin-token-456": {
182
+ "client_id": "admin-client",
183
+ "scopes": ["read", "write", "admin"],
184
+ },
185
+ }
186
+
187
+ config = StaticTokenConfig(
188
+ tokens=tokens,
189
+ required_scopes=required_scopes or [],
99
190
  )
191
+ configure_auth(config)
100
192
 
101
193
 
102
- def get_auth_config() -> tuple[ProviderConfig | None, list[str]]:
103
- """Get the current authentication configuration.
194
+ def get_auth_config() -> AuthConfig | None:
195
+ """Get the current auth configuration.
104
196
 
105
197
  Returns:
106
- Tuple of (provider_config, required_scopes)
198
+ AuthConfig if configured, None otherwise
107
199
  """
108
- if _auth_config:
109
- return _auth_config.provider_config, _auth_config.required_scopes
110
- return None, []
200
+ return _auth_config
201
+
202
+
203
+ def is_auth_configured() -> bool:
204
+ """Check if authentication is configured.
205
+
206
+ Returns:
207
+ True if authentication is configured, False otherwise
208
+ """
209
+ return _auth_config is not None
210
+
211
+
212
+ # Breaking change in Golf 0.2.x: Legacy auth system removed
213
+ # Users must migrate to modern auth configurations
111
214
 
112
215
 
113
- def create_auth_provider() -> GolfOAuthProvider | None:
114
- """Create an OAuth provider from the configured provider settings.
216
+ def create_auth_provider_from_config() -> object | None:
217
+ """Create an auth provider from the current configuration.
115
218
 
116
219
  Returns:
117
- GolfOAuthProvider instance or None if not configured
220
+ FastMCP AuthProvider instance or None if not configured
118
221
  """
119
- if not _auth_config:
222
+ config = get_auth_config()
223
+ if not config:
120
224
  return None
121
225
 
122
- return _auth_config.provider
226
+ 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 pre_build.py to set up API key handling.
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 pre_build.py
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: