1212use PhpMcp \Server \Definitions \ResourceDefinition ;
1313use PhpMcp \Server \Definitions \ResourceTemplateDefinition ;
1414use PhpMcp \Server \Definitions \ToolDefinition ;
15- use PhpMcp \Server \Exceptions \ McpException ;
15+ use PhpMcp \Server \Exception \ McpServerException ;
1616use PhpMcp \Server \Registry ;
1717use Psr \Log \LoggerInterface ;
1818use ReflectionAttribute ;
@@ -64,7 +64,7 @@ public function discover(string $basePath, array $directories, array $excludeDir
6464 $ finder = new Finder ();
6565 $ absolutePaths = [];
6666 foreach ($ directories as $ dir ) {
67- $ path = rtrim ($ basePath , '/ ' ). '/ ' . ltrim ($ dir , '/ ' );
67+ $ path = rtrim ($ basePath , '/ ' ) . '/ ' . ltrim ($ dir , '/ ' );
6868 if (is_dir ($ path )) {
6969 $ absolutePaths [] = $ path ;
7070 }
@@ -84,7 +84,6 @@ public function discover(string $basePath, array $directories, array $excludeDir
8484 foreach ($ finder as $ file ) {
8585 $ this ->processFile ($ file , $ discoveredCount );
8686 }
87-
8887 } catch (Throwable $ e ) {
8988 $ this ->logger ->error ('Error during file finding process for MCP discovery ' , [
9089 'exception ' => $ e ->getMessage (),
@@ -149,8 +148,10 @@ private function processFile(SplFileInfo $file, array &$discoveredCount): void
149148
150149 if (! $ processedViaClassAttribute ) {
151150 foreach ($ reflectionClass ->getMethods (ReflectionMethod::IS_PUBLIC ) as $ method ) {
152- if ($ method ->getDeclaringClass ()->getName () !== $ reflectionClass ->getName () ||
153- $ method ->isStatic () || $ method ->isAbstract () || $ method ->isConstructor () || $ method ->isDestructor () || $ method ->getName () === '__invoke ' ) {
151+ if (
152+ $ method ->getDeclaringClass ()->getName () !== $ reflectionClass ->getName () ||
153+ $ method ->isStatic () || $ method ->isAbstract () || $ method ->isConstructor () || $ method ->isDestructor () || $ method ->getName () === '__invoke '
154+ ) {
154155 continue ;
155156 }
156157 $ attributeTypes = [McpTool::class, McpResource::class, McpPrompt::class, McpResourceTemplate::class];
@@ -166,7 +167,6 @@ private function processFile(SplFileInfo $file, array &$discoveredCount): void
166167 }
167168 }
168169 }
169-
170170 } catch (ReflectionException $ e ) {
171171 $ this ->logger ->error ('Reflection error processing file for MCP discovery ' , ['file ' => $ filePath , 'class ' => $ className , 'exception ' => $ e ->getMessage ()]);
172172 } catch (Throwable $ e ) {
@@ -211,7 +211,7 @@ private function processMethod(ReflectionMethod $method, array &$discoveredCount
211211
212212 case McpResource::class:
213213 if (! isset ($ instance ->uri )) {
214- throw new McpException ("McpResource attribute on {$ className }:: {$ methodName } requires a 'uri'. " );
214+ throw new McpServerException ("McpResource attribute on {$ className }:: {$ methodName } requires a 'uri'. " );
215215 }
216216 $ definition = ResourceDefinition::fromReflection (
217217 $ method ,
@@ -240,7 +240,7 @@ private function processMethod(ReflectionMethod $method, array &$discoveredCount
240240
241241 case McpResourceTemplate::class:
242242 if (! isset ($ instance ->uriTemplate )) {
243- throw new McpException ("McpResourceTemplate attribute on {$ className }:: {$ methodName } requires a 'uriTemplate'. " );
243+ throw new McpServerException ("McpResourceTemplate attribute on {$ className }:: {$ methodName } requires a 'uriTemplate'. " );
244244 }
245245 $ definition = ResourceTemplateDefinition::fromReflection (
246246 $ method ,
@@ -255,8 +255,7 @@ private function processMethod(ReflectionMethod $method, array &$discoveredCount
255255 $ discoveredCount ['resourceTemplates ' ]++;
256256 break ;
257257 }
258-
259- } catch (McpException $ e ) {
258+ } catch (McpServerException $ e ) {
260259 $ this ->logger ->error ("Failed to process MCP attribute on {$ className }:: {$ methodName }" , ['attribute ' => $ attributeClassName , 'exception ' => $ e ->getMessage (), 'trace ' => $ e ->getPrevious () ? $ e ->getPrevious ()->getTraceAsString () : $ e ->getTraceAsString ()]);
261260 } catch (Throwable $ e ) {
262261 $ this ->logger ->error ("Unexpected error processing attribute on {$ className }:: {$ methodName }" , ['attribute ' => $ attributeClassName , 'exception ' => $ e ->getMessage (), 'trace ' => $ e ->getTraceAsString ()]);
@@ -344,7 +343,7 @@ private function getClassFromFile(string $filePath): ?string
344343 for ($ j = $ i + 1 ; $ j < $ tokenCount ; $ j ++) {
345344 if (is_array ($ tokens [$ j ]) && $ tokens [$ j ][0 ] === T_STRING ) {
346345 $ className = $ tokens [$ j ][1 ];
347- $ potentialClasses [] = $ namespace ? $ namespace. '\\' . $ className : $ className ;
346+ $ potentialClasses [] = $ namespace ? $ namespace . '\\' . $ className : $ className ;
348347 $ i = $ j ;
349348 break ;
350349 }
0 commit comments