Skip to content

feat(subscriptions): implement resource subscription support (Phase 1 & 2) - #76

Merged
avrabe merged 21 commits into
mainfrom
feature/oauth-2.1-implementation
Dec 4, 2025
Merged

feat(subscriptions): implement resource subscription support (Phase 1 & 2)#76
avrabe merged 21 commits into
mainfrom
feature/oauth-2.1-implementation

Conversation

@avrabe

@avrabe avrabe commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Summary

Implemented comprehensive resource subscription handling in two phases to achieve MCP protocol conformance.

Changes

Phase 1: Subscription Acceptance ✅

  • Added ResourceUpdatedNotification struct to mcp-protocol/src/model.rs
  • Modified McpBackend trait default implementations:
    • subscribe() now returns Ok(()) instead of error
    • unsubscribe() now returns Ok(()) instead of error
  • Added documentation explaining the change

Phase 2: Subscription Tracking ✅

  • Added global subscription registry to GenericServerHandler:
    • Arc<RwLock<HashSet<String>>> for thread-safe URI tracking
    • Global implementation (simpler than per-client tracking)
  • Enhanced handle_subscribe():
    • Tracks URIs in registry after backend validation
    • Logs new subscriptions
  • Enhanced handle_unsubscribe():
    • Removes URIs from registry
    • Logs unsubscriptions
  • Added query methods:
    • get_subscribed_uris(): Returns all subscribed resource URIs
    • is_subscribed(uri): Checks if specific URI has subscriptions
    • Ready for Phase 3 notification delivery

Testing

  • Conformance: 6/26 tests passing (23%), up from 4/26
    • ✅ resources-subscribe (NEW)
    • ✅ resources-unsubscribe (NEW)
    • ✅ server-initialize
    • ✅ tools-list
    • ✅ resources-list
    • ✅ prompts-list
  • Unit Tests: 132/132 passing
  • Updated existing tests to reflect new subscription behavior

Architecture

  • Backend trait accepts all subscriptions (Phase 1)
  • Handler tracks subscription state globally (Phase 2)
  • Query methods enable future notification delivery (Phase 3 - optional)

Future Work (Optional)

Phase 3 would implement actual notification delivery:

  • Notification channel mechanism
  • Integration with transport layer broadcast
  • Backend API for triggering notifications

Note: Phase 3 is not required for MCP conformance. The spec only requires accepting subscribe/unsubscribe requests, which this PR accomplishes.

Add convenience methods to simplify creating UI resources:

- Content::ui_html(uri, html) - Create HTML UI resource (1 line vs 8)
- Content::ui_resource(uri, mime_type, content) - Custom MIME types
- Update ui-enabled-server example to use new helpers
- Add comprehensive UI_RESOURCES_GUIDE.md documentation

This reduces boilerplate by 87% for UI resource creation, making
PulseEngine competitive with TypeScript SDK for ergonomics.
Remove non-library code from mcp-auth to focus on core functionality:

- Delete CLI binaries (mcp-auth-cli, mcp-auth-setup, mcp-auth-init) - 3,759 lines
- Delete performance.rs (benchmarking) - 840 lines
- Delete setup/ directory (wizard) - 526 lines
- Remove related dependencies (clap, dialoguer, colored, inotify)
- Update lib.rs exports to remove deleted modules

Total reduction: 5,125 lines (17% smaller)
Final size: 25,112 lines → targeting 13K core in Phase 2

Addresses #64
…ead code

## Changes

**Deleted Dead Code** (7,629 lines):
- Removed `integration/` module (7,484 lines) - not exported in lib.rs, completely inaccessible to external crates
- Updated lib.rs documentation to remove broken examples referencing integration module

**Added Optional Features**:
- `monitoring` - Security monitoring, event logging, and dashboards (2,154 lines)
- `vault` - Enterprise vault integration for Infisical, etc. (1,412 lines: vault/ + manager_vault.rs)
- `consent` - GDPR/CCPA compliance and consent management (1,167 lines)
- Convenience features: `production` (monitoring + vault), `compliance` (consent + monitoring), `full` (all features)

