These instructions apply to the entire repository.
Discord Management MCP is a Node.js 24, TypeScript ESM, stdio-only MCP server. It manages real Discord guilds, so correctness and explicit operator intent take priority over convenience.
src/index.ts: process entrypoint and tool registration.src/config.ts: environment and.env.localparsing.src/discordClient.ts: Discord client lifecycle.src/safety.ts: deterministic confirmation and backup guards.src/backup/: snapshot schema, validation, storage, diff, and restore primitives.src/tools/: MCP tool definitions grouped by domain.src/__tests__/: unit and regression tests. Tests must not contact Discord.docs/: design, configuration, safety, tool, and release documentation.examples/: explicitly confirmed operator examples; these may mutate a live guild..github/: contribution forms, ownership, CI, and release automation.
Use the repository-local toolchain; do not install or change global Node.js tooling.
npm ci
npm run lint
npm run typecheck
npm test
npm run build
npm run preflight
npm run pack:check
npm audit --omit=devRun focused tests while iterating, then run npm run preflight before handing off code changes. Run npm run pack:check whenever package metadata, build output, documentation included in the package, or release automation changes.
- Never print, return, commit, or place in fixtures a real bot token, webhook token, invite secret, authorization header,
.env.local, or backup payload. - Never run an example or perform a live Discord mutation unless the user explicitly asks for that live action and identifies the intended guild.
- Every mutating MCP tool must require
confirm: trueand a non-empty audit reason. - Delete and other high-impact tools must retain their backup guard or explicit
allowWithoutBackup: trueacknowledgement. - Guild-targeted destructive actions must verify that the backup belongs to the target guild.
- Core backup sections such as roles and channels must fail closed when they cannot be captured. Optional sections may emit structured warnings.
- Keep message-content and guild-member privileged intents opt-in.
- Keep webhook tokens out of tool output and recursively remove secret fields from snapshots.
- Cross-guild restore must remain explicit, conservative, and safe when IDs or permission targets cannot be mapped.
- Restore apply must create a pre-restore backup before the first Discord mutation and must report skipped or lossy operations truthfully.
- MCP annotations must describe actual behavior: read-only tools are read-only, additive tools are non-destructive, and updates/deletes are marked destructive where appropriate.
- Use strict TypeScript and ESM imports with
.jsextensions for local modules. - Prefer focused modules and typed helpers over broad casts. When an SDK boundary requires a cast, keep it narrow and validate the input first.
- Define bounded Zod input schemas for every tool. Use Discord API limits where known.
- Return both readable MCP text and structured content. Error responses must be actionable and must not expose secrets.
- Treat backup JSON as untrusted local input: validate it before planning or applying changes.
- Preserve stable identity across renames and reorders. Do not derive matching solely from mutable names or positions.
- Add regression tests for safety guards, snapshot validation, identity matching, restore mapping, and error paths.
- Keep comments focused on non-obvious safety or protocol decisions.
- Do not edit or commit
dist/; it is generated bynpm run buildand included at npm pack time. - Do not commit
.env*except.env.example,backups/,coverage/, logs,node_modules/, or generated package tarballs. - Do not inspect or echo
.env.localduring routine review. Verify only that Git ignores it. - Preserve unrelated working-tree changes and never rewrite user work to clean the repository.
- Use focused commits and pull requests. Prefer Conventional Commit subjects such as
fix:,feat:,docs:,test:, andchore:. - Do not commit, push, create tags/releases, change repository settings, or publish to npm unless the user explicitly authorizes that external action.
- Keep the required
build-and-teststatus context stable unless branch protection is updated in the same authorized operation. - Pin third-party GitHub Actions to full commit SHAs and retain a version comment.
- For a release, update
package.jsonandpackage-lock.json,CHANGELOG.md, andCITATION.cff; then runnpm run release:check -- vX.Y.Z,npm run preflight, andnpm run pack:check.release:checkfails unless all three files agree on the version. - Never publish from a workstation. Publication happens only when a GitHub Release whose tag is
vX.Y.Zis created; that event triggers.github/workflows/publish.yml, which republishes with provenance. - The package is live on npm as
discord-management-mcp(first publication 2026-08-01). Trusted Publishing is not configured yet, sopublish.ymlstill depends on the bootstrapNPM_TOKENsecret. Do not delete that secret or itsNODE_AUTH_TOKENenv block until Trusted Publishing is configured on npmjs.com; seedocs/github-publishing.md. - The
filesfield lists consumer-facing documentation explicitly.docs/implementation-plan.mdanddocs/github-publishing.mdare repository-only and must stay out of the npm tarball. Re-runnpm run pack:checkafter touchingfilesor adding a document. allowScriptsinpackage.jsonis a supported npm install-script allowlist, not dead metadata. Keep it in sync with the resolvedesbuildversion instead of deleting it.@types/nodeis intentionally pinned to the 24.x line to match theengines.noderuntime, and TypeScript is held at 6.x because the 7.x upgrade fails CI. Do not bump either just becausenpm outdatedreports a newer major.