Home / Function/ renderSymbolContext() — mcp Function Reference

renderSymbolContext() — mcp Function Reference

Architecture documentation for the renderSymbolContext() function in symbol-context.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  fd98a844_5daf_fa4c_d573_003b6d89b6be["renderSymbolContext()"]
  ca77ccf4_30df_6b5c_22dc_f7ba42fd0765["symbol-context.ts"]
  fd98a844_5daf_fa4c_d573_003b6d89b6be -->|defined in| ca77ccf4_30df_6b5c_22dc_f7ba42fd0765
  f6b4d8d8_12fd_640f_c545_748d0e260bf0["handler()"]
  f6b4d8d8_12fd_640f_c545_748d0e260bf0 -->|calls| fd98a844_5daf_fa4c_d573_003b6d89b6be
  59a82797_f6a2_36aa_02bd_7b2f22d1bc50["normalizePath()"]
  fd98a844_5daf_fa4c_d573_003b6d89b6be -->|calls| 59a82797_f6a2_36aa_02bd_7b2f22d1bc50
  695dacd2_046b_a108_405d_763a2f0a13aa["findDomain()"]
  fd98a844_5daf_fa4c_d573_003b6d89b6be -->|calls| 695dacd2_046b_a108_405d_763a2f0a13aa
  67223ccb_3c2b_174e_f218_e621b3b9d580["languageFromExtension()"]
  fd98a844_5daf_fa4c_d573_003b6d89b6be -->|calls| 67223ccb_3c2b_174e_f218_e621b3b9d580
  2ef71e67_fa6d_b33f_d005_85a400698718["get()"]
  fd98a844_5daf_fa4c_d573_003b6d89b6be -->|calls| 2ef71e67_fa6d_b33f_d005_85a400698718
  style fd98a844_5daf_fa4c_d573_003b6d89b6be fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/tools/symbol-context.ts lines 223–379

export async function renderSymbolContext(graph: IndexedGraph, node: CodeGraphNode, directory: string): Promise<string> {
  const name = node.properties?.name as string || '(unknown)';
  const rawFilePath = node.properties?.filePath as string || '';
  const filePath = normalizePath(rawFilePath);
  const startLine = node.properties?.startLine as number || 0;
  const endLine = node.properties?.endLine as number || 0;
  const kind = node.properties?.kind as string || node.labels?.[0]?.toLowerCase() || 'symbol';
  const language = node.properties?.language as string || '';

  const lines: string[] = [];

  // Header
  lines.push(`## ${name}`);
  lines.push('');
  lines.push(`**Defined in:** ${filePath}${startLine ? ':' + startLine : ''}${endLine ? '-' + endLine : ''}`);
  lines.push(`**Type:** ${kind}${language ? ' (' + language + ')' : ''}`);

  // Domain
  const domain = findDomain(graph, node.id);
  if (domain) {
    lines.push(`**Domain:** ${domain}`);
  }
  lines.push('');

  // Source code
  if (filePath && startLine > 0) {
    try {
      const absPath = path.resolve(directory, filePath);
      const content = await fs.readFile(absPath, 'utf-8');
      const fileLines = content.split('\n');
      const end = endLine > 0 ? Math.min(endLine, startLine + MAX_SOURCE_LINES - 1) : startLine + MAX_SOURCE_LINES - 1;
      const sourceSlice = fileLines.slice(startLine - 1, end);
      if (sourceSlice.length > 0) {
        const lang = languageFromExtension(filePath);
        lines.push(`### Source`);
        lines.push('');
        lines.push(`\`\`\`${lang}`);
        lines.push(sourceSlice.join('\n'));
        lines.push('```');
        if (endLine > 0 && endLine > startLine + MAX_SOURCE_LINES - 1) {
          lines.push(`*... truncated (showing ${MAX_SOURCE_LINES} of ${endLine - startLine + 1} lines)*`);
        }
        lines.push('');
      }
    } catch {
      // File unreadable — skip source section silently
    }
  }

  // Callers
  const adj = graph.callAdj.get(node.id);
  if (adj && adj.in.length > 0) {
    lines.push(`### Called by (${adj.in.length} callers):`);
    lines.push('');
    const callers = adj.in
      .map(id => graph.nodeById.get(id))
      .filter((n): n is CodeGraphNode => !!n)
      .sort((a, b) => {
        const aPath = a.properties?.filePath as string || '';
        const bPath = b.properties?.filePath as string || '';
        return aPath.localeCompare(bPath);
      })
      .slice(0, MAX_SYMBOL_CALLERS);

    for (const caller of callers) {
      const cName = caller.properties?.name as string || '(unknown)';
      const cFile = normalizePath(caller.properties?.filePath as string || '');
      const cLine = caller.properties?.startLine as number || 0;
      lines.push(`- \`${cName}\` — ${cFile}${cLine ? ':' + cLine : ''}`);
    }

    if (adj.in.length > MAX_SYMBOL_CALLERS) {
      lines.push(`- *... and ${adj.in.length - MAX_SYMBOL_CALLERS} more*`);
    }
    lines.push('');
  }

  // Callees
  if (adj && adj.out.length > 0) {
    lines.push(`### Calls (${adj.out.length} functions):`);
    lines.push('');

Domain

Subdomains

Called By

Frequently Asked Questions

What does renderSymbolContext() do?
renderSymbolContext() is a function in the mcp codebase, defined in src/tools/symbol-context.ts.
Where is renderSymbolContext() defined?
renderSymbolContext() is defined in src/tools/symbol-context.ts at line 223.
What does renderSymbolContext() call?
renderSymbolContext() calls 4 function(s): findDomain, get, languageFromExtension, normalizePath.
What calls renderSymbolContext()?
renderSymbolContext() is called by 1 function(s): handler.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free