GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — discogs-mcp/AGENTS.md at main · rianvdm/discogs-mcp

Expand file tree

/

AGENTS.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
97 lines (77 loc) · 8 KB
/

AGENTS.md

Copy path

File metadata and controls

97 lines (77 loc) · 8 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

AGENTS.md

This file provides guidance to coding agents (Claude Code, Codex, and others) when working with code in this repository.

Project

Discogs MCP — a Cloudflare Workers MCP server that lets AI assistants interact with users' Discogs music collections. Implements OAuth 1.0a authentication against the Discogs API, intelligent search with mood mapping, and context-aware recommendations. Deployed at discogs-mcp.com (locked to maintainer; users must self-host).

Commands

npm run dev              # Local dev server on port 8787
npm run build            # Dry-run build (wrangler deploy --dry-run)
npm test                 # Vitest with Cloudflare Workers pool
npm test -- path/to/file # Single test file
npm test -- --watch      # Watch mode
npm run lint             # ESLint (must pass before every commit)
npm run format           # Prettier --write
npm run format:check     # Prettier --check
npm run deploy           # Deploy to dev environment
npm run deploy:prod      # Deploy to production
npm run cf-typegen       # Regenerate Cloudflare Workers types

Architecture

Entry point: src/index-oauth.ts — routes requests through OAuthProvider which handles OAuth endpoints, then delegates MCP traffic to the server created by src/mcp/server.ts.

src/
├── auth/              # OAuth 1.0a flow against Discogs
├── clients/           # DiscogsClient (API calls + retry) → CachedDiscogsClient (KV cache wrapper)
├── mcp/
│   ├── server.ts      # MCP server factory — registers all tools, resources, prompts
│   ├── tools/
│   │   ├── public.ts          # Unauthenticated: ping, server_info, auth_status
│   │   └── authenticated.ts   # Requires auth: search_collection, search_discogs, get_release, etc.
│   ├── resources/     # MCP resource definitions
│   └── prompts/       # MCP prompt templates
├── rate-limiter/      # Durable Object for coordinated rate limiting across Workers
├── types/             # Shared TypeScript types
├── utils/
│   ├── moodMapping.ts         # Maps emotional descriptors ("mellow", "Sunday vibes") → genres/styles
│   ├── searchRanking.ts       # Deduplication, scoring, ranking of search results
│   ├── searchQueryParser.ts   # Classifies queries (mood, specific, genre, etc.)
│   ├── cache.ts               # KV-based caching utilities
│   └── kvLogger.ts            # Structured logging to KV
└── marketing-page.ts  # HTML landing page