**Made reqwest Optional**:
- `reqwest` now only required when `vault` feature is enabled

## Impact

- **Lines removed**: 7,629 (30% reduction from Phase 1 result)
- **Before Phase 2**: 25,109 lines
- **After Phase 2**: 17,480 lines total
- **Default build** (no features): ~13,758 lines (core library only)
- **With all features**: 17,480 lines

## Testing

- ✅ `cargo check --no-default-features` passes (core only)
- ✅ `cargo check --features monitoring` passes
- ✅ `cargo check --features vault` passes
- ✅ `cargo check --features consent` passes
- ✅ `cargo check --features full` passes (all features)

## Rationale

- **integration/ module**: Dead code - existed in src/ but was never declared in lib.rs, making it completely inaccessible to external crates. Only used by internal tests.
- **Optional features**: Allow users to opt-in to advanced functionality like security monitoring, vault backends, and compliance features without bloating the core library.
- **Reduced core**: Default build is now ~13,758 lines of essential auth code, within target of ~13,000 lines.

## Related Issues

Addresses #64 (Phase 2)
Implements foundational OAuth 2.1 authorization server with MCP compliance:

- RFC 7591: Dynamic Client Registration endpoint
- RFC 8414: Authorization Server Metadata discovery
- RFC 8707: Resource Indicators support in all flows
- RFC 9728: Protected Resource Metadata endpoint
- OAuth 2.1 Authorization Code flow with mandatory PKCE S256
- JWT-based access tokens with refresh token rotation

New modules:
- oauth/models.rs: Core data structures (173 lines)
- oauth/pkce.rs: PKCE S256 verification with RFC 7636 validation (120 lines)
- oauth/metadata.rs: Server metadata endpoint (50 lines)
- oauth/resource.rs: Resource metadata endpoint (40 lines)
- oauth/registration.rs: Dynamic client registration (190 lines)
- oauth/authorize.rs: Authorization endpoint with consent UI (220 lines)
- oauth/token.rs: Token exchange endpoint (210 lines)

Dependencies added:
- axum: HTTP framework for OAuth endpoints
- base64-url: PKCE base64-url encoding per RFC 7636

Security features:
- HTTPS-only redirect URIs (localhost allowed for dev)
- Cryptographically secure token generation
- PKCE S256 code challenge verification
- OAuth error responses per RFC 6749

Status:
- All endpoints compile successfully
- 227 tests passing (including existing tests)
- Database integration pending (TODO comments in place)
- JWT signing key from env/vault pending

Next steps per Issue #73:
- Create PostgreSQL migrations for oauth_clients, authorization_codes, refresh_tokens
- Wire up database operations in registration/authorize/token endpoints
- Integrate with mcp-transport extractors
- Map RBAC permissions to OAuth scopes
… API

Implements complete OAuth 2.1 storage layer with trait-based design that
enables easy swapping of backends (in-memory → database).

Storage Backend:
- OAuthStorage trait for client, auth code, and refresh token operations
- InMemoryOAuthStorage with thread-safe RwLock-based HashMaps
- Automatic expiration checking and cleanup utilities
- 7 comprehensive unit tests covering lifecycle and edge cases

"Easy as Pi" API (Zero Boilerplate):
- OAuthState::new_in_memory() factory for instant setup
- oauth_router() returns pre-configured Router<OAuthState>
- Usage: `let app = oauth_router().with_state(OAuthState::new_in_memory());`
- Custom storage: `OAuthState::new(Arc::new(MyStorage))`

Wired into registration.rs:
- State<OAuthState> extraction for type-safe storage access
- Client credentials now persisted via storage.save_client()
- Ready for authorize.rs and token.rs integration

Fixes:
- Applied clippy manual_range_contains suggestions in pkce.rs
- Changed token.rs helpers to concrete return types (opaque type fix)
- Removed unused imports across multiple modules

All tests passing (240 total: 223 existing + 7 new storage + 10 registration)
Completes OAuth 2.1 authorization code flow with full storage integration.

