Skip to content

πŸ“š Add JSDoc Documentation with Docdash TemplateΒ #67

@ahelme

Description

@ahelme

Overview

Implement comprehensive JSDoc documentation across all components using the modern docdash template to enhance developer experience and maintain consistency with our existing API documentation infrastructure.

🎯 Scope

Add JSDoc documentation generation for:

  1. MCP Server (.mjs) - Model Context Protocol implementation
  2. HTTP Bridge (.mjs) - Middleware layer between Chrome extension and MCP server
  3. Chrome Extension (.js) - Browser-based monitoring and communication layer
  4. Documentation Server (.mjs) - API documentation hosting and aggregation service

πŸ“‹ Requirements

Core Implementation

  • Install and configure JSDoc with docdash template
  • Create JSDoc configuration file (jsdoc.conf.json)
  • Add comprehensive JSDoc comments to all modules
  • Generate static documentation site
  • Integrate with existing documentation server at localhost:3020

Documentation Coverage

  • MCP Server: Document all MCP protocol implementations, tool definitions, and AI client compatibility
  • HTTP Bridge: Document middleware functions, WebSocket handlers, truncation logic, and security filtering
  • Chrome Extension: Document XHR monitoring, DOM tracking, WebSocket communication, and user configuration
  • Documentation Server: Document endpoint routing, static file serving, health checks, and API aggregation logic

Integration Requirements

  • Add documentation build scripts to package.json
  • Update start-docs.sh to include JSDoc-generated content
  • Add JSDoc endpoint to documentation portal (e.g., http://localhost:3020/jsdoc)
  • Ensure documentation builds are included in CI/CD pipeline

πŸ› οΈ Technical Specifications

JSDoc Configuration

{
  "source": {
    "include": [
      "./src/", 
      "./chrome-extension/", 
      "./http-bridge/",
      "./docs-server/"
    ],
    "includePattern": "\\.(js|mjs)$"
  },
  "opts": {
    "destination": "./docs/jsdoc/",
    "recurse": true
  },
  "plugins": ["plugins/markdown"],
  "templates": {
    "cleverLinks": false,
    "monospaceLinks": false
  }
}

package.json Updates

{
  "scripts": {
    "docs:build": "jsdoc -c jsdoc.conf.json",
    "docs:watch": "jsdoc -c jsdoc.conf.json --watch",
    "docs:serve": "npm run docs:build && ./chrome-extension/start-docs.sh",
    "start": "./start_all.sh",
    "dev": "npm run docs:watch & ./start_all.sh"
  }
}

Documentation Standards

πŸ”§ File Extension Best Practices

Recommended structure:

  • MCP Server: Keep as .mjs βœ… (ES modules for Node.js)
  • HTTP Bridge: Keep as .mjs βœ… (ES modules for Node.js)
  • Documentation Server: Keep as .mjs βœ… (ES modules for Node.js)
  • Chrome Extension: Keep as .js βœ… (Browser environment, Chrome extension manifest system)

Rationale: Chrome extensions use their own module system via manifest.json and run in browser context, while Node.js components benefit from explicit ES module declaration.

πŸ“š Integration with Existing Docs

Update documentation portal to include:

πŸ“š Documentation Portal: http://localhost:3020/docs
β”œβ”€β”€ πŸ”— REST API docs: /rest-docs
β”œβ”€β”€ πŸ”Œ WebSocket docs: /ws-docs  
β”œβ”€β”€ πŸ“– JSDoc API docs: /jsdoc          # NEW
β”œβ”€β”€ πŸ“„ OpenAPI spec: /openapi.yaml
β”œβ”€β”€ πŸ“‘ AsyncAPI spec: /asyncapi.yaml
└── πŸ€– AI-discoverable: /health

✨ Best Practice Recommendations

1. Unified Development Experience

# Simple startup commands
./start_all.sh                    # Start everything
npm start                         # Alias for start_all.sh
npm run dev                       # Development mode with doc watching

2. Type Annotations

Use JSDoc for type safety without TypeScript:

javascript/**
 * @param {string} elementSelector - CSS selector for DOM element
 * @param {Object} options - Configuration options
 * @param {number} options.maxTokens - Maximum token limit
 * @param {boolean} options.includeCookies - Whether to include cookies
 * @returns {Promise<Object>} Processed element data
 */

2. Service Orchestration

  • Dependency checking before startup
  • Health checks to verify service readiness
  • Graceful shutdown handling with proper cleanup
  • Process management with PID tracking
  • Colored output for better developer experience

3. Documentation Server Specific Coverage

Document the documentation server's:

  • Route handlers for each endpoint (/docs, /rest-docs, /ws-docs, etc.)
  • Static file serving logic for OpenAPI/AsyncAPI specs
  • Health endpoint metadata aggregation
  • CORS configuration for cross-origin access
  • Content-type handling for different documentation formats

4. Cross-Component Documentation

  • Link related functions across components using @see tags
  • Document data flow: Chrome extension β†’ HTTP bridge β†’ MCP server
  • Document how documentation server aggregates and serves all specs
  • Include startup and shutdown procedures in JSDoc

5. AI-Friendly Documentation

  • Ensure JSDoc output is accessible via /health endpoint metadata
  • Include service orchestration patterns for AI clients
  • Document the complete startup pipeline for automated deployment

🎯 Success Criteria

  • All public APIs documented with JSDoc across all four components
  • Single command startup (./start_all.sh) works reliably
  • Documentation integrates seamlessly with existing portal
  • Build process is automated and includes health checks
  • Documentation is discoverable by AI agents via existing endpoints
  • Service dependencies and startup order are properly managed
  • Graceful shutdown and error handling implemented

πŸ”— Related Documentation

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions