StuMason/coolify-mcp
TypeScript
Issue Opened
Issue #81 opened: refactor: eliminate `as any` type assertions in MCP tool handlers
Problem
The MCP tool handlers in mcp-server.ts use as any type assertions when passing arguments to client methods. This bypasses TypeScript's type checking and was the root cause of Issue #76 (action field leaking to API).
Current State
Multiple places in mcp-server.ts use patterns like:
return wrap(() => this.client.createApplicationPublic(apiData as any));
Proposed Solution
- Use proper type guards - Validate fields are present before calling client methods
- Use discriminated unions - The action parameter already discriminates, leverage this
- Method overloads or generics - Make client methods accept properly typed inputs
Benefits
- Compile-time safety prevents field leakage bugs like #76
- Better IDE autocomplete and error messages
- Self-documenting code
Affected Areas
applicationtool handler (create_public, create_github, create_key, create_dockerimage)servicetool handler (create)github_appstool handler (create) - already partially fixed with explicit field passing
Priority
Low - the immediate bug (#76) is fixed by stripping MCP-internal fields. This is a refactor for long-term code quality.
Filed for future improvement when tokens are plentiful ๐ช