From 66a5cd909b32e2b4f5b87c619d0c565e78f2e8c8 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Sat, 30 Aug 2025 17:15:48 +0300 Subject: [PATCH 1/4] fix: improve validation for schema' --- docs-v2/content/en/mcp/mcp.md | 25 +++++++++++++++++++++++++ src/Fields/Field.php | 6 +----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs-v2/content/en/mcp/mcp.md b/docs-v2/content/en/mcp/mcp.md index 8f0e9cfc7..d0320d7df 100644 --- a/docs-v2/content/en/mcp/mcp.md +++ b/docs-v2/content/en/mcp/mcp.md @@ -144,6 +144,31 @@ Terminal-based AI clients (like Claude Desktop) can connect to your local MCP se - Audit MCP field access patterns - Implement rate limiting for token-heavy operations +## Common Issues + +### Schema Validation Error + +**Error**: `[ERROR: Received tool input did not match expected schema]` + +**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. + +**Solution**: You need to explicitly override the field type for the MCP schema using the `toolSchema()` method: + +```php +field('project_id') + ->toolSchema(function(\Laravel\Mcp\Server\Tools\ToolInputSchema $schema) { + $schema->string('project_id') + ->description('The ID of the project associated with the timesheet entry.') + ->required(); + }), +``` + +This approach allows you to: +- Explicitly define the expected data type (string, integer, boolean, etc.) +- Add detailed descriptions for AI agents +- Set validation rules (required, optional) +- Override automatic type inference when it's incorrect + ## Configuration The MCP integration respects your existing Restify configuration and adds MCP-specific options: diff --git a/src/Fields/Field.php b/src/Fields/Field.php index c1b1f7914..3b0fad2bc 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -846,11 +846,7 @@ protected function guessTypeFromValidationRules(): ?string return 'number'; } - if ($this->hasAnyRule($ruleStrings, ['array'])) { - return 'array'; - } - - if ($this->hasAnyRule($ruleStrings, ['email', 'url', 'ip', 'uuid'])) { + if ($this->hasAnyRule($ruleStrings, ['email', 'url', 'ip', 'uuid', 'string', 'regex', 'in', 'array'])) { return 'string'; } From cbd49f0af559dcb86e26061955f8478f6c818399 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Sat, 30 Aug 2025 17:30:41 +0300 Subject: [PATCH 2/4] fix: improve validation rules detection --- src/Fields/Field.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 3b0fad2bc..00b6db1c5 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -842,10 +842,6 @@ protected function guessTypeFromValidationRules(): ?string return 'boolean'; } - if ($this->hasAnyRule($ruleStrings, ['integer', 'int', 'numeric', 'min:', 'max:', 'between:'])) { - return 'number'; - } - if ($this->hasAnyRule($ruleStrings, ['email', 'url', 'ip', 'uuid', 'string', 'regex', 'in', 'array'])) { return 'string'; } @@ -858,6 +854,9 @@ protected function guessTypeFromValidationRules(): ?string return 'string'; // Files are typically handled as strings (paths/URLs) } + if ($this->hasAnyRule($ruleStrings, ['integer', 'int', 'numeric', 'between:'])) { + return 'number'; + } return null; } From 90cff9f607e8c09aae6cd06bbba46bd15b7b09ce Mon Sep 17 00:00:00 2001 From: binaryk Date: Sat, 30 Aug 2025 14:31:13 +0000 Subject: [PATCH 3/4] Fix styling --- src/Fields/Field.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 00b6db1c5..ce9523076 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -857,6 +857,7 @@ protected function guessTypeFromValidationRules(): ?string if ($this->hasAnyRule($ruleStrings, ['integer', 'int', 'numeric', 'between:'])) { return 'number'; } + return null; } From cedb88412f9ea4d226d047598430f871c907613b Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Sat, 30 Aug 2025 17:33:27 +0300 Subject: [PATCH 4/4] fix: wip --- src/Fields/Field.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 3b0fad2bc..ce9523076 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -842,10 +842,6 @@ protected function guessTypeFromValidationRules(): ?string return 'boolean'; } - if ($this->hasAnyRule($ruleStrings, ['integer', 'int', 'numeric', 'min:', 'max:', 'between:'])) { - return 'number'; - } - if ($this->hasAnyRule($ruleStrings, ['email', 'url', 'ip', 'uuid', 'string', 'regex', 'in', 'array'])) { return 'string'; } @@ -858,6 +854,10 @@ protected function guessTypeFromValidationRules(): ?string return 'string'; // Files are typically handled as strings (paths/URLs) } + if ($this->hasAnyRule($ruleStrings, ['integer', 'int', 'numeric', 'between:'])) { + return 'number'; + } + return null; }