8000 feat[core]: release FastMCP 4 dual-era support by aschlean · Pull Request #140 · golf-mcp/golf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Supported Versions
| Version | Supported |
| ------- | ------------------ |
| 0.4.0 | :white_check_mark: |
| 0.3.0 | :white_check_mark: |
| 0.2.19 | :white_check_mark: |
| 0.2.18 | :white_check_mark: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
# Ensure telemetry is disabled in CI
GOLF_TELEMETRY: "0"
GOLF_TEST_MODE: "1"
FASTMCP_MCP_CAMELCASE_COMPAT: "false"

jobs:
test:
Expand Down
15 changes: 9 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

Golf is a Python framework for building MCP (Model Context Protocol) servers with zero boilerplate. It automatically discovers, parses, and compiles Python files containing tools, resources, and prompts into a runnable FastMCP server.

## Breaking Changes in Golf 0.2.x
## Authentication Compatibility

Golf 0.2.x introduces breaking changes to align with FastMCP 2.11.x:
Golf 0.3.x targets FastMCP 4.0.0 and MCP 2026-07-28 while retaining
FastMCP's legacy-client compatibility:

- **Authentication System**: Complete rewrite using FastMCP's built-in auth providers (JWT, OAuth, Static tokens)
- **Legacy OAuth Removed**: Custom OAuth implementation replaced with standards-compliant FastMCP providers
- **Configuration Changes**: `auth.py` configuration must be updated to use new auth configs (legacy `pre_build.py` supported)
- **Dependency Updates**: Requires FastMCP >=2.14.0
- **Dependency Updates**: Requires exactly FastMCP 4.0.0, Python >=3.10, and Pydantic >=2.12
- **Removed Files**: Legacy `oauth.py` and `provider.py` files removed from auth module
- **Deprecated Functions**: `get_provider_token()` and OAuth-related helpers return None (legacy compatibility)

Expand All @@ -23,7 +24,7 @@ Golf 0.2.x introduces breaking changes to align with FastMCP 2.11.x:
- **Code Generation**: The `ManifestBuilder` in `src/golf/core/builder.py` generates FastMCP server code from parsed components
- **CLI Interface**: Entry point is `src/golf/cli/main.py` with commands: `init`, `build`, `run`
- **Configuration**: Project settings managed via `golf.json` files, parsed by `src/golf/core/config.py`
- **Authentication**: Modern JWT/OAuth auth using FastMCP 2.11+ providers in `src/golf/auth/`
- **Authentication**: JWT/OAuth auth using FastMCP 4.0.0 providers in `src/golf/auth/`
- **Telemetry**: Anonymous usage tracking with OpenTelemetry support in `src/golf/telemetry/`

## Common Development Commands
Expand Down Expand Up @@ -115,9 +116,11 @@ project/

Component IDs are derived from file paths: `tools/payments/charge.py` becomes `charge_payments`.

## Authentication in Golf 0.2.x
## Authentication in Golf 0.3.x

Golf 0.2.x uses FastMCP's built-in authentication providers:
Golf 0.3.x uses FastMCP 4.0.0's built-in authentication providers. JWT
configurations require an audience/resource binding; inbound MCP resource
tokens must never be forwarded to upstream APIs.

