You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: improve type safety with Zod schema inference
- Add InferToolParams type utility for inferring types from Zod schemas
- Update withErrorHandling to preserve parameter types generically
- Refactor all tool handlers to use inferred types instead of manual assertions
- Eliminate all 'args as {...}' type assertions in tool implementations
- Update AGENTS.md with comprehensive type-safe development patterns
- Add type inference examples and best practices documentation
This ensures single source of truth for types (Zod schemas) and eliminates
redundant type definitions while maintaining full type safety.
Copy file name to clipboardExpand all lines: AGENTS.md
+95-9Lines changed: 95 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@
6
6
-**hevy-mcp** is a Model Context Protocol (MCP) server for the Hevy Fitness API, enabling AI agents to manage workouts, routines, exercise templates, and folders via the Hevy API.
7
7
- The codebase is TypeScript (Node.js v20+), with a clear separation between tool implementations (`src/tools/`), generated API clients (`src/generated/`), and utility logic (`src/utils/`).
8
8
- API client code is generated from the OpenAPI spec using [Kubb](https://kubb.dev/). **Do not manually edit generated files.**
9
+
-**Type Safety:** The project uses Zod schema inference for type-safe tool parameters, eliminating manual type assertions and ensuring compile-time type safety.
9
10
10
11
## Working Effectively
11
12
@@ -127,17 +128,27 @@ Always perform these validation steps after making changes:
127
128
pnpm run check
128
129
```
129
130
- Must complete without errors (warnings about Biome schema are acceptable).
131
+
-**EXPECTED:** Warnings about `any` usage in `webhooks.ts` are acceptable (API methods not yet available).
130
132
131
-
4.**MCP tool functionality validation (if API key available):**
133
+
4.**Type checking validation:**
134
+
```bash
135
+
npx tsc --noEmit
136
+
```
137
+
- Must complete without errors.
138
+
- Verifies all type inference is working correctly.
139
+
140
+
5.**MCP tool functionality validation (if API key available):**
132
141
- Start development server: `pnpm run dev`
133
142
- Test MCP tool endpoints with a client
134
143
- Verify tool responses are correctly formatted
135
144
136
145
### Critical Validation Notes
137
146
-**ALWAYS** run unit tests after any source code changes
138
147
-**ALWAYS** run build validation before committing changes
148
+
-**ALWAYS** use type inference (`InferToolParams`) instead of manual type assertions
139
149
-**DO NOT** attempt to fix TypeScript errors in `src/generated/` - these are auto-generated files
140
150
-**DO NOT** commit `.env` files containing real API keys
151
+
-**DO NOT** use `as any` or `as unknown` type assertions in tool handlers
141
152
142
153
## Project Structure and Key Files
143
154
@@ -155,8 +166,14 @@ src/
155
166
│ ├── client/ # Kubb-generated client code
156
167
│ └── schemas/ # Zod validation schemas
157
168
└── utils/ # Shared helper functions
158
-
├── formatters.ts # Data formatting helpers
159
-
└── hevyClient.ts # API client configuration
169
+
├── tool-helpers.ts # Type inference utilities (InferToolParams)
└── httpServer.ts # HTTP server utilities (deprecated)
160
177
```
161
178
162
179
### Testing Structure
@@ -168,22 +185,73 @@ tests/
168
185
169
186
## Development Patterns
170
187
188
+
### Type-Safe Tool Implementation
189
+
190
+
The project uses **Zod schema inference** for type-safe tool parameters. This eliminates manual type assertions and ensures types match schemas automatically.
191
+
192
+
#### Pattern: Using Type Inference
193
+
194
+
**Always** extract Zod schemas and use `InferToolParams` for type safety:
0 commit comments