Repository navigation
Implement MCP initialization handshake and capability discovery - #313
Merged
Merged
Conversation
…closes #308) This commit adds the MCP initialization handshake to enable proper capability negotiation between NodeSpace and MCP clients like Claude Code. ## Changes ### New Files - `packages/core/src/mcp/handlers/initialize.rs`: Initialize handler with protocol version validation and tool schema generation - `packages/core/src/mcp/handlers/initialize_test.rs`: Comprehensive unit tests for initialize handler (11 test cases) ### Modified Files - `packages/core/src/mcp/types.rs`: Added MCPNotification struct for notifications (no id field) - `packages/core/src/mcp/types_test.rs`: Added 7 notification parsing tests - `packages/core/src/mcp/server.rs`: - Added ServerState with AtomicBool for initialization tracking - Updated message loop to handle both requests and notifications - Added initialize and ping method handlers - Added state validation (blocks operations before initialization) - Added handle_notification function for initialized notification - `packages/core/src/mcp/handlers/mod.rs`: Exported initialize module ## Features ### Protocol Compliance - ✅ Version negotiation (accepts 2024-11-05, rejects others) - ✅ Capability advertisement with full tool schemas - ✅ Notification support for `initialized` event - ✅ State tracking prevents operations before initialization - ✅ Ping method for health checks ### Tool Schemas Manual schemas for all 6 MCP methods: - create_node, get_node, update_node, delete_node, query_nodes, create_nodes_from_markdown Each schema includes: - Method name and description - Full JSON Schema for parameters - Required field specifications - Enum constraints for node types ### Testing - 11 initialize handler unit tests - 7 notification parsing tests - All 55 MCP tests passing - Quality checks passing (cargo clippy, fmt) ## MCP Lifecycle 1. Client sends `initialize` request with protocol version 2. Server validates version and returns capabilities 3. Client sends `initialized` notification 4. Server marks session as initialized 5. Normal operations begin Operations attempted before initialization receive error: "Session not initialized. Send initialize request first." 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit addresses the minor suggestions from the pragmatic code review: 1. **Integration Tests**: Added 4 comprehensive integration tests for full MCP handshake flow - test_full_initialization_handshake: Complete flow from uninitialized → initialized → operations allowed - test_operation_rejected_before_initialization: Verifies all operations blocked before init - test_initialize_then_wrong_version: Version validation works even after initialization - test_initialize_idempotent: Initialize can be called multiple times safely 2. **Enhanced Error Diagnostics**: Improved logging for message parsing failures - Now provides detailed diagnostics when both request and notification parsing fail - Distinguishes between: empty messages, invalid JSON, missing fields, wrong version, malformed structures - Helps debugging by showing specific validation failures instead of generic "parse error" Changes: - packages/core/src/mcp/handlers/initialize_test.rs: +195 lines (4 new integration tests) - packages/core/src/mcp/server.rs: Enhanced parse error handling with detailed diagnostics All 59 MCP tests passing. No lint/clippy warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 4, 2026
* feat: Implement MCP initialization handshake and capability discovery (closes #308) This commit adds the MCP initialization handshake to enable proper capability negotiation between NodeSpace and MCP clients like Claude Code. ## Changes ### New Files - `packages/core/src/mcp/handlers/initialize.rs`: Initialize handler with protocol version validation and tool schema generation - `packages/core/src/mcp/handlers/initialize_test.rs`: Comprehensive unit tests for initialize handler (11 test cases) ### Modified Files - `packages/core/src/mcp/types.rs`: Added MCPNotification struct for notifications (no id field) - `packages/core/src/mcp/types_test.rs`: Added 7 notification parsing tests - `packages/core/src/mcp/server.rs`: - Added ServerState with AtomicBool for initialization tracking - Updated message loop to handle both requests and notifications - Added initialize and ping method handlers - Added state validation (blocks operations before initialization) - Added handle_notification function for initialized notification - `packages/core/src/mcp/handlers/mod.rs`: Exported initialize module ## Features ### Protocol Compliance - ✅ Version negotiation (accepts 2024-11-05, rejects others) - ✅ Capability advertisement with full tool schemas - ✅ Notification support for `initialized` event - ✅ State tracking prevents operations before initialization - ✅ Ping method for health checks ### Tool Schemas Manual schemas for all 6 MCP methods: - create_node, get_node, update_node, delete_node, query_nodes, create_nodes_from_markdown Each schema includes: - Method name and description - Full JSON Schema for parameters - Required field specifications - Enum constraints for node types ### Testing - 11 initialize handler unit tests - 7 notification parsing tests - All 55 MCP tests passing - Quality checks passing (cargo clippy, fmt) ## MCP Lifecycle 1. Client sends `initialize` request with protocol version 2. Server validates version and returns capabilities 3. Client sends `initialized` notification 4. Server marks session as initialized 5. Normal operations begin Operations attempted before initialization receive error: "Session not initialized. Send initialize request first." 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Address code review nits for MCP initialization This commit addresses the minor suggestions from the pragmatic code review: 1. **Integration Tests**: Added 4 comprehensive integration tests for full MCP handshake flow - test_full_initialization_handshake: Complete flow from uninitialized → initialized → operations allowed - test_operation_rejected_before_initialization: Verifies all operations blocked before init - test_initialize_then_wrong_version: Version validation works even after initialization - test_initialize_idempotent: Initialize can be called multiple times safely 2. **Enhanced Error Diagnostics**: Improved logging for message parsing failures - Now provides detailed diagnostics when both request and notification parsing fail - Distinguishes between: empty messages, invalid JSON, missing fields, wrong version, malformed structures - Helps debugging by showing specific validation failures instead of generic "parse error" Changes: - packages/core/src/mcp/handlers/initialize_test.rs: +195 lines (4 new integration tests) - packages/core/src/mcp/server.rs: Enhanced parse error handling with detailed diagnostics All 59 MCP tests passing. No lint/clippy warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 5, 2026
* feat: Implement MCP initialization handshake and capability discovery (closes #308) This commit adds the MCP initialization handshake to enable proper capability negotiation between NodeSpace and MCP clients like Claude Code. ## Changes ### New Files - `packages/core/src/mcp/handlers/initialize.rs`: Initialize handler with protocol version validation and tool schema generation - `packages/core/src/mcp/handlers/initialize_test.rs`: Comprehensive unit tests for initialize handler (11 test cases) ### Modified Files - `packages/core/src/mcp/types.rs`: Added MCPNotification struct for notifications (no id field) - `packages/core/src/mcp/types_test.rs`: Added 7 notification parsing tests - `packages/core/src/mcp/server.rs`: - Added ServerState with AtomicBool for initialization tracking - Updated message loop to handle both requests and notifications - Added initialize and ping method handlers - Added state validation (blocks operations before initialization) - Added handle_notification function for initialized notification - `packages/core/src/mcp/handlers/mod.rs`: Exported initialize module ## Features ### Protocol Compliance - ✅ Version negotiation (accepts 2024-11-05, rejects others) - ✅ Capability advertisement with full tool schemas - ✅ Notification support for `initialized` event - ✅ State tracking prevents operations before initialization - ✅ Ping method for health checks ### Tool Schemas Manual schemas for all 6 MCP methods: - create_node, get_node, update_node, delete_node, query_nodes, create_nodes_from_markdown Each schema includes: - Method name and description - Full JSON Schema for parameters - Required field specifications - Enum constraints for node types ### Testing - 11 initialize handler unit tests - 7 notification parsing tests - All 55 MCP tests passing - Quality checks passing (cargo clippy, fmt) ## MCP Lifecycle 1. Client sends `initialize` request with protocol version 2. Server validates version and returns capabilities 3. Client sends `initialized` notification 4. Server marks session as initialized 5. Normal operations begin Operations attempted before initialization receive error: "Session not initialized. Send initialize request first." 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Address code review nits for MCP initialization This commit addresses the minor suggestions from the pragmatic code review: 1. **Integration Tests**: Added 4 comprehensive integration tests for full MCP handshake flow - test_full_initialization_handshake: Complete flow from uninitialized → initialized → operations allowed - test_operation_rejected_before_initialization: Verifies all operations blocked before init - test_initialize_then_wrong_version: Version validation works even after initialization - test_initialize_idempotent: Initialize can be called multiple times safely 2. **Enhanced Error Diagnostics**: Improved logging for message parsing failures - Now provides detailed diagnostics when both request and notification parsing fail - Distinguishes between: empty messages, invalid JSON, missing fields, wrong version, malformed structures - Helps debugging by showing specific validation failures instead of generic "parse error" Changes: - packages/core/src/mcp/handlers/initialize_test.rs: +195 lines (4 new integration tests) - packages/core/src/mcp/server.rs: Enhanced parse error handling with detailed diagnostics All 59 MCP tests passing. No lint/clippy warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 26, 2026
* feat: Implement MCP initialization handshake and capability discovery (closes #308) This commit adds the MCP initialization handshake to enable proper capability negotiation between NodeSpace and MCP clients like Claude Code. ## Changes ### New Files - `packages/core/src/mcp/handlers/initialize.rs`: Initialize handler with protocol version validation and tool schema generation - `packages/core/src/mcp/handlers/initialize_test.rs`: Comprehensive unit tests for initialize handler (11 test cases) ### Modified Files - `packages/core/src/mcp/types.rs`: Added MCPNotification struct for notifications (no id field) - `packages/core/src/mcp/types_test.rs`: Added 7 notification parsing tests - `packages/core/src/mcp/server.rs`: - Added ServerState with AtomicBool for initialization tracking - Updated message loop to handle both requests and notifications - Added initialize and ping method handlers - Added state validation (blocks operations before initialization) - Added handle_notification function for initialized notification - `packages/core/src/mcp/handlers/mod.rs`: Exported initialize module ## Features ### Protocol Compliance - ✅ Version negotiation (accepts 2024-11-05, rejects others) - ✅ Capability advertisement with full tool schemas - ✅ Notification support for `initialized` event - ✅ State tracking prevents operations before initialization - ✅ Ping method for health checks ### Tool Schemas Manual schemas for all 6 MCP methods: - create_node, get_node, update_node, delete_node, query_nodes, create_nodes_from_markdown Each schema includes: - Method name and description - Full JSON Schema for parameters - Required field specifications - Enum constraints for node types ### Testing - 11 initialize handler unit tests - 7 notification parsing tests - All 55 MCP tests passing - Quality checks passing (cargo clippy, fmt) ## MCP Lifecycle 1. Client sends `initialize` request with protocol version 2. Server validates version and returns capabilities 3. Client sends `initialized` notification 4. Server marks session as initialized 5. Normal operations begin Operations attempted before initialization receive error: "Session not initialized. Send initialize request first." 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Address code review nits for MCP initialization This commit addresses the minor suggestions from the pragmatic code review: 1. **Integration Tests**: Added 4 comprehensive integration tests for full MCP handshake flow - test_full_initialization_handshake: Complete flow from uninitialized → initialized → operations allowed - test_operation_rejected_before_initialization: Verifies all operations blocked before init - test_initialize_then_wrong_version: Version validation works even after initialization - test_initialize_idempotent: Initialize can be called multiple times safely 2. **Enhanced Error Diagnostics**: Improved logging for message parsing failures - Now provides detailed diagnostics when both request and notification parsing fail - Distinguishes between: empty messages, invalid JSON, missing fields, wrong version, malformed structures - Helps debugging by showing specific validation failures instead of generic "parse error" Changes: - packages/core/src/mcp/handlers/initialize_test.rs: +195 lines (4 new integration tests) - packages/core/src/mcp/server.rs: Enhanced parse error handling with detailed diagnostics All 59 MCP tests passing. No lint/clippy warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #308