@@ -15,6 +15,13 @@ import { type McpToolContext, type McpToolDeclaration, declareTool } from '../to
1515
1616const devserverStartToolInputSchema = z . object ( {
1717 ...workspaceAndProjectOptions ,
18+ port : z
19+ . number ( )
20+ . optional ( )
21+ . describe (
22+ 'The port number to run the server on. If not provided, a random available port will be chosen. ' +
23+ 'It is recommended to reuse port numbers across calls within the same workspace to maintain consistency.' ,
24+ ) ,
1825} ) ;
1926
2027export type DevserverStartToolInput = z . infer < typeof devserverStartToolInputSchema > ;
@@ -53,7 +60,17 @@ export async function startDevserver(input: DevserverStartToolInput, context: Mc
5360 } ) ;
5461 }
5562
56- const port = await context . host . getAvailablePort ( ) ;
63+ let port : number ;
64+ if ( input . port ) {
65+ if ( ! ( await context . host . isPortAvailable ( input . port ) ) ) {
66+ throw new Error (
67+ `Port ${ input . port } is unavailable. Try calling this tool again without the 'port' parameter to auto-assign a free port.` ,
68+ ) ;
69+ }
70+ port = input . port ;
71+ } else {
72+ port = await context . host . getAvailablePort ( ) ;
73+ }
5774
5875 devserver = new LocalDevserver ( {
5976 host : context . host ,
@@ -87,14 +104,18 @@ the first build completes.
87104 background.
88105* **Get Initial Build Logs:** Once a dev server has started, use the "devserver.wait_for_build" tool to ensure it's alive. If there are any
89106 build errors, "devserver.wait_for_build" would provide them back and you can give them to the user or rely on them to propose a fix.
90- * **Get Updated Build Logs:** Important: as long as a devserver is alive (i.e. "devserver.stop" wasn't called), after every time you make a
91- change to the workspace, re-run "devserver.wait_for_build" to see whether the change was successfully built and wait for the devserver to
92- be updated.
107+ * **Get Updated Build Logs:** Important: as long as a devserver is alive (i.e. "devserver.stop" wasn't called), after every time you
108+ make a change to the workspace, re-run "devserver.wait_for_build" to see whether the change was successfully built and wait for the
109+ devserver to be updated.
93110</Use Cases>
94111<Operational Notes>
95112* This tool manages development servers by itself. It maintains at most a single dev server instance for each project in the monorepo.
96113* This is an asynchronous operation. Subsequent commands can be ran while the server is active.
97114* Use 'devserver.stop' to gracefully shut down the server and access the full log output.
115+ * **Keeping the Server Alive**: It is often better to keep the server alive between tool calls if you expect the user to request more
116+ changes or run more tests, as it saves time on restarts and maintains the file watcher state. You must still call
117+ 'devserver.wait_for_build' after every change to see whether the change was successfully built and be sure that that app was updated.
118+ * **Consistent Ports**: If making multiple calls, it is recommended to reuse the port you got from the first call for subsequent ones.
98119</Operational Notes>
99120` ,
100121 isReadOnly : true ,
0 commit comments