### JWT Authentication (Production)
```python
Expand Down
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

Golf is a **framework** designed to streamline the creation of MCP server applications. It allows developers to define server's capabilities—*tools*, *prompts*, and *resources*—as simple Python files within a conventional directory structure. Golf then automatically discovers, parses, and compiles these components into a runnable MCP server, minimizing boilerplate and accelerating development.

Golf targets FastMCP 4.0.0 and the current MCP 2026-07-28 protocol.
FastMCP also negotiates legacy MCP clients through its compatibility mode.

With Golf v0.2.0, you get **enterprise-grade authentication** (JWT, OAuth Server, API key, development tokens), **built-in utilities** for LLM interactions, and **automatic telemetry** integration. Focus on implementing your agent's logic while Golf handles authentication, monitoring, and server infrastructure.

## Quick Start
Expand All @@ -38,7 +41,7 @@ Get your Golf project up and running in a few simple steps:

### 1. Install Golf

Ensure you have Python (3.10+ recommended) installed. Then, install Golf using pip:
Golf requires Python 3.10 or newer. Then, install Golf using pip:

```bash
pip install golf-mcp
Expand Down Expand Up @@ -153,9 +156,31 @@ configure_auth(JWTAuthConfig(
# ))

# Built-in utilities available in all tools
from golf.utils import elicit, sample, get_context
from golf.utilities import elicit, sample, get_current_context
```

On MCP 2026-07-28, elicitation and sampling use caller-owned multi-round-trip
control flow. A nested helper cannot transparently continue the containing
tool: declare `InputRequiredResult` in the tool's return type and return any
such result unchanged. The tool is then re-entered with the answer. Legacy
connections continue to use imperative requests.

```python
from mcp_types import InputRequiredResult
from golf.utilities import sample

async def explain(topic: str) -> str | InputRequiredResult:
result = await sample(f"Explain {topic}")
if isinstance(result, InputRequiredResult):
return result
return result
```

JWT authentication requires an audience so tokens are bound to this MCP
resource. Inbound MCP JWT/OAuth bearer tokens must never be forwarded to an
upstream API; use a separate upstream credential or a standards-based token
exchange/delegation flow.

```bash
# Enable OpenTelemetry tracing
export OTEL_TRACES_EXPORTER="otlp_http"
Expand All @@ -174,13 +199,16 @@ Basic configuration in `golf.json`:
"name": "My Golf Server",
"host": "localhost",
"port": 3000,
"transport": "sse",
"transport": "streamable-http",
"opentelemetry_enabled": false,
"detailed_tracing": false
}
```

- **`transport`**: Choose `"sse"`, `"streamable-http"`, or `"stdio"`
- **`transport`**: Use `"streamable-http"` or `"stdio"`. SSE remains available
only as a deprecated legacy transport.
- **`stateless_http`**: Optional legacy Streamable HTTP behavior. MCP
2026-07-28 is intrinsically sessionless and does not depend on this setting.
- **`opentelemetry_enabled`**: Enable OpenTelemetry tracing
- **`detailed_tracing`**: Capture input/output (use carefully with sensitive data)

Expand Down
21 changes: 11 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"

[project]
name = "golf-mcp"
version = "0.3.0"
version = "0.4.0"
description = "Framework for building MCP servers"
authors = [
{name = "Antoni Gmitruk", email = "antoni@golf.dev"}
]
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.10"
license = "Apache-2.0"
license-files = ["LICENSE"]
classifiers = [
Expand All @@ -19,17 +19,16 @@ classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
dependencies = [
"typer>=0.15.4",
"rich>=14.0.0",
"fastmcp>=3.2.0,<4.0.0",
"pydantic>=2.11.0",
"fastmcp==4.0.0",
"mcp-types>=2.1.1,<3.0.0",
"pydantic>=2.12",
"pydantic-settings>=2.0.0",
"python-dotenv>=1.1.0",
"pyjwt>=2.0.0",
Expand Down Expand Up @@ -73,7 +72,7 @@ golf = ["examples/**/*"]

[tool.poetry]
name = "golf-mcp"
version = "0.3.0"
version = "0.4.0"
description = "Framework for building MCP servers with zero boilerplate"
authors = ["Antoni Gmitruk <antoni@golf.dev>"]
license = "Apache-2.0"
Expand All @@ -86,15 +85,17 @@ classifiers = [
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]

[tool.poetry.dependencies]
python = ">=3.8" # Match requires-python
fastmcp = ">=3.2.0,<4.0.0"
python = ">=3.10" # Match requires-python
fastmcp = "==4.0.0"
mcp-types = ">=2.1.1,<3.0.0"
typer = {extras = ["all"], version = ">=0.15.4"}
pydantic = ">=2.11.0"
pydantic = ">=2.12"
pydantic-settings = ">=2.0.0"
rich = ">=14.0.0"
python-dotenv = ">=1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/golf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.3.0"
__version__ = "0.4.0"

from golf.decorators import prompt, resource, tool

Expand Down
19 changes: 9 additions & 10 deletions src/golf/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Modern authentication for Golf MCP servers using FastMCP 2.11+ providers.
"""Authentication for Golf MCP servers using FastMCP 4.0.0 providers.

This module provides authentication configuration and utilities for Golf servers,
leveraging FastMCP's built-in authentication system with JWT verification,
Expand Down Expand Up @@ -36,9 +36,10 @@
# Re-export for backward compatibility
from .api_key import configure_api_key, get_api_key_config, is_api_key_configured
from .helpers import (
CallerAuth,
extract_token_from_header,
get_api_key,
get_auth_token,
get_caller_auth,
set_api_key,
)

Expand Down Expand Up @@ -76,9 +77,10 @@
"get_api_key_config",
"is_api_key_configured",
# Helper functions
"CallerAuth",
"extract_token_from_header",
"get_api_key",
"get_auth_token",
"get_caller_auth",
"set_api_key",
]

Expand Down Expand Up @@ -284,7 +286,8 @@ def validate_redirect_uri(uri: str) -> bool:
client_id: Your registered client ID with the OAuth provider
client_secret: Your registered client secret with the OAuth provider
base_url: Public URL of this OAuth proxy server
token_verifier_config: JWT or Static token configuration for verifying tokens
token_verifier_config: Deprecated optional source of default scopes or upstream audience hints.
Proxy-owned client tokens are validated by the enterprise proxy itself.
scopes_supported: List of OAuth scopes this proxy supports
revocation_endpoint: Optional token revocation endpoint
redirect_path: OAuth callback path (default: "/oauth/callback")
Expand All @@ -304,14 +307,10 @@ def validate_redirect_uri(uri: str) -> bool:
- allowed_redirect_schemes_env_var: Env var for redirect schemes

Raises:
ValueError: If token_verifier_config is not provided or invalid
ValueError: If token_verifier_config is invalid
ValueError: If required fields lack both direct value and env var
"""
# Validate token_verifier_config is provided (always required)
if token_verifier_config is None:
raise ValueError("token_verifier_config is required and must be JWTAuthConfig or StaticTokenConfig")

if not isinstance(token_verifier_config, (JWTAuthConfig, StaticTokenConfig)):
if token_verifier_config is not None and not isinstance(token_verifier_config, (JWTAuthConfig, StaticTokenConfig)):
raise ValueError(
f"token_verifier_config must be JWTAuthConfig or StaticTokenConfig, "
f"got {type(token_verifier_config).__name__}"
Expand Down
8 changes: 4 additions & 4 deletions src/golf/auth/api_key.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""API Key authentication support for Golf MCP servers.

This module provides a simple API key pass-through mechanism for Golf servers,
allowing tools to access API keys from request headers and forward them to
upstream services.
This module provides an explicitly non-MCP custom API-key mode. It is separate
from FastMCP JWT/OAuth resource-token authentication. Never configure it as a
way to expose or forward inbound MCP resource tokens to upstream services.
"""

from pydantic import BaseModel, Field
Expand Down Expand Up @@ -44,7 +44,7 @@ def configure_api_key(header_name: str = "X-API-Key", header_prefix: str = "", r
required=True
)

# Or make API key optional (pass-through mode)
# Or make this custom API key optional
configure_api_key(
header_name="Authorization",
header_prefix="Bearer ",
Expand Down
26 changes: 13 additions & 13 deletions src/golf/auth/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _create_jwt_provider(config: JWTAuthConfig) -> "JWTVerifier":
try:
from fastmcp.server.auth import JWTVerifier
except ImportError as e:
raise ImportError("JWTVerifier not available. Please install fastmcp>=2.11.0") from e
raise ImportError("JWTVerifier not available. Please install fastmcp==4.0.0") from e

return JWTVerifier(
public_key=public_key,
Expand All @@ -123,7 +123,7 @@ def _create_static_provider(config: StaticTokenConfig) -> "StaticTokenVerifier":
try:
from fastmcp.server.auth import StaticTokenVerifier
except ImportError as e:
raise ImportError("StaticTokenVerifier not available. Please install fastmcp>=2.11.0") from e
raise ImportError("StaticTokenVerifier not available. Please install fastmcp==4.0.0") from e

return StaticTokenVerifier(
tokens=config.tokens,
Expand All @@ -136,9 +136,7 @@ def _create_oauth_server_provider(config: OAuthServerConfig) -> "AuthProvider":
try:
from fastmcp.server.auth import OAuthProvider
except ImportError as e:
raise ImportError(
"OAuthProvider not available in this FastMCP version. Please upgrade to FastMCP 2.11.0 or later."
) from e
raise ImportError("OAuthProvider not available. Please install fastmcp==4.0.0.") from e

# Resolve runtime values from environment variables with validation
base_url = config.base_url
Expand Down Expand Up @@ -216,9 +214,7 @@ def _create_remote_provider(config: RemoteAuthConfig) -> "AuthProvider":
try:
from fastmcp.server.auth import RemoteAuthProvider
except ImportError as e:
raise ImportError(
"RemoteAuthProvider not available in this FastMCP version. Please upgrade to FastMCP 2.11.0 or later."
) from e
raise ImportError("RemoteAuthProvider not available. Please install fastmcp==4.0.0.") from e

# Resolve runtime values from environment variables
authorization_servers = config.authorization_servers
Expand All @@ -241,15 +237,19 @@ def _create_remote_provider(config: RemoteAuthConfig) -> "AuthProvider":
if not hasattr(token_verifier, "verify_token"):
raise ValueError(f"Remote auth provider requires a TokenVerifier, got {type(token_verifier).__name__}")

# Update token verifier's required_scopes to match our scopes_supported for PRM
# RemoteAuthProvider uses token_verifier.required_scopes for scopes_supported in PRM
if config.scopes_supported and hasattr(token_verifier, "required_scopes"):
token_verifier.required_scopes = list(config.scopes_supported)
if isinstance(config.token_verifier_config, JWTAuthConfig):
audience = getattr(token_verifier, "audience", None)
audiences = [audience] if isinstance(audience, str) else audience or []
if resource_server_url not in audiences:
raise ValueError(
"Resolved JWT audience must include resource_server_url to bind accepted tokens to this MCP resource"
)

return RemoteAuthProvider(
token_verifier=token_verifier,
authorization_servers=authorization_servers,
resource_server_url=resource_server_url,
base_url=resource_server_url,
scopes_supported=config.scopes_supported or None,
)


Expand Down
Loading
Loading
0