Authorization Endpoint (authorize.rs):
- Client validation via storage.get_client()
- Redirect URI verification against registered URIs
- Authorization code generation and persistence
- Stores code with PKCE challenge, scopes, resource, 10min expiration

Token Endpoint (token.rs):
- Client credential verification via storage.verify_client_secret()
- Authorization code grant:
  * Loads auth code from storage
  * Verifies client_id, redirect_uri, PKCE code_verifier
  * Single-use enforcement (deletes code after validation)
  * Generates JWT access token + refresh token
  * Stores refresh token with 30-day expiration
- Refresh token grant:
  * Loads refresh token from storage
  * Verifies client_id match
  * Token rotation (new refresh token, delete old)
  * Generates new JWT access token

OAuth 2.1 Compliance:
- PKCE S256 mandatory verification
- Single-use authorization codes
- Refresh token rotation per OAuth 2.1
- JWT access tokens (1 hour expiration)
- Refresh tokens (30 day expiration)

All 261 tests passing
Add comprehensive conformance testing infrastructure using the official
@modelcontextprotocol/conformance test suite.

Features:
- Rust-based test runner with type-safe configuration
- Support for all transport types: stdio, HTTP, SSE, WebSocket
- Automatic server lifecycle management (spawn, ready-wait, shutdown)
- JSON configuration files for server test profiles
- Detailed test result aggregation and reporting
- Timestamped results directories with failure analysis

Test Infrastructure:
- conformance-tests/ - New workspace crate for test runner
- conformance-tests/servers/ - Server configuration profiles
- conformance-tests/results/ - Generated test results (gitignored)
- conformance-tests/RESULTS.md - Comprehensive test result documentation

Initial Test Results:
- Ran 26 scenarios against hello-world server
- All tests failing due to stdio logging interference
- Identified root cause: stderr output during server init
- Documented unimplemented features for future work

Server Configs:
- hello-world (stdio) - Basic tools testing
- ui-enabled-server (HTTP) - Tools + resources + future OAuth
- test-tools-server (stdio) - Comprehensive tool testing

Usage:
  cargo run --bin mcp-conformance servers
  cargo run --bin mcp-conformance run hello-world
  cargo run --bin mcp-conformance -- run server --scenario tools-list

Next Steps:
- Fix stdio transport logging to pass basic tests
- Run tests on HTTP transport servers
- Test OAuth implementation with auth scenarios
- Create GitHub issues for unimplemented features
Added comprehensive conformance testing infrastructure:

- Created conformance-tests/ workspace crate with CLI
- Supports all MCP transport types (stdio, HTTP, SSE, WebSocket)
- Type-safe JSON server configuration
- Automated server lifecycle management (spawn, ready poll, shutdown)
- Integration with @modelcontextprotocol/conformance npm package
- Timestamped results with detailed failure analysis

Initial test results:
- hello-world (stdio): 0/26 passing - stdio transport issues
- ui-enabled-server (HTTP): 4/26 passing (15.4%)
  ✓ server-initialize
  ✓ tools-list
  ✓ resources-list
  ✓ prompts-list

Also fixed stdio logging in McpServerBuilder::configure_stdio_logging()
to disable all logging by default for MCP conformance.
…entation

Documented complete conformance testing status including:

**Current Results:**
- HTTP transport: 4/26 passing (15.4%)
  ✓ server-initialize, tools-list, resources-list, prompts-list
  ✗ 22 tests fail due to missing test-specific tools/resources/prompts
- stdio transport: 0/26 passing (protocol-level issues)

**Key Findings:**
- MCP protocol implementation is SOLID - basic capabilities work correctly
- Conformance tests are scenario-based, expect specific tools/resources/prompts
- Low score due to testing against wrong server, not framework bugs
- OAuth 2.1 implementation complete (1,806 lines, all RFCs implemented)

