Skip to main content
Glama

contentrain_scan

Scan project source code to identify content strings for localization and content management. Analyze code structure, extract string candidates, or get overview statistics without modifying files.

Instructions

Scan project source code for content strings. Three modes: "graph" builds import/component graph for project intelligence, "candidates" extracts string literals with pre-filtering and pagination, "summary" provides quick overview stats. Read-only — no changes to disk or git. MCP finds strings deterministically; the agent decides what is content. Recommended workflow: start with "summary" or "graph" for orientation, then paginate through "candidates" to evaluate strings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modeNoScan mode. Default: candidates
pathsNoDirectories to scan (relative to project root). Default: auto-detect
includeNoFile extensions to include. Default: .tsx, .jsx, .vue, .ts, .js, .mjs, .astro, .svelte
excludeNoAdditional directory names to exclude
limitNoCandidates mode: batch size. Default: 50
offsetNoCandidates mode: pagination offset. Default: 0
min_lengthNoCandidates mode: minimum string length. Default: 2
max_lengthNoCandidates mode: maximum string length. Default: 500

Implementation Reference

  • The handler function for the `contentrain_scan` tool, which delegates to `buildGraph`, `scanCandidates`, or `scanSummary` based on the input mode.
    async (input) => {
      const config = await readConfig(projectRoot)
      if (!config) {
        return {
          content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],
          isError: true,
        }
      }
    
      const mode = input.mode ?? 'candidates'
    
      try {
        switch (mode) {
          case 'graph': {
            const graph = await buildGraph(projectRoot, {
              paths: input.paths,
              include: input.include,
              exclude: input.exclude,
            })
    
            return {
              content: [{ type: 'text' as const, text: JSON.stringify({
                mode: 'graph',
                ...graph,
                next_steps: [
                  'Use mode:candidates to scan specific files/directories for strings',
                  'Focus on pages and components with high string counts first',
                ],
              }, null, 2) }],
            }
          }
    
          case 'candidates': {
            const result = await scanCandidates(projectRoot, {
              paths: input.paths,
              include: input.include,
              exclude: input.exclude,
              limit: input.limit,
              offset: input.offset,
              min_length: input.min_length,
              max_length: input.max_length,
            })
    
            const nextSteps: string[] = []
            if (result.stats.has_more) {
              nextSteps.push(`Use offset:${(input.offset ?? 0) + (input.limit ?? 50)} for next batch`)
            }
            nextSteps.push('Evaluate each candidate: is it user-facing content? Which domain/model?')
            if (result.duplicates.length > 0) {
              nextSteps.push('Consider deduplicating repeated strings into shared models')
            }
    
            return {
              content: [{ type: 'text' as const, text: JSON.stringify({
                mode: 'candidates',
                ...result,
                next_steps: nextSteps,
              }, null, 2) }],
            }
          }
    
          case 'summary': {
            const result = await scanSummary(projectRoot, {
              paths: input.paths,
              include: input.include,
              exclude: input.exclude,
              min_length: input.min_length,
              max_length: input.max_length,
            })
    
            return {
              content: [{ type: 'text' as const, text: JSON.stringify({
                mode: 'summary',
                ...result,
                next_steps: [
                  'Use mode:graph for project structure analysis',
                  'Use mode:candidates to scan directories with most candidates',
                ],
              }, null, 2) }],
            }
          }
    
          default:
            return {
              content: [{ type: 'text' as const, text: JSON.stringify({ error: `Unknown mode: ${mode}` }) }],
              isError: true,
            }
        }
      } catch (error) {
        return {
          content: [{ type: 'text' as const, text: JSON.stringify({
            error: `Scan failed: ${error instanceof Error ? error.message : String(error)}`,
          }) }],
          isError: true,
        }
      }
    },
  • Registration of the `contentrain_scan` tool in the `registerNormalizeTools` function within `packages/mcp/src/tools/normalize.ts`.
    server.tool(
      'contentrain_scan',
      'Scan project source code for content strings. Three modes: "graph" builds import/component graph for project intelligence, "candidates" extracts string literals with pre-filtering and pagination, "summary" provides quick overview stats. Read-only — no changes to disk or git. MCP finds strings deterministically; the agent decides what is content. Recommended workflow: start with "summary" or "graph" for orientation, then paginate through "candidates" to evaluate strings.',
      {
        mode: z.enum(['graph', 'candidates', 'summary']).optional().describe('Scan mode. Default: candidates'),
        paths: z.array(z.string()).optional().describe('Directories to scan (relative to project root). Default: auto-detect'),
        include: z.array(z.string()).optional().describe('File extensions to include. Default: .tsx, .jsx, .vue, .ts, .js, .mjs, .astro, .svelte'),
        exclude: z.array(z.string()).optional().describe('Additional directory names to exclude'),
        limit: z.number().optional().describe('Candidates mode: batch size. Default: 50'),
        offset: z.number().optional().describe('Candidates mode: pagination offset. Default: 0'),
        min_length: z.number().optional().describe('Candidates mode: minimum string length. Default: 2'),
        max_length: z.number().optional().describe('Candidates mode: maximum string length. Default: 500'),
      },
      async (input) => {
        const config = await readConfig(projectRoot)
        if (!config) {
          return {
            content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],
            isError: true,
          }
        }
    
        const mode = input.mode ?? 'candidates'
    
        try {
          switch (mode) {
            case 'graph': {
              const graph = await buildGraph(projectRoot, {
                paths: input.paths,
                include: input.include,
                exclude: input.exclude,
              })
    
              return {
                content: [{ type: 'text' as const, text: JSON.stringify({
                  mode: 'graph',
                  ...graph,
                  next_steps: [
                    'Use mode:candidates to scan specific files/directories for strings',
                    'Focus on pages and components with high string counts first',
                  ],
                }, null, 2) }],
              }
            }
    
            case 'candidates': {
              const result = await scanCandidates(projectRoot, {
                paths: input.paths,
                include: input.include,
                exclude: input.exclude,
                limit: input.limit,
                offset: input.offset,
                min_length: input.min_length,
                max_length: input.max_length,
              })
    
              const nextSteps: string[] = []
              if (result.stats.has_more) {
                nextSteps.push(`Use offset:${(input.offset ?? 0) + (input.limit ?? 50)} for next batch`)
              }
              nextSteps.push('Evaluate each candidate: is it user-facing content? Which domain/model?')
              if (result.duplicates.length > 0) {
                nextSteps.push('Consider deduplicating repeated strings into shared models')
              }
    
              return {
                content: [{ type: 'text' as const, text: JSON.stringify({
                  mode: 'candidates',
                  ...result,
                  next_steps: nextSteps,
                }, null, 2) }],
              }
            }
    
            case 'summary': {
              const result = await scanSummary(projectRoot, {
                paths: input.paths,
                include: input.include,
                exclude: input.exclude,
                min_length: input.min_length,
                max_length: input.max_length,
              })
    
              return {
                content: [{ type: 'text' as const, text: JSON.stringify({
                  mode: 'summary',
                  ...result,
                  next_steps: [
                    'Use mode:graph for project structure analysis',
                    'Use mode:candidates to scan directories with most candidates',
                  ],
                }, null, 2) }],
              }
            }
    
            default:
              return {
                content: [{ type: 'text' as const, text: JSON.stringify({ error: `Unknown mode: ${mode}` }) }],
                isError: true,
              }
          }
        } catch (error) {
          return {
            content: [{ type: 'text' as const, text: JSON.stringify({
              error: `Scan failed: ${error instanceof Error ? error.message : String(error)}`,
            }) }],
            isError: true,
          }
        }
      },
    )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Discloses critical safety trait ('Read-only — no changes to disk or git'), determinism ('MCP finds strings deterministically'), and pagination behavior for candidates mode. Deducting one point as it lacks details on error handling (e.g., invalid paths) or performance characteristics for large codebases.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Every sentence earns its place: purpose statement, mode definitions, safety guarantee, determinism clarification, and workflow recommendation. Efficiently structured with no redundancy despite covering 8 parameters and 3 distinct behavioral modes. Front-loaded with the core action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given high complexity (3 modes, 8 optional parameters) and lack of annotations/output schema, description successfully covers operational modes, workflow sequencing, and safety constraints. Would benefit from brief mention of output structure (e.g., 'returns JSON with strings array') to achieve full completeness without an output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% (baseline 3). Description adds significant conceptual meaning beyond schema: explains 'graph' builds import/component graphs for intelligence, 'candidates' performs extraction with pre-filtering, and 'summary' provides stats. Connects 'paginate through candidates' to the limit/offset parameters, adding usage context not in schema definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with specific verb 'Scan' and resource 'project source code for content strings'. Clearly distinguishes from mutation siblings (contentrain_apply, contentrain_save) by stating read-only nature. Explicitly enumerates the three operational modes (graph, candidates, summary) with their distinct purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit workflow recommendation: 'start with summary or graph for orientation, then paginate through candidates'. Clarifies decision boundary ('MCP finds strings deterministically; the agent decides what is content'). Implicitly guides when not to use mutation siblings by emphasizing read-only safety.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Contentrain/ai'

If you have feedback or need assistance with the MCP directory API, please join our Discord server