create_type_definition
Generate TypeScript type definitions or interfaces by specifying name, file path, and properties to structure your Node.js project's data types.
Instructions
Create TypeScript type definitions or interfaces
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Type name | |
| path | Yes | File path | |
| properties | Yes | Type properties and their types |
Implementation Reference
- src/index.ts:854-882 (handler)The handler function that implements the create_type_definition tool by generating and writing a TypeScript interface file based on the provided name, path, and properties.
private async handleCreateTypeDefinition(args: CreateTypeDefinitionArgs) { await this.validatePath(args.path); const typeContent = `export interface ${args.name} { ${Object.entries(args.properties) .map(([key, type]) => `${key}: ${type};`) .join('\n ')} } `; const filePath = path.join(args.path, `${args.name}.ts`); try { await fs.writeFile(filePath, typeContent); return { content: [ { type: 'text', text: `Type definition ${args.name} created successfully at ${filePath}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to create type definition: ${error instanceof Error ? error.message : String(error)}` ); } } - src/index.ts:49-53 (schema)TypeScript interface defining the input arguments for the create_type_definition tool.
interface CreateTypeDefinitionArgs extends Record<string, unknown> { name: string; path: string; properties: Record<string, string>; } - src/index.ts:301-323 (registration)Registration of the create_type_definition tool in the ListToolsRequestSchema response, including its input schema.
{ name: 'create_type_definition', description: 'Create TypeScript type definitions or interfaces', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Type name', }, path: { type: 'string', description: 'File path', }, properties: { type: 'object', description: 'Type properties and their types', additionalProperties: { type: 'string' }, }, }, required: ['name', 'path', 'properties'], }, }, - src/index.ts:401-402 (registration)Dispatch case in the CallToolRequestSchema handler that routes to the create_type_definition handler.
case 'create_type_definition': return await this.handleCreateTypeDefinition(args as CreateTypeDefinitionArgs);