|
| 1 | +import { LATEST_PROTOCOL_VERSION } from '@modelcontextprotocol/sdk/types.js'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import { SERVER_NAME, SERVER_TITLE, SERVER_VERSION } from '../../src/const.js'; |
| 5 | +import { getServerCard } from '../../src/server_card.js'; |
| 6 | +import { readJsonFile } from '../../src/utils/generic.js'; |
| 7 | + |
| 8 | +const serverJson = readJsonFile<{ description: string }>(import.meta.url, '../../server.json'); |
| 9 | + |
| 10 | +describe('getServerCard', () => { |
| 11 | + it('should return a valid MCP server card object', () => { |
| 12 | + const card = getServerCard(); |
| 13 | + |
| 14 | + expect(card.$schema).toBe('https://static.modelcontextprotocol.io/schemas/mcp-server-card/v1.json'); |
| 15 | + expect(card.version).toBe('1.0'); |
| 16 | + expect(card.protocolVersion).toBe(LATEST_PROTOCOL_VERSION); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should contain required serverInfo fields using constants from const.ts', () => { |
| 20 | + const card = getServerCard(); |
| 21 | + |
| 22 | + expect(card.serverInfo.name).toBe(SERVER_NAME); |
| 23 | + expect(card.serverInfo.title).toBe(SERVER_TITLE); |
| 24 | + expect(card.serverInfo.version).toBe(SERVER_VERSION); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should declare streamable-http transport at root endpoint', () => { |
| 28 | + const card = getServerCard(); |
| 29 | + |
| 30 | + expect(card.transport.type).toBe('streamable-http'); |
| 31 | + expect(card.transport.endpoint).toBe('/'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should declare tools capability with listChanged', () => { |
| 35 | + const card = getServerCard(); |
| 36 | + |
| 37 | + expect(card.capabilities.tools.listChanged).toBe(true); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should require authentication with bearer and oauth2 schemes', () => { |
| 41 | + const card = getServerCard(); |
| 42 | + |
| 43 | + expect(card.authentication.required).toBe(true); |
| 44 | + expect(card.authentication.schemes).toEqual(['bearer', 'oauth2']); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should declare tools as dynamic', () => { |
| 48 | + const card = getServerCard(); |
| 49 | + |
| 50 | + expect(card.tools).toBe('dynamic'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should load description from server.json', () => { |
| 54 | + const card = getServerCard(); |
| 55 | + |
| 56 | + expect(card.description).toBe(serverJson.description); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should include documentation URL', () => { |
| 60 | + const card = getServerCard(); |
| 61 | + |
| 62 | + expect(card.documentationUrl).toBe('https://docs.apify.com/platform/integrations/mcp'); |
| 63 | + }); |
| 64 | +}); |
0 commit comments