Skip to content

Commit 57dacc4

Browse files
author
Adam Bloomston
committed
docs: add parameter validation documentation for strict mode
Add Advanced Usage section explaining the strict parameter for registerTool: - Show examples of strict vs lenient validation - Explain when to use each mode (development vs production) - Document that strict parameter is only available in registerTool() - Note that legacy tool() method uses lenient validation for compatibility This helps developers understand when and how to use strict validation to catch parameter name typos and unexpected data.
1 parent b2b2257 commit 57dacc4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,31 @@ server.registerTool("tool3", ...).disable();
11101110
// Only one 'notifications/tools/list_changed' is sent.
11111111
```
11121112

1113+
### Parameter Validation and Error Handling
1114+
1115+
Control how tools handle parameter validation errors and unexpected inputs:
1116+
1117+
```typescript
1118+
// Strict validation for development - catches typos immediately
1119+
const devTool = server.registerTool("dev-tool", {
1120+
inputSchema: { userName: z.string(), itemCount: z.number() },
1121+
strict: true // Reject { username: "test", itemcount: 42 }
1122+
}, handler);
1123+
1124+
// Lenient validation for production - handles client variations gracefully
1125+
const prodTool = server.registerTool("prod-tool", {
1126+
inputSchema: { userName: z.string().optional(), itemCount: z.number().optional() },
1127+
strict: false // Accept extra parameters (default behavior)
1128+
}, handler);
1129+
```
1130+
1131+
**When to use strict validation:**
1132+
- Development and testing: Catch parameter name typos early
1133+
- Production APIs: Ensure clients send only expected parameters
1134+
- Security-sensitive tools: Prevent injection of unexpected data
1135+
1136+
**Note:** The `strict` parameter is only available in `registerTool()`. The legacy `tool()` method uses lenient validation for backward compatibility.
1137+
11131138
### Low-Level Server
11141139

11151140
For more control, you can use the low-level Server class directly:

0 commit comments

Comments
 (0)