Key patterns

  • MCP transport: createMcpHandler from agents/mcp/server with a per-request server factory (@modelcontextprotocol/server v2, protocol 2026-07-28, legacy initialize clients served by the handler's compatibility lane). allowedOriginHostnames replaces the handler defaults and is built per request from the request hostname plus localhost, so self-hosted copies accept their own browser clients. The repo's own ?session_id= parameter selects the manual-login session path; there is no Mcp-Session-Id header. Hand-rolled requests to the modern lane fail (missing _meta); use an SDK client
  • Request context injection: MCP server injects auth context before each tool handler call — tools receive the authenticated user's Discogs client
  • Two-layer caching: CachedDiscogsClient wraps DiscogsClient; cache keys in KV with TTLs to stay within Discogs' 60 req/min rate limit
  • Rate limiting via Durable Objects: src/rate-limiter/durable-object.ts coordinates rate limits across Worker instances. Its queue holds 20 requests (MAX_QUEUE_DEPTH), so a tool that makes many Discogs calls in one invocation issues them sequentially
  • Mood intelligence: moodMapping.ts converts emotional/situational descriptors into genre and style filters — core differentiator of the search experience
  • Adding or renaming a tool: the catalogue is listed by hand in several places that must move together: the auth_status lists in src/mcp/tools/public.ts (signed-in and signed-out), the tool count and annotation map in test/mcp/server.test.ts, the tool count in test/integration/mcp-client.test.ts, the catalogue snapshot (npm test -- test/mcp/server.test.ts -u, then read the diff), and the tables in README.md. test/mcp/tools/authStatusToolList.spec.ts fails if auth_status drifts
  • OAuth dance: Discogs uses OAuth 1.0a (not 2.0); oauth-1.0a library signs requests. The Workers OAuth Provider wraps this with OAuth 2.1 for MCP clients

Infrastructure

  • Runtime: Cloudflare Workers (ES2021 target, Node.js compat enabled)
  • Storage: KV namespaces for sessions (MCP_SESSIONS) and OAuth state (OAUTH_KV); sync outcomes structured-log to console (Workers Observability)
  • Durable Objects: DiscogsRateLimiter class
  • Secrets (via wrangler secret put): DISCOGS_CONSUMER_KEY, DISCOGS_CONSUMER_SECRET
  • CI: GitHub Actions — lint → test → build → auto-deploy to prod on main push

Code conventions

  • ABOUTME comments: Every code file starts with a 2-line comment where each line begins with ABOUTME: — explains what the file does
  • Formatting: Prettier — 140 char width, single quotes, no semicolons, tabs
  • TypeScript: Strict mode, explicit types, avoid any (ESLint warns)
  • Naming: No temporal names like "improved", "new", "enhanced" — names must be evergreen
  • Evergreen comments: Describe code as-is, never reference refactors or recent changes
  • Error handling: Fail fast for programming errors, recover gracefully for user/external errors
  • Changes: Make the smallest reasonable change. Never rewrite from scratch without explicit permission
  • Unrelated fixes: Don't fix unrelated issues in a task — document them in development/todo.md with priority (P0/P1/P2)
  • Schema validation: Zod for runtime validation of API responses and tool inputs

Testing

  • Framework: Vitest 4 with @cloudflare/vitest-pool-workers 0.22 — tests run in a Workers-compatible environment. Requires Node 22 (see .nvmrc)
  • A mock that the source constructs with new must be implemented as a function or a class, not an arrow function: vi.fn().mockImplementation(function () { return { ... } })
  • wrangler is pinned to the exact version @cloudflare/vitest-pool-workers depends on, so tests, npm run dev and deploys share one wrangler and one workerd. When bumping vitest-pool-workers, move the pin to npm view @cloudflare/vitest-pool-workers@<version> dependencies.wrangler in the same change
  • Change dependencies with npx npm@11 install. npm 10 crashes on this dependency graph (Cannot read properties of null (reading 'edgesOut')); npm ci on npm 10 works from the resulting lockfile. zod is held at 4.1.13 at the top level while vitest-pool-workers nests its own copy
  • Mock Discogs API responses for unit tests; real protocol compliance checks for integration tests
  • Test output must be clean — no warnings, no unexpected errors in logs
  • Tests live in test/ mirroring src/ structure

Releases

GitHub releases follow Rian's side-project release notes contract: ~/git/product-ai/05-personal/side-projects/release-notes-contract.md. Read it before drafting. The name is discogs-mcp vX.Y.Z — <tagline> (em dash), and the body is a 1-3 sentence opening paragraph, then only ## Breaking changes / ## What's new / ## Fixes / ## Under the hood, written from the user's side.

A release stays on GitHub unless Rian explicitly asks for an elezea.com cross-post. Only then, put <!-- post-to-elezea --> on its own line at the end of the body: .github/workflows/elezea-release-post.yml posts a release that carries the marker to elezea.com, and the endpoint rejects anything off-contract. Adding the marker after publishing does nothing, because the workflow runs only when a release is published. A release runs the workflow from its tagged commit, so tag a commit that includes this version of the workflow.

Check every claim against the commits since the last tag, show Rian the final text, and wait for a go before gh release create.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.