AI Dossier

MCP Server Implementation Summary

Date: 2025-11-07 Session: Completed MVP Implementation Status: βœ… Ready for testing with Claude Code


What Was Built

Core Infrastructure βœ…

  1. TypeScript Project Setup

    • Package: @ai-dossier/mcp-server v1.0.0
    • Dependencies: @modelcontextprotocol/sdk, zod
    • Build system: TypeScript β†’ CommonJS
    • Scripts: build, dev, start
  2. Project Structure

    mcp-server/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ index.ts              # MCP server entry point
    β”‚   β”œβ”€β”€ tools/                # Tool implementations
    β”‚   β”‚   β”œβ”€β”€ verifyDossier.ts  # Security verification ⭐
    β”‚   β”‚   β”œβ”€β”€ readDossier.ts    # Content retrieval
    β”‚   β”‚   └── listDossiers.ts   # Discovery
    β”‚   β”œβ”€β”€ resources/            # Resource providers
    β”‚   β”‚   β”œβ”€β”€ protocol.ts       # dossier://protocol
    β”‚   β”‚   β”œβ”€β”€ security.ts       # dossier://security
    β”‚   β”‚   └── concept.ts        # dossier://concept
    β”‚   β”œβ”€β”€ parsers/              # Dossier parsing logic
    β”‚   β”‚   β”œβ”€β”€ dossierParser.ts      # Frontmatter + body parsing
    β”‚   β”‚   β”œβ”€β”€ checksumVerifier.ts   # SHA256 verification
    β”‚   β”‚   └── signatureVerifier.ts  # minisign verification
    β”‚   β”œβ”€β”€ types/
    β”‚   β”‚   └── dossier.ts        # TypeScript definitions
    β”‚   └── utils/
    β”‚       β”œβ”€β”€ logger.ts         # Structured logging (stderr)
    β”‚       └── errors.ts         # Error types
    β”œβ”€β”€ dist/                     # Compiled JavaScript
    β”œβ”€β”€ package.json
    β”œβ”€β”€ tsconfig.json
    └── test-*.js                 # Test scripts

MCP Tools Implemented βœ…

  1. verify_dossier (CRITICAL) ⭐

    • Input: { path: string, trusted_keys_path?: string }
    • Output: Full security report with recommendation
    • Features:
      • SHA256 checksum verification (integrity)
      • minisign signature verification (authenticity)
      • Trusted keys management (~/.dossier/trusted-keys.txt)
      • Risk assessment from frontmatter
      • Returns: ALLOW, WARN, or BLOCK
    • Status: βœ… Tested successfully
  2. read_dossier

    • Input: { path: string }
    • Output: Metadata + frontmatter + body
    • Purpose: Content retrieval after verification passes
    • Status: βœ… Implemented
  3. list_dossiers

    • Input: { path?: string, recursive?: boolean }
    • Output: Array of dossier metadata
    • Features:
      • Scans for *.ds.md files
      • Recursive directory scanning
      • Parses frontmatter for metadata
      • Filters out node_modules, .git, etc.
    • Status: βœ… Tested (found all 5 examples)

MCP Resources Implemented βœ…

  1. dossier://protocol

    • Serves: PROTOCOL.md
    • Purpose: Execution protocol for LLMs
    • Status: βœ… Implemented
  2. dossier://security

    • Serves: security/ARCHITECTURE.md
    • Purpose: Security model and trust documentation
    • Status: βœ… Implemented
  3. dossier://concept

    • Serves: README.md
    • Purpose: Introduction to dossiers
    • Status: βœ… Implemented

Security Implementation ⭐

Multi-Layer Verification:

  1. Integrity (REQUIRED)

    • SHA256 checksum of dossier body
    • Detects tampering
    • BLOCKS execution if mismatch
  2. Authenticity (OPTIONAL)

    • minisign signature verification
    • Trust management (user-controlled keys)
    • Statuses: verified, signed_unknown, unsigned, invalid
  3. Risk Assessment

    • From frontmatter: low, medium, high, critical
    • Risk factors array
    • Destructive operations list
    • Approval requirements
  4. Recommendation Logic

    BLOCK: checksum invalid OR signature invalid
    ALLOW: verified signature + low risk
    WARN:  unsigned OR high risk OR unknown signer

