golf-mcp 0.2.5__py3-none-any.whl → 0.2.6__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 -1
- golf/auth/__init__.py +17 -15
- golf/auth/helpers.py +66 -0
- golf/auth/providers.py +19 -23
- golf/examples/basic/resources/weather/client.py +1 -1
- {golf_mcp-0.2.5.dist-info → golf_mcp-0.2.6.dist-info}/METADATA +1 -1
- {golf_mcp-0.2.5.dist-info → golf_mcp-0.2.6.dist-info}/RECORD +11 -11
- {golf_mcp-0.2.5.dist-info → golf_mcp-0.2.6.dist-info}/WHEEL +0 -0
- {golf_mcp-0.2.5.dist-info → golf_mcp-0.2.6.dist-info}/entry_points.txt +0 -0
- {golf_mcp-0.2.5.dist-info → golf_mcp-0.2.6.dist-info}/licenses/LICENSE +0 -0
- {golf_mcp-0.2.5.dist-info → golf_mcp-0.2.6.dist-info}/top_level.txt +0 -0
golf/__init__.py
CHANGED
golf/auth/__init__.py
CHANGED
|
@@ -35,6 +35,7 @@ from .helpers import (
|
|
|
35
35
|
debug_api_key_context,
|
|
36
36
|
extract_token_from_header,
|
|
37
37
|
get_api_key,
|
|
38
|
+
get_auth_token,
|
|
38
39
|
get_provider_token,
|
|
39
40
|
set_api_key,
|
|
40
41
|
)
|
|
@@ -72,6 +73,7 @@ __all__ = [
|
|
|
72
73
|
"debug_api_key_context",
|
|
73
74
|
"extract_token_from_header",
|
|
74
75
|
"get_api_key",
|
|
76
|
+
"get_auth_token",
|
|
75
77
|
"get_provider_token",
|
|
76
78
|
"set_api_key",
|
|
77
79
|
]
|
|
@@ -195,14 +197,14 @@ def configure_dev_auth(
|
|
|
195
197
|
|
|
196
198
|
|
|
197
199
|
def configure_oauth_proxy(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
authorization_endpoint: str,
|
|
201
|
+
token_endpoint: str,
|
|
202
|
+
client_id: str,
|
|
203
|
+
client_secret: str,
|
|
202
204
|
base_url: str,
|
|
203
205
|
token_verifier_config: JWTAuthConfig | StaticTokenConfig,
|
|
204
206
|
scopes_supported: list[str] | None = None,
|
|
205
|
-
|
|
207
|
+
revocation_endpoint: str | None = None,
|
|
206
208
|
redirect_path: str = "/oauth/callback",
|
|
207
209
|
) -> None:
|
|
208
210
|
"""Configure OAuth proxy authentication for non-DCR providers.
|
|
@@ -212,25 +214,25 @@ def configure_oauth_proxy(
|
|
|
212
214
|
fixed client credentials.
|
|
213
215
|
|
|
214
216
|
Args:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
authorization_endpoint: Provider's authorization URL
|
|
218
|
+
token_endpoint: Provider's token endpoint URL
|
|
219
|
+
client_id: Your client ID registered with the provider
|
|
220
|
+
client_secret: Your client secret from the provider
|
|
219
221
|
base_url: This proxy server's public URL
|
|
220
222
|
token_verifier_config: JWT or static token config for token verification
|
|
221
223
|
scopes_supported: Scopes to advertise to MCP clients
|
|
222
|
-
|
|
224
|
+
revocation_endpoint: Optional token revocation endpoint
|
|
223
225
|
redirect_path: OAuth callback path (default: /oauth/callback)
|
|
224
226
|
|
|
225
227
|
Note:
|
|
226
228
|
Requires golf-mcp-enterprise package for implementation.
|
|
227
229
|
"""
|
|
228
230
|
config = OAuthProxyConfig(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
authorization_endpoint=authorization_endpoint,
|
|
232
|
+
token_endpoint=token_endpoint,
|
|
233
|
+
client_id=client_id,
|
|
234
|
+
client_secret=client_secret,
|
|
235
|
+
revocation_endpoint=revocation_endpoint,
|
|
234
236
|
base_url=base_url,
|
|
235
237
|
redirect_path=redirect_path,
|
|
236
238
|
scopes_supported=scopes_supported or [],
|
golf/auth/helpers.py
CHANGED
|
@@ -142,6 +142,72 @@ def get_api_key_from_request(request: Request) -> str | None:
|
|
|
142
142
|
return _current_api_key.get()
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
def get_auth_token() -> str | None:
|
|
146
|
+
"""Get the authorization token from the current request context.
|
|
147
|
+
|
|
148
|
+
This function should be used in tools to retrieve the authorization token
|
|
149
|
+
(typically a JWT or OAuth token) that was sent in the request headers.
|
|
150
|
+
|
|
151
|
+
Unlike get_api_key(), this function extracts the raw token from the Authorization
|
|
152
|
+
header without stripping any prefix, making it suitable for passing through
|
|
153
|
+
to upstream APIs that expect the full Authorization header value.
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
The authorization token if available, None otherwise
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
# In a tool file
|
|
160
|
+
from golf.auth import get_auth_token
|
|
161
|
+
|
|
162
|
+
async def call_upstream_api():
|
|
163
|
+
auth_token = get_auth_token()
|
|
164
|
+
if not auth_token:
|
|
165
|
+
return {"error": "No authorization token provided"}
|
|
166
|
+
|
|
167
|
+
# Use the full token in upstream request
|
|
168
|
+
headers = {"Authorization": f"Bearer {auth_token}"}
|
|
169
|
+
async with httpx.AsyncClient() as client:
|
|
170
|
+
response = await client.get("https://api.example.com/data", headers=headers)
|
|
171
|
+
...
|
|
172
|
+
"""
|
|
173
|
+
# Try to get directly from HTTP request if available (FastMCP pattern)
|
|
174
|
+
try:
|
|
175
|
+
# This follows the FastMCP pattern for accessing HTTP requests
|
|
176
|
+
from fastmcp.server.dependencies import get_http_request
|
|
177
|
+
|
|
178
|
+
request = get_http_request()
|
|
179
|
+
|
|
180
|
+
if request and hasattr(request, "state") and hasattr(request.state, "auth_token"):
|
|
181
|
+
return request.state.auth_token
|
|
182
|
+
|
|
183
|
+
if request:
|
|
184
|
+
# Extract authorization token from Authorization header
|
|
185
|
+
auth_header = None
|
|
186
|
+
for k, v in request.headers.items():
|
|
187
|
+
if k.lower() == "authorization":
|
|
188
|
+
auth_header = v
|
|
189
|
+
break
|
|
190
|
+
|
|
191
|
+
if auth_header:
|
|
192
|
+
# Extract the token part (everything after "Bearer ")
|
|
193
|
+
token = extract_token_from_header(auth_header)
|
|
194
|
+
if token:
|
|
195
|
+
return token
|
|
196
|
+
|
|
197
|
+
# If not Bearer format, return the whole header value minus "Bearer " prefix if present
|
|
198
|
+
if auth_header.lower().startswith("bearer "):
|
|
199
|
+
return auth_header[7:] # Remove "Bearer " prefix
|
|
200
|
+
return auth_header
|
|
201
|
+
|
|
202
|
+
except (ImportError, RuntimeError):
|
|
203
|
+
# FastMCP not available or not in HTTP context
|
|
204
|
+
pass
|
|
205
|
+
except Exception:
|
|
206
|
+
pass
|
|
207
|
+
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
|
|
145
211
|
def debug_api_key_context() -> dict[str, Any]:
|
|
146
212
|
"""Debug function to inspect API key context.
|
|
147
213
|
|
golf/auth/providers.py
CHANGED
|
@@ -458,12 +458,12 @@ class OAuthProxyConfig(BaseModel):
|
|
|
458
458
|
|
|
459
459
|
provider_type: Literal["oauth_proxy"] = "oauth_proxy"
|
|
460
460
|
|
|
461
|
-
#
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
461
|
+
# OAuth provider configuration
|
|
462
|
+
authorization_endpoint: str = Field(..., description="OAuth provider's authorization endpoint URL")
|
|
463
|
+
token_endpoint: str = Field(..., description="OAuth provider's token endpoint URL")
|
|
464
|
+
client_id: str = Field(..., description="Your registered client ID with the OAuth provider")
|
|
465
|
+
client_secret: str = Field(..., description="Your registered client secret with the OAuth provider")
|
|
466
|
+
revocation_endpoint: str | None = Field(None, description="Optional token revocation endpoint")
|
|
467
467
|
|
|
468
468
|
# This proxy server configuration
|
|
469
469
|
base_url: str = Field(..., description="Public URL of this OAuth proxy server")
|
|
@@ -476,22 +476,18 @@ class OAuthProxyConfig(BaseModel):
|
|
|
476
476
|
)
|
|
477
477
|
|
|
478
478
|
# Environment variable names for runtime configuration
|
|
479
|
-
|
|
480
|
-
None, description="Environment variable name for
|
|
479
|
+
authorization_endpoint_env_var: str | None = Field(
|
|
480
|
+
None, description="Environment variable name for authorization endpoint"
|
|
481
481
|
)
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
)
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
None, description="Environment variable name for upstream client secret"
|
|
488
|
-
)
|
|
489
|
-
upstream_revocation_endpoint_env_var: str | None = Field(
|
|
490
|
-
None, description="Environment variable name for upstream revocation endpoint"
|
|
482
|
+
token_endpoint_env_var: str | None = Field(None, description="Environment variable name for token endpoint")
|
|
483
|
+
client_id_env_var: str | None = Field(None, description="Environment variable name for client ID")
|
|
484
|
+
client_secret_env_var: str | None = Field(None, description="Environment variable name for client secret")
|
|
485
|
+
revocation_endpoint_env_var: str | None = Field(
|
|
486
|
+
None, description="Environment variable name for revocation endpoint"
|
|
491
487
|
)
|
|
492
488
|
base_url_env_var: str | None = Field(None, description="Environment variable name for base URL")
|
|
493
489
|
|
|
494
|
-
@field_validator("
|
|
490
|
+
@field_validator("authorization_endpoint", "token_endpoint", "base_url")
|
|
495
491
|
@classmethod
|
|
496
492
|
def validate_required_urls(cls, v: str) -> str:
|
|
497
493
|
"""Validate required URLs are properly formatted."""
|
|
@@ -514,7 +510,7 @@ class OAuthProxyConfig(BaseModel):
|
|
|
514
510
|
|
|
515
511
|
return url
|
|
516
512
|
|
|
517
|
-
@field_validator("
|
|
513
|
+
@field_validator("revocation_endpoint")
|
|
518
514
|
@classmethod
|
|
519
515
|
def validate_optional_url(cls, v: str | None) -> str | None:
|
|
520
516
|
"""Validate optional URLs are properly formatted."""
|
|
@@ -588,12 +584,12 @@ class OAuthProxyConfig(BaseModel):
|
|
|
588
584
|
|
|
589
585
|
urls_to_check = [
|
|
590
586
|
("base_url", self.base_url),
|
|
591
|
-
("
|
|
592
|
-
("
|
|
587
|
+
("authorization_endpoint", self.authorization_endpoint),
|
|
588
|
+
("token_endpoint", self.token_endpoint),
|
|
593
589
|
]
|
|
594
590
|
|
|
595
|
-
if self.
|
|
596
|
-
urls_to_check.append(("
|
|
591
|
+
if self.revocation_endpoint:
|
|
592
|
+
urls_to_check.append(("revocation_endpoint", self.revocation_endpoint))
|
|
597
593
|
|
|
598
594
|
for field_name, url in urls_to_check:
|
|
599
595
|
parsed = urlparse(url)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
golf/__init__.py,sha256=
|
|
1
|
+
golf/__init__.py,sha256=qWIRfT1s1Et0Jru9N8JfQhbMc-CsZpqWQV9S0Ay5YPk,306
|
|
2
2
|
golf/_endpoints.py,sha256=-mvAmjx3YtqfAdajO13Kv7LKVBMdqsKqX0_3aCmCK4I,317
|
|
3
3
|
golf/_endpoints.py.in,sha256=MeqcSF6xinnPknpBGF26xA9FYmSYKSWqCFXOSDlXiOA,216
|
|
4
4
|
golf/_endpoints_fallback.py,sha256=CD6m45Ams1A9HVKowY8dCFUDMiFmJ8ZWSwHCENvU5u4,386
|
|
5
|
-
golf/auth/__init__.py,sha256=
|
|
5
|
+
golf/auth/__init__.py,sha256=u-6_EFTvfs91B2Jko39swp3tCpHkj3r9wDQzQBmfxn0,8027
|
|
6
6
|
golf/auth/api_key.py,sha256=OonqTlG6USJxqK8TlPviJTv7sgYmTVfCxG_JsEjnEM4,2320
|
|
7
7
|
golf/auth/factory.py,sha256=3-il1GbjjZlQfvWUZs-09r61Y_-b5cYEegWF7sY_cUs,13128
|
|
8
|
-
golf/auth/helpers.py,sha256=
|
|
9
|
-
golf/auth/providers.py,sha256=
|
|
8
|
+
golf/auth/helpers.py,sha256=WoYyjUAQwgDnLvJDvyhuEOmm8w0fQ-ZDqaYxs_lC8nw,8127
|
|
9
|
+
golf/auth/providers.py,sha256=qgybeHtrb0MojUsXZm813gzT4zBCNxCiSCWvxKG2iis,25950
|
|
10
10
|
golf/auth/registry.py,sha256=Rjj7LnWvzEsI1GCnFbFcxpRllrVanD9bumWPaJ1giFQ,7960
|
|
11
11
|
golf/cli/__init__.py,sha256=R8Y8KdD2C8gDo24fXGq-fdWWNeaq3MYjrbaSB8Hb-Hg,45
|
|
12
12
|
golf/cli/branding.py,sha256=ndpy2kVxBzqr4fwsAlh_fbhxqgRPoF6kM3ufP9hg5QI,6896
|
|
@@ -34,7 +34,7 @@ golf/examples/basic/prompts/welcome.py,sha256=xyW4pwvpcPQi0_H9tP7OX53Kv62R1aCYcV
|
|
|
34
34
|
golf/examples/basic/resources/current_time.py,sha256=bJMrRZQ0WPgnQxMl_4-4ynZyq7ki-wGMbMFpaYOH7PY,859
|
|
35
35
|
golf/examples/basic/resources/info.py,sha256=LxHzg_TmwonSu1vSkuNcpUq5JrBu-9yzoGaARE1f2KU,727
|
|
36
36
|
golf/examples/basic/resources/weather/city.py,sha256=pRgceEP4ZRDVFEJA4kQf54n0pb37TMdFLgqFL1cHZZs,1278
|
|
37
|
-
golf/examples/basic/resources/weather/client.py,sha256=
|
|
37
|
+
golf/examples/basic/resources/weather/client.py,sha256=E6250OfgjSLcRSK14B0LFth8siKNRhN8yRwjy0LuO9A,1679
|
|
38
38
|
golf/examples/basic/resources/weather/current.py,sha256=muT77pUxnHQJSnrX5x4itzrjTSzK_hPbbkjVh3LGlh4,933
|
|
39
39
|
golf/examples/basic/resources/weather/forecast.py,sha256=xhSpK71gWsCIpyzYyqY7KhoUHn38xpR6srZ-2Vqww8Q,990
|
|
40
40
|
golf/examples/basic/tools/calculator.py,sha256=QTDvE7ItMol2eIR1mgc6moRhhl3p-q63bgieWr5yF5c,3070
|
|
@@ -48,9 +48,9 @@ golf/utilities/__init__.py,sha256=X9iY9yi3agz1GVcn8-qWeOCt8CSSsruHxqPNtiF63TY,53
|
|
|
48
48
|
golf/utilities/context.py,sha256=DGGvhVe---QMhy0wtdWhNp-_WVk1NvAcOFn0uBKBpYo,1579
|
|
49
49
|
golf/utilities/elicitation.py,sha256=MParZZZsY45s70-KXduHa6IvpWXnLW2FCPfrGijMaHs,5223
|
|
50
50
|
golf/utilities/sampling.py,sha256=88nDv-trBE4gZQbcnMjXl3LW6TiIhv5zR_cuEIGjaIM,7233
|
|
51
|
-
golf_mcp-0.2.
|
|
52
|
-
golf_mcp-0.2.
|
|
53
|
-
golf_mcp-0.2.
|
|
54
|
-
golf_mcp-0.2.
|
|
55
|
-
golf_mcp-0.2.
|
|
56
|
-
golf_mcp-0.2.
|
|
51
|
+
golf_mcp-0.2.6.dist-info/licenses/LICENSE,sha256=5_j2f6fTJmvfmUewzElhkpAaXg2grVoxKouOA8ihV6E,11348
|
|
52
|
+
golf_mcp-0.2.6.dist-info/METADATA,sha256=yE954KDxWowq6DfMIUQne6Ypl4LsWEqSTeqeHFXomaE,9558
|
|
53
|
+
golf_mcp-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
54
|
+
golf_mcp-0.2.6.dist-info/entry_points.txt,sha256=5y7rHYM8jGpU-nfwdknCm5XsApLulqsnA37MO6BUTYg,43
|
|
55
|
+
golf_mcp-0.2.6.dist-info/top_level.txt,sha256=BQToHcBUufdyhp9ONGMIvPE40jMEtmI20lYaKb4hxOg,5
|
|
56
|
+
golf_mcp-0.2.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|