1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| import { describeMCP, it, expect, beforeAll, afterAll, } from 'mcp-jest';
describeMCP('Weather MCP Server', () => { beforeAll(async () => { });
afterAll(async () => { });
describe('Tools', () => { it('should list weather tools', async () => { const tools = await mcp.listTools();
expect(tools.tools).toMatchObject([ { name: 'get-current-weather', description: expect.stringContaining('current weather'), }, { name: 'get-forecast', description: expect.stringContaining('forecast'), }, ]); });
it('should get current weather for location', async () => { const result = await mcp.callTool('get-current-weather', { location: 'San Francisco, CA', });
expect(result.content).toMatch(/San Francisco/); expect(result.content).toMatch(/\d+°/); });
it('should get weather forecast', async () => { const result = await mcp.callTool('get-forecast', { location: 'New York, NY', days: 3, });
expect(result.content).toContain('New York'); expect(result.content.split('\n').length).toBeGreaterThan(2); }); });
describe('Resources', () => { it('should list available resources', async () => { const resources = await mcp.listResources();
expect(resources.resources).toBeInstanceOf(Array); expect(resources.resources.length).toBeGreaterThan(0); });
it('should read weather-data resource', async () => { const resource = await mcp.readResource( 'weather-data://current' );
expect(resource.contents).toBeDefined(); expect(resource.contents[0].text).toBeDefined(); }); });
describe('Prompts', () => { it('should list available prompts', async () => { const prompts = await mcp.listPrompts();
expect(prompts.prompts).toBeInstanceOf(Array); });
it('should render weather report prompt', async () => { const prompt = await mcp.getPrompt('weather-report', { location: 'Boston, MA', });
expect(prompt.messages).toBeDefined(); expect(prompt.messages.length).toBeGreaterThan(0); expect(prompt.messages[0].content).toContain('Boston'); }); }); });
|