**OAuth Status:**
- ✅ RFC 8414: Authorization Server Metadata
- ✅ RFC 9728: Protected Resource Metadata
- ✅ RFC 7591: Dynamic Client Registration
- ✅ OAuth 2.1 with mandatory PKCE (S256)
- ✅ Refresh Token Rotation, JWT Bearer Tokens
- ✅ MCP-specific scopes
- 📋 Blocker: Need OAuth-enabled HTTP server example to run tests

**Missing MCP Features:**
- logging/setLevel
- completion/complete
- resources/subscribe and unsubscribe
- Progress notifications
- Sampling support

**Next Steps:**
1. Create OAuth-enabled server example for OAuth conformance testing
2. Create conformance test server with test-specific tools/resources/prompts
3. Debug stdio transport protocol issues
4. Implement missing MCP protocol features

Also started examples/oauth-server/ (Cargo.toml) for OAuth conformance testing.
Created detailed 3-track roadmap to achieve 80%+ MCP conformance:

**Track B: Implement Missing MCP Features (Priority 1)**
- Phase B1: Logging Support (logging/setLevel)
- Phase B2: Resource Subscriptions (subscribe/unsubscribe)
- Phase B3: Completion Support (auto-completion)
- Phase B4: Progress Notifications
- Phase B5: Sampling Support (LLM requests)
- Phase B6: Elicitation Support (SEP-1034)
- Expected: +6-8 tests passing

**Track A: OAuth Conformance Testing (Priority 2)**
- Create OAuth-enabled HTTP server example
- Combine MCP backend with OAuth router
- Run 11 OAuth conformance tests
- Expected: 9-11/11 OAuth tests passing (82-100%)

**Track C: stdio Transport Debugging (Priority 3)**
- Deep investigation of protocol issues
- Compare with working HTTP transport
- Fix stdio communication
- Expected: +20-22 tests passing

**Timeline Estimates:**
- Track A: 3-4 hours (OAuth server)
- Track B: 16-24 hours (all features)
- Track C: 6-10 hours (stdio debugging)

**Final Goal:** 20+/26 server tests (77%+), complete MCP implementation
Completed MCP logging/setLevel implementation:

Protocol changes (mcp-protocol):
- Updated LogLevel enum with RFC 5424 syslog severity levels
- Implemented std::str::FromStr trait for LogLevel (Clippy compliance)
- Added LogLevel::as_str() method for string conversion
- Updated SetLevelRequestParam to use typed LogLevel instead of String
- Removed duplicate SetLevelParams struct

Server implementation (mcp-server):
- Handler for logging/setLevel already exists in handler.rs
- Backend trait already has set_level() method
- Fixed test to use LogLevel enum

Example updates (ui-enabled-server):
- Added .enable_logging() to server capabilities
- Implemented set_level() method in UiBackend

This implementation allows MCP clients to dynamically change the server's
logging verbosity level using the logging/setLevel method.

Related: #75
…source] macro

BREAKING: Version bump from 0.13.0 to 0.14.0 (backwards compatible)

## New Features

### Transport Methods in #[mcp_server] Macro
- Added serve_http(port) for HTTP transport servers
- Added serve_websocket(port) for WebSocket transport servers
- Added build_server(config) for custom ServerConfig
- Enhanced serve_stdio() with proper error handling
- Macros now support all MCP transport types (stdio, HTTP, WebSocket)

### Resources Demo Example
- Created examples/resources-demo showcasing #[mcp_resource] macro
- Demonstrates URI-templated resources with {param} syntax
- Uses HTTP transport for conformance testing
- Added conformance test configuration at conformance-tests/servers/resources-demo.json

## Bug Fixes

### #[mcp_resource] Macro (mcp-macros/src/mcp_tool.rs)
- Fixed Resource struct initialization - added missing fields:
  - title: None
  - icons: None
  - _meta: None
- Fixed ResourceContents struct - added missing _meta field
- Fixed attribute scoping issue - now strips #[mcp_resource] attributes from output
  to prevent "attribute not found in scope" compiler errors

## Test Results
- resources-demo conformance: 4/26 passing (15.4%)
  ✓ server-initialize
  ✓ tools-list
  ✓ resources-list
  ✓ resources-read

