Skip to content

fix(api): return 409 on duplicate name for MCP submit and agent draft#1283

Open
shreyansh232 wants to merge 1 commit into
BlazeUp-AI:mainfrom
shreyansh232:fix/duplicate-name-409
Open

fix(api): return 409 on duplicate name for MCP submit and agent draft#1283
shreyansh232 wants to merge 1 commit into
BlazeUp-AI:mainfrom
shreyansh232:fix/duplicate-name-409

Conversation

@shreyansh232
Copy link
Copy Markdown
Contributor

@shreyansh232 shreyansh232 commented May 30, 2026

Purpose / Description

Submitting an MCP with a name that already exists for the same user returns HTTP 500 (Internal Server Error) instead of a proper 409 Conflict. The same issue affects the agent draft endpoint saving a draft with a duplicate name crashes with an unhandled 500.

Fixes

Approach

Root cause was a CircularDependencyError in the delete+recreate pattern for existing listings. The latest_version_id FK creates a cycle with the versions cascade.

Fix: replaced the delete+recreate with a simple pre-check SELECT → 409 for all duplicate names, matching the existing pattern used by skill, hook, prompt, sandbox, and agent create endpoints. Applied the same pre-check to agent draft, which had no duplicate-name handling at all.

How Has This Been Tested?

  • Unit tests in test_mcp_submit_conflict.py and test_agent_draft_conflict.py verify both endpoints return 409 on duplicate name
  • Manual curl testing confirmed 200 on first submit, 409 on second

Learning (optional, can help others)

The issue's suggested fix (try/except IntegrityError) would not have worked as there is no PostgreSQL unique constraint on mcp_listings.name, so the IntegrityError never fires. The actual 500 was from CircularDependencyError during SQLAlchemy's delete cascade, not a database constraint violation.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)

@github-actions github-actions Bot added server Pull request touches server code tests Pull request adds or modifies tests new contributor Pull request from a first-time contributor labels May 30, 2026
@shreyansh232
Copy link
Copy Markdown
Contributor Author

Screenshot of working solution:
Screenshot 2026-05-30 at 9 39 36 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new contributor Pull request from a first-time contributor server Pull request touches server code tests Pull request adds or modifies tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/v1/mcps/submit returns 500 on duplicate name instead of 409

1 participant