How vibeflowing-inc/convex-mcp works
1. What this repo is
- @vibeflowai/convex-mcp is a TypeScript library that turns a Convex backend into a stateless MCP server.
- Its core job is to map Convex functions and local prompt/resource definitions into MCP-compatible protocol endpoints.
2. Public API surface
- The package entrypoint is src/index.ts, which re-exports the library’s main constructors and helpers.
- The README’s main API is: defineMcpServer, tool, prompt, resource, resourceTemplate, bearerAuth, plus result/content helpers like promptResult, assistantText, and userText.
3. Server composition layer
- src/lib/server.ts is the central orchestration layer.
- It likely builds an MCP server definition from the user’s configured tools, prompts, and resources, and exposes route mounting via addHttpRoutes(...).
- This is the main boundary between the consumer’s Convex app and the MCP runtime.
4. Capability adapters
- src/lib/tools.ts adapts Convex query/action functions into MCP tools.
- src/lib/prompts.ts handles MCP prompt definitions with Zod-based argument schemas and prompt-result generation.
- src/lib/resources.ts handles static and templated MCP resources, mapping Convex-backed data into MCP resource reads.
- These modules are the “translation layer” from Convex primitives to MCP capabilities.
5. Protocol and RPC boundary
- src/lib/protocol.ts and src/lib/rpc.ts represent the transport and message-handling layer.
- The repo is built around MCP’s JSON-RPC style interaction over HTTP, so requests are decoded, routed to the right capability, and encoded back into protocol responses.
- This boundary separates external MCP clients from internal Convex execution.
6. Convex integration
- The package is designed specifically for Convex’s backend runtime and HTTP router.
- The README shows integration through httpRouter() from convex/server, with mcp.addHttpRoutes(http) mounting the MCP endpoint(s) into the Convex HTTP entrypoint.
- That means Convex remains the execution engine for backend logic, while this package supplies the MCP façade.
7. Authentication boundary
- src/lib/auth.ts implements optional HTTP auth, with bearerAuth({ env: "MCP_AUTH_TOKEN" }) as the documented mechanism.
- Auth is enforced at the HTTP route layer before MCP requests reach the dispatcher, so unauthorized clients are blocked early.
8. Validation and typing
- src/lib/schema.ts and src/lib/types.ts define the shared shape of tools, prompts, resources, and MCP request/response data.
- Zod appears to be used for argument validation and schema generation, especially for prompt and tool parameters.
- This keeps the public API strongly typed and ensures MCP-exposed interfaces remain well-formed.
9. Result shaping
- src/lib/result.ts converts handler outputs into MCP content/result structures.
- The README examples promptResult, assistantText, and userText indicate a small result-assembly layer that normalizes different output types into MCP message content.
10. End-to-end request flow
- An MCP client sends an HTTP request to the Convex route.
- addHttpRoutes hands it to the MCP transport layer.
- The protocol/RPC layer resolves the request to a tool, prompt, or resource handler.
- The handler may invoke a Convex function or local prompt logic.
- The result layer formats the output into MCP response content and returns it to the client.
11. Test coverage as architecture signal
- The tests (addHttpRoutes.test.ts, defineMcpServer.test.ts, mcpHttp.test.ts, resources.test.ts, result.test.ts, tool.test.ts) mirror the main boundaries.
- This suggests the architecture is intentionally split into:
- server assembly,
- HTTP mounting,
- protocol handling,
- capability adapters,
- result formatting.
12. Overall architectural shape
- This is a library-style adapter architecture, not an application with internal business state.
- The key external dependency is Convex; the key protocol boundary is MCP over HTTP/JSON-RPC.
- The repository’s structure is centered on translating between those two worlds while keeping execution stateless and composable.
Main entry points: index.ts Lib index · server.ts Server · tools.ts Tools · prompts.ts Prompts
Components 19
Source
Library implementation
- Entrypoint · Package exports for consumers
src/index.ts - Lib index · Internal module re-exports
src/lib/index.ts - Server · Builds MCP server and mounts HTTP routes
src/lib/server.ts - Auth · Optional bearer-token authorization
src/lib/auth.ts - Protocol · Encodes and decodes MCP messages
src/lib/protocol.ts - RPC · Dispatches JSON-RPC calls to handlers
src/lib/rpc.ts - Tools · Maps Convex functions to MCP tools
src/lib/tools.ts - Prompts · Defines prompt schemas and prompt results
src/lib/prompts.ts - Resources · Serves static and templated resources
src/lib/resources.ts - Results · Formats handler output into MCP content
src/lib/result.ts - Schema · Shared Zod schemas and protocol shapes
src/lib/schema.ts - Types · Shared TypeScript interfaces and unions
src/lib/types.ts - Define server · Main server-construction entrypoint
- Tool API · Tool definition helper
- Prompt API · Prompt definition helper
- Resource API · Resource definition helper
Other components
- Convex · User backend functions executed by adapters
- HTTP route · Mounted MCP endpoint inside Convex router
- MCP client · Consumes the server over HTTP
Connections 28
- Entrypoint → Lib index: re-exports · Public package surface forwards core helpers
- Lib index → Server: exports · Internal barrel exposes server composition
- Lib index → Tools: exports · Exports capability adapters
- Lib index → Prompts: exports · Exports prompt helpers
- Lib index → Resources: exports · Exports resource helpers
- Lib index → Results: exports · Exports result-shaping helpers
- Lib index → Auth: exports · Exports auth helpers
- Server → Auth: guards · Checks auth before request handling
- Server → Protocol: uses · Builds protocol-facing responses
- Server → RPC: dispatches · Hands validated requests to RPC routing
- RPC → Tools: invokes · Routes tool calls to adapters
- RPC → Prompts: invokes · Routes prompt calls to adapters
- RPC → Resources: invokes · Routes resource reads to adapters
- Tools → Convex: executes · Calls Convex query/action functions
- Prompts → Schema: validates · Uses schemas for prompt arguments
- Resources → Schema: validates · Uses schemas for resource definitions
- Tools → Results: formats · Normalizes tool outputs for MCP
- Prompts → Results: formats · Builds prompt results and content
- Resources → Results: formats · Shapes resource payloads for transport
- Results → Protocol: encodes · Turns outputs into protocol content
- Protocol → HTTP route: served on · Protocol endpoint is exposed over HTTP
- HTTP route → MCP client: receives · External clients call the mounted route
- HTTP route → Convex: bridges · Convex runtime hosts the MCP facade
- Define server → Server: builds · Server definition helper composes the runtime
- Tool API → Tools: creates · Tool helper produces tool adapters
- Prompt API → Prompts: creates · Prompt helper produces prompt adapters
- Resource API → Resources: creates · Resource helper produces resource adapters
- Schema → Types: aligns · Schemas and type shapes are kept in sync