Skip to main content
Glama

init_project

Initialize a trace project structure with configuration directory for watch mode and caching. Sets up producer and consumer code paths to validate schema contracts and prevent runtime errors.

Instructions

Initialize a trace project with .trace-mcp config directory. Creates project structure for watch mode and caching.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectDirYesRoot directory for the trace project
producerPathYesRelative path to producer/server code
consumerPathYesRelative path to consumer/client code
producerLanguageNoProducer language (default: typescript)
consumerLanguageNoConsumer language (default: typescript)

Implementation Reference

  • Main handler logic for the 'init_project' tool within the CallToolRequestSchema switch statement. Parses input, loads project, initializes if new, and returns JSON response.
    case 'init_project': {
      const input = InitProjectInput.parse(args);
      log(`Initializing trace project at: ${input.projectDir}`);
      
      const project = loadProject(input.projectDir);
      
      if (project.exists()) {
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              success: false,
              error: `Project already exists at ${input.projectDir}. Use get_project_status to view it.`,
            }, null, 2),
          }],
        };
      }
      
      const config = project.init({
        producer: {
          path: input.producerPath,
          language: input.producerLanguage || 'typescript',
          include: ['**/*.ts'],
          exclude: ['**/*.test.ts', '**/node_modules/**', '**/dist/**'],
        },
        consumer: {
          path: input.consumerPath,
          language: input.consumerLanguage || 'typescript',
          include: ['**/*.ts', '**/*.tsx'],
          exclude: ['**/*.test.ts', '**/node_modules/**', '**/dist/**'],
        },
      });
      
      log(`Project initialized with config:`, config);
      
      return {
        content: [{
          type: 'text',
          text: JSON.stringify({
            success: true,
            projectDir: input.projectDir,
            traceDir: project.traceDir,
            config,
          }, null, 2),
        }],
      };
    }
  • Zod schema definition for init_project input validation, used in handler parse().
    const InitProjectInput = z.object({
      projectDir: z.string().describe('Root directory for the trace project'),
      producerPath: z.string().describe('Relative path to producer/server code'),
      consumerPath: z.string().describe('Relative path to consumer/client code'),
      producerLanguage: z.enum(['typescript', 'python', 'go', 'rust', 'json_schema']).optional().default('typescript'),
      consumerLanguage: z.enum(['typescript', 'python', 'go', 'rust', 'json_schema']).optional().default('typescript'),
    });
  • src/index.ts:237-251 (registration)
    Registration of 'init_project' tool in ListToolsRequestSchema response, defining name, description, and JSON input schema.
    {
      name: 'init_project',
      description: 'Initialize a trace project with .trace-mcp config directory. Creates project structure for watch mode and caching.',
      inputSchema: {
        type: 'object',
        properties: {
          projectDir: { type: 'string', description: 'Root directory for the trace project' },
          producerPath: { type: 'string', description: 'Relative path to producer/server code' },
          consumerPath: { type: 'string', description: 'Relative path to consumer/client code' },
          producerLanguage: { type: 'string', enum: ['typescript', 'python', 'go', 'rust', 'json_schema'], description: 'Producer language (default: typescript)' },
          consumerLanguage: { type: 'string', enum: ['typescript', 'python', 'go', 'rust', 'json_schema'], description: 'Consumer language (default: typescript)' },
        },
        required: ['projectDir', 'producerPath', 'consumerPath'],
      },
    },
  • TraceProject.init() method: core logic called by handler to create .trace-mcp directories, parse/write config.json, and .gitignore.
    init(config: Partial<ProjectConfig>): ProjectConfig {
      // Create directories
      mkdirSync(this.traceDir, { recursive: true });
      mkdirSync(this.cachePath, { recursive: true });
      mkdirSync(this.contractsPath, { recursive: true });
      mkdirSync(this.reportsPath, { recursive: true });
    
      // Create config with defaults
      const fullConfig = ProjectConfigSchema.parse(config);
      
      // Write config
      writeFileSync(this.configPath, JSON.stringify(fullConfig, null, 2));
      this._config = fullConfig;
    
      // Create .gitignore for cache
      writeFileSync(
        join(this.traceDir, '.gitignore'),
        '# Trace MCP cache (regenerated)\ncache/\nreports/\n'
      );
    
      return fullConfig;
    }
  • ProjectConfigSchema: Zod schema for validating project configuration used in TraceProject.init().
    export const ProjectConfigSchema = z.object({
      version: z.string().default('1.0.0'),
      producer: z.object({
        path: z.string(),
        language: z.enum(['typescript', 'python', 'go', 'rust', 'json_schema']).default('typescript'),
        include: z.array(z.string()).optional().default(['**/*.ts']),
        exclude: z.array(z.string()).optional().default(['**/*.test.ts', '**/node_modules/**', '**/dist/**']),
      }),
      consumer: z.object({
        path: z.string(),
        language: z.enum(['typescript', 'python', 'go', 'rust', 'json_schema']).default('typescript'),
        include: z.array(z.string()).optional().default(['**/*.ts', '**/*.tsx']),
        exclude: z.array(z.string()).optional().default(['**/*.test.ts', '**/node_modules/**', '**/dist/**']),
      }),
      options: z.object({
        strict: z.boolean().default(false),
        direction: z.enum(['producer_to_consumer', 'consumer_to_producer', 'bidirectional']).default('producer_to_consumer'),
        debounceMs: z.number().default(300),
        autoWatch: z.boolean().default(true),
      }).default({}),
    });

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.6/5.0
Behavior3/5

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

No annotations provided. Description says it creates project structure, but doesn't disclose idempotency, overwrite behavior, or side effects. Adequate but could be more transparent.

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 concise sentences with no wasted words. Action verb front-loaded. Every sentence adds value.

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

Completeness2/5

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

For a setup tool with 5 parameters and no output schema, description is too minimal. Does not explain return value, what files are created, or what happens if project already exists. Incomplete for effective agent usage.

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 coverage is 100%; each parameter is documented in schema. Description adds no additional parameter context beyond schema. Baseline score 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?

Description clearly states verb (initialize) and resource (trace project), and specifies what it creates (.trace-mcp config directory, project structure for watch mode and caching). Distinguishes from siblings like scaffold_consumer which focus on code scaffolding.

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

Usage Guidelines3/5

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

Implies use when starting a trace project, but no explicit guidance on when to use vs alternatives like scaffold_consumer or get_project_status. No exclusions or prerequisites mentioned.

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