## Version Updates
- Bumped workspace version: 0.13.0 → 0.14.0
- Updated all internal dependency versions to 0.14.0
- Verified full workspace builds successfully
…upport

Implemented comprehensive subscription handling in two phases:

**Phase 1: Subscription Acceptance** ✅
- Added ResourceUpdatedNotification struct to mcp-protocol/src/model.rs
  - Defines notification message format for resource updates
- Modified backend.rs McpBackend trait:
  - Changed subscribe() default: returns Ok(()) instead of Err
  - Changed unsubscribe() default: returns Ok(()) instead of Err
  - Added documentation explaining tracking requirements
- Conformance results: resources-subscribe and resources-unsubscribe now pass

**Phase 2: Subscription Tracking** ✅
- Added global subscription registry to GenericServerHandler:
  - Arc<RwLock<HashSet<String>>> for tracking subscribed URIs
  - Thread-safe, supports concurrent access
  - Global implementation (simpler than per-client tracking)
- Enhanced handle_subscribe():
  - Tracks URI in global registry after backend validation
  - Logs new subscriptions
- Enhanced handle_unsubscribe():
  - Removes URI from registry after backend notification
  - Logs unsubscribes
- Added query methods:
  - get_subscribed_uris(): Get all subscribed resource URIs
  - is_subscribed(uri): Check if specific URI has subscriptions
  - Useful for Phase 3 notification delivery optimization

**Architecture:**
- Backend trait accepts all subscriptions (Phase 1)
- Handler tracks subscription state globally (Phase 2)
- Query methods enable notification delivery (ready for Phase 3)

**Testing:**
- Updated unit tests to reflect new subscription behavior
- Conformance: 6/26 tests passing (23%)
  ✓ resources-subscribe
  ✓ resources-unsubscribe
  ✓ server-initialize
  ✓ tools-list
  ✓ resources-list
  ✓ prompts-list
- All unit tests pass (132 passed; 0 failed)

**Next Steps (Phase 3):**
- Implement notification delivery mechanism
- Integrate with transport layer broadcast
- Add examples demonstrating notification usage
@github-actions

github-actions Bot commented Dec 3, 2025

Copy link
Copy Markdown

PR Validation Results

Quick Validation: ✅

  • Format check
  • Clippy lints
  • Unit tests
  • Documentation

Compatibility Check: ✅

  • Protocol compliance
  • Server compatibility

Summary: ✅ All checks passed

…nitoring

The storage module uses inotify for filesystem monitoring on Linux but the
dependency was not declared in Cargo.toml, causing build failures in CI.

Added inotify 0.10 as a Linux-specific dependency.
The conformance-tests workspace member was missing from the Docker COPY
commands, causing build failures when the workspace tried to load all members.
@github-actions

github-actions Bot commented Dec 3, 2025

Copy link
Copy Markdown

Code Coverage Report 📊

Local Coverage: 22.78%
Validation: Handled by Codecov

Note: Coverage validation is now performed by Codecov to ensure consistency across all platforms.

