Skip to content

Commit 23d21d7

Browse files
authored
fix: improve validation for schema' (#657)
1 parent c550438 commit 23d21d7

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

docs-v2/content/en/mcp/mcp.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,31 @@ Terminal-based AI clients (like Claude Desktop) can connect to your local MCP se
144144
- Audit MCP field access patterns
145145
- Implement rate limiting for token-heavy operations
146146

147+
## Common Issues
148+
149+
### Schema Validation Error
150+
151+
**Error**: `[ERROR: Received tool input did not match expected schema]`
152+
153+
**Cause**: This occurs when the field type is not identified correctly by the MCP server, leading to schema mismatches between what the AI agent sends and what Laravel Restify expects.
154+
155+
**Solution**: You need to explicitly override the field type for the MCP schema using the `toolSchema()` method:
156+
157+
```php
158+
field('project_id')
159+
->toolSchema(function(\Laravel\Mcp\Server\Tools\ToolInputSchema $schema) {
160+
$schema->string('project_id')
161+
->description('The ID of the project associated with the timesheet entry.')
162+
->required();
163+
}),
164+
```
165+
166+
This approach allows you to:
167+
- Explicitly define the expected data type (string, integer, boolean, etc.)
168+
- Add detailed descriptions for AI agents
169+
- Set validation rules (required, optional)
170+
- Override automatic type inference when it's incorrect
171+
147172
## Configuration
148173

149174
The MCP integration respects your existing Restify configuration and adds MCP-specific options:

src/Fields/Field.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,7 @@ protected function guessTypeFromValidationRules(): ?string
846846
return 'number';
847847
}
848848

849-
if ($this->hasAnyRule($ruleStrings, ['array'])) {
850-
return 'array';
851-
}
852-
853-
if ($this->hasAnyRule($ruleStrings, ['email', 'url', 'ip', 'uuid'])) {
849+
if ($this->hasAnyRule($ruleStrings, ['email', 'url', 'ip', 'uuid', 'string', 'regex', 'in', 'array'])) {
854850
return 'string';
855851
}
856852

0 commit comments

Comments
 (0)