handler() — mcp Function Reference
Architecture documentation for the handler() function in find-connections.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD 37989e20_855d_701d_ca13_a196d7d4a37e["handler()"] 05b504b7_268e_7c49_d109_73f7c3744be0["asErrorResult()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| 05b504b7_268e_7c49_d109_73f7c3744be0 1721f7fd_bb7b_c8c3_9b4b_5677293ae256["resolveOrFetchGraph()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| 1721f7fd_bb7b_c8c3_9b4b_5677293ae256 f8f0f24b_951e_04ad_fb80_1ae3dde982e9["classifyApiError()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| f8f0f24b_951e_04ad_fb80_1ae3dde982e9 26a0dd39_b74f_8d6e_4e9a_819fdf30a8e8["collectDomainMembers()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| 26a0dd39_b74f_8d6e_4e9a_819fdf30a8e8 67622b0f_6b47_8f68_bac5_409b3145d2f2["asTextContentResult()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| 67622b0f_6b47_8f68_bac5_409b3145d2f2 d6ed9355_f977_306b_b0ef_d7220fdefe68["get()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| d6ed9355_f977_306b_b0ef_d7220fdefe68 90af3150_ce81_c645_faa7_5b8b9bcf5ecc["has()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| 90af3150_ce81_c645_faa7_5b8b9bcf5ecc 6666a1f2_0912_ade3_4b0e_42190c41cd97["normalizePath()"] 37989e20_855d_701d_ca13_a196d7d4a37e -->|calls| 6666a1f2_0912_ade3_4b0e_42190c41cd97 style 37989e20_855d_701d_ca13_a196d7d4a37e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/tools/find-connections.ts lines 72–166
export const handler: HandlerFunction = async (client, args, defaultWorkdir) => {
const domainA = typeof args?.domain_a === 'string' ? args.domain_a.trim() : '';
const domainB = typeof args?.domain_b === 'string' ? args.domain_b.trim() : '';
if (!domainA || !domainB) {
return asErrorResult({
type: 'validation_error',
message: 'Missing required "domain_a" and/or "domain_b" parameters.',
code: 'MISSING_DOMAIN',
recoverable: false,
suggestion: 'Provide two domain or subdomain names to find connections between.',
});
}
const rawDir = args?.directory as string | undefined;
const directory = (rawDir && rawDir.trim()) || defaultWorkdir || process.cwd();
if (!directory || typeof directory !== 'string') {
return asErrorResult({
type: 'validation_error',
message: 'No directory provided and no default workdir configured.',
code: 'MISSING_DIRECTORY',
recoverable: false,
suggestion: 'Provide a directory parameter or start the MCP server with a workdir argument.',
});
}
let graph: IndexedGraph;
try {
graph = await resolveOrFetchGraph(client, directory);
} catch (error: any) {
return asErrorResult(classifyApiError(error));
}
const aNodes = collectDomainMembers(graph, domainA);
const bNodes = collectDomainMembers(graph, domainB);
if (aNodes.size === 0) {
return asTextContentResult(`No functions found in domain/subdomain matching "${domainA}".`);
}
if (bNodes.size === 0) {
return asTextContentResult(`No functions found in domain/subdomain matching "${domainB}".`);
}
// Find call edges between domain A and domain B in both directions
const bridges: string[] = [];
for (const aId of aNodes) {
const adj = graph.callAdj.get(aId);
if (!adj) continue;
// A calls B (downstream)
for (const targetId of adj.out) {
if (!bNodes.has(targetId)) continue;
const srcNode = graph.nodeById.get(aId);
const tgtNode = graph.nodeById.get(targetId);
const srcName = srcNode?.properties?.name as string || '(unknown)';
const tgtName = tgtNode?.properties?.name as string || '(unknown)';
const srcFile = normalizePath(srcNode?.properties?.filePath as string || '');
const tgtFile = normalizePath(tgtNode?.properties?.filePath as string || '');
bridges.push(
`\`${srcName}\` (${domainA}) calls \`${tgtName}\` (${domainB}) — ${srcFile} → ${tgtFile}`
);
}
}
for (const bId of bNodes) {
const adj = graph.callAdj.get(bId);
if (!adj) continue;
// B calls A (reverse direction)
for (const targetId of adj.out) {
if (!aNodes.has(targetId)) continue;
const srcNode = graph.nodeById.get(bId);
const tgtNode = graph.nodeById.get(targetId);
const srcName = srcNode?.properties?.name as string || '(unknown)';
const tgtName = tgtNode?.properties?.name as string || '(unknown)';
const srcFile = normalizePath(srcNode?.properties?.filePath as string || '');
const tgtFile = normalizePath(tgtNode?.properties?.filePath as string || '');
bridges.push(
`\`${srcName}\` (${domainB}) calls \`${tgtName}\` (${domainA}) — ${srcFile} → ${tgtFile}`
);
}
}
if (bridges.length === 0) {
return asTextContentResult(
`No direct call connections found between "${domainA}" and "${domainB}".`
);
}
return asTextContentResult(
`Connections between ${domainA} and ${domainB}:\n\n${bridges.join('\n')}`
);
};
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does handler() do?
handler() is a function in the mcp codebase.
What does handler() call?
handler() calls 8 function(s): asErrorResult, asTextContentResult, classifyApiError, collectDomainMembers, get, has, normalizePath, resolveOrFetchGraph.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free