Skip to content

feat: add collection write tools (folders, ratings, custom fields)#9

Merged
jhuggart merged 5 commits intorianvdm:mainfrom
jhuggart:feat/collection-write-tools
Mar 24, 2026
Merged

feat: add collection write tools (folders, ratings, custom fields)#9
jhuggart merged 5 commits intorianvdm:mainfrom
jhuggart:feat/collection-write-tools

Conversation

@jhuggart
Copy link
Copy Markdown
Collaborator

@jhuggart jhuggart commented Mar 23, 2026

Summary

Adds 11 new MCP tools for modifying Discogs collections, complementing the existing read-only tools. This enables LLM-powered collection management workflows like bulk classification, folder organization, and rating.

New Tools

Folder management:

  • list_folders — List all collection folders with IDs and counts
  • create_folder — Create a new folder
  • edit_folder — Rename an existing folder
  • delete_folder — Delete an empty folder

Collection items:

  • add_to_collection — Add a release to a folder
  • remove_from_collection — Remove a release instance
  • move_release — Move a release between folders

Ratings:

  • rate_release — Rate a release 0-5 stars

Custom fields:

  • list_custom_fields — List defined custom fields
  • edit_custom_field — Set a custom field value on a release instance

Implementation

  • Client layer (src/clients/discogs.ts): 9 new methods wrapping Discogs API v2 endpoints with OAuth 1.0a, throttling, and retry — following existing patterns exactly
  • Cached layer (src/clients/cachedDiscogs.ts): Pass-through wrappers that call invalidateUserCache() after mutations to ensure cache consistency
  • Tools layer (src/mcp/tools/authenticated.ts): 11 new server.tool() registrations with auth guards, Zod validation, and consistent response formatting
  • New types: DiscogsFolder and DiscogsCustomField interfaces

Discogs API endpoints used

Method Endpoint Tool
GET /users/{u}/collection/folders list_folders
POST /users/{u}/collection/folders create_folder
POST /users/{u}/collection/folders/{id} edit_folder
DELETE /users/{u}/collection/folders/{id} delete_folder
POST /users/{u}/collection/folders/{f}/releases/{r} add_to_collection
DELETE .../instances/{i} remove_from_collection
POST .../instances/{i} move_release, rate_release
GET /users/{u}/collection/fields list_custom_fields
POST .../fields/{f} edit_custom_field

Cache invalidation

All write operations invalidate the user's collection cache (collections, searches, stats) to ensure subsequent reads reflect changes. edit_custom_field skips invalidation since custom fields don't affect cached collection structure.

Test plan

  • Verify wrangler deploy --dry-run succeeds (confirmed locally)
  • TypeScript compilation passes with no errors (confirmed)
  • Manual test: list_folderscreate_folderlist_folders (folder appears)
  • Manual test: add_to_collectionmove_release → verify folder change
  • Manual test: rate_releasesearch_collection (rating reflected)
  • Manual test: list_custom_fieldsedit_custom_field → verify value set
  • Manual test: delete_folder on non-empty folder returns error
  • Verify cache invalidation: create folder → immediate list shows new folder

Add 11 new MCP tools for modifying Discogs collections:

Folder management:
- list_folders, create_folder, edit_folder, delete_folder

Collection items:
- add_to_collection, remove_from_collection, move_release

Ratings:
- rate_release

Custom fields:
- list_custom_fields, edit_custom_field

All write operations invalidate the user's collection cache to
ensure subsequent reads reflect the changes. Custom field edits
skip cache invalidation since they don't affect collection structure.

Client layer (discogs.ts): 9 new API methods wrapping Discogs v2
endpoints with OAuth 1.0a auth, throttling, and retry.

Cached layer (cachedDiscogs.ts): Pass-through wrappers that call
invalidateUserCache() after mutations.

Tools layer (authenticated.ts): 11 new server.tool() registrations
following existing patterns (auth guard, Zod validation, consistent
response format).
Add unit tests for new DiscogsClient write methods (folders, ratings,
custom fields) and CachedDiscogsClient cache invalidation behavior.
Fix hardcoded tool count in integration test (8 → 18).
Adds createCustomField() to DiscogsClient and CachedDiscogsClient (with
cache invalidation), registers the create_custom_field MCP tool, and
adds full test coverage — success, body shape, cache invalidation, and
429 rate limit tests. Bumps wrangler to ^4.76.0.
@jhuggart jhuggart marked this pull request as ready for review March 24, 2026 12:38
@jhuggart jhuggart merged commit ec824f1 into rianvdm:main Mar 24, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown

🚀 Deploy succeeded! Your changes have been deployed to production.

@jhuggart jhuggart deleted the feat/collection-write-tools branch March 24, 2026 12:47
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