# vibeflowing-inc/convex-mcp architecture

> Architecture diagram of the GitHub repository vibeflowing-inc/convex-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vibeflowing-inc/convex-mcp
- Repository: https://github.com/vibeflowing-inc/convex-mcp

## Overview

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: [`src/lib/index.ts`](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/index.ts) (Lib index), [`src/lib/server.ts`](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/server.ts) (Server), [`src/lib/tools.ts`](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/tools.ts) (Tools), [`src/lib/prompts.ts`](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/prompts.ts) (Prompts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_src["Source"]
  node_index["Entrypoint<br/>public API<br/>[index.ts]"]
  node_libindex["Lib index<br/>barrel<br/>[index.ts]"]
  node_server["Server<br/>orchestrator<br/>[server.ts]"]
  node_httpauth["Auth<br/>http guard<br/>[auth.ts]"]
  node_protocol["Protocol<br/>[protocol.ts]"]
  node_rpc["RPC<br/>request router<br/>[rpc.ts]"]
  node_tools["Tools<br/>adapter<br/>[tools.ts]"]
  node_prompts["Prompts<br/>adapter<br/>[prompts.ts]"]
  node_resources["Resources<br/>adapter<br/>[resources.ts]"]
  node_result["Results<br/>shaping<br/>[result.ts]"]
  node_schema["Schema<br/>validation<br/>[schema.ts]"]
  node_types["Types<br/>typing<br/>[types.ts]"]
  node_define["Define server<br/>API helper"]
  node_toolapi["Tool API<br/>API helper"]
  node_promptapi["Prompt API<br/>API helper"]
  node_resourceapi["Resource API<br/>API helper"]
end

subgraph group_tests["Tests"]
end

node_convex[("Convex<br/>backend runtime")]
node_http(("HTTP route<br/>transport"))
node_mcpclient(("MCP client<br/>external client"))

node_index -->|"re-exports"| node_libindex
node_libindex -->|"exports"| node_server
node_libindex -->|"exports"| node_tools
node_libindex -->|"exports"| node_prompts
node_libindex -->|"exports"| node_resources
node_libindex -->|"exports"| node_result
node_libindex -->|"exports"| node_httpauth
node_server -->|"guards"| node_httpauth
node_server -->|"uses"| node_protocol
node_server -->|"dispatches"| node_rpc
node_rpc -->|"invokes"| node_tools
node_rpc -->|"invokes"| node_prompts
node_rpc -->|"invokes"| node_resources
node_tools -->|"executes"| node_convex
node_prompts -->|"validates"| node_schema
node_resources -->|"validates"| node_schema
node_tools -->|"formats"| node_result
node_prompts -->|"formats"| node_result
node_resources -->|"formats"| node_result
node_result -->|"encodes"| node_protocol
node_protocol -->|"served on"| node_http
node_http -->|"receives"| node_mcpclient
node_http -->|"bridges"| node_convex
node_define -->|"builds"| node_server
node_toolapi -->|"creates"| node_tools
node_promptapi -->|"creates"| node_prompts
node_resourceapi -->|"creates"| node_resources
node_schema -.->|"aligns"| node_types

click node_index "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/index.ts"
click node_libindex "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/index.ts"
click node_server "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/server.ts"
click node_httpauth "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/auth.ts"
click node_protocol "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/protocol.ts"
click node_rpc "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/rpc.ts"
click node_tools "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/tools.ts"
click node_prompts "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/prompts.ts"
click node_resources "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/resources.ts"
click node_result "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/result.ts"
click node_schema "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/schema.ts"
click node_types "https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/types.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_index,node_libindex,node_server,node_httpauth,node_protocol,node_rpc,node_tools,node_prompts,node_resources,node_result,node_schema,node_types,node_define,node_toolapi,node_promptapi,node_resourceapi toneBlue
class node_convex,node_http,node_mcpclient toneNeutral
```

## Components

### Source

Library implementation

- [Entrypoint](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/index.ts): public API · Package exports for consumers · `src/index.ts`
- [Lib index](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/index.ts): barrel · Internal module re-exports · `src/lib/index.ts`
- [Server](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/server.ts): orchestrator · Builds MCP server and mounts HTTP routes · `src/lib/server.ts`
- [Auth](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/auth.ts): http guard · Optional bearer-token authorization · `src/lib/auth.ts`
- [Protocol](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/protocol.ts): mcp protocol · Encodes and decodes MCP messages · `src/lib/protocol.ts`
- [RPC](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/rpc.ts): request router · Dispatches JSON-RPC calls to handlers · `src/lib/rpc.ts`
- [Tools](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/tools.ts): adapter · Maps Convex functions to MCP tools · `src/lib/tools.ts`
- [Prompts](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/prompts.ts): adapter · Defines prompt schemas and prompt results · `src/lib/prompts.ts`
- [Resources](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/resources.ts): adapter · Serves static and templated resources · `src/lib/resources.ts`
- [Results](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/result.ts): shaping · Formats handler output into MCP content · `src/lib/result.ts`
- [Schema](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/schema.ts): validation · Shared Zod schemas and protocol shapes · `src/lib/schema.ts`
- [Types](https://github.com/vibeflowing-inc/convex-mcp/blob/main/src/lib/types.ts): typing · Shared TypeScript interfaces and unions · `src/lib/types.ts`
- **Define server**: API helper · Main server-construction entrypoint
- **Tool API**: API helper · Tool definition helper
- **Prompt API**: API helper · Prompt definition helper
- **Resource API**: API helper · Resource definition helper

### Other components

- **Convex**: backend runtime · User backend functions executed by adapters
- **HTTP route**: transport · Mounted MCP endpoint inside Convex router
- **MCP client**: external client · Consumes the server over HTTP

## Connections

- 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
