Skip to content

feat: add comprehensive validation system for all 67 tools#109

Merged
ooples merged 2 commits intomasterfrom
feat/validation-system-all-tools
Oct 31, 2025
Merged

feat: add comprehensive validation system for all 67 tools#109
ooples merged 2 commits intomasterfrom
feat/validation-system-all-tools

Conversation

@ooples
Copy link
Copy Markdown
Owner

@ooples ooples commented Oct 31, 2025

Summary

Implements comprehensive argument validation for all 67 MCP tools, bringing validation coverage from 16% to 100%.

Problem

Only 11 of 67 tools had argument validation, leaving 84% vulnerable to runtime errors from invalid arguments.

Solution

Created centralized validation system using Zod schemas for all 67 tools.

Changes

  • New: src/validation/tool-schemas.ts (332 lines)
  • New: src/validation/validator.ts (77 lines)
  • Modified: src/server/index.ts (integrated validation)

Validation Coverage

  • Before: 11 tools (16%)
  • After: 67 tools (100%)

Testing

  • Build: TypeScript compilation successful
  • Tests: 138 suites, 3681 tests passed
  • Manual: Verified proper error messages

Based on comprehensive Gemini CLI analysis (2M token context window).

Co-Authored-By: Claude noreply@anthropic.com

- Add Zod schemas for all 67 tools in src/validation/tool-schemas.ts
- Add validateToolArgs function in src/validation/validator.ts
- Integrate validation into CallToolRequestSchema handler
- Validation coverage: 16% to 100% (11 to 67 tools)

Based on comprehensive Gemini CLI analysis (2M token context window)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 31, 2025

Warning

Rate limit exceeded

@ooples has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 718b36a and 517671a.

📒 Files selected for processing (3)
  • src/server/index.ts (2 hunks)
  • src/validation/tool-schemas.ts (1 hunks)
  • src/validation/validator.ts (1 hunks)
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/validation-system-all-tools

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Performance Benchmark Results


@github-actions
Copy link
Copy Markdown

Performance Benchmark Results


@ooples ooples merged commit 7c5a5d2 into master Oct 31, 2025
14 of 16 checks passed
@ooples ooples deleted the feat/validation-system-all-tools branch October 31, 2025 03:32
@github-actions
Copy link
Copy Markdown

This PR is included in version 3.1.0. 🎉

The release is available on:

Your semantic-release bot 📦🚀

ooples added a commit that referenced this pull request Oct 31, 2025
BREAKING FIXES (v3.1.0 → v3.1.1):

1. **Token Tracking Serialization Bug (CRITICAL)**
   - Fixed PowerShell Hashtable serialization in invoke-mcp.ps1
   - Root cause: Nested Hashtables serialize as [] empty array in JSON
   - Solution: Explicit PSCustomObject conversion for nested arguments
   - Impact: Restores ALL token counting (was 0 tokens with 49,578 ops)

2. **Package Version Sync**
   - Updated package.json from 2.20.0 to 3.1.0
   - Syncs with GitHub release v3.1.0 created by semantic-release
   - Fixes version mismatch for users installing from source

3. **Dynamic Model Detection**
   - Added auto-detection of Claude/GPT model from environment
   - Checks CLAUDE_MODEL and ANTHROPIC_MODEL env vars
   - Maps Claude models (Sonnet/Opus/Haiku) to GPT-4 tokenizer
   - Provides accurate token counts for all supported models

TESTING:
- Created comprehensive test-critical-fixes.ps1 script
- All 7 tests passing locally before PR creation
- Verified MCP invocation with proper argument serialization
- Confirmed TypeScript compilation successful

IMPACT:
- Token tracking now functional after 49K+ operations with 0 tokens
- Version consistency across GitHub, npm, and source installs
- Accurate token counts regardless of active model

Related PRs: #107 (attempted fix), #108, #109
ooples added a commit that referenced this pull request Oct 31, 2025
…110)

* fix: resolve critical token tracking and versioning issues

BREAKING FIXES (v3.1.0 → v3.1.1):

1. **Token Tracking Serialization Bug (CRITICAL)**
   - Fixed PowerShell Hashtable serialization in invoke-mcp.ps1
   - Root cause: Nested Hashtables serialize as [] empty array in JSON
   - Solution: Explicit PSCustomObject conversion for nested arguments
   - Impact: Restores ALL token counting (was 0 tokens with 49,578 ops)

2. **Package Version Sync**
   - Updated package.json from 2.20.0 to 3.1.0
   - Syncs with GitHub release v3.1.0 created by semantic-release
   - Fixes version mismatch for users installing from source

3. **Dynamic Model Detection**
   - Added auto-detection of Claude/GPT model from environment
   - Checks CLAUDE_MODEL and ANTHROPIC_MODEL env vars
   - Maps Claude models (Sonnet/Opus/Haiku) to GPT-4 tokenizer
   - Provides accurate token counts for all supported models

TESTING:
- Created comprehensive test-critical-fixes.ps1 script
- All 7 tests passing locally before PR creation
- Verified MCP invocation with proper argument serialization
- Confirmed TypeScript compilation successful

IMPACT:
- Token tracking now functional after 49K+ operations with 0 tokens
- Version consistency across GitHub, npm, and source installs
- Accurate token counts regardless of active model

Related PRs: #107 (attempted fix), #108, #109

* fix: remove typescript any type from maptotiktokenmodel method
ooples added a commit that referenced this pull request Oct 31, 2025
…ollision

CRITICAL BUG FIX: Token tracking completely non-functional due to parameter name collision

Root Cause:
- PowerShell parameter named $Args conflicted with automatic $args variable
- Caused all MCP tool arguments to become empty System.Object[] instead of Hashtable
- Result: 49,578+ operations tracked with 0 tokens (100% failure rate)

Evidence (MCP logs):
BEFORE: "arguments":{} (empty)
AFTER:  "arguments":{"enableCache":true,"path":"...","includeMetadata":true,...} (populated)

The Fix:
- Renamed parameter from $Args to $ToolArguments (hooks/helpers/invoke-mcp.ps1:73)
- Removed unnecessary [PSCustomObject] casting (lines 84-87)
- Updated function call site (line 141)

Investigation:
- 3 independent expert agents converged on same root cause
- Gemini CLI 2M token analysis confirmed PowerShell reserved variable issue
- Web research (Stack Overflow, MS docs) validated $args is automatic variable
- Git history showed bug introduced in commit d38efe0, never properly fixed

Impact:
- ALL MCP tools now receive correct arguments (smart_read, optimize_session, etc.)
- Token tracking will now function as designed (60-80% reduction target)
- Fixes ~350K tokens of savings per session that were lost

Testing:
- Live logs show arguments properly serialized after fix
- Test confirms $Args becomes empty array, $ToolArguments works correctly

Related: #107, #108, #109, #110

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant