Skip to main content
Glama
darbotlabs

Darbot Deepmind MCP Server

by darbotlabs
darbot-deepmind.test.ts11.4 kB
import { describe, it, expect, beforeEach, jest } from '@jest/globals'; // Mock the MCP SDK jest.mock('@modelcontextprotocol/sdk/server/index.js', () => ({ Server: jest.fn().mockImplementation(() => ({ setRequestHandler: jest.fn(), connect: jest.fn().mockResolvedValue(void 0), close: jest.fn().mockResolvedValue(void 0), })), })); jest.mock('@modelcontextprotocol/sdk/server/stdio.js', () => ({ StdioServerTransport: jest.fn().mockImplementation(() => ({})), })); // Mock chalk to avoid color codes in tests jest.mock('chalk', () => ({ __esModule: true, default: { yellow: (text: string) => text, green: (text: string) => text, blue: (text: string) => text, }, })); describe('Darbot Deepmind MCP Server', () => { beforeEach(() => { jest.clearAllMocks(); // Clear environment variables delete process.env.DISABLE_THOUGHT_LOGGING; }); describe('Input Validation', () => { it('should validate required thought parameters', () => { const validThought = { thought: 'Analyzing the problem', nextThoughtNeeded: true, thoughtNumber: 1, totalThoughts: 5, }; const isValidThought = (thought: any) => { return ( typeof thought.thought === 'string' && thought.thought.length > 0 && typeof thought.nextThoughtNeeded === 'boolean' && typeof thought.thoughtNumber === 'number' && typeof thought.totalThoughts === 'number' && thought.thoughtNumber > 0 && thought.totalThoughts > 0 ); }; expect(isValidThought(validThought)).toBe(true); }); it('should reject invalid thought parameters', () => { const invalidThoughts = [ { thought: '', nextThoughtNeeded: true, thoughtNumber: 1, totalThoughts: 5 }, // empty thought { thought: 'Valid', nextThoughtNeeded: 'true', thoughtNumber: 1, totalThoughts: 5 }, // wrong type { thought: 'Valid', nextThoughtNeeded: true, thoughtNumber: 0, totalThoughts: 5 }, // invalid number { thought: 'Valid', nextThoughtNeeded: true, thoughtNumber: 1, totalThoughts: 0 }, // invalid total ]; const isValidThought = (thought: any) => { try { return ( typeof thought.thought === 'string' && thought.thought.length > 0 && typeof thought.nextThoughtNeeded === 'boolean' && typeof thought.thoughtNumber === 'number' && typeof thought.totalThoughts === 'number' && thought.thoughtNumber > 0 && thought.totalThoughts > 0 ); } catch { return false; } }; invalidThoughts.forEach((thought) => { expect(isValidThought(thought)).toBe(false); }); }); }); describe('Revision Logic', () => { it('should handle revision parameters correctly', () => { const revisionThought = { thought: 'Revising previous analysis', nextThoughtNeeded: true, thoughtNumber: 3, totalThoughts: 5, isRevision: true, revisesThought: 2, }; const isValidRevision = (thought: any) => { if (thought.isRevision) { return ( typeof thought.revisesThought === 'number' && thought.revisesThought < thought.thoughtNumber && thought.revisesThought > 0 ); } return true; }; expect(isValidRevision(revisionThought)).toBe(true); }); it('should reject invalid revision parameters', () => { const invalidRevisions = [ { thought: 'Invalid revision', nextThoughtNeeded: true, thoughtNumber: 2, totalThoughts: 5, isRevision: true, revisesThought: 3, // Cannot revise future thought }, { thought: 'Invalid revision', nextThoughtNeeded: true, thoughtNumber: 2, totalThoughts: 5, isRevision: true, revisesThought: 0, // Invalid thought number }, ]; const isValidRevision = (thought: any) => { if (thought.isRevision) { return ( typeof thought.revisesThought === 'number' && thought.revisesThought < thought.thoughtNumber && thought.revisesThought > 0 ); } return true; }; invalidRevisions.forEach((thought) => { expect(isValidRevision(thought)).toBe(false); }); }); }); describe('Branching Logic', () => { it('should validate branch parameters', () => { const branchThought = { thought: 'Exploring alternative approach', nextThoughtNeeded: true, thoughtNumber: 5, totalThoughts: 8, branchFromThought: 3, branchId: 'alternative-1', }; const isValidBranch = (thought: any) => { if (thought.branchFromThought !== undefined) { return ( typeof thought.branchFromThought === 'number' && thought.branchFromThought < thought.thoughtNumber && thought.branchFromThought > 0 && typeof thought.branchId === 'string' && thought.branchId.length > 0 ); } return true; }; expect(isValidBranch(branchThought)).toBe(true); }); it('should reject invalid branch parameters', () => { const invalidBranches = [ { thought: 'Invalid branch', nextThoughtNeeded: true, thoughtNumber: 3, totalThoughts: 5, branchFromThought: 4, // Cannot branch from future branchId: 'test', }, { thought: 'Invalid branch', nextThoughtNeeded: true, thoughtNumber: 3, totalThoughts: 5, branchFromThought: 2, branchId: '', // Empty branch ID }, { thought: 'Invalid branch', nextThoughtNeeded: true, thoughtNumber: 3, totalThoughts: 5, branchFromThought: 2, // Missing branchId }, ]; const isValidBranch = (thought: any) => { if (thought.branchFromThought !== undefined) { return ( typeof thought.branchFromThought === 'number' && thought.branchFromThought < thought.thoughtNumber && thought.branchFromThought > 0 && typeof thought.branchId === 'string' && thought.branchId.length > 0 ); } return true; }; invalidBranches.forEach((thought) => { expect(isValidBranch(thought)).toBe(false); }); }); }); describe('Thought Completion', () => { it('should handle thought completion correctly', () => { const finalThought = { thought: 'Solution verified and complete', nextThoughtNeeded: false, thoughtNumber: 10, totalThoughts: 10, }; const isComplete = (thought: any) => { return !thought.nextThoughtNeeded; }; expect(isComplete(finalThought)).toBe(true); }); it('should handle dynamic total adjustment', () => { const extendedThought = { thought: 'Need more analysis than initially planned', nextThoughtNeeded: true, thoughtNumber: 8, totalThoughts: 5, // Less than current thought needsMoreThoughts: true, }; // Simulate the adjustment logic const adjustedTotalThoughts = Math.max(extendedThought.thoughtNumber, extendedThought.totalThoughts); expect(adjustedTotalThoughts).toBe(8); expect(extendedThought.needsMoreThoughts).toBe(true); }); }); describe('Environment Configuration', () => { it('should respect DISABLE_THOUGHT_LOGGING environment variable', () => { process.env.DISABLE_THOUGHT_LOGGING = 'true'; // This would be tested with the actual class implementation const shouldDisableLogging = (process.env.DISABLE_THOUGHT_LOGGING as string)?.toLowerCase() === 'true'; expect(shouldDisableLogging).toBe(true); }); it('should default to logging enabled', () => { delete process.env.DISABLE_THOUGHT_LOGGING; const shouldDisableLogging = (process.env.DISABLE_THOUGHT_LOGGING as string)?.toLowerCase() === 'true'; expect(shouldDisableLogging).toBe(false); }); }); describe('Response Format', () => { it('should format successful responses correctly', () => { const mockResponse = { thoughtNumber: 5, totalThoughts: 10, nextThoughtNeeded: true, branches: ['alternative-1', 'optimization-path'], thoughtHistoryLength: 5, }; const isValidResponse = (response: any) => { return ( typeof response.thoughtNumber === 'number' && typeof response.totalThoughts === 'number' && typeof response.nextThoughtNeeded === 'boolean' && Array.isArray(response.branches) && typeof response.thoughtHistoryLength === 'number' ); }; expect(isValidResponse(mockResponse)).toBe(true); }); it('should format error responses correctly', () => { const mockErrorResponse = { error: 'Validation failed: thought is required', status: 'failed', }; const isValidErrorResponse = (response: any) => { return ( typeof response.error === 'string' && response.status === 'failed' ); }; expect(isValidErrorResponse(mockErrorResponse)).toBe(true); }); }); describe('Complex Reasoning Scenarios', () => { it('should handle multi-step reasoning with revisions', () => { const reasoningSteps = [ { thought: 'Initial analysis of the problem', nextThoughtNeeded: true, thoughtNumber: 1, totalThoughts: 5, }, { thought: 'Breaking down requirements', nextThoughtNeeded: true, thoughtNumber: 2, totalThoughts: 5, }, { thought: 'Actually, need to revise the initial analysis', nextThoughtNeeded: true, thoughtNumber: 3, totalThoughts: 6, isRevision: true, revisesThought: 1, }, { thought: 'Exploring alternative solution', nextThoughtNeeded: true, thoughtNumber: 4, totalThoughts: 6, branchFromThought: 2, branchId: 'alternative-solution', }, ]; // Validate each step reasoningSteps.forEach((step, index) => { expect(step.thoughtNumber).toBe(index + 1); expect(typeof step.thought).toBe('string'); expect(step.thought.length).toBeGreaterThan(0); }); // Check revision logic const revisionStep = reasoningSteps.find(step => step.isRevision); expect(revisionStep).toBeDefined(); expect(revisionStep!.isRevision).toBe(true); expect(revisionStep!.revisesThought).toBeLessThan(revisionStep!.thoughtNumber); // Check branching logic const branchStep = reasoningSteps.find(step => step.branchFromThought); expect(branchStep).toBeDefined(); expect(branchStep!.branchFromThought).toBeLessThan(branchStep!.thoughtNumber); expect(branchStep!.branchId).toBeDefined(); }); }); });

Latest Blog Posts

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/darbotlabs/Darbot-Deepmind-MCP'

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