Skip to main content
Glama

run_typecheck

Verify TypeScript code correctness by running type-checking on a specified service path, receiving structured error details for pre-commit validation.

Instructions

Run TypeScript type-checking (tsc --noEmit) for a service. Returns structured errors with file, line, column, and message. Call after writing code to verify correctness before committing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
servicePathYesRelative path from repo root to the service to typecheck. E.g. "ops/control-panel/server", "SeID/seid-core", "packages/overlay-contracts".

Implementation Reference

  • Registers the 'run_typecheck' tool on the MCP server with its schema and handler.
    server.tool(
      'run_typecheck',
      'Run TypeScript type-checking (tsc --noEmit) for a service. Returns structured errors with file, line, column, and message. Call after writing code to verify correctness before committing.',
      RunTypecheckSchema.shape,
      async (args) => {
        const result = await manager.runTypecheck(args.servicePath);
        return {
          content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],
        };
      },
    );
  • Zod schema for run_typecheck input, requiring 'servicePath' (string).
    export const RunTypecheckSchema = z.object({
      servicePath: z
        .string()
        .describe(
          'Relative path from repo root to the service to typecheck. E.g. "ops/control-panel/server", "SeID/seid-core", "packages/overlay-contracts".',
        ),
    });
  • Core handler logic: resolves path, finds tsc binary, runs 'tsc --noEmit', parses structured errors from output, returns TypecheckResult.
    async function runTypecheck(servicePath: string): Promise<TypecheckResult> {
      const absPath = resolveSafe(repoDir, servicePath);
    
      // Prefer local tsc, fall back to workspace root, then PATH
      const localTsc = join(absPath, 'node_modules', '.bin', 'tsc');
      const rootTsc = join(repoDir, 'node_modules', '.bin', 'tsc');
      const tscBin = existsSync(localTsc) ? localTsc : existsSync(rootTsc) ? rootTsc : 'tsc';
    
      const hasTsConfig = existsSync(join(absPath, 'tsconfig.json'));
      const args = ['--noEmit'];
      if (hasTsConfig) args.push('-p', 'tsconfig.json');
    
      const result = await proc.run(tscBin, args, { cwd: absPath, timeout: 90_000 });
      const combined = (result.stdout + result.stderr).trim();
      const errors = parseTscOutput(combined, repoDir);
    
      return {
        success: result.success && errors.length === 0,
        errorCount: errors.length,
        errors,
        raw: combined.slice(0, 5_000),
      };
    }
  • Helper that parses raw tsc stdout/stderr into structured TypecheckError[] using regex.
    const TSC_ERROR_RE = /^(.+?)\((\d+),(\d+)\):\s+error\s+(TS\d+):\s+(.+)$/gm;
    
    function parseTscOutput(output: string, repoDir: string): TypecheckError[] {
      const errors: TypecheckError[] = [];
      let match: RegExpExecArray | null;
      TSC_ERROR_RE.lastIndex = 0;
      while ((match = TSC_ERROR_RE.exec(output)) !== null) {
        const rawFile = match[1] ?? '';
        const line = match[2] ?? '0';
        const col = match[3] ?? '0';
        const code = match[4] ?? '';
        const message = match[5] ?? '';
        const file = rawFile.startsWith(repoDir)
          ? rawFile.slice(repoDir.length + 1)
          : rawFile.trim();
        errors.push({
          file,
          line: parseInt(line, 10),
          col: parseInt(col, 10),
          code: code.trim(),
          message: message.trim(),
        });
      }
      return errors;
    }
  • Factory that creates the process runner (execFileAsync) used by runTypecheck to invoke tsc.
    export function createProcessAccess(): ProcessAccess {
      async function run(
        cmd: string,
        args: string[],
        options: { cwd: string; timeout?: number; env?: Record<string, string> },
      ): Promise<ProcessResult> {
        const timeout = options.timeout ?? 120_000;
        try {
          const { stdout, stderr } = await execFileAsync(cmd, args, {
            cwd: options.cwd,
            timeout,
            env: { ...process.env, ...(options.env ?? {}) },
            maxBuffer: 10 * 1024 * 1024, // 10MB
          });
          return { stdout, stderr, exitCode: 0, success: true };
        } catch (err: unknown) {
          const e = err as { stdout?: string; stderr?: string; code?: number };
          return {
            stdout: e.stdout ?? '',
            stderr: e.stderr ?? '',
            exitCode: typeof e.code === 'number' ? e.code : 1,
            success: false,
          };
        }
      }
    
      return { run };
    }
Behavior4/5

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

Discloses that it runs tsc --noEmit (no output files) and returns structured errors with file, line, column, and message. No annotations provided, but description covers main behavioral aspects for a type-check tool.

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?

Two sentences, front-loaded with action and return format, then usage guidance. Every sentence adds value with no waste.

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

Completeness5/5

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

Given the simplicity (one parameter, no output schema, no nested objects), the description is fully adequate: it explains what the tool does, what it returns, and when to call it.

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

Parameters3/5

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

Schema has 100% coverage with a description for servicePath. The tool description does not add additional meaning beyond what the schema provides, so baseline of 3 is appropriate.

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?

Clearly states the action: run TypeScript type-checking (tsc --noEmit) for a service. Distinguishes from siblings like run_tests and search_code by specifying it's for TypeScript type-checking and returning structured errors.

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

Usage Guidelines4/5

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

Explicitly advises calling 'after writing code to verify correctness before committing.' Provides clear context for when to use the tool, though does not mention alternatives or when not to use it.

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/2loch-ness6/mempalace-mcp-dev'

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