create_documentation
Generate project documentation for Node.js applications, including README files, API documentation, and component documentation based on specified paths and types.
Instructions
Generate project documentation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Project directory path | |
| type | Yes | Documentation type | |
| name | No | Component or API name for specific documentation |
Implementation Reference
- src/index.ts:992-1037 (handler)The main handler function implementing the create_documentation tool. It validates the path, generates documentation content based on the specified type (readme, api, or component), writes it to a file, stores it in memory, and returns a success message.private async handleCreateDocumentation(args: CreateDocumentationArgs) { await this.validatePath(args.path); try { let content = ''; let fileName = ''; switch (args.type) { case 'readme': content = await this.generateProjectDocumentation(args.path); fileName = 'README.md'; break; case 'api': content = await this.generateApiDocumentation(args.path); fileName = 'API.md'; break; case 'component': if (!args.name) { throw new McpError(ErrorCode.InvalidParams, 'Component name is required for component documentation'); } content = await this.generateComponentDoc(args.path, args.name); fileName = `${args.name}.md`; break; } const docPath = path.join(args.path, fileName); await fs.writeFile(docPath, content); // Store in memory for resource access this.projectDocs.set(path.basename(args.path), content); return { content: [ { type: 'text', text: `Documentation created successfully at ${docPath}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to create documentation: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:365-387 (registration)Tool registration in the ListToolsRequestSchema response, defining the name, description, and JSON input schema for the create_documentation tool.{ name: 'create_documentation', description: 'Generate project documentation', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Project directory path', }, type: { type: 'string', enum: ['readme', 'api', 'component'], description: 'Documentation type', }, name: { type: 'string', description: 'Component or API name for specific documentation', }, }, required: ['path', 'type'], }, },
- src/index.ts:66-70 (schema)TypeScript interface defining the shape of arguments for the create_documentation handler.interface CreateDocumentationArgs extends Record<string, unknown> { path: string; type: 'readme' | 'api' | 'component'; name?: string; }
- src/index.ts:407-408 (registration)Dispatch case in the CallToolRequestSchema handler that routes calls to the create_documentation handler function.case 'create_documentation': return await this.handleCreateDocumentation(args as CreateDocumentationArgs);
- src/index.ts:1039-1069 (helper)Helper function that generates README-style project documentation by reading and formatting the package.json file.private async generateProjectDocumentation(projectPath: string): Promise<string> { const packageJson = JSON.parse( await fs.readFile(path.join(projectPath, 'package.json'), 'utf-8') ); return `# ${packageJson.name} ## Description ${packageJson.description || 'A Node.js project'} ## Installation \`\`\`bash npm install \`\`\` ## Scripts ${Object.entries(packageJson.scripts || {}) .map(([name, command]) => `- \`npm run ${name}\`: ${command}`) .join('\n')} ## Dependencies ${Object.entries(packageJson.dependencies || {}) .map(([name, version]) => `- \`${name}\`: ${version}`) .join('\n')} ## Dev Dependencies ${Object.entries(packageJson.devDependencies || {}) .map(([name, version]) => `- \`${name}\`: ${version}`) .join('\n')} `; }