Logging & Error Handling βœ…

  1. Structured Logging

    • JSON format to stderr (NEVER stdout - MCP protocol requirement)
    • Levels: debug, info, warn, error
    • Context-rich log entries
    • Environment variable: LOG_LEVEL
  2. Error Types

    • DossierError (base)
    • DossierParseError
    • DossierVerificationError
    • DossierNotFoundError
    • ExternalToolError

Testing Results βœ…

Test 1: Verification

Command: node test-verify.js Result: βœ… Success

{
  "integrity": {
    "status": "valid",
    "message": "Checksum matches - content has not been tampered with",
    "expectedHash": "a76760f...",
    "actualHash": "a76760f..."
  },
  "authenticity": {
    "status": "unsigned",
    "message": "No signature found - authenticity cannot be verified",
    "isTrusted": false
  },
  "riskAssessment": {
    "riskLevel": "high",
    "riskFactors": [
      "modifies_directory_structure",
      "moves_files_within_repository",
      ...
    ],
    "destructiveOperations": [
      "Moves all repository files into a new subdirectory (main/)",
      ...
    ],
    "requiresApproval": true
  },
  "recommendation": "WARN",
  "message": "WARNING: Dossier is not signed (cannot verify author). High risk level: high. Review before execution."
}

Test 2: List Dossiers

Command: node test-list.js Result: βœ… Found all 5 example dossiers

  • train-ml-model.ds.md (medium risk)
  • migrate-schema.ds.md (critical risk)
  • add-git-worktree-support.ds.md (high risk)
  • setup-react-library.ds.md (medium risk)
  • deploy-to-aws.ds.md (high risk)

How It Works

Architecture: Hybrid Verification + Delegation Model

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User: "run deploy-to-aws.ds.md"       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LLM (Claude Code)                       β”‚
β”‚  - Calls verify_dossier tool           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ MCP Server: verify_dossier              β”‚
β”‚  1. Calculate SHA256 checksum           β”‚
β”‚  2. Compare with frontmatter            β”‚
β”‚  3. Verify signature (if present)       β”‚
β”‚  4. Check trusted keys                  β”‚
β”‚  5. Assess risk level                   β”‚
β”‚  6. Return ALLOW/WARN/BLOCK             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LLM (Claude Code)                       β”‚
β”‚  - Receives verification result         β”‚
β”‚  - Shows risk info to user              β”‚
β”‚  - Requests approval if WARN/HIGH       β”‚
β”‚  - Calls read_dossier if approved       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ MCP Server: read_dossier                β”‚
β”‚  - Returns dossier content              β”‚
β”‚  - Parsed frontmatter + body            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LLM (Claude Code)                       β”‚
β”‚  - Interprets dossier instructions      β”‚
β”‚  - Adapts to project context            β”‚
β”‚  - Executes using user's tools          β”‚
β”‚  - Reports progress                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Insight: MCP server enforces security (code-level), LLM handles execution (context-adaptive).


Configuration for Claude Code

Method 1: Local Development (Current)

  1. Build the server:

    cd mcp-server
    npm install
    npm run build
  2. Configure Claude Code settings:

    {
      "mcpServers": {
        "dossier": {
          "command": "node",
          "args": ["/absolute/path/to/dossier/mcp-server/dist/index.js"],
          "cwd": "/absolute/path/to/dossier"
        }
      }
    }
  3. Restart Claude Code

Method 2: Global Install (Future - after NPM publish)

npm install -g @ai-dossier/mcp-server
{
  "mcpServers": {
    "dossier": {
      "command": "dossier-mcp-server"
    }
  }
}

What’s NOT Built Yet

Future Tools (Phase 2)

  • validate_dossier - Schema validation against SCHEMA.md
  • get_registry - Registry relationship parsing
  • Enhanced error recovery

