Skip to content

Add schema management MCP tools (Issue #703) - #713

Merged
malibio merged 2 commits into
mainfrom
feature/issue-703-schema-management-tools
Dec 1, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-703-schema-management-tools

Conversation

@malibio

@malibio malibio commented Dec 1, 2025

Copy link
Copy Markdown
Collaborator

Summary

Adds 3 new MCP tools for schema relationship management, completing Phase 5-6 of Issue #703.

New Tools

  • add_schema_relationship - Add a relationship definition to an existing schema (creates edge table DDL)
  • remove_schema_relationship - Soft-delete a relationship (preserves edge table and data)
  • update_schema - Batch update schema description and relationships

Changes

  • schema.rs: +292 lines - 3 new handlers with proper NodeUpdate usage
  • tools.rs: +128 lines - Tool routing and comprehensive JSON schemas
  • Test files: Updated tool count (25 → 28) and added assertions for new tools

Testing

  • All 523 Rust tests pass
  • Quality checks pass (clippy, fmt, svelte-check)

Related

🤖 Generated with Claude Code

## Summary
- Add `add_schema_relationship` tool for adding relationships to existing schemas
- Add `remove_schema_relationship` tool for soft-delete of relationships
- Add `update_schema` tool for batch schema updates

## Changes
- schema.rs: Add 3 new handlers with proper NodeUpdate usage
- tools.rs: Register tools and add comprehensive tool schemas
- Update test files: 25 → 28 tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Dec 1, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Initial Review

This PR adds 3 new MCP tools for schema relationship management (add_schema_relationship, remove_schema_relationship, update_schema), completing Phases 5-6 of Issue #703. The implementation is clean, follows established patterns, and properly extends the existing schema management infrastructure.


Requirements Check (from Issue #703)

Criterion Status
SchemaRelationship and EdgeField structs defined and tested Previously completed
Schema spoke table supports relationships array Previously completed
Edge table DDL generation working with tests Previously completed
Atomic schema + relationship creation working Previously completed
Relationship CRUD API working Previously completed
NLP discovery API working Previously completed
MCP handlers support relationship CRUD Completed in this PR

Code Review Findings

Positive Observations

  1. Consistent Error Handling - All three handlers follow the established pattern: parse params, fetch schema, validate, update, return response. Error messages are descriptive and actionable.

  2. Proper Use of NodeUpdate - The PR correctly uses the NodeUpdate struct pattern (lines 323-326, 395-398, 488-491 in schema.rs) instead of directly manipulating nodes, which is consistent with the codebase's design.

  3. Good API Design - The handlers provide both granular operations (add_schema_relationship, remove_schema_relationship) and a batch operation (update_schema), giving API consumers flexibility.

  4. Comprehensive JSON Schemas - The tool schemas in tools.rs are well-documented with descriptions for every field, which aids NLP/AI clients in understanding how to use the tools.

  5. Test Updates - Test files properly updated with new tool count (25 -> 28) and assertions for new tools.


Suggested Improvements

1. [Improvement] Missing Duplicate Relationship Check in update_schema

Location: schema.rs:471-474

The update_schema handler extends relationships without checking for duplicates. If a relationship with the same name already exists, extending will create duplicates.

if let Some(add_rels) = params.add_relationships {
    relationships_added = add_rels.len();
    relationships.extend(add_rels);  // No duplicate check
}

Recommendation: Add validation similar to handle_add_schema_relationship:

if let Some(add_rels) = params.add_relationships {
    for rel in &add_rels {
        if relationships.iter().any(|r| r.name == rel.name) {
            return Err(MCPError::invalid_params(format!(
                "Relationship '{}' already exists in schema",
                rel.name
            )));
        }
    }
    relationships_added = add_rels.len();
    relationships.extend(add_rels);
}

Principle: Input validation should be consistent across all entry points to prevent data inconsistency.


2. [Improvement] Missing Duplicate Field Check in update_schema

Location: schema.rs:455-458

Similar to relationships, add_fields doesn't check for duplicates:

if let Some(add_fields) = params.add_fields {
    fields_added = add_fields.len();
    fields.extend(add_fields);  // No duplicate check
}

Recommendation: Add validation to prevent duplicate field names.


3. [Nit] JSON Schema Missing add_fields and remove_fields Properties

Location: tools.rs:913-949

The update_schema tool JSON schema documents add_relationships and remove_relationships but omits add_fields and remove_fields, even though the handler supports them in UpdateSchemaParams (lines 240-245 in schema.rs).

Recommendation: Either:

  • Add the missing properties to the JSON schema for completeness, OR
  • Document why field operations are intentionally omitted from the tool (e.g., if they should use a different tool)

4. [Nit] Consider Schema Version Increment on Relationship Changes

Location: schema.rs:314-321, 387-392, 479-485

The handlers preserve schema.schema_version but don't increment it when relationships change. While this may be intentional (version only for field changes), it could be worth documenting or considering for auditing purposes.


Security Considerations

  • Input Validation: Schema IDs and relationship names are validated against the database (schema must exist, relationship must/must not exist). No security concerns identified.
  • No Hardcoded Secrets: The code contains no credentials or API keys.
  • Error Messages: Error messages expose schema IDs and relationship names, which is appropriate for debugging without leaking sensitive data.

Testing

  • All 96 schema-related tests pass
  • Test count properly updated (25 -> 28 tools)
  • Tool presence assertions added for new tools

Gap: No integration tests for the new handlers' async behavior (e.g., testing actual schema updates through the MCP interface). Consider adding tests in a future PR for end-to-end validation.


Recommendation: APPROVE with Minor Suggestions

This is a well-implemented PR that completes the MCP handler integration for Issue #703. The code follows established patterns, has proper error handling, and includes appropriate test updates.

The duplicate validation suggestions are improvements that could prevent edge-case bugs but are not blocking issues for this greenfield project with no production users.

Action Items (non-blocking):

  1. Consider adding duplicate checks for add_relationships and add_fields in update_schema
  2. Consider adding add_fields/remove_fields to the JSON schema if field operations should be exposed

Reviewed by: Claude Code (Principal Engineer Reviewer)

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete. See detailed comment above. Recommendation: APPROVE with minor suggestions.

- Add duplicate field check in update_schema handler
- Add duplicate relationship check in update_schema handler
- Add add_fields/remove_fields to update_schema JSON schema

Addresses reviewer recommendations from PR #713 review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Dec 1, 2025

Copy link
Copy Markdown
Collaborator Author

Review Recommendations Addressed

✅ Addressed (3/4 suggestions)

  1. Duplicate relationship check in update_schema - Added validation to reject duplicate relationship names before adding
  2. Duplicate field check in update_schema - Added validation to reject duplicate field names before adding
  3. JSON schema completeness - Added add_fields and remove_fields properties to the update_schema tool schema

⏭️ Skipped (1/4 suggestions)

  1. Schema version increment on relationship changes - Intentionally skipped. The schema_version field is designed to track schema structure migrations, not every modification. Relationship changes don't require DDL migrations in the same way field changes do. This behavior is consistent with how the codebase handles other schema updates.

Commits: 1
Tests: 523 passed ✅
Quality checks: Passed ✅

@malibio
malibio merged commit 14d2754 into main Dec 1, 2025
@malibio
malibio deleted the feature/issue-703-schema-management-tools branch December 1, 2025 16:27
malibio added a commit that referenced this pull request Feb 4, 2026
* Add schema management MCP tools (Issue #703)

## Summary
- Add `add_schema_relationship` tool for adding relationships to existing schemas
- Add `remove_schema_relationship` tool for soft-delete of relationships
- Add `update_schema` tool for batch schema updates

## Changes
- schema.rs: Add 3 new handlers with proper NodeUpdate usage
- tools.rs: Register tools and add comprehensive tool schemas
- Update test files: 25 → 28 tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Address review: Add duplicate validation and complete JSON schema

- Add duplicate field check in update_schema handler
- Add duplicate relationship check in update_schema handler
- Add add_fields/remove_fields to update_schema JSON schema

Addresses reviewer recommendations from PR #713 review.

🤖 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
* Add schema management MCP tools (Issue #703)

## Summary
- Add `add_schema_relationship` tool for adding relationships to existing schemas
- Add `remove_schema_relationship` tool for soft-delete of relationships
- Add `update_schema` tool for batch schema updates

## Changes
- schema.rs: Add 3 new handlers with proper NodeUpdate usage
- tools.rs: Register tools and add comprehensive tool schemas
- Update test files: 25 → 28 tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Address review: Add duplicate validation and complete JSON schema

- Add duplicate field check in update_schema handler
- Add duplicate relationship check in update_schema handler
- Add add_fields/remove_fields to update_schema JSON schema

Addresses reviewer recommendations from PR #713 review.

🤖 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
* Add schema management MCP tools (Issue #703)

## Summary
- Add `add_schema_relationship` tool for adding relationships to existing schemas
- Add `remove_schema_relationship` tool for soft-delete of relationships
- Add `update_schema` tool for batch schema updates

## Changes
- schema.rs: Add 3 new handlers with proper NodeUpdate usage
- tools.rs: Register tools and add comprehensive tool schemas
- Update test files: 25 → 28 tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Address review: Add duplicate validation and complete JSON schema

- Add duplicate field check in update_schema handler
- Add duplicate relationship check in update_schema handler
- Add add_fields/remove_fields to update_schema JSON schema

Addresses reviewer recommendations from PR #713 review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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