You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/server-builder.md
+59-23Lines changed: 59 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,8 +99,9 @@ $server = Server::builder()
99
99
->setDiscovery(
100
100
basePath: __DIR__,
101
101
scanDirs: ['.', 'src', 'lib'], // Where to look for MCP attributes
102
-
excludeDirs: ['vendor', 'tests'], // Where NOT to look
103
-
cache: $cacheInstance // Optional: cache discovered elements
102
+
excludeDirs: ['vendor', 'tests'], // Where NOT to look
103
+
cache: $cacheInstance, // Optional: cache discovered elements
104
+
namePatterns: ['*.php', '*.inc'], // Optional: list of filename patterns to match
104
105
);
105
106
```
106
107
@@ -109,6 +110,7 @@ $server = Server::builder()
109
110
-`$scanDirs` (array): Directories to recursively scan for `#[McpTool]`, `#[McpResource]`, etc. All subdirectories are included. (default: `['.', 'src']`)
110
111
-`$excludeDirs` (array): Directory names to exclude **within** the scanned directories during recursive scanning
111
112
-`$cache` (CacheInterface|null): Optional PSR-16 cache to store discovered elements for performance
113
+
-`$namePatterns` (array): Optional list of patterns (regexp, glob, or string) for file names (default: `['*.php']`)
112
114
113
115
**Basic Discovery (scans current directory and `src/`):**
114
116
```php
@@ -137,7 +139,7 @@ $server = Server::builder()
137
139
138
140
**How `excludeDirs` works:**
139
141
- If scanning `src/` and there's `src/vendor/`, it will be excluded
140
-
- If scanning `lib/` and there's `lib/tests/`, it will be excluded
142
+
- If scanning `lib/` and there's `lib/tests/`, it will be excluded
141
143
- But if `vendor/` and `tests/` are at the same level as `src/`, they're not scanned anyway (not in `scanDirs`)
142
144
143
145
> **Performance**: Always use a cache in production. The first run scans and caches all discovered MCP elements, making
@@ -154,11 +156,6 @@ use Mcp\Server\Session\Psr16SessionStore;
0 commit comments