MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / handle

Function handle

src/tools/get-codebase-health.ts:30–112  ·  view source on GitHub ↗
(
  args: Record<string, unknown>,
  ctx: ToolContext
)

Source from the content-addressed store, hash-verified

28};
29
30export async function handle(
31 args: Record<string, unknown>,
32 ctx: ToolContext
33): Promise<ToolResponse> {
34 const file = typeof args.file === 'string' ? args.file.trim() : undefined;
35 const limit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? args.limit : 10;
36 const level =
37 args.level === 'low' || args.level === 'medium' || args.level === 'high'
38 ? args.level
39 : undefined;
40
41 const health = await readHealthFile(ctx.paths.health);
42 if (!health) {
43 return {
44 content: [
45 {
46 type: 'text',
47 text: JSON.stringify(
48 {
49 status: 'no_data',
50 message:
51 'No codebase health artifact found. Run refresh_index to generate health.json.'
52 },
53 null,
54 2
55 )
56 }
57 ]
58 };
59 }
60
61 const orderedLevels = { high: 3, medium: 2, low: 1 };
62 const minLevel = level ? orderedLevels[level] : 1;
63
64 if (file) {
65 const byFile = indexHealthByFile(health, ctx.rootPath);
66 const fileHealth = byFile.get(normalizeHealthLookupKey(file, ctx.rootPath));
67 return {
68 content: [
69 {
70 type: 'text',
71 text: JSON.stringify(
72 fileHealth
73 ? {
74 status: 'success',
75 generatedAt: health.generatedAt,
76 file: fileHealth
77 }
78 : {
79 status: 'not_found',
80 message: `No health record found for ${file}.`,
81 generatedAt: health.generatedAt
82 },
83 null,
84 2
85 )
86 }
87 ]

Callers

nothing calls this directly

Calls 4

readHealthFileFunction · 0.85
indexHealthByFileFunction · 0.85
normalizeHealthLookupKeyFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected