Skip to content

Commit d0480c7

Browse files
authored
Merge pull request #177 from WolframResearch/feature/deploy-all
Support DeployAgentTools[All] for deploying to every supported client
2 parents f37c983 + 2aea1e2 commit d0480c7

5 files changed

Lines changed: 448 additions & 2 deletions

File tree

Kernel/DeployAgentTools.wl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,15 @@ $$deployAgentToolsOptions = OptionsPattern @ { DeployAgentTools, InstallMCPServe
261261
(* ::**************************************************************************************************************:: *)
262262
(* ::Subsection::Closed:: *)
263263
(*Main Definition*)
264+
(* Default server is `Automatic` *)
264265
DeployAgentTools[ target_, opts: $$deployAgentToolsOptions ] :=
265266
catchMine @ DeployAgentTools[ target, Automatic, opts ];
266267

268+
(* Deploy for all clients *)
269+
DeployAgentTools[ All, server_, opts: $$deployAgentToolsOptions ] :=
270+
catchMine @ deployAllAgentTools[ server, opts ];
271+
272+
(* Resolve automatic server *)
267273
DeployAgentTools[ target_, Automatic, opts: $$deployAgentToolsOptions ] :=
268274
catchMine @ DeployAgentTools[
269275
target,
@@ -278,11 +284,83 @@ DeployAgentTools[ target_, Automatic, opts: $$deployAgentToolsOptions ] :=
278284
opts
279285
];
280286

287+
(* Proceed with deployment *)
281288
DeployAgentTools[ target_, server_, opts: $$deployAgentToolsOptions ] :=
282289
catchMine @ deployAgentTools[ target, ensureMCPServerExists @ MCPServerObject @ server, opts ];
283290

284291
DeployAgentTools // endExportedDefinition;
285292

293+
(* ::**************************************************************************************************************:: *)
294+
(* ::Subsubsection::Closed:: *)
295+
(*deployAllAgentTools*)
296+
deployAllAgentTools // beginDefinition;
297+
298+
deployAllAgentTools[ server0_, opts: $$deployAgentToolsOptions ] := Enclose[
299+
Module[ { clients, server, results },
300+
clients = ConfirmMatch[ Keys @ $SupportedMCPClients, { __String }, "Clients" ];
301+
302+
server = If[ server0 === Automatic,
303+
Automatic,
304+
ConfirmBy[ ensureMCPServerExists @ MCPServerObject @ server0, MCPServerObjectQ, "Server" ]
305+
];
306+
307+
results = ConfirmMatch[
308+
Map[ deployAgentToolsQuietly[ #, resolveServerForClient[ #, server ], opts ] &, clients ],
309+
{ (_AgentToolsDeployment | Missing[ "DeploymentExists", _ ] | Missing[ "Unsupported", _ ]).. },
310+
"Results"
311+
];
312+
313+
If[ MemberQ[ results, Missing[ "DeploymentExists", _ ] ],
314+
messagePrint[ "DeploymentsExistWarning" ]
315+
];
316+
317+
results
318+
],
319+
throwInternalFailure
320+
];
321+
322+
deployAllAgentTools // endDefinition;
323+
324+
(* ::**************************************************************************************************************:: *)
325+
(* ::Subsubsection::Closed:: *)
326+
(*resolveServerForClient*)
327+
(* When `server === Automatic`, resolve each client's `DefaultToolset` directly
328+
from the client name. Going through the 2-arg `defaultToolsetForTarget`
329+
inside `DeployAgentTools[target, Automatic, opts]` would let an explicit
330+
`"ApplicationName" -> name` option override the per-client default, which
331+
defeats the point of `All`. *)
332+
resolveServerForClient // beginDefinition;
333+
resolveServerForClient[ client_String, Automatic ] := defaultToolsetForTarget @ client;
334+
resolveServerForClient[ _, server_ ] := server;
335+
resolveServerForClient // endDefinition;
336+
337+
(* ::**************************************************************************************************************:: *)
338+
(* ::Subsubsection::Closed:: *)
339+
(*deployAgentToolsQuietly*)
340+
deployAgentToolsQuietly // beginDefinition;
341+
342+
deployAgentToolsQuietly[ target_, server_, opts: $$deployAgentToolsOptions ] :=
343+
Quiet[
344+
Replace[
345+
catchAlways @ DeployAgentTools[ target, server, opts ],
346+
{
347+
(* Used to issue a single warning about OverwriteTarget: *)
348+
Failure[ "DeployAgentTools::DeploymentExists", _ ] :>
349+
Missing[ "DeploymentExists", target ],
350+
351+
(* Some clients aren't supported on all operating systems: *)
352+
Failure[ "DeployAgentTools::UnknownInstallLocation", _ ] :>
353+
Missing[ "Unsupported", { target, $OperatingSystem } ],
354+
355+
(* Other failures are propagated to the top level: *)
356+
other_Failure :> throwTop @ other
357+
}
358+
],
359+
{ DeployAgentTools::DeploymentExists, DeployAgentTools::UnknownInstallLocation }
360+
];
361+
362+
deployAgentToolsQuietly // endDefinition;
363+
286364
(* ::**************************************************************************************************************:: *)
287365
(* ::Subsection::Closed:: *)
288366
(*deployAgentTools*)

Kernel/Messages.wl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ AgentTools::CodeInspectorInvalidConfidence = "Confidence level must be between
6969

7070
(* DeployAgentTools messages *)
7171
AgentTools::DeploymentExists = "A deployment already exists for target `1`. Use OverwriteTarget -> True to replace it.";
72+
AgentTools::DeploymentsExistWarning = "Warning: Some deployments already exist. Use OverwriteTarget -> True to replace them.";
7273
AgentTools::DeploymentNotFound = "No deployment found with UUID \"`1`\".";
7374
AgentTools::InvalidDeploymentData = "Invalid deployment data: `1`.";
74-
AgentTools::InvalidDeployTarget = "Invalid deployment target: `1`. Expected a client name string, {name, directory}, or File[\[Ellipsis]].";
75+
AgentTools::InvalidDeployTarget = "Invalid deployment target: `1`. Expected a client name string, {name, directory}, File[\[Ellipsis]], or All.";
7576

7677
(* PacletTools messages *)
7778
AgentTools::PacletToolsInvalidPath = "The path \"`1`\" does not exist. Provide an absolute path to either the paclet root directory or the definition notebook (.nb) file.";

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ CreateMCPServer["My MCP Server", <|
273273
| `UninstallMCPServer[client]` | Remove all servers from a client |
274274
| `UninstallMCPServer[client, name]` | Remove a specific server from a client |
275275
| `DeployAgentTools[target]` | Deploy tools to a client with tracked deployment management |
276+
| `DeployAgentTools[All]` | Deploy tools to every client in `$SupportedMCPClients` (see [docs/deploy-agent-tools.md](docs/deploy-agent-tools.md#deploying-to-all-clients)) |
276277
| `ValidateAgentToolsPacletExtension[paclet]` | Validate an `"AgentTools"` paclet extension |
277278
| `DeployedAgentTools[]` | List all tracked deployments |
278279
| `CreatePreferencesContent[]` | Build the preferences panel UI for managing deployed Wolfram toolsets (see [docs/preferences-content.md](docs/preferences-content.md)) |

0 commit comments

Comments
 (0)