mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-17 21:54:05 +02:00
Removed ~29 tests that were adding noise rather than coverage: - Registration boilerplate tests (16): redundant with registrations.test.ts - Redundant role/type checks (3): consolidated into behavioral tests - "Should not throw" tests (6): consolidated into single lifecycle test - Constant identity tests (2): provided no safety net - expect(true).toBe(true) test (1): replaced with actual assertion - Weak capability test (1): removed, handler check already exists Strengthened remaining tests: - Resource templates test now verifies specific resource names - File resources test now asserts registerResource was called Test count: 124 → 95 (29 removed) Coverage unchanged at ~71% Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
140 lines
5.1 KiB
TypeScript
140 lines
5.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
|
// Create mock server
|
|
function createMockServer() {
|
|
return {
|
|
registerTool: vi.fn(),
|
|
registerPrompt: vi.fn(),
|
|
registerResource: vi.fn(),
|
|
server: {
|
|
getClientCapabilities: vi.fn(() => ({})),
|
|
setRequestHandler: vi.fn(),
|
|
},
|
|
sendLoggingMessage: vi.fn(),
|
|
sendResourceUpdated: vi.fn(),
|
|
} as unknown as McpServer;
|
|
}
|
|
|
|
describe('Registration Index Files', () => {
|
|
describe('tools/index.ts', () => {
|
|
it('should register all standard tools', async () => {
|
|
const { registerTools } = await import('../tools/index.js');
|
|
const mockServer = createMockServer();
|
|
|
|
registerTools(mockServer);
|
|
|
|
// Should register 12 standard tools (non-conditional)
|
|
expect(mockServer.registerTool).toHaveBeenCalledTimes(12);
|
|
|
|
// Verify specific tools are registered
|
|
const registeredTools = (mockServer.registerTool as any).mock.calls.map(
|
|
(call: any[]) => call[0]
|
|
);
|
|
expect(registeredTools).toContain('echo');
|
|
expect(registeredTools).toContain('get-sum');
|
|
expect(registeredTools).toContain('get-env');
|
|
expect(registeredTools).toContain('get-tiny-image');
|
|
expect(registeredTools).toContain('get-structured-content');
|
|
expect(registeredTools).toContain('get-annotated-message');
|
|
expect(registeredTools).toContain('trigger-long-running-operation');
|
|
expect(registeredTools).toContain('get-resource-links');
|
|
expect(registeredTools).toContain('get-resource-reference');
|
|
expect(registeredTools).toContain('gzip-file-as-resource');
|
|
expect(registeredTools).toContain('toggle-simulated-logging');
|
|
expect(registeredTools).toContain('toggle-subscriber-updates');
|
|
});
|
|
|
|
it('should register conditional tools based on capabilities', async () => {
|
|
const { registerConditionalTools } = await import('../tools/index.js');
|
|
|
|
// Server with all capabilities
|
|
const mockServerWithCapabilities = {
|
|
registerTool: vi.fn(),
|
|
server: {
|
|
getClientCapabilities: vi.fn(() => ({
|
|
roots: {},
|
|
elicitation: {},
|
|
sampling: {},
|
|
})),
|
|
},
|
|
} as unknown as McpServer;
|
|
|
|
registerConditionalTools(mockServerWithCapabilities);
|
|
|
|
// Should register 3 conditional tools when all capabilities present
|
|
expect(mockServerWithCapabilities.registerTool).toHaveBeenCalledTimes(3);
|
|
|
|
const registeredTools = (
|
|
mockServerWithCapabilities.registerTool as any
|
|
).mock.calls.map((call: any[]) => call[0]);
|
|
expect(registeredTools).toContain('get-roots-list');
|
|
expect(registeredTools).toContain('trigger-elicitation-request');
|
|
expect(registeredTools).toContain('trigger-sampling-request');
|
|
});
|
|
|
|
it('should not register conditional tools when capabilities missing', async () => {
|
|
const { registerConditionalTools } = await import('../tools/index.js');
|
|
|
|
const mockServerNoCapabilities = {
|
|
registerTool: vi.fn(),
|
|
server: {
|
|
getClientCapabilities: vi.fn(() => ({})),
|
|
},
|
|
} as unknown as McpServer;
|
|
|
|
registerConditionalTools(mockServerNoCapabilities);
|
|
|
|
// Should not register any tools when capabilities are missing
|
|
expect(mockServerNoCapabilities.registerTool).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('prompts/index.ts', () => {
|
|
it('should register all prompts', async () => {
|
|
const { registerPrompts } = await import('../prompts/index.js');
|
|
const mockServer = createMockServer();
|
|
|
|
registerPrompts(mockServer);
|
|
|
|
// Should register 4 prompts
|
|
expect(mockServer.registerPrompt).toHaveBeenCalledTimes(4);
|
|
|
|
const registeredPrompts = (mockServer.registerPrompt as any).mock.calls.map(
|
|
(call: any[]) => call[0]
|
|
);
|
|
expect(registeredPrompts).toContain('simple-prompt');
|
|
expect(registeredPrompts).toContain('args-prompt');
|
|
expect(registeredPrompts).toContain('completable-prompt');
|
|
expect(registeredPrompts).toContain('resource-prompt');
|
|
});
|
|
});
|
|
|
|
describe('resources/index.ts', () => {
|
|
it('should register resource templates', async () => {
|
|
const { registerResources } = await import('../resources/index.js');
|
|
const mockServer = createMockServer();
|
|
|
|
registerResources(mockServer);
|
|
|
|
// Should register at least the 2 resource templates (text and blob) plus file resources
|
|
expect(mockServer.registerResource).toHaveBeenCalled();
|
|
const registeredResources = (mockServer.registerResource as any).mock.calls.map(
|
|
(call: any[]) => call[0]
|
|
);
|
|
expect(registeredResources).toContain('Dynamic Text Resource');
|
|
expect(registeredResources).toContain('Dynamic Blob Resource');
|
|
});
|
|
|
|
it('should read instructions from file', async () => {
|
|
const { readInstructions } = await import('../resources/index.js');
|
|
|
|
const instructions = readInstructions();
|
|
|
|
// Should return a string (either content or error message)
|
|
expect(typeof instructions).toBe('string');
|
|
expect(instructions.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
});
|