@@ -150,6 +150,60 @@ When no client credentials are provided ([`pkg/auth/oauth/dynamic_registration.g
1501504 . ** Store Credentials** : Use returned client_id (and client_secret if provided)
1511515 . ** Proceed with OAuth Flow** : Using registered credentials
152152
153+ ## Resource Parameter (RFC 8707) Implementation
154+
155+ ToolHive implements the OAuth 2.0 Resource Indicators (RFC 8707) as required by the MCP specification:
156+
157+ ** Location** : [ ` pkg/auth/remote/handler.go:52-69 ` ] ( ../pkg/auth/remote/handler.go#L52 )
158+
159+ ### Automatic Defaulting
160+ When no explicit ` --remote-auth-resource ` flag is provided, ToolHive automatically:
161+ 1 . Defaults the resource parameter to the remote server URL (the canonical URI of the MCP server)
162+ 2 . Validates the URI format according to MCP specification requirements
163+ 3 . Normalizes the URI (lowercase scheme/host, strips fragments, preserves trailing slashes)
164+ 4 . If the resource parameter cannot be derived, then it will not be sent
165+
166+ ### Validation Rules
167+ The resource parameter must conform to MCP canonical URI requirements:
168+ - ** Must** include a scheme (http/https)
169+ - ** Must** include a host
170+ - ** Must not** contain fragments (#)
171+
172+ When the resource parameter is ** defaulted** from the remote URL:
173+ - Scheme and host are normalized to lowercase
174+ - Fragments are stripped (not allowed in resource indicators per spec)
175+ - Trailing slashes are preserved (we cannot determine semantic significance)
176+
177+ When the resource parameter is ** explicitly provided** by the user:
178+ - Value is validated but ** not modified**
179+ - Returns an error if the value is invalid
180+ - User must provide a properly formatted canonical URI
181+
182+ ### Examples
183+ ``` bash
184+ # Automatic resource parameter (defaults and normalizes to remote URL)
185+ thv run https://MCP.Example.COM/api#section
186+ # Resource defaults to: https://mcp.example.com/api (normalized, fragment stripped)
187+
188+ # Explicit resource parameter (not modified, must be valid)
189+ thv run https://mcp.example.com/api \
190+ --remote-auth-resource https://mcp.example.com
191+
192+ # Invalid explicit resource parameter with fragment (returns error)
193+ thv run https://mcp.example.com/api \
194+ --remote-auth-resource https://mcp.example.com#fragment
195+ # Error: invalid resource parameter: resource URI must not contain fragments
196+
197+ # Invalid explicit resource parameter without scheme (returns error)
198+ thv run https://mcp.example.com/api \
199+ --remote-auth-resource mcp.example.com
200+ # Error: invalid resource parameter: resource URI must include a scheme
201+ ```
202+
203+ The validated and normalized resource parameter is sent in both:
204+ - Authorization requests (as ` resource ` query parameter)
205+ - Token exchange requests (as ` resource ` parameter)
206+
153207## Security Features
154208
155209### HTTPS Enforcement
@@ -277,17 +331,18 @@ The `oauth_config` section supports:
277331| OAuth 2.1 PKCE | ✅ Compliant | Enabled by default |
278332| WWW-Authenticate Parsing | ✅ Compliant | Supports Bearer with realm/resource_metadata |
279333| Multiple Auth Servers | ✅ Compliant | Iterates and validates all servers |
280- | Resource Parameter (RFC 8707) | ⚠️ Partial | Infrastructure ready, not yet sent in requests |
334+ | Resource Parameter (RFC 8707) | ✅ Compliant | Automatically defaults to remote server URL, validated and normalized |
281335| Token Audience Validation | ⚠️ Partial | Server-side validation support ready |
282336
337+
338+
283339## Future Enhancements
284340
285341While ToolHive is highly compliant with the current MCP specification, potential improvements include:
286342
287- 1 . ** Resource Parameter** : Add explicit ` resource ` parameter to OAuth requests (infrastructure exists)
288- 2 . ** Token Audience Validation** : Enhanced client-side validation of token audience claims
289- 3 . ** Refresh Token Rotation** : Implement automatic refresh token rotation for long-lived sessions
290- 4 . ** Client Credential Caching** : Persist dynamically registered clients across sessions
343+ 1 . ** Token Audience Validation** : Enhanced client-side validation of token audience claims
344+ 2 . ** Refresh Token Rotation** : Implement automatic refresh token rotation for long-lived sessions
345+ 3 . ** Client Credential Caching** : Persist dynamically registered clients across sessions
291346
292347## Conclusion
293348
0 commit comments