update_tsconfig
Modify TypeScript compiler settings in a project directory to configure build behavior and development environment.
Instructions
Update TypeScript configuration
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Project directory path | |
| options | Yes | TypeScript compiler options |
Implementation Reference
- src/index.ts:915-962 (handler)The handler function that reads (or creates) tsconfig.json, merges the provided options into compilerOptions, writes it back, and returns a success message. Uses validatePath helper.private async handleUpdateTsConfig(args: UpdateTsConfigArgs) { await this.validatePath(args.path); try { const tsconfigPath = path.join(args.path, 'tsconfig.json'); interface TsConfig { compilerOptions: Record<string, unknown>; include?: string[]; exclude?: string[]; } let tsconfig: TsConfig = { compilerOptions: {} }; try { tsconfig = JSON.parse(await fs.readFile(tsconfigPath, 'utf-8')) as TsConfig; } catch { // Create new tsconfig if it doesn't exist tsconfig = { compilerOptions: {}, include: ["src/**/*"], exclude: ["node_modules", "dist"] }; } // Deep merge the new options tsconfig.compilerOptions = { ...tsconfig.compilerOptions, ...args.options, }; await fs.writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2)); return { content: [ { type: 'text', text: `Updated TypeScript configuration at ${tsconfigPath}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to update TypeScript configuration: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:346-364 (registration)The tool registration in ListToolsRequestSchema, defining name, description, and inputSchema for MCP tool listing.{ name: 'update_tsconfig', description: 'Update TypeScript configuration', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Project directory path', }, options: { type: 'object', description: 'TypeScript compiler options', additionalProperties: true, }, }, required: ['path', 'options'], }, },
- src/index.ts:61-64 (schema)TypeScript interface defining the arguments for the update_tsconfig handler.interface UpdateTsConfigArgs extends Record<string, unknown> { path: string; options: Record<string, unknown>; }
- src/index.ts:405-406 (registration)The switch case in CallToolRequestSchema handler that routes to the specific tool handler.case 'update_tsconfig': return await this.handleUpdateTsConfig(args as UpdateTsConfigArgs);
- src/index.ts:920-924 (schema)Local interface used within the handler for typing the tsconfig.json structure.interface TsConfig { compilerOptions: Record<string, unknown>; include?: string[]; exclude?: string[]; }