Skip to content

Commit 1d741c6

Browse files
authored
Merge pull request #167 from WolframResearch/166-wolframlanguageevaluator-tool-fails-with-agenttoolsinternalpath-error-on-windows-11-when-used-with-claude-desktop
Fall back to non-UI results when cloud notebook deployment fails
2 parents 68757d2 + f332c0e commit 1d741c6

9 files changed

Lines changed: 278 additions & 121 deletions

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ See [building.md](docs/building.md) for detailed instructions.
5353
- `PacletExtension.wl`: Paclet discovery, name resolution, and definition loading for the [paclet extension](docs/paclet-extensions.md) system
5454
- `StartMCPServer.wl`: Implementation for starting MCP servers
5555
- `ValidateAgentToolsPacletExtension.wl`: Validation of `"AgentTools"` [paclet extensions](docs/paclet-extensions.md)
56-
- `UIResources.wl`: [MCP Apps](docs/mcp-apps.md) UI resource registry and client capability detection
56+
- `UIResources.wl`: [MCP Apps](docs/mcp-apps.md) UI resource registry, client capability detection, and shared cloud notebook deployment helper
5757
- `YAML.wl`: YAML import/export helpers (`importYAML`, `importYAMLString`, `exportYAML`, `exportYAMLString`) used by YAML-based MCP clients (e.g. Goose)
5858
- `Tools/`: Contains several files defining predefined MCP tools used by default servers. If tool schemas are modified, we need to rebuild agent skills.
5959
- `Prompts/`: Contains files defining predefined [MCP prompts](docs/mcp-prompts.md) used by default servers

Kernel/CommonSymbols.wl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BeginPackage[ "Wolfram`AgentTools`Common`" ];
66
`$cloudNotebooks;
77
`$debug;
88
`$defaultMCPServer;
9+
`$deployCloudNotebooks;
910
`$deploymentsPath;
1011
`$imagePath;
1112
`$mcpEvaluation;
@@ -25,6 +26,7 @@ BeginPackage[ "Wolfram`AgentTools`Common`" ];
2526
`catchTopAs;
2627
`chatbookVersionCheck;
2728
`defaultEnvironment;
29+
`deployCloudNotebookForMCPApp;
2830
`directoryQ;
2931
`endDefinition;
3032
`endExportedDefinition;

Kernel/Tools/WolframAlpha.wl

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ Needs[ "Wolfram`AgentTools`Tools`" ];
1010

1111
Needs[ "Wolfram`Chatbook`" -> "cb`" ];
1212

13-
(* ::**************************************************************************************************************:: *)
14-
(* ::Section::Closed:: *)
15-
(*Config*)
16-
17-
(* Cloud path root for deployed WA notebooks *)
18-
$deployedNotebookRoot = "AgentTools/Notebooks";
19-
2013
(* ::**************************************************************************************************************:: *)
2114
(* ::Section::Closed:: *)
2215
(*Prompts*)
@@ -66,12 +59,11 @@ $defaultMCPTools[ "WolframAlpha" ] := LLMTool @ <|
6659
(*wolframAlphaToolEvaluate*)
6760
wolframAlphaToolEvaluate // beginDefinition;
6861

