@@ -28,6 +28,9 @@ class McpApiController extends Controller
2828{
2929 use HasApiResponses;
3030
31+ private const VALIDATION_SERVER_ID_INVALID = 'The selected server id is invalid. ' ;
32+ private const VALIDATION_TOOL_NAME_INVALID = 'The selected tool name is invalid. ' ;
33+
3134 /**
3235 * Safe MCP server identifier pattern.
3336 *
@@ -106,7 +109,7 @@ public function server(Request $request, string $id): JsonResponse
106109 {
107110 if (! $ this ->isValidServerId ($ id )) {
108111 return $ this ->validationErrorResponse ([
109- 'id ' => [' The selected server id is invalid. ' ],
112+ 'id ' => [self :: VALIDATION_SERVER_ID_INVALID ],
110113 ]);
111114 }
112115
@@ -155,7 +158,7 @@ public function tools(Request $request, string $id): JsonResponse
155158 {
156159 if (! $ this ->isValidServerId ($ id )) {
157160 return $ this ->validationErrorResponse ([
158- 'id ' => [' The selected server id is invalid. ' ],
161+ 'id ' => [self :: VALIDATION_SERVER_ID_INVALID ],
159162 ]);
160163 }
161164
@@ -222,7 +225,7 @@ public function resources(Request $request, string $id): JsonResponse
222225 {
223226 if (! $ this ->isValidServerId ($ id )) {
224227 return $ this ->validationErrorResponse ([
225- 'id ' => [' The selected server id is invalid. ' ],
228+ 'id ' => [self :: VALIDATION_SERVER_ID_INVALID ],
226229 ]);
227230 }
228231
@@ -343,7 +346,7 @@ public function callTool(Request $request): JsonResponse
343346
344347 if (! $ this ->isValidToolName ($ validated ['tool ' ])) {
345348 return $ this ->validationErrorResponse ([
346- 'tool ' => [' The selected tool name is invalid. ' ],
349+ 'tool ' => [self :: VALIDATION_TOOL_NAME_INVALID ],
347350 ]);
348351 }
349352
@@ -374,13 +377,13 @@ public function callToolByRoute(Request $request, string $server, string $tool):
374377 {
375378 if (! $ this ->isValidServerId ($ server )) {
376379 return $ this ->validationErrorResponse ([
377- 'server ' => [' The selected server id is invalid. ' ],
380+ 'server ' => [self :: VALIDATION_SERVER_ID_INVALID ],
378381 ]);
379382 }
380383
381384 if (! $ this ->isValidToolName ($ tool )) {
382385 return $ this ->validationErrorResponse ([
383- 'tool ' => [' The selected tool name is invalid. ' ],
386+ 'tool ' => [self :: VALIDATION_TOOL_NAME_INVALID ],
384387 ]);
385388 }
386389
@@ -418,7 +421,7 @@ protected function executeToolCall(
418421 ): JsonResponse {
419422 if (! $ this ->isValidToolName ($ tool )) {
420423 return $ this ->validationErrorResponse ([
421- 'tool ' => [' The selected tool name is invalid. ' ],
424+ 'tool ' => [self :: VALIDATION_TOOL_NAME_INVALID ],
422425 ]);
423426 }
424427
@@ -667,13 +670,13 @@ public function toolVersions(Request $request, string $server, string $tool): Js
667670 {
668671 if (! $ this ->isValidServerId ($ server )) {
669672 return $ this ->validationErrorResponse ([
670- 'server ' => [' The selected server id is invalid. ' ],
673+ 'server ' => [self :: VALIDATION_SERVER_ID_INVALID ],
671674 ]);
672675 }
673676
674677 if (! $ this ->isValidToolName ($ tool )) {
675678 return $ this ->validationErrorResponse ([
676- 'tool ' => [' The selected tool name is invalid. ' ],
679+ 'tool ' => [self :: VALIDATION_TOOL_NAME_INVALID ],
677680 ]);
678681 }
679682
@@ -712,13 +715,13 @@ public function toolVersion(Request $request, string $server, string $tool, stri
712715 {
713716 if (! $ this ->isValidServerId ($ server )) {
714717 return $ this ->validationErrorResponse ([
715- 'server ' => [' The selected server id is invalid. ' ],
718+ 'server ' => [self :: VALIDATION_SERVER_ID_INVALID ],
716719 ]);
717720 }
718721
719722 if (! $ this ->isValidToolName ($ tool )) {
720723 return $ this ->validationErrorResponse ([
721- 'tool ' => [' The selected tool name is invalid. ' ],
724+ 'tool ' => [self :: VALIDATION_TOOL_NAME_INVALID ],
722725 ]);
723726 }
724727
@@ -767,7 +770,7 @@ public function resource(Request $request, string $uri): JsonResponse
767770
768771 if (! $ this ->isValidServerId ($ serverId )) {
769772 return $ this ->validationErrorResponse ([
770- 'uri ' => [' The selected server id is invalid. ' ],
773+ 'uri ' => [self :: VALIDATION_SERVER_ID_INVALID ],
771774 ]);
772775 }
773776
0 commit comments