-
Notifications
You must be signed in to change notification settings - Fork 309
fix: add MCP server config to ExpandChatSession for feature creation #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: add MCP server config to ExpandChatSession for feature creation #88
Conversation
📝 WalkthroughWalkthroughAdded EXPAND_FEATURE_TOOLS and MCP setup to the expand chat session service; initialized ClaudeSDKClient with mcp_servers and updated allowed tools; added Feature.regression_count plus legacy columns and migration support; added MCP tool Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ExpandService as "Expand Service"
participant Env as Environment
participant ClaudeClient as "ClaudeSDKClient"
participant MCP as "feature_mcp (MCP Server)"
participant DB as Database
Client->>ExpandService: request expand chat session
ExpandService->>Env: prepare env vars (PROJECT_DIR, PYTHONPATH)
ExpandService->>MCP: declare/start feature_mcp via mcp_servers
ExpandService->>ClaudeClient: init with mcp_servers + EXPAND_FEATURE_TOOLS
ClaudeClient->>MCP: invoke feature tool (feature_get_for_regression)
MCP->>DB: query passing features ordered by regression_count
DB-->>MCP: return features
MCP->>DB: increment regression_count, commit
DB-->>MCP: confirm update
MCP-->>ClaudeClient: return feature payload
ClaudeClient-->>ExpandService: receive tool result
ExpandService-->>Client: return expanded session
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When adding features to existing projects, the ExpandChatSession was unable to use feature creation MCP tools because it lacked the MCP server configuration that AssistantChatSession has. This commit adds: - EXPAND_FEATURE_TOOLS constant for feature_create, feature_create_bulk, and feature_get_stats MCP tools - MCP server configuration pointing to mcp_server.feature_mcp - Updated allowed_tools and security settings to include feature tools The existing XML parsing fallback continues to work as defense-in-depth if MCP fails. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
cff1808 to
32ec92e
Compare
Existing databases have testing_in_progress (NOT NULL) and last_tested_at columns from before commit 486979c. Re-add them to the Feature model with defaults to prevent NOT NULL violations when creating features via MCP. The columns are no longer used by the application but must exist in the model so SQLAlchemy populates them on INSERT. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@api/database.py`:
- Around line 61-66: The migration function _migrate_add_testing_columns is
currently a no-op but must add the deprecated columns for DBs created after
their removal; update _migrate_add_testing_columns to check the target table
schema (e.g., via inspector or PRAGMA) for the absence of testing_in_progress
and last_tested_at and, if missing, execute DDL to ALTER TABLE and add
testing_in_progress BOOLEAN NOT NULL DEFAULT FALSE and last_tested_at DATETIME
NULL (or equivalent for SQLite), ensuring the column definitions match the
SQLAlchemy model defaults and nullability and that the operation is safe (wrap
in try/except and commit/rollback as in existing migration patterns). Ensure the
function references the same table name used by the model and handles both
SQLite and other RDBMS dialect nuances when issuing ALTER statements.
| # DEPRECATED: Kept for backward compatibility with existing databases. | ||
| # These columns are no longer used but prevent NOT NULL violations on insert. | ||
| # Removed in commit 486979c but old databases still have them. | ||
| testing_in_progress = Column(Boolean, nullable=False, default=False) | ||
| last_tested_at = Column(DateTime, nullable=True, default=None) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration gap: databases created after column removal won't have these columns.
The columns are added to the model, but _migrate_add_testing_columns() (lines 241-253) is a no-op. This creates a problem for databases that were created after the columns were removed in commit 486979c but before this PR—they won't have these columns, and INSERT operations will fail.
Consider updating _migrate_add_testing_columns to actually add the columns if missing:
Proposed fix for _migrate_add_testing_columns
def _migrate_add_testing_columns(engine) -> None:
- """Legacy migration - no longer adds testing columns.
-
- The testing_in_progress and last_tested_at columns were removed from the
- Feature model as part of simplifying the testing agent architecture.
- Multiple testing agents can now test the same feature concurrently
- without coordination.
-
- This function is kept for backwards compatibility but does nothing.
- Existing databases with these columns will continue to work - the columns
- are simply ignored.
- """
- pass
+ """Add testing columns for backward compatibility.
+
+ These columns are deprecated but required in the model so SQLAlchemy
+ populates them on INSERT (preventing NOT NULL violations in old databases).
+ """
+ with engine.connect() as conn:
+ result = conn.execute(text("PRAGMA table_info(features)"))
+ columns = [row[1] for row in result.fetchall()]
+
+ if "testing_in_progress" not in columns:
+ conn.execute(text(
+ "ALTER TABLE features ADD COLUMN testing_in_progress BOOLEAN DEFAULT 0"
+ ))
+ if "last_tested_at" not in columns:
+ conn.execute(text(
+ "ALTER TABLE features ADD COLUMN last_tested_at DATETIME DEFAULT NULL"
+ ))
+ conn.commit()🤖 Prompt for AI Agents
In `@api/database.py` around lines 61 - 66, The migration function
_migrate_add_testing_columns is currently a no-op but must add the deprecated
columns for DBs created after their removal; update _migrate_add_testing_columns
to check the target table schema (e.g., via inspector or PRAGMA) for the absence
of testing_in_progress and last_tested_at and, if missing, execute DDL to ALTER
TABLE and add testing_in_progress BOOLEAN NOT NULL DEFAULT FALSE and
last_tested_at DATETIME NULL (or equivalent for SQLite), ensuring the column
definitions match the SQLAlchemy model defaults and nullability and that the
operation is safe (wrap in try/except and commit/rollback as in existing
migration patterns). Ensure the function references the same table name used by
the model and handles both SQLite and other RDBMS dialect nuances when issuing
ALTER statements.
Implements the regression_count column and feature_get_for_regression MCP tool to ensure even distribution of regression testing across all passing features. Changes: - Add regression_count column to Feature model with migration - Add feature_get_for_regression MCP tool that: - Returns passing features ordered by regression_count (ascending) - Increments count after selection for round-robin behavior - Prevents duplicate testing of same features - Remove unused RegressionInput class Based on PR leonvanzyl#47 by connor-tyndall, cleanly reimplemented to avoid merge conflicts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@mcp_server/feature_mcp.py`:
- Around line 304-352: The feature_get_for_regression function currently reads
Feature.regression_count and then updates it in-memory, which allows lost
increments under concurrent requests; change the selection/update to perform
row-level locking or an atomic update: use
session.query(Feature).with_for_update().filter(Feature.passes ==
True).order_by(Feature.regression_count.asc(), Feature.id.asc()).limit(limit) to
lock rows before incrementing regression_count, then increment and commit (or
perform an UPDATE ... RETURNING to atomically increment regression_count and
fetch the rows), ensure session.commit() and session.refresh(...) are used after
the locked/atomic update so returned features reflect the new counts.
♻️ Duplicate comments (1)
api/database.py (1)
61-65: Missing migration for deprecated testing columns can break inserts.Adding
testing_in_progress/last_tested_atto the model means SQLAlchemy will include them in INSERTs; databases created after their removal but before this change won’t have those columns and will error._migrate_add_testing_columns()is still a no‑op, so this gap persists.🛠️ Suggested fix (in
_migrate_add_testing_columns)def _migrate_add_testing_columns(engine) -> None: - """Legacy migration - no longer adds testing columns. - - The testing_in_progress and last_tested_at columns were removed from the - Feature model as part of simplifying the testing agent architecture. - Multiple testing agents can now test the same feature concurrently - without coordination. - - This function is kept for backwards compatibility but does nothing. - Existing databases with these columns will continue to work - the columns - are simply ignored. - """ - pass + """Add testing columns if missing (backward compatibility).""" + with engine.connect() as conn: + result = conn.execute(text("PRAGMA table_info(features)")) + columns = [row[1] for row in result.fetchall()] + if "testing_in_progress" not in columns: + conn.execute(text( + "ALTER TABLE features ADD COLUMN testing_in_progress BOOLEAN DEFAULT 0" + )) + if "last_tested_at" not in columns: + conn.execute(text( + "ALTER TABLE features ADD COLUMN last_tested_at DATETIME DEFAULT NULL" + )) + conn.commit()
Use with_for_update() to acquire locks before reading features in feature_get_for_regression. This prevents concurrent requests from both selecting the same features and losing increment updates. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
As you referenced my issue, I tested this PR:
|
…onvanzyl#88) - Created tests/test_validate_dependency_graph_complex_cycles.py (19 tests) - Verified complex cycles (A->B->C->A) are detected with full path [1, 2, 3] - Verified missing dependencies are also detected alongside cycles - All cycle issues correctly marked as auto_fixable=False (requires user action) - Updated claude-progress.txt with session notes Feature leonvanzyl#88 marked as PASSING. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SUMMARY:
Fixed TypeScript build error in ProjectSetupRequired.tsx where startAgent
was being called with a boolean instead of an options object.
DETAILS:
- The startAgent API function signature was updated (in previous PR merges)
to accept an options object: { yoloMode?, parallelMode?, maxConcurrency?, testingAgentRatio? }
- ProjectSetupRequired.tsx was still calling it with the old signature:
startAgent(projectName, yoloMode) - passing boolean directly
- Changed to: startAgent(projectName, { yoloMode }) - wrapping in options object
This was the only remaining build error after merging 13+ PRs from upstream:
- PR leonvanzyl#112: Security vulnerabilities and race conditions
- PR leonvanzyl#89: Windows subprocess blocking fix
- PR leonvanzyl#109: Rate limit handling with exponential backoff
- PR leonvanzyl#88: MCP server config for ExpandChatSession
- PR leonvanzyl#100: Diagnostic warnings for config loading
- PR leonvanzyl#110: Quality gates (quality_gates.py)
- PR leonvanzyl#113: Structured logging (structured_logging.py)
- PR leonvanzyl#48: Knowledge files support (API, schemas, prompts)
- PR leonvanzyl#29: Feature editing/deletion (MCP tools)
- PR leonvanzyl#45: Chat persistence
- PR leonvanzyl#52: Refactoring feature guidance
- PR leonvanzyl#4: Project reset functionality
- PR leonvanzyl#95: UI polish, health checks, cross-platform fixes
Build now passes: npm run build succeeds with all 2245 modules transformed.
Problem
When adding features to existing projects via the "Add Features" / expand project flow, Claude reports it "could not access the MCP tool required to add features" and asks users to add them manually.
Root cause: The
ExpandChatSessionclass does NOT configure an MCP server, whileAssistantChatSessiondoes. This means Claude cannot usefeature_create_bulkorfeature_createMCP tools during project expansion.Solution
Added MCP server configuration to
ExpandChatSession, matching the pattern used inAssistantChatSession:EXPAND_FEATURE_TOOLSconstant forfeature_create,feature_create_bulk, andfeature_get_statsmcp_server.feature_mcpallowed_toolsand security settings to include feature toolsTesting
Notes
<features_to_create>tags) continues to work as defense-in-depth if MCP failsSummary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.