# Discovery UX Implementation Plan
**Project:** code-executor-mcp
**Version:** 0.4.0 → 0.5.0
**Date:** 2025-11-12
**Status:** Plan - Awaiting Approval
---
## Executive Summary
**Problem:** AI agents using code-executor-mcp don't know discovery tools exist (`discoverMCPTools`, `getToolSchema`, `searchTools`) because they're hidden inside the sandbox, only visible after execution starts.
**Solution:** Multi-layer discovery awareness (Option C from Zen consensus) - enhance server-side hints without breaking progressive disclosure.
**Zen Consensus:** 2/2 models (Gemini-2.5-Pro, O3-Mini) voted for Option C with 9/10 confidence.
**Token Impact:** +150 tokens (560 → 710 tokens, still 29% under 1000 token budget)
**Outcome:** 4 redundant discovery touchpoints, preserves 98% token reduction, client-agnostic portability.
---
## Table of Contents
1. [Problem Statement](#problem-statement)
2. [Zen Consensus Analysis](#zen-consensus-analysis)
3. [Proposed Solution](#proposed-solution)
4. [Technical Implementation](#technical-implementation)
5. [Testing Strategy](#testing-strategy)
6. [Success Criteria](#success-criteria)
7. [Rollout Plan](#rollout-plan)
8. [Risk Mitigation](#risk-mitigation)
9. [Future Enhancements](#future-enhancements)
---
## 1. Problem Statement
### Current State
**Architecture:**
- Progressive disclosure: Only 3 top-level tools visible to AI agents (~560 tokens)
- Discovery functions (`discoverMCPTools`, `getToolSchema`, `searchTools`) exist but are "hidden" in sandbox
- Goal: Maintain 98% token reduction vs exposing all MCP tools upfront
**Problem:**
- AI agents don't know discovery tools exist
- No hints, examples, or guidance in top-level schemas
- Agents must read documentation or stumble upon discovery by accident
- Low discovery adoption despite powerful feature (added in v0.4.0)
### User Requirements (from Elicitation)
✓ Enhanced tool descriptions (add examples to executeTypescript schema)
✓ Injected code comments (JSDoc in sandbox globals)
✓ Keep discovery sandbox-only (NO 4th top-level tool)
✓ Conditional startup hints (show on first execution)
✓ Agents learn WHEN using executeTypescript, not just on failures
### Impact
**Without Discovery Tools:**
- Agents repeatedly ask "what tools are available?"
- Manual tool name lookup required
- Poor UX, slows development velocity
- Underutilization of v0.4.0 discovery feature
**With Discovery Tools (if agents know they exist):**
- Self-service tool exploration
- Faster development cycles
- Better UX, natural workflow
- Full utilization of progressive disclosure architecture
---
## 2. Zen Consensus Analysis
### Options Evaluated
**A. Claude Code Hook (Pre-Tool-Use Injection)**
- Token cost: 0 (client-side)
- Portability: ❌ Claude Code only
- Verdict: Rejected - not portable
**B. New Top-Level Tool (listAvailableTools)**
- Token cost: +200 (breaks progressive disclosure)
- Portability: ✅ Client-agnostic
- Verdict: Rejected - defeats core architecture goal
**C. Multi-Layer In-Server (Enhanced Description + JSDoc + Banner + Errors)**
- Token cost: +150 (710 total, 29% under budget)
- Portability: ✅ Client-agnostic
- Verdict: ✅ APPROVED - 9/10 confidence from 2/2 models
**D. Hybrid (Hook + Multi-Layer)**
- Token cost: +150 server + 0 client
- Portability: ⚠️ Optional client enhancement
- Verdict: Optional enhancement to C
**E. Conditional Tool (Dynamic Schema)**
- Token cost: 0-200 (adaptive)
- Portability: ✅ Client-agnostic
- Verdict: Rejected - too complex, non-standard MCP pattern
### Consensus Results
**Models Consulted:**
- ✅ Gemini-2.5-Pro: Vote C - Confidence 9/10
- ✅ O3-Mini: Vote C - Confidence 9/10
**Key Consensus Quotes:**
**Gemini-2.5-Pro:**
> "Option C aligns best with the project's core goals. It preserves the primary achievement of progressive disclosure (98% token reduction) by adding only a modest 150 tokens. Crucially, as a server-side solution, it is client-agnostic, fitting the architectural goal of a portable protocol."
**O3-Mini:**
> "Option C preserves token efficiency by only adding 150 tokens while meeting the token reduction goals better than alternatives with higher overhead. It is fully portable, working across different MCP clients by relying on server enhancements rather than client-specific hooks."
### Decision: Option C (Multi-Layer In-Server)
**Rationale:**
1. **Portability:** Works on ALL MCP clients (Claude Code, Continue, Cline, etc.)
2. **Token Efficiency:** +150 tokens preserves progressive disclosure (still 98% reduction)
3. **Discoverability:** 4 redundant touchpoints maximize awareness
4. **Maintenance:** Centralized server changes, straightforward implementation
5. **Industry Best Practice:** Multi-channel communication proven in UX design
---
## 3. Proposed Solution
### Solution Overview: Multi-Layer Discovery Awareness
**4 Independent Discovery Touchpoints:**
1. **Layer 1:** Enhanced Tool Description (+150 tokens, always visible)
2. **Layer 2:** JSDoc Comments (0 tokens, visible during coding)
3. **Layer 3:** Conditional Startup Banner (0 tokens, first execution only)
4. **Layer 4:** Enhanced Error Messages (0 tokens, reactive fallback)
### Layer 1: Enhanced Tool Description
**Location:** `src/index.ts` - `executeTypescript` tool definition
**Current Description:**
```typescript
description: "Execute TypeScript code in a Deno sandbox with access to MCP tools."
```
**Enhanced Description:**
```typescript
description: `Execute TypeScript code in a Deno sandbox with access to MCP tools.
🔍 Discovery functions available in sandbox:
- discoverMCPTools(options?) - Find all available MCP tools
- getToolSchema(toolName) - Get detailed schema for a specific tool
- searchTools(query, limit?) - Search tools by keywords
Example workflow:
const tools = await discoverMCPTools({ search: ['file'] });
const schema = await getToolSchema(tools[0].name);
const result = await callMCPTool(tools[0].name, { path: '/path' });`
```
**Token Cost:** ~150 tokens
**Visibility:** Always visible in top-level MCP schema
**Benefit:** Agents see discovery hint before executing any code
---
### Layer 2: JSDoc Comments
**Location:** `src/executors/typescript-executor.ts` - injected sandbox code
**Current Code:**
```typescript
globalThis.discoverMCPTools = async (options) => { /* implementation */ };
globalThis.getToolSchema = async (toolName) => { /* implementation */ };
globalThis.searchTools = async (query, limit = 10) => { /* implementation */ };
```
**Enhanced Code:**
```typescript
/**
* Discover all available MCP tools with optional keyword filtering.
* @param {Object} options - Optional configuration
* @param {string[]} options.search - Array of keywords for OR-logic filtering
* @returns {Promise<ToolSchema[]>} Array of tool schemas
* @example
* // Get all tools
* const allTools = await discoverMCPTools();
*
* // Filter by keywords
* const fileTools = await discoverMCPTools({ search: ['file', 'read'] });
*/
globalThis.discoverMCPTools = async (options) => { /* implementation */ };
/**
* Get detailed JSON Schema for a specific MCP tool.
* @param {string} toolName - Full tool name (e.g., 'mcp__filesystem__read_file')
* @returns {Promise<ToolSchema|null>} Tool schema or null if not found
* @example
* const schema = await getToolSchema('mcp__filesystem__read_file');
* console.log(schema.parameters); // JSON Schema for parameters
*/
globalThis.getToolSchema = async (toolName) => { /* implementation */ };
/**
* Search MCP tools by keywords with result limiting.
* @param {string} query - Space-separated keywords (OR logic, case-insensitive)
* @param {number} limit - Maximum results to return (default: 10)
* @returns {Promise<ToolSchema[]>} Filtered and limited tool schemas
* @example
* const tools = await searchTools('file read write', 5);
* // Returns top 5 tools matching any of: file, read, write
*/
globalThis.searchTools = async (query, limit = 10) => { /* implementation */ };
```
**Token Cost:** 0 (not in top-level schema, only visible in sandbox)
**Visibility:** Visible during code writing (IDE autocomplete, agent code inspection)
**Benefit:** Detailed usage examples when agents explore sandbox environment
---
### Layer 3: Conditional Startup Banner
**Location:** `src/executors/typescript-executor.ts` - `execute()` method
**Implementation:**
```typescript
export class TypeScriptExecutor {
private static firstExecution = true;
async execute(
code: string,
allowedTools: string[] = [],
timeoutMs: number = DEFAULT_TIMEOUT_MS,
permissions: SandboxPermissions = {}
): Promise<ExecutionResult> {
let wrappedCode = code;
// Show discovery hint on first execution only
if (TypeScriptExecutor.firstExecution) {
TypeScriptExecutor.firstExecution = false;
wrappedCode = `
// 🔍 Discovery Tools Available:
// - discoverMCPTools(options?) - Find all available MCP tools
// - getToolSchema(toolName) - Get detailed schema for a specific tool
// - searchTools(query, limit?) - Search tools by keywords
//
// Example: const tools = await discoverMCPTools({ search: ['file'] });
${code}
`.trim();
}
// Continue with normal execution...
return this.executeSandboxed(wrappedCode, allowedTools, timeoutMs, permissions);
}
}
```
**Token Cost:** 0 (injected at runtime, not in schema)
**Visibility:** First `executeTypescript` call only (per session)
**Benefit:** Runtime nudge when agents actually use the tool
**Behavior:**
- Shows ONCE per session (static flag)
- Non-intrusive (comment format, doesn't affect execution)
- Disappears on subsequent calls (no noise for experienced users)
---
### Layer 4: Enhanced Error Messages
**Location:** `src/executors/typescript-executor.ts` - error handling
**Current Error:**
```typescript
throw new Error(`Tool '${toolName}' not in allowedTools list.`);
```
**Enhanced Error:**
```typescript
throw new Error(
`Tool '${toolName}' not in allowedTools list.\n\n` +
`💡 TIP: Use discoverMCPTools() to find available tools:\n` +
` const tools = await discoverMCPTools();\n` +
` console.log(tools.map(t => t.name));`
);
```
**Token Cost:** 0 (contextual error message, not in schema)
**Visibility:** Only when tool call fails (reactive)
**Benefit:** Guides agents to discovery when they encounter errors
---
### Token Budget Analysis
| Component | Token Cost | Running Total |
|-----------|-----------|---------------|
| Base (3 tools: executeTypescript, executePython, health) | 560 | 560 |
| Layer 1: Enhanced description | +150 | 710 |
| Layer 2: JSDoc comments | 0 | 710 |
| Layer 3: Startup banner | 0 | 710 |
| Layer 4: Error messages | 0 | 710 |
| **Total** | **710** | **710** |
| **Budget** | **1000** | **-** |
| **Headroom** | **290 (29%)** | **-** |
**Verdict:** ✅ Well within budget, preserves progressive disclosure
---
## 4. Technical Implementation
### Phase 1: Core Multi-Layer Implementation
#### Task 1: Enhanced Tool Description
**File:** `src/index.ts`
**Changes:**
```typescript
{
name: "executeTypescript",
description: `Execute TypeScript code in a Deno sandbox with access to MCP tools.
🔍 Discovery functions available in sandbox:
- discoverMCPTools(options?) - Find all available MCP tools
- getToolSchema(toolName) - Get detailed schema for a specific tool
- searchTools(query, limit?) - Search tools by keywords
Example workflow:
const tools = await discoverMCPTools({ search: ['file'] });
const schema = await getToolSchema(tools[0].name);
const result = await callMCPTool(tools[0].name, { path: '/path' });`,
inputSchema: { /* existing schema */ }
}
```
**Testing:**
- Verify token count: `JSON.stringify(schema).length` ≈ 710 tokens
- Verify description renders correctly in MCP clients
- Verify example code is valid TypeScript
---
#### Task 2: JSDoc Comments in Sandbox
**File:** `src/executors/typescript-executor.ts`
**Changes:** Add JSDoc comments to all 3 discovery functions (see Layer 2 above)
**Testing:**
- Verify JSDoc syntax is valid
- Test autocomplete in IDE (if agents use IDE-like inspection)
- Verify examples execute correctly
---
#### Task 3: Conditional Startup Banner
**File:** `src/executors/typescript-executor.ts`
**Changes:**
```typescript
export class TypeScriptExecutor {
private static firstExecution = true;
async execute(code: string, ...args): Promise<ExecutionResult> {
let wrappedCode = code;
if (TypeScriptExecutor.firstExecution) {
TypeScriptExecutor.firstExecution = false;
wrappedCode = `
// 🔍 Discovery Tools Available:
// - discoverMCPTools(options?) - Find all MCP tools
// - getToolSchema(toolName) - Get tool schema
// - searchTools(query, limit?) - Search by keywords
${code}
`.trim();
}
return this.executeSandboxed(wrappedCode, ...args);
}
}
```
**Testing:**
- First call: Verify banner appears in output
- Second call: Verify banner does NOT appear
- Restart server: Verify banner appears again (first call)
---
#### Task 4: Enhanced Error Messages
**File:** `src/executors/typescript-executor.ts`
**Changes:**
```typescript
// In callMCPTool error handling
if (!allowedTools.includes(toolName)) {
throw new Error(
`Tool '${toolName}' not in allowedTools list.\n\n` +
`💡 TIP: Use discoverMCPTools() to find available tools:\n` +
` const tools = await discoverMCPTools();\n` +
` console.log(tools.map(t => t.name));`
);
}
```
**Testing:**
- Trigger error by calling disallowed tool
- Verify error message includes discovery hint
- Verify formatting is readable
---
### Phase 2: Documentation Updates
#### Task 5: README Discovery Section
**File:** `README.md`
**Location:** After "Quick Start" section
**Content:**
```markdown
## Discovery Workflow
Find and use MCP tools on-demand inside `executeTypescript`:
### Step 1: Discover Available Tools
```typescript
const tools = await discoverMCPTools();
console.log(tools); // [{ name, description, parameters }, ...]
```
### Step 2: Search by Keywords
```typescript
const fileTools = await searchTools('file read write', 10);
// Returns top 10 tools matching any keyword
```
### Step 3: Inspect Tool Schema
```typescript
const schema = await getToolSchema('mcp__filesystem__read_file');
console.log(schema.parameters); // Full JSON Schema
```
### Step 4: Execute Tool
```typescript
const result = await callMCPTool('mcp__filesystem__read_file', {
path: '/path/to/file'
});
```
**Example: Self-Discovering Workflow**
```typescript
// Find all file-related tools
const fileTools = await discoverMCPTools({ search: ['file'] });
// Inspect the first tool's schema
const schema = await getToolSchema(fileTools[0].name);
console.log('Tool:', fileTools[0].name);
console.log('Parameters:', schema.parameters);
// Execute the tool
const result = await callMCPTool(fileTools[0].name, {
/* parameters based on schema */
});
```
```
---
#### Task 6: Architecture Documentation
**File:** `docs/architecture.md`
**Section:** Add new section "Discovery UX Strategy"
**Content:**
```markdown
### Discovery UX Strategy
**Problem:** Discovery functions (`discoverMCPTools`, `getToolSchema`, `searchTools`) are hidden in sandbox, invisible in top-level schemas.
**Solution:** Multi-layer discovery awareness (4 redundant touchpoints)
**Layers:**
1. **Enhanced Description (+150 tokens):** Discovery hints in executeTypescript schema
2. **JSDoc Comments (0 tokens):** Detailed examples in sandbox globals
3. **Startup Banner (0 tokens):** First-execution hint
4. **Error Messages (0 tokens):** Reactive guidance on failures
**Token Impact:** 560 → 710 tokens (still 29% under 1000 token budget)
**Design Rationale:** Multi-channel communication is industry best practice for user onboarding. Redundant touchpoints ensure agents discover tools regardless of attention patterns.
**Zen Consensus:** Gemini-2.5-Pro (9/10) and O3-Mini (9/10) unanimously approved this approach over alternatives (Claude Code hooks, 4th top-level tool, dynamic schemas).
```
---
#### Task 7: CHANGELOG Entry
**File:** `CHANGELOG.md`
**Entry:**
```markdown
## [0.5.0] - 2025-11-XX
### Added
- **Discovery UX Enhancements:** Multi-layer awareness for discovery tools
- Enhanced `executeTypescript` description with discovery examples (+150 tokens)
- JSDoc comments for `discoverMCPTools`, `getToolSchema`, `searchTools`
- Conditional startup banner (first execution hint)
- Enhanced error messages with discovery guidance
- Total token cost: 710 (was 560, budget 1000)
- Documentation: "Discovery Workflow" section in README
- Architecture: "Discovery UX Strategy" section in docs/architecture.md
### Changed
- `executeTypescript` description now includes discovery function documentation
### Performance
- Token usage: 560 → 710 tokens (+150, still 29% under 1000 token budget)
- Preserves 98% token reduction vs exposing all MCP tools upfront
```
---
### Phase 3: Testing & Validation
#### Task 8: Unit Tests
**File:** `tests/discovery-ux.test.ts` (new file)
**Test Cases:**
```typescript
describe('Discovery UX', () => {
describe('Enhanced Tool Description', () => {
it('should include discovery functions in description', () => {
const tool = mcpServer.tools.find(t => t.name === 'executeTypescript');
expect(tool.description).toContain('discoverMCPTools');
expect(tool.description).toContain('getToolSchema');
expect(tool.description).toContain('searchTools');
});
it('should include example workflow', () => {
const tool = mcpServer.tools.find(t => t.name === 'executeTypescript');
expect(tool.description).toContain('Example workflow');
expect(tool.description).toContain('const tools = await discoverMCPTools');
});
it('should stay within token budget', () => {
const allSchemas = JSON.stringify(mcpServer.tools);
const tokenCount = allSchemas.length; // Approximate
expect(tokenCount).toBeLessThan(1000);
});
});
describe('Startup Banner', () => {
it('should show banner on first execution', async () => {
const result = await executor.execute('console.log("test");');
expect(result.output).toContain('🔍 Discovery Tools Available');
});
it('should NOT show banner on second execution', async () => {
await executor.execute('console.log("first");');
const result = await executor.execute('console.log("second");');
expect(result.output).not.toContain('🔍 Discovery Tools Available');
});
});
describe('Enhanced Error Messages', () => {
it('should include discovery hint on tool not found error', async () => {
const code = 'await callMCPTool("nonexistent", {});';
await expect(executor.execute(code)).rejects.toThrow('discoverMCPTools');
});
});
});
```
---
#### Task 9: Integration Testing
**Scenario:** Fresh AI Agent Session
**Test Steps:**
1. AI agent starts new session
2. Agent calls `executeTypescript` for first time
3. Verify banner appears in output
4. Agent reads `executeTypescript` description
5. Verify description includes discovery examples
6. Agent calls `discoverMCPTools()` in code
7. Verify JSDoc hints visible (if agent inspects)
8. Agent calls invalid tool
9. Verify error message includes discovery hint
**Success Criteria:**
- Agent discovers `discoverMCPTools` through at least ONE of 4 touchpoints
- Agent successfully uses discovery workflow
- No errors, no token budget overrun
---
#### Task 10: Token Budget Validation
**Script:** `scripts/validate-token-budget.ts` (new file)
```typescript
import { MCPServer } from '../src/index.js';
const server = new MCPServer(/* config */);
const tools = await server.listTools();
const schema = JSON.stringify(tools);
const tokenCount = schema.length; // Approximate (real count may vary by tokenizer)
console.log(`Token count: ${tokenCount}`);
console.log(`Budget: 1000`);
console.log(`Headroom: ${1000 - tokenCount} (${((1000 - tokenCount) / 1000 * 100).toFixed(1)}%)`);
if (tokenCount > 1000) {
console.error('❌ FAILED: Token budget exceeded!');
process.exit(1);
} else {
console.log('✅ PASSED: Within token budget');
}
```
**Run:** `npm run validate:tokens` (add to package.json scripts)
---
### Phase 4: Optional Enhancement (Claude Code Hook)
**Note:** This is OPTIONAL and does NOT block the core implementation. It's a bonus enhancement for Claude Code users.
#### Task 11: Claude Code Session Start Hook (Optional)
**File:** `.claude/hooks/onSessionStart.json` (new file, optional)
**Content:**
```json
{
"message": "💡 **Discovery Tip:** This project uses code-executor-mcp with progressive disclosure.\n\nInside `executeTypescript`, use:\n- `discoverMCPTools()` - Find all available MCP tools\n- `getToolSchema(toolName)` - Get tool schema\n- `searchTools(query)` - Search by keywords\n\nExample: `const tools = await discoverMCPTools({ search: ['file'] });`"
}
```
**Benefit:**
- Extra hint for Claude Code users (5th touchpoint)
- Does NOT impact portability (core implementation works without it)
- Optional enhancement, not required
---
## 5. Testing Strategy
### Test Pyramid
```
/\
/ \ E2E (1 test)
/────\ - Fresh AI agent session, full discovery workflow
/ \
/────────\ Integration (3 tests)
/ \ - Banner on first execution
/────────────\ - Error message with hint
/ \ - JSDoc visible in sandbox
/────────────────\
| Unit (10 tests) | - Description content
|________________| - Token budget validation
- Banner logic
- Error formatting
- JSDoc syntax
```
### Test Coverage Goals
- **Unit Tests:** 95%+ coverage on new code
- **Integration Tests:** 90%+ coverage on discovery workflow
- **E2E Tests:** 1 happy path (agent discovers and uses tools)
### Manual Testing Checklist
- [ ] Load schema in Claude Code - verify description visible
- [ ] Execute code first time - verify banner appears
- [ ] Execute code second time - verify banner hidden
- [ ] Call invalid tool - verify error includes hint
- [ ] Inspect sandbox globals - verify JSDoc visible
- [ ] Test on Continue.dev (portability check)
- [ ] Test on Cline (portability check)
- [ ] Measure token count - verify <1000
---
## 6. Success Criteria
### Quantitative Metrics
| Metric | Target | Measurement |
|--------|--------|-------------|
| Token count (top-level schema) | <1000 | JSON.stringify(tools).length |
| Discovery adoption rate | >50% of sessions | Telemetry: % sessions using discoverMCPTools |
| First-execution banner shown | 100% | Unit test |
| Error hint shown on failures | 100% | Integration test |
| Test coverage | >90% | Vitest coverage report |
### Qualitative Metrics
- [ ] AI agents discover tools without manual documentation lookup
- [ ] Agents successfully use discovery workflow (discover → inspect → execute)
- [ ] No user complaints about "missing tools" or "how do I find tools?"
- [ ] Positive feedback on discovery UX
- [ ] Works seamlessly on multiple MCP clients (Claude Code, Continue, Cline)
### Release Criteria
**Must Have (Blocking):**
- ✅ All 4 layers implemented and tested
- ✅ Token count <1000 (current: 710)
- ✅ Unit tests passing (>95% coverage)
- ✅ Integration tests passing (>90% coverage)
- ✅ Manual testing checklist complete
- ✅ Documentation updated (README, architecture.md, CHANGELOG)
**Nice to Have (Non-Blocking):**
- ⭐ Claude Code hook implemented (optional enhancement)
- ⭐ E2E test with real AI agent session
- ⭐ Telemetry for discovery adoption tracking
---
## 7. Rollout Plan
### Pre-Release (v0.4.x)
**Week 1: Development**
- Implement Phase 1 (core multi-layer implementation)
- Implement Phase 2 (documentation updates)
- Implement Phase 3 (testing & validation)
**Week 2: Testing & Refinement**
- Run full test suite
- Manual testing on multiple MCP clients
- Token budget validation
- Documentation review
### Release (v0.5.0)
**Version:** 0.5.0 (minor version bump - new feature)
**Release Notes:**
```markdown
## v0.5.0 - Discovery UX Enhancements
**What's New:**
- 🔍 **Multi-layer discovery awareness** - AI agents now see 4 redundant hints about discovery tools
- 📖 Enhanced `executeTypescript` description with discovery examples
- 💬 First-execution banner with discovery tips
- ❌ Helpful error messages when tools aren't found
- 📚 Comprehensive "Discovery Workflow" documentation in README
**Token Impact:** +150 tokens (710 total vs 1000 budget, still 29% headroom)
**Compatibility:** Fully backward compatible, no breaking changes
**Upgrade:** `npm install -g code-executor-mcp@0.5.0`
```
**Channels:**
- GitHub Release
- npm Registry
- Docker Hub (new image tag: `0.5.0`)
- Announce in relevant communities (if applicable)
### Post-Release
**Week 3: Monitoring**
- Monitor telemetry for discovery adoption rate
- Collect user feedback
- Monitor GitHub issues for UX complaints
- Track token usage in production
**Week 4: Iteration**
- Address any bugs or UX issues
- Consider implementing optional Claude Code hook (Phase 4)
- Evaluate success criteria
- Plan next iteration (if needed)
---
## 8. Risk Mitigation
### Risk 1: Token Budget Overrun
**Risk:** Enhanced description exceeds 150 token estimate, total >1000 tokens
**Probability:** Low (carefully measured)
**Impact:** High (breaks progressive disclosure goal)
**Mitigation:**
- Pre-validate token count before release (script in Task 10)
- Add CI check: `npm run validate:tokens` fails build if >1000
- Fallback: Shorten description if needed, prioritize brevity
---
### Risk 2: Startup Banner Annoys Users
**Risk:** First-execution banner is too noisy, users find it annoying
**Probability:** Medium (subjective UX)
**Impact:** Low (banner shows once per session)
**Mitigation:**
- Banner is comment format (non-intrusive)
- Shows ONCE per session (static flag)
- Can be disabled in future version if needed (config flag)
- Collect user feedback post-release
---
### Risk 3: Portability Issues
**Risk:** Multi-layer approach works on Claude Code but not other MCP clients
**Probability:** Low (server-controlled, client-agnostic)
**Impact:** Medium (poor UX on non-Claude clients)
**Mitigation:**
- Test on multiple MCP clients (Claude Code, Continue, Cline)
- Server-side implementation ensures consistency
- Description visible in ALL MCP clients (standard protocol)
---
### Risk 4: Low Discovery Adoption
**Risk:** Despite hints, agents still don't use discovery tools
**Probability:** Medium (agent behavior unpredictable)
**Impact:** Medium (feature underutilization, but not breaking)
**Mitigation:**
- 4 redundant touchpoints maximize awareness
- Monitor telemetry for actual usage
- Iterate based on data (add more hints if needed)
- Consider optional Claude Code hook (5th touchpoint)
---
### Risk 5: Breaking Changes
**Risk:** Implementation breaks existing functionality
**Probability:** Low (additive changes only)
**Impact:** High (regression)
**Mitigation:**
- Comprehensive test coverage (>90%)
- Backward compatibility guaranteed (no API changes)
- Beta testing with select users before release
- Rollback plan: revert to v0.4.0 if critical issues
---
## 9. Future Enhancements
### Short-Term (v0.5.x)
**Optional Claude Code Hook:**
- Implement `.claude/hooks/onSessionStart.json` (Task 11)
- Document hook pattern for other MCP clients
- Provide template for users to customize
**Telemetry Dashboard:**
- Track discovery function usage
- Measure adoption rate over time
- Identify which layers are most effective
### Medium-Term (v0.6.0)
**Smart Banner:**
- Show banner if agent hasn't used discovery in N executions
- Adaptive: hide if agent demonstrates discovery knowledge
- Persistent per-agent (store in metadata)
**Interactive Tutorial:**
- Add `tutorialMode` flag to `executeTypescript`
- Step-by-step guided discovery workflow
- Opt-in feature for new users
### Long-Term (v1.0.0)
**Dynamic Description:**
- Adjust description verbosity based on agent behavior
- Concise for experienced agents, verbose for new agents
- AI-powered description optimization
**Discovery Analytics:**
- Which tools are most discovered?
- Which discovery functions are most used?
- Optimize hints based on data
---
## Appendix A: Zen Consensus Full Report
### Models Consulted
1. **Gemini-2.5-Pro** (Google)
- Vote: Option C (Multi-Layer In-Server)
- Confidence: 9/10
- Key Quote: "Option C aligns best with the project's core goals. It preserves the primary achievement of progressive disclosure (98% token reduction) by adding only a modest 150 tokens."
2. **O3-Mini** (OpenAI)
- Vote: Option C (Multi-Layer In-Server)
- Confidence: 9/10
- Key Quote: "Option C preserves token efficiency by only adding 150 tokens while meeting the token reduction goals better than alternatives with higher overhead."
3. **GPT-5-Pro** (OpenAI)
- Status: Request timeout (consensus already achieved with 2/2 votes)
### Consensus Analysis
**Agreement:** 100% (2/2 models voted for Option C)
**Confidence:** 9/10 average
**Key Consensus Points:**
1. Portability is critical - server-side solution is client-agnostic
2. Token efficiency preserved - 150 tokens is acceptable cost
3. Multi-layer approach is industry best practice
4. Redundancy ensures high discovery probability
5. Centralized implementation simplifies maintenance
**Rejected Options:**
- Option A (Hook): Not portable, Claude Code specific
- Option B (4th Tool): Defeats progressive disclosure goal
- Option D (Hybrid): High complexity, tight coupling
- Option E (Conditional): Non-standard, brittle
---
## Appendix B: Token Budget Breakdown
### Current State (v0.4.0)
| Tool | Description Length | Input Schema | Total (approx) |
|------|-------------------|--------------|----------------|
| executeTypescript | ~100 chars | ~400 chars | ~500 tokens |
| executePython | ~80 chars | ~350 chars | ~430 tokens |
| health | ~50 chars | ~50 chars | ~100 tokens |
| **Total** | - | - | **~560 tokens** |
### Proposed State (v0.5.0)
| Tool | Description Length | Input Schema | Total (approx) |
|------|-------------------|--------------|----------------|
| executeTypescript | ~250 chars | ~400 chars | ~650 tokens |
| executePython | ~80 chars | ~350 chars | ~430 tokens |
| health | ~50 chars | ~50 chars | ~100 tokens |
| **Total** | - | - | **~710 tokens** |
**Delta:** +150 tokens
**Budget:** 1000 tokens
**Headroom:** 290 tokens (29%)
**Progressive Disclosure Preserved:** ✅ Yes (still 98% reduction vs exposing all tools)
---
## Appendix C: Implementation Checklist
### Phase 1: Core Implementation
- [ ] Task 1: Enhanced tool description (`src/index.ts`)
- [ ] Task 2: JSDoc comments (`src/executors/typescript-executor.ts`)
- [ ] Task 3: Conditional startup banner (`src/executors/typescript-executor.ts`)
- [ ] Task 4: Enhanced error messages (`src/executors/typescript-executor.ts`)
### Phase 2: Documentation
- [ ] Task 5: README Discovery section
- [ ] Task 6: Architecture documentation
- [ ] Task 7: CHANGELOG entry
### Phase 3: Testing
- [ ] Task 8: Unit tests (`tests/discovery-ux.test.ts`)
- [ ] Task 9: Integration testing
- [ ] Task 10: Token budget validation script
### Phase 4: Optional Enhancement
- [ ] Task 11: Claude Code hook (`.claude/hooks/onSessionStart.json`)
### Release Checklist
- [ ] All Phase 1-3 tasks complete
- [ ] Test coverage >90%
- [ ] Token count <1000 verified
- [ ] Manual testing on Claude Code
- [ ] Manual testing on Continue.dev
- [ ] Manual testing on Cline
- [ ] Documentation reviewed
- [ ] CHANGELOG updated
- [ ] Version bumped to 0.5.0
- [ ] Git tag created: `v0.5.0`
- [ ] npm package published
- [ ] Docker image built and pushed
- [ ] GitHub release created
- [ ] Announcement posted (if applicable)
---
## Approval
**Plan Status:** ✅ Ready for Review
**Awaiting Approval From:** Project Owner / Technical Lead
**Next Steps:**
1. Review this plan
2. Approve or request changes
3. Assign tasks to implementation team
4. Set timeline for v0.5.0 release
**Questions or Concerns:** [Open GitHub Issue or Discussion]
---
**Document Version:** 1.0
**Last Updated:** 2025-11-12
**Author:** Claude (AI Assistant)
**Reviewed By:** [Pending]
**Approved By:** [Pending]