Skip to main content
Glama

HomeAssistant MCP

context.test.tsโ€ข2.2 kB
import { describe, expect, test, beforeEach, it } from "bun:test"; import { jest } from '@jest/globals'; import { z } from 'zod'; import { DomainSchema } from '../../src/schemas.js'; type MockResponse = { success: boolean }; // Define types for tool and server interface Tool { name: string; description: string; execute: (params: any) => Promise<MockResponse>; parameters: z.ZodType<any>; } interface MockService { [key: string]: jest.Mock<Promise<MockResponse>>; } interface MockServices { light: { turn_on: jest.Mock<Promise<MockResponse>>; turn_off: jest.Mock<Promise<MockResponse>>; }; climate: { set_temperature: jest.Mock<Promise<MockResponse>>; }; } interface MockHassInstance { services: MockServices; } // Mock LiteMCP class class MockLiteMCP { private tools: Tool[] = []; constructor(public name: string, public version: string) { } addTool(tool: Tool) { this.tools.push(tool); } getTools() { return this.tools; } } const createMockFn = (): jest.Mock<Promise<MockResponse>> => { return jest.fn<() => Promise<MockResponse>>().mockResolvedValue({ success: true }); }; // Mock the Home Assistant instance const mockHassServices: MockHassInstance = { services: { light: { turn_on: createMockFn(), turn_off: createMockFn(), }, climate: { set_temperature: createMockFn(), }, }, }; // Mock get_hass function const get_hass = jest.fn<() => Promise<MockHassInstance>>().mockResolvedValue(mockHassServices); describe('Context Tests', () => { let mockTool: Tool; beforeEach(() => { mockTool = { name: 'test_tool', description: 'A test tool', execute: jest.fn<(params: any) => Promise<MockResponse>>().mockResolvedValue({ success: true }), parameters: z.object({ test: z.string() }) }; }); // Add your test cases here test('should execute tool successfully', async () => { const result = await mockTool.execute({ test: 'value' }); expect(result.success).toBe(true); }); });

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/jango-blockchained/advanced-homeassistant-mcp'

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