Coverage Details
Filename                                                  Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
integration-tests/src/auth_server_integration.rs              392                63    83.93%          26                 9    65.38%         291                72    75.26%           0                 0         -
integration-tests/src/cli_server_integration.rs               400                32    92.00%          35                 5    85.71%         357                23    93.56%           0                 0         -
integration-tests/src/end_to_end_scenarios.rs                 922               176    80.91%          40                 9    77.50%         638                94    85.27%           0                 0         -
integration-tests/src/lib.rs                                   22                12    45.45%           5                 2    60.00%          44                17    61.36%           0                 0         -
integration-tests/src/monitoring_integration.rs               440                56    87.27%          28                 6    78.57%         375                75    80.00%           0                 0         -
integration-tests/src/transport_server_integration.rs         448               117    73.88%          31                11    64.52%         385               144    62.60%           0                 0         -
mcp-auth/src/audit.rs                                         390               262    32.82%          28                17    39.29%         276               177    35.87%           0                 0         -
mcp-auth/src/config.rs                                         48                41    14.58%          11                10     9.09%          75                68     9.33%           0                 0         -
mcp-auth/src/crypto/encryption.rs                              89                89     0.00%           9                 9     0.00%          51                51     0.00%           0                 0         -
mcp-auth/src/crypto/hashing.rs                                 98                98     0.00%          10                10     0.00%          53                53     0.00%           0                 0         -
mcp-auth/src/crypto/keys.rs                                   115               115     0.00%           8                 8     0.00%          78                78     0.00%           0                 0         -
mcp-auth/src/crypto/mod.rs                                     15                15     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
mcp-auth/src/jwt.rs                                           321               284    11.53%          29                27     6.90%         255               226    11.37%           0                 0         -
mcp-auth/src/lib.rs                                            18                15    16.67%           6                 5    16.67%          16                13    18.75%           0                 0         -
mcp-auth/src/manager.rs                                      1258              1116    11.29%         117               101    13.68%         938               794    15.35%           0                 0         -
mcp-auth/src/middleware/mcp_auth.rs                           235               235     0.00%          24                24     0.00%         206               206     0.00%           0                 0         -
mcp-auth/src/middleware/session_middleware.rs                 430               430     0.00%          41                41     0.00%         357               357     0.00%           0                 0         -
mcp-auth/src/models.rs                                        195               195     0.00%          19                19     0.00%         166               166     0.00%           0                 0         -
mcp-auth/src/oauth/authorize.rs                               159               159     0.00%          20                20     0.00%         232               232     0.00%           0                 0         -
mcp-auth/src/oauth/metadata.rs                                 28                28     0.00%           3                 3     0.00%          18                18     0.00%           0                 0         -
mcp-auth/src/oauth/mod.rs                                      25                25     0.00%           3                 3     0.00%          20                20     0.00%           0                 0         -
mcp-auth/src/oauth/models.rs                                   30                30     0.00%           6                 6     0.00%          42                42     0.00%           0                 0         -
mcp-auth/src/oauth/pkce.rs                                     45                45     0.00%           5                 5     0.00%          27                27     0.00%           0                 0         -
mcp-auth/src/oauth/registration.rs                            105               105     0.00%           7                 7     0.00%         106               106     0.00%           0                 0         -
mcp-auth/src/oauth/resource.rs                                 19                19     0.00%           3                 3     0.00%          13                13     0.00%           0                 0         -
mcp-auth/src/oauth/storage.rs                                 124               124     0.00%          17                17     0.00%          81                81     0.00%           0                 0         -
mcp-auth/src/oauth/token.rs                                   229               229     0.00%          24                24     0.00%         280               280     0.00%           0                 0         -
mcp-auth/src/permissions/mcp_permissions.rs                   419               419     0.00%          33                33     0.00%         319               319     0.00%           0                 0         -
mcp-auth/src/security/request_security.rs                     702               702     0.00%          49                49     0.00%         615               615     0.00%           0                 0         -
mcp-auth/src/session/session_manager.rs                       457               457     0.00%          50                50     0.00%         353               353     0.00%           0                 0         -
mcp-auth/src/storage.rs                                       697               680     2.44%          50                46     8.00%         412               394     4.37%           0                 0         -
mcp-auth/src/transport/auth_extractors.rs                     155               155     0.00%          27                27     0.00%         137               137     0.00%           0                 0         -
mcp-auth/src/transport/http_auth.rs                           303               303     0.00%          20                20     0.00%         216               216     0.00%           0                 0         -
mcp-auth/src/transport/stdio_auth.rs                          268               268     0.00%          22                22     0.00%         195               195     0.00%           0                 0         -
mcp-auth/src/transport/websocket_auth.rs                      351               351     0.00%          23                23     0.00%         258               258     0.00%           0                 0         -
mcp-auth/src/validation.rs                                    144               144     0.00%          13                13     0.00%          95                95     0.00%           0                 0         -
mcp-cli-derive/src/lib.rs                                     324               324     0.00%          22                22     0.00%         262               262     0.00%           0                 0         -
mcp-cli/src/config.rs                                          81                68    16.05%          13                10    23.08%          70                61    12.86%           0                 0         -
mcp-cli/src/lib.rs                                             15                15     0.00%           5                 5     0.00%          15                15     0.00%           0                 0         -
mcp-cli/src/server.rs                                         241               241     0.00%          34                34     0.00%         207               207     0.00%           0                 0         -
mcp-cli/src/utils.rs                                          101               101     0.00%          13                13     0.00%          73                73     0.00%           0                 0         -
mcp-logging/src/aggregation.rs                                311               311     0.00%          27                27     0.00%         228               228     0.00%           0                 0         -
mcp-logging/src/alerting.rs                                   552               344    37.68%          39                17    56.41%         419               226    46.06%           0                 0         -
mcp-logging/src/correlation.rs                                415               415     0.00%          34                34     0.00%         299               299     0.00%           0                 0         -
mcp-logging/src/dashboard.rs                                  391               197    49.62%          21                15    28.57%         394               182    53.81%           0                 0         -
mcp-logging/src/metrics.rs                                    306               127    58.50%          36                19    47.22%         329               123    62.61%           0                 0         -
mcp-logging/src/persistence.rs                                360               360     0.00%          26                26     0.00%         202               202     0.00%           0                 0         -
mcp-logging/src/profiling.rs                                  502               496     1.20%          37                36     2.70%         398               354    11.06%           0                 0         -
mcp-logging/src/sanitization.rs                               268               265     1.12%          22                21     4.55%         181               173     4.42%           0                 0         -
mcp-logging/src/structured.rs                                 258               255     1.16%          24                23     4.17%         230               227     1.30%           0                 0         -
mcp-logging/src/telemetry.rs                                   75                34    54.67%          12                 5    58.33%          78                24    69.23%           0                 0         -
mcp-monitoring/src/collector.rs                               179                78    56.42%          19                 8    57.89%         133                52    60.90%           0                 0         -
mcp-monitoring/src/config.rs                                    3                 0   100.00%           1                 0   100.00%           8                 0   100.00%           0                 0         -
mcp-monitoring/src/lib.rs                                       3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
mcp-monitoring/src/metrics.rs                                   3                 3     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
mcp-protocol/src/error.rs                                     193               153    20.73%          27                18    33.33%         151               117    22.52%           0                 0         -
mcp-protocol/src/errors.rs                                     83                83     0.00%          12                12     0.00%          40                40     0.00%           0                 0         -
mcp-protocol/src/lib.rs                                        12                12     0.00%           2                 2     0.00%          11                11     0.00%           0                 0         -
mcp-protocol/src/model.rs                                     352               342     2.84%          57                55     3.51%         386               379     1.81%           0                 0         -
mcp-protocol/src/validation.rs                                238               238     0.00%          25                25     0.00%         176               176     0.00%           0                 0         -
mcp-security/src/config.rs                                      4                 0   100.00%           1                 0   100.00%           9                 0   100.00%           0                 0         -
mcp-security/src/lib.rs                                         3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
mcp-security/src/middleware.rs                                 18                 3    83.33%           3                 0   100.00%          25                 3    88.00%           0                 0         -
mcp-security/src/validation.rs                                 10                10     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
mcp-server/src/alerting_endpoint.rs                           117               117     0.00%          15                15     0.00%         110               110     0.00%           0                 0         -
mcp-server/src/backend.rs                                     114                99    13.16%          26                22    15.38%          99                86    13.13%           0                 0         -
mcp-server/src/builder_trait.rs                                44                44     0.00%           3                 3     0.00%          37                37     0.00%           0                 0         -
mcp-server/src/common_backend.rs                               59                59     0.00%          11                11     0.00%          82                82     0.00%           0                 0         -
mcp-server/src/context.rs                                      55                14    74.55%          10                 3    70.00%          46                16    65.22%           0                 0         -
mcp-server/src/dashboard_endpoint.rs                          104               104     0.00%          12                12     0.00%          79                79     0.00%           0                 0         -
mcp-server/src/handler.rs                                     344               233    32.27%          57                33    42.11%         248               151    39.11%           0                 0         -
mcp-server/src/health_endpoint.rs                              83                83     0.00%           5                 5     0.00%          91                91     0.00%           0                 0         -
mcp-server/src/metrics_endpoint.rs                            133               133     0.00%           7                 7     0.00%          86                86     0.00%           0                 0         -
mcp-server/src/middleware.rs                                  128                33    74.22%          13                 5    61.54%         104                17    83.65%           0                 0         -
mcp-server/src/server.rs                                      330               111    66.36%          38                19    50.00%         232                77    66.81%           0                 0         -
mcp-transport/src/batch.rs                                    195               195     0.00%          14                14     0.00%         128               128     0.00%           0                 0         -
mcp-transport/src/config.rs                                    15                12    20.00%           5                 4    20.00%          15                12    20.00%           0                 0         -
mcp-transport/src/http.rs                                     651               634     2.61%          39                36     7.69%         438               408     6.85%           0                 0         -
mcp-transport/src/lib.rs                                       13                 3    76.92%           1                 0   100.00%          12                 3    75.00%           0                 0         -
mcp-transport/src/stdio.rs                                    233               186    20.17%          17                12    29.41%         162               119    26.54%           0                 0         -
mcp-transport/src/streamable_http.rs                          231               231     0.00%          19                19     0.00%         171               171     0.00%           0                 0         -
mcp-transport/src/validation.rs                               193               193     0.00%          14                14     0.00%         135               135     0.00%           0                 0         -
mcp-transport/src/websocket.rs                                 15                 9    40.00%           5                 3    40.00%          17                11    35.29%           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                       18454             14562    21.09%        1671              1352    19.09%       14636             11302    22.78%           0                 0         -

