$ show PV-Bhat/vibe-check-mcp-server
Vibe Check MCP is a production-ready MCP (Model Context Protocol) server that provides metacognitive oversight for AI agents. It implements the research-backed Chain-Pattern Interrupt (CPI) methodology to prevent reasoning lock-in by injecting reflective pauses during agent workflows. The server exposes six tools: `vibe_check` for generating clarifying questions via a secondary LLM, `vibe_learn` for logging patterns of mistakes and successes, and three constitution management tools (`update_constitution`, `reset_constitution`, `check_constitution`) for per-session behavioral rules. It supports multiple LLM providers (Gemini, OpenAI, Anthropic, OpenRouter) with automatic fallback to static questions when the LLM is unavailable, and maintains session history for context-aware feedback. The architecture is a monolithic MCP server with dual transport modes: stdio for local agent clients (Claude Desktop, Cursor, Windsurf, VS Code) and streamable HTTP for remote access. A CLI tool (`vibe-check-mcp`) automates installation into all major MCP client configurations with atomic writes and backup creation, handles secret management via interactive prompts or env files, and provides diagnostic commands. The server includes robust HTTP security hardening: DNS-rebinding protection via Host header validation, loopback-only CORS by default with a configurable allowlist, explicit JSON body size limits, and proper JSON-RPC error responses instead of HTML pages. The codebase is well-organized with separation of concerns, extensive unit and integration tests (over 30 test files), CI/CD with security scanning, and clean abstraction layers such as a central model registry and request-scoped transport wrappers.
The LLM identified 4 files worth highlighting for reuse:
A self-contained security module for Express-based HTTP servers. It implements DNS-rebinding protection via Host header validation against a configurable allowlist, loopback-only CORS origin defaults with optional comma-separated allowlist, and explicit JSON body size limits that fall back to defaults rather than silently disabling enforcement (a common pitfall with body-parser). The module includes utilities for normalizing hostnames from headers, handling IPv6 literals, and rejecting malformed Host values that could bypass checks. This is a reusable security layer that any local-first MCP server or other HTTP service should adopt, and it is well-documented with inline comments explaining the threat model.
A centralized model registry that defines supported LLM providers, their default models, fallback models, and suggested model IDs with human-readable labels and notes. It is a pure data module with no runtime dependencies, making it trivially extractable into any project that needs to maintain a canonical catalog of provider-model mappings. The LLM dispatcher and tool schema both read from this registry, ensuring they never drift apart when a provider ships a new tier. It also provides a helper `listModelIds()` for generating discovery hints.
A reusable abstraction layer for MCP client configuration management. It defines a `ClientAdapter` interface with methods for locating, reading, merging, and atomically writing configuration files, along with a generic `mergeIntoMap` function that handles sentinel-tagged managed entries, unmanaged entry preservation, and deep-strict-equality checks to avoid unnecessary writes. Includes utilities for atomic JSON file writing with 0600 permissions, home-directory tilde expansion, and path existence checks. This pattern is directly reusable for any CLI tool that needs to install MCP server entries into multiple clients (Claude, Cursor, Windsurf, VS Code) with idempotent merge behavior and backup creation.
A compatibility layer that backfills missing JSON-RPC 2.0 `id` fields on `tools/call` requests using a stable hash of the method and params combined with a random nonce. It also provides a `wrapTransportForCompatibility` function that transparently patches a transport's onmessage handler to apply the shim automatically. The shim ensures the server can respond to clients (like Windsurf or raw SDK users) that neglect to send request identifiers. The module is self-contained (only importing `crypto`) and can be extracted into any JSON-RPC server that needs to tolerate non-compliant clients.