refactor.ts•9.07 kB
import { Tool } from '@modelcontextprotocol/sdk/types.js';
export const refactorTools: Tool[] = [
{
name: 'refactor_for_project',
description: 'Refactor code from a repository to fit a specific target project structure and conventions',
inputSchema: {
type: 'object',
properties: {
url: {
type: 'string',
description: 'GitHub repository URL',
},
targetProject: {
type: 'object',
properties: {
framework: {
type: 'string',
description: 'Target framework (e.g., "react", "vue", "angular")',
},
language: {
type: 'string',
description: 'Target language (e.g., "typescript", "javascript")',
},
structure: {
type: 'object',
description: 'Target project structure and conventions',
},
},
required: ['framework'],
},
refactorOptions: {
type: 'object',
properties: {
namingConvention: {
type: 'string',
enum: ['camelCase', 'snake_case', 'kebab-case', 'PascalCase'],
description: 'Naming convention to apply',
},
modernizationLevel: {
type: 'string',
enum: ['minimal', 'moderate', 'aggressive'],
description: 'Level of modernization to apply',
default: 'moderate',
},
removeProjectSpecific: {
type: 'boolean',
description: 'Remove project-specific code and dependencies',
default: true,
},
extractComponents: {
type: 'boolean',
description: 'Extract reusable components',
default: true,
},
addTypeScript: {
type: 'boolean',
description: 'Convert to TypeScript if applicable',
default: false,
},
},
},
filesToRefactor: {
type: 'array',
items: { type: 'string' },
description: 'Specific files to refactor (optional - refactors all if not specified)',
},
},
required: ['url', 'targetProject'],
},
},
{
name: 'extract_reusable_components',
description: 'Identify and extract reusable components from a repository',
inputSchema: {
type: 'object',
properties: {
url: {
type: 'string',
description: 'GitHub repository URL',
},
componentTypes: {
type: 'array',
items: {
type: 'string',
enum: ['ui-components', 'hooks', 'utilities', 'services', 'models', 'types'],
},
description: 'Types of components to extract',
},
minReusabilityScore: {
type: 'number',
description: 'Minimum reusability score (0-100)',
default: 60,
},
includeDependencies: {
type: 'boolean',
description: 'Include component dependencies',
default: true,
},
},
required: ['url'],
},
},
{
name: 'adapt_dependencies',
description: 'Adapt import paths and dependencies to match target project structure',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description: 'Source code to adapt',
},
dependencyMappings: {
type: 'object',
description: 'Mapping of old dependencies to new ones',
},
targetStructure: {
type: 'object',
properties: {
srcPath: {
type: 'string',
description: 'Path to source directory',
},
aliasMapping: {
type: 'object',
description: 'Path alias mappings',
},
},
},
language: {
type: 'string',
description: 'Programming language',
},
},
required: ['code'],
},
},
{
name: 'transform_naming_conventions',
description: 'Transform code to use different naming conventions',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description: 'Source code to transform',
},
fromConvention: {
type: 'string',
enum: ['camelCase', 'snake_case', 'kebab-case', 'PascalCase'],
description: 'Source naming convention',
},
toConvention: {
type: 'string',
enum: ['camelCase', 'snake_case', 'kebab-case', 'PascalCase'],
description: 'Target naming convention',
},
scope: {
type: 'array',
items: {
type: 'string',
enum: ['variables', 'functions', 'classes', 'files', 'folders'],
},
description: 'Scope of transformation',
default: ['variables', 'functions'],
},
preserveConstants: {
type: 'boolean',
description: 'Preserve constant naming (UPPER_CASE)',
default: true,
},
},
required: ['code', 'fromConvention', 'toConvention'],
},
},
{
name: 'modernize_code',
description: 'Modernize code to use latest language features and patterns',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description: 'Source code to modernize',
},
language: {
type: 'string',
description: 'Programming language',
},
targetVersion: {
type: 'string',
description: 'Target language version (e.g., "ES2022", "Python 3.10")',
},
transformations: {
type: 'array',
items: { type: 'string' },
description: 'Specific transformations to apply',
},
preserveCompatibility: {
type: 'boolean',
description: 'Preserve backward compatibility',
default: false,
},
},
required: ['code', 'language'],
},
},
{
name: 'remove_project_coupling',
description: 'Remove project-specific coupling and make code more generic',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description: 'Source code to decouple',
},
language: {
type: 'string',
description: 'Programming language',
},
couplingTypes: {
type: 'array',
items: {
type: 'string',
enum: ['hard-coded-values', 'specific-apis', 'tight-dependencies', 'environment-specific'],
},
description: 'Types of coupling to remove',
},
replacementStrategy: {
type: 'string',
enum: ['parameters', 'config', 'interfaces', 'injection'],
description: 'Strategy for replacing coupled code',
default: 'parameters',
},
},
required: ['code', 'language'],
},
},
{
name: 'optimize_performance',
description: 'Apply performance optimizations to code',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description: 'Source code to optimize',
},
language: {
type: 'string',
description: 'Programming language',
},
optimizationTypes: {
type: 'array',
items: {
type: 'string',
enum: ['memory', 'cpu', 'io', 'network', 'rendering'],
},
description: 'Types of optimizations to apply',
},
targetEnvironment: {
type: 'string',
enum: ['browser', 'node', 'mobile', 'server'],
description: 'Target runtime environment',
},
preserveReadability: {
type: 'boolean',
description: 'Preserve code readability',
default: true,
},
},
required: ['code', 'language'],
},
},
{
name: 'add_error_handling',
description: 'Add comprehensive error handling to code',
inputSchema: {
type: 'object',
properties: {
code: {
type: 'string',
description: 'Source code to enhance',
},
language: {
type: 'string',
description: 'Programming language',
},
errorHandlingStyle: {
type: 'string',
enum: ['try-catch', 'promises', 'result-type', 'exceptions'],
description: 'Error handling style to use',
},
includeLogs: {
type: 'boolean',
description: 'Include logging statements',
default: true,
},
includeValidation: {
type: 'boolean',
description: 'Include input validation',
default: true,
},
},
required: ['code', 'language'],
},
},
];