Skip to main content
Glama

Convex MCP server

Official
by get-convex
mockConvexReactClient.ts2.83 kB
/* eslint-disable class-methods-use-this */ import { ConvexReactClient, Watch } from "convex/react"; import { getFunctionName, FunctionReference } from "convex/server"; // TODO(ari): Use convex-test export function mockConvexReactClient(): MockConvexReactClient & ConvexReactClient { return new MockConvexReactClient() as any; } class MockConvexReactClient { // These are written to and read from type safe APIs (`registerQueryFake`, `watchQuery`), // so it's ok to be looser with the types here since they're never directly accessed. private queries: Record<string, (...args: any[]) => any>; private mutations: Record<string, (...args: any[]) => any>; constructor() { this.queries = {}; this.mutations = {}; } registerQueryFake<FuncRef extends FunctionReference<"query", "public">>( funcRef: FuncRef, impl: (args: FuncRef["_args"]) => FuncRef["_returnType"], ): this { this.queries[getFunctionName(funcRef)] = impl; return this; } registerMutationFake<FuncRef extends FunctionReference<"mutation", "public">>( funcRef: FuncRef, impl: (args: FuncRef["_args"]) => FuncRef["_returnType"], ): this { this.mutations[getFunctionName(funcRef)] = impl; return this; } setAuth() { throw new Error("Auth is not implemented"); } clearAuth() { throw new Error("Auth is not implemented"); } watchQuery<Query extends FunctionReference<"query">>( query: FunctionReference<"query">, ...args: Query["_args"] ): Watch<Query["_returnType"]> { return { localQueryResult: () => { const name = getFunctionName(query); const queryImpl = this.queries && this.queries[name]; if (queryImpl) { return queryImpl(...args); } throw new Error( `Unexpected query: ${name}. Try providing a function for this query in the mock client constructor.`, ); }, onUpdate: () => () => ({ unsubscribe: () => null, }), journal: () => void 0, localQueryLogs: () => { throw new Error("not implemented"); }, }; } mutation<Mutation extends FunctionReference<"mutation">>( mutation: Mutation, ...args: Mutation["_args"] ): Promise<Mutation["_returnType"]> { const name = getFunctionName(mutation); const mutationImpl = this.mutations && this.mutations[name]; if (mutationImpl) { return mutationImpl(args[0]); } throw new Error( `Unexpected mutation: ${name}. Try providing a function for this mutation in the mock client constructor.`, ); } action(): Promise<any> { throw new Error("Actions are not implemented"); } connectionState() { return { hasInflightRequests: false, isWebSocketConnected: true, }; } close() { return Promise.resolve(); } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/get-convex/convex-backend'

If you have feedback or need assistance with the MCP directory API, please join our Discord server