Skip to main content
Glama

FalkorDB MCP Server

Official
by FalkorDB
falkordb.service.test.ts3.83 kB
import { falkorDBService } from './falkordb.service'; // Mock the FalkorDB library jest.mock('falkordb', () => { const mockSelectGraph = jest.fn(); const mockQuery = jest.fn(); const mockList = jest.fn(); const mockClose = jest.fn(); const mockPing = jest.fn(); return { FalkorDB: { connect: jest.fn().mockResolvedValue({ connection: Promise.resolve({ ping: mockPing }), selectGraph: mockSelectGraph.mockReturnValue({ query: mockQuery }), list: mockList, close: mockClose }) }, mockSelectGraph, mockQuery, mockList, mockClose, mockPing }; }); describe('FalkorDB Service', () => { let mockFalkorDB: any; beforeAll(() => { // Access the mocks mockFalkorDB = require('falkordb'); }); beforeEach(() => { jest.clearAllMocks(); }); describe('executeQuery', () => { it('should execute a query on the specified graph', async () => { // Arrange const graphName = 'testGraph'; const query = 'MATCH (n) RETURN n'; const params = { param1: 'value1' }; const expectedResult = { records: [{ id: 1 }] }; mockFalkorDB.mockQuery.mockResolvedValue(expectedResult); // Ensure service is initialized (private method, so we need to call a method first) await falkorDBService.executeQuery(graphName, query, params).catch(() => {}); // Reset mocks after initialization jest.clearAllMocks(); // Force client to be available (falkorDBService as any).client = { selectGraph: mockFalkorDB.mockSelectGraph }; // Act const result = await falkorDBService.executeQuery(graphName, query, params); // Assert expect(mockFalkorDB.mockSelectGraph).toHaveBeenCalledWith(graphName); expect(mockFalkorDB.mockQuery).toHaveBeenCalledWith(query, params); expect(result).toEqual(expectedResult); }); it('should throw an error if client is not initialized', async () => { // Arrange (falkorDBService as any).client = null; // Act & Assert await expect(falkorDBService.executeQuery('graph', 'query')) .rejects .toThrow('FalkorDB client not initialized'); }); }); describe('listGraphs', () => { it('should return a list of graphs', async () => { // Arrange const expectedGraphs = ['graph1', 'graph2']; mockFalkorDB.mockList.mockResolvedValue(expectedGraphs); // Force client to be available (falkorDBService as any).client = { list: mockFalkorDB.mockList }; // Act const result = await falkorDBService.listGraphs(); // Assert expect(mockFalkorDB.mockList).toHaveBeenCalled(); expect(result).toEqual(expectedGraphs); }); it('should throw an error if client is not initialized', async () => { // Arrange (falkorDBService as any).client = null; // Act & Assert await expect(falkorDBService.listGraphs()) .rejects .toThrow('FalkorDB client not initialized'); }); }); describe('close', () => { it('should close the client connection', async () => { // Arrange (falkorDBService as any).client = { close: mockFalkorDB.mockClose }; // Act await falkorDBService.close(); // Assert expect(mockFalkorDB.mockClose).toHaveBeenCalled(); expect((falkorDBService as any).client).toBeNull(); }); it('should not throw if client is already null', async () => { // Arrange (falkorDBService as any).client = null; // Act & Assert await expect(falkorDBService.close()).resolves.not.toThrow(); }); }); });

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/FalkorDB/FalkorDB-MCPServer'

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