|
| 1 | +/// <reference types="bun-types" /> |
| 2 | + |
| 3 | +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; |
| 4 | +import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 5 | +import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; |
| 6 | +import { afterEach, beforeEach, expect, test } from "bun:test"; |
| 7 | + |
| 8 | +import { registerDocsTools } from "@/lib/mcp/tools/docs"; |
| 9 | + |
| 10 | +const configured = { |
| 11 | + token: process.env.MINTLIFY_ASSISTANT_API_TOKEN, |
| 12 | + domain: process.env.MINTLIFY_DOMAIN, |
| 13 | +}; |
| 14 | + |
| 15 | +beforeEach(() => { |
| 16 | + delete process.env.MINTLIFY_ASSISTANT_API_TOKEN; |
| 17 | + delete process.env.MINTLIFY_DOMAIN; |
| 18 | +}); |
| 19 | + |
| 20 | +afterEach(() => { |
| 21 | + if (configured.token) |
| 22 | + process.env.MINTLIFY_ASSISTANT_API_TOKEN = configured.token; |
| 23 | + if (configured.domain) process.env.MINTLIFY_DOMAIN = configured.domain; |
| 24 | +}); |
| 25 | + |
| 26 | +test("search_docs reports missing configuration as a failure", async () => { |
| 27 | + const server = new McpServer({ name: "test", version: "0.0.0" }); |
| 28 | + registerDocsTools(server); |
| 29 | + |
| 30 | + const client = new Client({ name: "test-client", version: "0.0.0" }); |
| 31 | + const [clientTransport, serverTransport] = |
| 32 | + InMemoryTransport.createLinkedPair(); |
| 33 | + await Promise.all([ |
| 34 | + server.connect(serverTransport), |
| 35 | + client.connect(clientTransport), |
| 36 | + ]); |
| 37 | + |
| 38 | + const result = await client.callTool({ |
| 39 | + name: "search_docs", |
| 40 | + arguments: { query: "how to deploy an app" }, |
| 41 | + }); |
| 42 | + await client.close(); |
| 43 | + |
| 44 | + expect(result.isError).toBe(true); |
| 45 | + expect(result.content).toEqual([ |
| 46 | + { |
| 47 | + type: "text", |
| 48 | + text: "Error: Documentation search is not configured (missing MINTLIFY_ASSISTANT_API_TOKEN or MINTLIFY_DOMAIN).", |
| 49 | + }, |
| 50 | + ]); |
| 51 | +}); |
0 commit comments