create_type_definition
Generate TypeScript type definitions or interfaces by specifying type name, file path, and properties. Simplify development with automated type creation for Node.js projects.
Instructions
Create TypeScript type definitions or interfaces
Input Schema
TableJSON 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 validates the path, generates a TypeScript interface from the provided properties, writes it to a .ts file, and returns success message or throws error.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:301-323 (registration)Registers the 'create_type_definition' tool in the MCP server with its description and input schema defining name, path, and properties.{ 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:49-53 (schema)TypeScript interface defining the expected arguments for the create_type_definition handler.interface CreateTypeDefinitionArgs extends Record<string, unknown> { name: string; path: string; properties: Record<string, string>; }
- src/index.ts:401-402 (handler)Switch case in the main tool request handler that dispatches to the specific create_type_definition handler.case 'create_type_definition': return await this.handleCreateTypeDefinition(args as CreateTypeDefinitionArgs);