We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/godlewis/zendao-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
/**
* get_project_by_id 工具测试
*/
/// <reference path="../global.d.ts" />
import { getProjectById } from '../../src/tools/getProjectById';
describe('get_project_by_id Tool', () => {
beforeEach(() => {
global.testCache.clear();
});
test('should fetch project details by ID', async () => {
const projectId = 2; // 使用已存在的项目 ID
const result = await getProjectById(global.testClient, global.testCache, projectId);
expect(result).toBeDefined();
expect(result.content).toBeDefined();
expect(result.content[0]).toHaveProperty('type', 'text');
expect(result.content[0]).toHaveProperty('text');
const text = result.content[0].text;
expect(text).toContain('项目详情');
expect(text).toContain(`ID: ${projectId}`);
expect(text).toContain('名称:');
expect(text).toContain('代码:');
console.log(`✅ Fetched project details for ID ${projectId}`);
});
test('should cache project details', async () => {
const projectId = 2;
const cacheKey = `project:${projectId}`;
// 第一次调用
await getProjectById(global.testClient, global.testCache, projectId);
// 检查缓存
const cached = global.testCache.get(cacheKey);
expect(cached).toBeDefined();
expect(cached.id).toBe(projectId);
console.log(`✅ Project details cached`);
});
test('should return cached result on second call', async () => {
const projectId = 2;
const params = { page: 1, limit: 50 };
// 第一次调用
const start1 = Date.now();
await getProjectById(global.testClient, global.testCache, projectId);
const time1 = Date.now() - start1;
// 第二次调用(应该从缓存返回)
const start2 = Date.now();
const result2 = await getProjectById(global.testClient, global.testCache, projectId);
const time2 = Date.now() - start2;
// 缓存命中应该显著更快
expect(result2).toBeDefined();
expect(time2).toBeLessThan(time1 * 0.5);
console.log(`✅ Cached response faster: ${time2}ms vs ${time1}ms`);
});
test('should handle non-existent project ID', async () => {
const nonExistentId = 999999;
const result = await getProjectById(global.testClient, global.testCache, nonExistentId);
expect(result).toBeDefined();
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('失败');
console.log(`✅ Non-existent project handled: ${result.content[0].text}`);
});
test('should format output with project information', async () => {
const projectId = 2;
const result = await getProjectById(global.testClient, global.testCache, projectId);
const text = result.content[0].text;
expect(text).toContain('项目详情');
expect(text).toContain('ID:');
expect(text).toContain('名称:');
expect(text).toContain('代码:');
expect(text).toContain('状态:');
console.log(`✅ Output formatted correctly`);
});
});