69-
wolframAlphaToolEvaluate[ as_ ] := (
70-
If[ TrueQ @ $clientSupportsUI && TrueQ @ $CloudConnected (* must be connected to deploy notebooks *),
62+
wolframAlphaToolEvaluate[ as_ ] :=
63+
If[ TrueQ @ $clientSupportsUI && TrueQ @ $deployCloudNotebooks,
7164
wolframAlphaToolEvaluateUI @ as,
7265
wolframAlphaToolEvaluate[ as, cb`$DefaultTools[ "WolframAlpha" ][ as ] ]
73-
]
74-
);
66+
];
7567

7668
wolframAlphaToolEvaluate[ as_, result_String ] := extractWolframAlphaImages @ result;
7769
wolframAlphaToolEvaluate[ as_, KeyValuePattern[ "String" -> result_String ] ] := extractWolframAlphaImages @ result;
@@ -113,7 +105,7 @@ wolframAlphaToolEvaluateUI // endDefinition;
113105
makeUIResult // beginDefinition;
114106

115107
makeUIResult[ as_, KeyValuePattern[ { "Result" -> waResult_, "String" -> stringResult_String } ] ] := Enclose[
116-
Module[ { textContent, formatted, nb, query, target, deployed, notebookUrl },
108+
Catch @ Module[ { textContent, formatted, nb, query, deployed },
117109

118110
textContent = ConfirmMatch[
119111
toContentList @ extractWolframAlphaImages @ stringResult,
@@ -143,32 +135,16 @@ makeUIResult[ as_, KeyValuePattern[ { "Result" -> waResult_, "String" -> stringR
143135

144136
query = ConfirmBy[ as[ "query" ], StringQ, "Query" ];
145137

146-
target = ConfirmMatch[
147-
FileNameJoin @ {
148-
CloudObject[ $deployedNotebookRoot, Permissions -> { "All" -> { "Read", "Interact" } } ],
149-
"WolframAlpha",
150-
Hash[ query, Automatic, "HexString" ] <> ".nb"
151-
},
152-
_CloudObject,
153-
"Target"
154-
];
155-
156138
deployed = ConfirmMatch[
157-
CloudDeploy[
158-
nb,
159-
target,
160-
Permissions -> { "All" -> { "Read", "Interact" } },
161-
AppearanceElements -> None,
162-
AutoRemove -> True,
163-
IconRules -> { }
164-
],
165-
_CloudObject,
166-
"CloudDeploy"
139+
deployCloudNotebookForMCPApp[ nb, query ],
140+
_String|$Failed,
141+
"Deployed"
167142
];
168143

169-
notebookUrl = ConfirmBy[ First @ deployed, StringQ, "NotebookURL" ];
170-
171-
<| "Content" -> textContent, "_meta" -> <| "notebookUrl" -> notebookUrl |> |>
144+
If[ StringQ @ deployed,
145+
<| "Content" -> textContent, "_meta" -> <| "notebookUrl" -> deployed |> |>,
146+
$Failed
147+
]
172148
],
173149
throwInternalFailure
174150
];

Kernel/Tools/WolframLanguageEvaluator.wl

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ System`HoldCompleteForm;
1919
$cloudImagePath := CloudObject[ "AgentTools/Images", Permissions -> $cloudImagePermissions ];
2020
$cloudImagePermissions := If[ $imageExportMethod === "CloudPublic", "Public", "Private" ];
2121
$line = 1;
22-
23-
$deployedNotebookRoot = "AgentTools/Notebooks";
24-
$outputSizeLimit = 100000;
22+
$outputSizeLimit = 100000;
2523

2624
(* ::**************************************************************************************************************:: *)
2725
(* ::Subsection::Closed:: *)
@@ -98,7 +96,7 @@ $defaultToolOptions[ "WolframLanguageEvaluator" ] = <|
9896
evaluateWolframLanguage // beginDefinition;
9997

10098
evaluateWolframLanguage[ KeyValuePattern @ { "code" -> code_, "timeConstraint" -> timeConstraint_ } ] :=
101-
If[ TrueQ @ $clientSupportsUI && TrueQ @ $CloudConnected,
99+
If[ TrueQ @ $clientSupportsUI && TrueQ @ $deployCloudNotebooks,
102100
evaluateWolframLanguageUI[ code, timeConstraint ],
103101
evaluateWolframLanguage[ code, timeConstraint ]
104102
];
@@ -292,7 +290,7 @@ makeEvaluatorUIResult[
292290
code0_String,
293291
KeyValuePattern[ { "Result" -> heldResult_, "String" -> stringResult_String } ]
294292
] := Enclose[
295-
Module[ { code, textContent, outLabel, inLabel, inputCell, outputCell, nb, hash, target, deployed, notebookUrl },
293+
Catch @ Module[ { code, textContent, outLabel, inLabel, inputCell, outputCell, nb, deployed },
296294

297295
code = StringTrim @ code0;
298296

@@ -329,36 +327,16 @@ makeEvaluatorUIResult[
329327
CellLabelAutoDelete -> False
330328
];
331329

332-
(* Hash-based cloud path *)
333-
hash = ConfirmBy[ Hash[ { code, heldResult }, "Expression", "HexString" ], StringQ, "Hash" ];
334-
335-
target = ConfirmMatch[
336-
FileNameJoin @ {
337-
CloudObject[ $deployedNotebookRoot, Permissions -> { "All" -> { "Read", "Interact" } } ],
338-
"WolframLanguageEvaluator",
339-
StringTake[ hash, 3 ],
340-
hash <> ".nb"
341-
},
342-
_CloudObject,
343-
"Target"
344-
];
345-
346330
deployed = ConfirmMatch[
347-
CloudDeploy[
348-
nb,
349-
target,
350-
AppearanceElements -> None,
351-
AutoRemove -> True,
352-
IconRules -> { },
353-
Permissions -> { "All" -> { "Read", "Interact" } }
354-
],
355-
_CloudObject,
356-
"CloudDeploy"
331+
deployCloudNotebookForMCPApp[ nb, { code, heldResult } ],
332+
_String|$Failed,
333+
"Deployed"
357334
];
358335

359-
notebookUrl = ConfirmBy[ First @ deployed, StringQ, "NotebookURL" ];
360-
361-
<| "Content" -> textContent, "_meta" -> <| "notebookUrl" -> notebookUrl |> |>
336+
If[ StringQ @ deployed,
337+
<| "Content" -> textContent, "_meta" -> <| "notebookUrl" -> deployed |> |>,
338+
$Failed
339+
]
362340
],
363341
throwInternalFailure
364342
];

Kernel/UIResources.wl

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,67 @@ Needs[ "Wolfram`AgentTools`Common`" ];
1414
$toolUIAssociations = <|
1515
"NotebookViewer" -> "ui://wolfram/notebook-viewer",
1616
"MCPAppsTest" -> "ui://wolfram/mcp-apps-test",
17-
"WolframAlpha" -> "ui://wolfram/wolframalpha-viewer",
18-
"WolframLanguageEvaluator" -> "ui://wolfram/evaluator-viewer"
17+
"WolframLanguageEvaluator" -> "ui://wolfram/evaluator-viewer",
18+
(* The WolframAlpha tool does not have a text-only fallback app view, so we make it conditional *)
19+
"WolframAlpha" :> If[ $deployCloudNotebooks, "ui://wolfram/wolframalpha-viewer", None ]
1920
|>;
2021

22+
$deployedNotebookRoot = "AgentTools/Notebooks";
23+
$deployCloudNotebooks := $deployCloudNotebooks = $CloudConnected; (* must be connected to deploy notebooks *)
24+
2125
(* ::**************************************************************************************************************:: *)
2226
(* ::Section::Closed:: *)
27+
(*Cloud Notebooks*)
28+
29+
(* ::**************************************************************************************************************:: *)
30+
(* ::Subsection::Closed:: *)
31+
(*deployCloudNotebookForMCPApp*)
32+
deployCloudNotebookForMCPApp // beginDefinition;
33+
34+
deployCloudNotebookForMCPApp[ nb_Notebook, identifier_ ] := Enclose[
35+
Module[ { hash, target, deployed },
36+
37+
(* This should be true if this function is being called: *)
38+
ConfirmAssert[ $deployCloudNotebooks, "DeployCloudNotebooksAssert" ];
39+
40+
hash = ConfirmBy[ Hash[ Unevaluated @ identifier, Automatic, "HexString" ], StringQ, "Hash" ];
41+
42+
target = ConfirmMatch[
43+
FileNameJoin @ {
44+
CloudObject[ $deployedNotebookRoot, Permissions -> { "All" -> { "Read", "Interact" } } ],
45+
hash <> ".nb"
46+
},
47+
_CloudObject,
48+
"Target"
49+
];
50+
51+
deployed = CloudDeploy[
52+
nb,
53+
target,
54+
AppearanceElements -> None,
55+
AutoRemove -> True,
56+
IconRules -> { },
57+
Permissions -> { "All" -> { "Read", "Interact" } }
58+
];
59+
60+
If[ MatchQ[ deployed, _CloudObject ],
61+
ConfirmBy[ First @ deployed, StringQ, "Result" ],
62+
(* If deploying failed, disable cloud notebook deployment for the remainder of the session: *)
63+
$deployCloudNotebooks = False;
64+
$Failed
65+
]
66+
],
67+
throwInternalFailure
68+
];
69+
70+
deployCloudNotebookForMCPApp // endDefinition;
71+
72+
(* ::**************************************************************************************************************:: *)
73+
(* ::Section::Closed:: *)
74+
(*MCP Integration Helpers*)
75+
76+
(* ::**************************************************************************************************************:: *)
77+
(* ::Subsection::Closed:: *)
2378
(*clientSupportsUIQ*)
2479
clientSupportsUIQ // beginDefinition;
2580

@@ -31,7 +86,7 @@ clientSupportsUIQ[ _ ] := False;
3186
clientSupportsUIQ // endDefinition;
3287

3388
(* ::**************************************************************************************************************:: *)
34-
(* ::Section::Closed:: *)
89+
(* ::Subsection::Closed:: *)
3590
(*mcpAppsEnabledQ*)
3691
mcpAppsEnabledQ // beginDefinition;
3792

@@ -43,7 +98,7 @@ mcpAppsEnabledQ[ ] :=
4398
mcpAppsEnabledQ // endDefinition;
4499

45100
(* ::**************************************************************************************************************:: *)
46-
(* ::Section::Closed:: *)
101+
(* ::Subsection::Closed:: *)
47102
(*initializeUIResources*)
48103
initializeUIResources // beginDefinition;
49104

@@ -98,7 +153,7 @@ loadUIResource[ htmlFile_String ] := Enclose[
98153
loadUIResource // endDefinition;
99154

100155
(* ::**************************************************************************************************************:: *)
101-
(* ::Section::Closed:: *)
156+
(* ::Subsection::Closed:: *)
102157
(*listUIResources*)
103158
listUIResources // beginDefinition;
104159

@@ -121,7 +176,7 @@ listUIResources[ ] :=
121176
listUIResources // endDefinition;
122177

123178
(* ::**************************************************************************************************************:: *)
124-
(* ::Section::Closed:: *)
179+
(* ::Subsection::Closed:: *)
125180
(*readUIResource*)
126181
readUIResource // beginDefinition;
127182

@@ -147,7 +202,7 @@ readUIResource[ msg_Association, req_ ] := Enclose[
147202
readUIResource // endDefinition;
148203

149204
(* ::**************************************************************************************************************:: *)
150-
(* ::Section::Closed:: *)
205+
(* ::Subsection::Closed:: *)
151206
(*toolUIMetadata*)
152207
toolUIMetadata // beginDefinition;
153208

@@ -165,7 +220,7 @@ toolUIMetadata[ toolName_String, None ] := { };
165220
toolUIMetadata // endDefinition;
166221

167222
(* ::**************************************************************************************************************:: *)
168-
(* ::Section::Closed:: *)
223+
(* ::Subsection::Closed:: *)
169224
(*withToolUIMetadata*)
170225
withToolUIMetadata // beginDefinition;
171226

0 commit comments

Comments
 (0)