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({}),
    });
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions creating a project structure and .trace-mcp config directory, but doesn't disclose critical behavioral traits: whether this is idempotent (can it be run multiple times?), what permissions are needed, if it overwrites existing files, or what happens on failure. For a tool that creates directories and configs, this is a significant gap.

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

Conciseness4/5

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

Two concise sentences that efficiently state the purpose and outcome. The description is front-loaded with the main action ('Initialize a trace project'), and every sentence adds value without redundancy. It could be slightly more structured by explicitly listing key behaviors, but it's appropriately sized.

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?

Given the complexity (initializing a project with multiple parameters) and no annotations or output schema, the description is incomplete. It doesn't explain what the tool returns, error conditions, or side effects. For a tool that likely creates files and directories, more context on outcomes and behaviors is needed to be fully helpful to an AI agent.

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 description coverage is 100%, so the schema already documents all 5 parameters with descriptions and enums. The description adds no parameter-specific information beyond what's in the schema. According to rules, with high schema coverage (>80%), the baseline is 3 even with no param info in description.

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

Purpose4/5

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

The description clearly states the verb 'Initialize' and resource 'trace project', specifying it creates a project structure for watch mode and caching. It distinguishes from siblings like 'get_project_status' (status check) and 'watch' (monitoring), but doesn't explicitly contrast with 'scaffold_consumer' or 'scaffold_producer' which might have overlapping initialization functions.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternatives like 'scaffold_consumer' or 'scaffold_producer'. The description implies it's for initial setup, but doesn't specify prerequisites, timing, or exclusions. Without context signals about when this should be called first versus other tools, usage is unclear.

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/Mnehmos/trace-mcp'

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