// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.
//
// Only runs when RUN_E2E_TESTS=true (see vitest.config.ts). Connects a real
// MCP client to a real MCP server instance (in-memory transport) to verify
// protocol-level behavior, not just the underlying functions.

import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { AuthManager } from '../../src/auth/auth-manager.js';
import { DEFAULT_API_VERSION, type Config } from '../../src/core/config-schema.js';
import { createMcpServer } from '../../src/core/mcp-server.js';
import { closeStore, openStore, type Store } from '../../src/data/store-repository.js';
import { registerTools } from '../../src/tools/register-tools.js';
import { connectTestClient } from '../helpers/mcp-test-client.js';
import { startMockApiServer, type MockApiServer } from '../helpers/mock-api-server.js';

let store: Store;
let mockApi: MockApiServer;

beforeAll(async () => {
  store = openStore(DEFAULT_API_VERSION);
  mockApi = await startMockApiServer();
});

afterAll(async () => {
  closeStore(store);
  await mockApi.close();
});

describe('MCP protocol', () => {
  it('lists exactly the 3 universal tools', async () => {
    const config: Config = {
      url: mockApi.url,
      auth_method: '{{ auth_method_keys.0 }}',
      api_version: DEFAULT_API_VERSION,
      log_level: 'info',
      rate_limit: 100,
      timeout_ms: 5000,
      cache_size: 500,
      retry_attempts: 0,
      transport: 'stdio',
      host: '127.0.0.1',
      port: 3000,
    };
    const server = createMcpServer();
    registerTools(server, { store, config, authManager: new AuthManager(config.auth_method) });

    const client = await connectTestClient(server);
    const { tools } = await client.listTools();

    expect(tools.map((tool) => tool.name).sort()).toEqual(['call', 'get', 'search']);
  });
});
