mcp.test.ts•2.51 kB
import { z } from 'zod'; // Import Zod for potential validation tests
// Import the handlers and schemas we want to test
import { sampleToolSchema, sampleToolHandler } from '../../services/mcp-tools/sample.tool';
// TODO: Import other handlers/schemas as needed
// import { addDocumentationSchema, addDocumentationHandler } from '../../services/mcp-tools/add-documentation.tool';
// import { getJobStatusSchema, getJobStatusHandler } from '../../services/mcp-tools/get-job-status.tool';
// import { listDocumentationSchema, listDocumentationHandler } from '../../services/mcp-tools/list-documentation.tool';
// import { queryDocumentationSchema, queryDocumentationHandler } from '../../services/mcp-tools/query-documentation.tool';
describe('MCP Tool Handlers', () => {
describe('sampleToolHandler', () => {
it('should echo back the message the specified number of times', async () => {
const params = { message: 'test', count: 3 };
const expectedText = 'test test test';
// Directly call the handler
const result = await sampleToolHandler(params);
// Assert the SDK-expected return structure
expect(result).toBeDefined();
expect(result.content).toBeDefined();
expect(Array.isArray(result.content)).toBe(true);
expect(result.content.length).toBe(1);
expect(result.content[0].type).toBe('text');
expect(result.content[0].text).toBe(expectedText);
});
it('should echo back the message once if count is not provided', async () => {
const params = { message: 'hello' }; // Count omitted
const expectedText = 'hello';
const result = await sampleToolHandler(params);
expect(result.content[0].text).toBe(expectedText);
});
// Optional: Test schema validation separately if needed
// it('should validate parameters using the schema', () => {
// const validParams = { message: 'valid' };
// const invalidParams = { count: 3 }; // Missing required message
// const schemaObject = z.object(sampleToolSchema);
// expect(() => schemaObject.parse(validParams)).not.toThrow();
// expect(() => schemaObject.parse(invalidParams)).toThrow();
// });
});
// TODO: Add describe blocks for other tool handlers
// describe('addDocumentationHandler', () => { ... });
// describe('getJobStatusHandler', () => { ... });
// describe('listDocumentationHandler', () => { ... });
// describe('queryDocumentationHandler', () => { ... });
});