Future Resources (Phase 2)

  • dossier://keys - Public keys list
  • dossier://examples - Example dossiers JSON

Future Features (Phase 3)

  • Prompts: execute-dossier, create-dossier, improve-dossier
  • Journey map support
  • Dependency tracking
  • Web UI for trust management
  • NPM package publishing

Key Technical Decisions

1. Checksum Calculation

CRITICAL: Hash ONLY the body (after --- closing), not entire file

const body = content.match(/^---dossier\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/m)[2];
const hash = crypto.createHash('sha256').update(body, 'utf8').digest('hex');

2. Logging to stderr

CRITICAL: MCP uses stdout for JSON-RPC messages

console.error(JSON.stringify(logEntry)); // stderr only!

3. Trust Management

Decentralized: Like PGP web of trust, not centralized PKI

  • Users manage ~/.dossier/trusted-keys.txt
  • Format: <public-key> <key-id>
  • No automatic trust

4. Risk-Based Approval

if (riskLevel === 'high' || riskLevel === 'critical') {
  return 'WARN';  // Always require approval
}

Documentation Created

  1. README.md - Updated with MVP status, configuration, roadmap
  2. CLAUDE_CODE_SETUP.md - Step-by-step setup guide
  3. MCP_SERVER_IMPLEMENTATION_SUMMARY.md - This file

Success Metrics

βœ… MVP Complete:

  • User says β€œrun dossier.ds.md” in Claude Code
  • MCP server automatically verifies checksum (code-enforced)
  • MCP server verifies signature (if present)
  • LLM receives security report with recommendation
  • LLM shows risk info to user and requests approval
  • LLM executes dossier instructions after approval
  • Security verification is automatic and code-enforced (not LLM-dependent)

Next Steps (Phase 2)

  1. Integration Testing

    • Test with Claude Code in real session
    • Verify all tools work end-to-end
    • Test with multiple dossiers
  2. NPM Package Preparation

    • Add shebang to built index.js
    • Test global install locally
    • Prepare package.json for publish
  3. Advanced Tools

    • Implement validate_dossier
    • Implement get_registry
    • Add comprehensive tests
  4. Documentation

    • Video walkthrough
    • Troubleshooting guide
    • API documentation

Timeline

  • Phase 1 (MVP): βœ… Completed in ~6 hours

    • Project setup: 1 hour
    • Core parsers: 1 hour
    • Security tools: 2 hours
    • MCP integration: 1 hour
    • Testing & docs: 1 hour
  • Phase 2 (Testing & Publishing): Target 1-2 days

  • Phase 3 (Ecosystem): Target 2-4 weeks


Handoff Notes

For Next Session:

  1. Test with Claude Code:

    • Follow CLAUDE_CODE_SETUP.md
    • Try: β€œlist available dossiers”
    • Try: β€œverify examples/development/add-git-worktree-support.ds.md”
    • Try: β€œread dossier://protocol”
  2. If Issues:

    • Check logs in Claude Code console
    • Verify absolute paths in config
    • Ensure dist/ exists (run npm run build)
    • Test manually: node mcp-server/dist/index.js
  3. Known Limitations:

    • Signature verification requires minisign installed
    • Resources use relative paths (works from project root)
    • No validation tool yet (accepts any frontmatter)
  4. Code Quality:

    • All TypeScript, no linting errors
    • Structured error handling
    • Comprehensive logging
    • Type-safe throughout

Status: Ready for real-world testing! πŸš€

Commit: Ready to be committed with message:

feat(mcp-server): implement MVP with security verification

- Add verify_dossier tool with checksum + signature verification
- Add read_dossier and list_dossiers tools
- Add dossier://protocol, security, concept resources
- Implement structured logging and error handling
- Add TypeScript types and comprehensive error types
- Test successfully with example dossiers

Ready for Claude Code integration testing.

Rendered from docs/contributing/mcp/summary.md in the repository. Edit it there.