Skip to content

Commit c5202d4

Browse files
committed
#906 Add watchPaths option to McpHub for file change detection
1 parent 1b37a71 commit c5202d4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/services/mcp/McpHub.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const BaseConfigSchema = z.object({
4141
disabled: z.boolean().optional(),
4242
timeout: z.number().min(1).max(3600).optional().default(60),
4343
alwaysAllow: z.array(z.string()).default([]),
44+
watchPaths: z.array(z.string()).optional(), // paths to watch for changes and restart server
4445
})
4546

4647
// Custom error messages for better user feedback
@@ -683,6 +684,22 @@ export class McpHub {
683684
private setupFileWatcher(name: string, config: z.infer<typeof ServerConfigSchema>) {
684685
// Only stdio type has args
685686
if (config.type === "stdio") {
687+
if (config.watchPaths && config.watchPaths.length > 0) {
688+
console.log(`Setting up file watchers for ${name} MCP server...`)
689+
const watcher = chokidar.watch(config.watchPaths, {
690+
// persistent: true,
691+
// ignoreInitial: true,
692+
// awaitWriteFinish: true,
693+
})
694+
695+
watcher.on("change", (changedPath) => {
696+
console.log(`Detected change in ${changedPath}. Restarting server ${name}...`)
697+
this.restartConnection(name)
698+
})
699+
700+
this.fileWatchers.set(name, watcher)
701+
}
702+
686703
const filePath = config.args?.find((arg: string) => arg.includes("build/index.js"))
687704
if (filePath) {
688705
// we use chokidar instead of onDidSaveTextDocument because it doesn't require the file to be open in the editor. The settings config is better suited for onDidSave since that will be manually updated by the user or Cline (and we want to detect save events, not every file change)

0 commit comments

Comments
 (0)