📋 Full Report: View on Codecov

@codecov

codecov Bot commented Dec 3, 2025

Copy link
Copy Markdown

Fixed all failing doctests in mcp-auth OAuth code:

1. authorize.rs line 32: Changed HTTP request example from code block to text format
2. oauth/mod.rs lines 47, 62, 79: Added explicit type annotations for Router to fix type inference errors

All doctests now compile and pass successfully.
Added 15 integration tests covering:
- PKCE verification and validation (verify_pkce, validate_code_verifier, validate_code_challenge)
- OAuth error model creation (all error types)
- Storage operations for clients, authorization codes, and refresh tokens
- Token/code expiration handling
- Cleanup of expired entries
- Model validation for OAuthClient, AuthorizationCode, and RefreshToken

All tests pass successfully. This should significantly improve test coverage
for the OAuth implementation.
Added comprehensive HTTP endpoint testing:
- RFC 8414: Authorization server metadata endpoint
- RFC 7591: Dynamic client registration with validation
- RFC 9728: Protected resource metadata
- Token endpoint error handling
- Request validation (redirect URIs, grant types, response types)

Tests cover:
- Client registration success and error cases
- Invalid redirect URI detection (non-HTTPS, custom schemes)
- Localhost development URI support
- Invalid grant type and response type handling
- Token endpoint client authentication
- Metadata endpoint responses

Added 11 new integration tests (26 total OAuth tests now)
Coverage improvements for registration.rs, token.rs, metadata.rs
Added 10 new integration tests for full OAuth 2.1 authorization flow:

Authorization endpoint tests:
- GET /oauth/authorize consent form display
- Invalid response_type validation
- Invalid code_challenge_method validation (S256 required)
- POST user approval with redirect
- POST user denial with access_denied error

Token endpoint tests:
- Full authorization code grant flow with PKCE
- Refresh token flow with token rotation
- Wrong PKCE code_verifier rejection
- Expired authorization code handling
- Wrong redirect_uri validation

These tests exercise both authorize.rs and token.rs OAuth modules
through complete HTTP request/response cycles, improving coverage
of critical OAuth security flows.
@avrabe
avrabe merged commit 95e3592 into main Dec 4, 2025
22 checks passed
@avrabe
avrabe deleted the feature/oauth-2.1-implementation branch December 4, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant