Skip to content

Commit ef99378

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 8016684 commit ef99378

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
@@ -949,6 +949,31 @@ server.registerTool("tool3", ...).disable();
949949
// Only one 'notifications/tools/list_changed' is sent.
950950
```
951951

952+
### Parameter Validation and Error Handling
953+
954+
Control how tools handle parameter validation errors and unexpected inputs:
955+
956+
```typescript
957+
// Strict validation for development - catches typos immediately
958+
const devTool = server.registerTool("dev-tool", {
959+
inputSchema: { userName: z.string(), itemCount: z.number() },
960+
strict: true // Reject { username: "test", itemcount: 42 }
961+
}, handler);
962+
963+
// Lenient validation for production - handles client variations gracefully
964+
const prodTool = server.registerTool("prod-tool", {
965+
inputSchema: { userName: z.string().optional(), itemCount: z.number().optional() },
966+
strict: false // Accept extra parameters (default behavior)
967+
}, handler);
968+
```
969+
970+
**When to use strict validation:**
971+
- Development and testing: Catch parameter name typos early
972+
- Production APIs: Ensure clients send only expected parameters
973+
- Security-sensitive tools: Prevent injection of unexpected data
974+
975+
**Note:** The `strict` parameter is only available in `registerTool()`. The legacy `tool()` method uses lenient validation for backward compatibility.
976+
952977
### Low-Level Server
953978

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

0 commit comments

Comments
 (0)