@sassoftware/sas-score-mcp-serverjs 0.4.1-1 → 0.4.1-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/createMcpServer.js +3 -5
- package/src/toolSet/devaScore.js +62 -61
- package/src/toolSet/findJob.js +1 -1
- package/src/toolSet/findJobdef.js +2 -2
- package/src/toolSet/findLibrary.js +67 -67
- package/src/toolSet/findModel.js +2 -2
- package/src/toolSet/findTable.js +3 -2
- package/src/toolSet/getEnv.js +8 -4
- package/src/toolSet/listJobdefs.js +61 -61
- package/src/toolSet/listJobs.js +61 -61
- package/src/toolSet/listLibraries.js +78 -78
- package/src/toolSet/listModels.js +56 -56
- package/src/toolSet/listTables.js +65 -65
- package/src/toolSet/modelInfo.js +2 -2
- package/src/toolSet/modelScore.js +6 -5
- package/src/toolSet/readTable.js +63 -65
- package/src/toolSet/runCasProgram.js +7 -6
- package/src/toolSet/runJob.js +81 -81
- package/src/toolSet/runJobdef.js +82 -82
- package/src/toolSet/runMacro.js +80 -80
- package/src/toolSet/runProgram.js +2 -2
- package/src/toolSet/sasQuery.js +77 -78
- package/src/toolSet/scrInfo.js +1 -1
- package/src/toolSet/scrScore.js +70 -68
- package/src/toolSet/setContext.js +65 -65
- package/src/toolSet/superstat.js +61 -59
- package/src/toolSet/tableInfo.js +57 -57
- package/skills/mcp-tool-description-optimizer/SKILL.md +0 -129
- package/skills/mcp-tool-description-optimizer/references/examples.md +0 -123
- package/skills/sas-read-and-score/SKILL.md +0 -91
- package/skills/sas-read-strategy/SKILL.md +0 -143
- package/skills/sas-score-workflow/SKILL.md +0 -283
package/src/toolSet/runJob.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import _jobSubmit from '../toolHelpers/_jobSubmit.js';
|
|
8
|
-
|
|
9
|
-
function runJob(_appContext) {
|
|
10
|
-
|
|
11
|
-
let description = `
|
|
12
|
-
run-job — execute a deployed SAS Viya job.
|
|
13
|
-
|
|
14
|
-
USE when: run job, execute job, run with parameters
|
|
15
|
-
DO NOT USE for: arbitrary SAS code (use run-sas-program), macros (use run-macro), list/find jobs
|
|
16
|
-
|
|
17
|
-
PARAMETERS
|
|
18
|
-
- name: string — job name (required)
|
|
19
|
-
- scenario: string | object — input parameters. Accepts: "x=1, y=2" or {x:1, y:2}
|
|
20
|
-
|
|
21
|
-
ROUTING RULES
|
|
22
|
-
- "run job xyz" → { name: "xyz" }
|
|
23
|
-
- "run job xyz with param1=10, param2=val2" → { name: "xyz", scenario: {param1:10, param2:"val2"} }
|
|
24
|
-
|
|
25
|
-
EXAMPLES
|
|
26
|
-
- "run job xyz" → { name: "xyz" }
|
|
27
|
-
- "run job monthly_etl with month=10, year=2025" → { name: "monthly_etl", scenario: {month:10, year:2025} }
|
|
28
|
-
|
|
29
|
-
NEGATIVE EXAMPLES (do not route here)
|
|
30
|
-
- "run SAS code" (use run-sas-program)
|
|
31
|
-
- "run macro X" (use run-macro)
|
|
32
|
-
- "list jobs" (use list-jobs)
|
|
33
|
-
- "find job X" (use find-job)
|
|
34
|
-
|
|
35
|
-
ERRORS
|
|
36
|
-
Returns log output, listings, tables from job. Error if job not found.
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
let spec = {
|
|
40
|
-
name: 'run-job',
|
|
41
|
-
description: description,
|
|
42
|
-
inputSchema: z.object({
|
|
43
|
-
name: z.string(),
|
|
44
|
-
scenario: z.
|
|
45
|
-
}),
|
|
46
|
-
handler: async (params) => {
|
|
47
|
-
let scenario = params.scenario;
|
|
48
|
-
let scenarioObj = {};
|
|
49
|
-
let count = 0;
|
|
50
|
-
//
|
|
51
|
-
if (scenario == null) {
|
|
52
|
-
scenarioObj = {};
|
|
53
|
-
} else if (typeof scenario === 'object') {
|
|
54
|
-
scenarioObj = scenario;
|
|
55
|
-
} else if (Array.isArray(scenario)) {
|
|
56
|
-
scenarioObj = scenario[0];
|
|
57
|
-
} else if (typeof scenario === 'string') {
|
|
58
|
-
if (scenario.trim() === '') {
|
|
59
|
-
scenarioObj = {};
|
|
60
|
-
} else {
|
|
61
|
-
// console.error('Incoming scenario', scenario);
|
|
62
|
-
scenarioObj = scenario.split(',').reduce((acc, pair) => {
|
|
63
|
-
let [key, value] = pair.split('=');
|
|
64
|
-
acc[key.trim()] = value;
|
|
65
|
-
count++;
|
|
66
|
-
return acc;
|
|
67
|
-
}, {});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
params.type = 'job';
|
|
71
|
-
params.scenario = scenarioObj;
|
|
72
|
-
// Provide runtime context for auth and server settings
|
|
73
|
-
let r = await _jobSubmit(params);
|
|
74
|
-
return r;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
return spec;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default runJob;
|
|
81
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import _jobSubmit from '../toolHelpers/_jobSubmit.js';
|
|
8
|
+
|
|
9
|
+
function runJob(_appContext) {
|
|
10
|
+
|
|
11
|
+
let description = `
|
|
12
|
+
run-job — execute a deployed SAS Viya job.
|
|
13
|
+
|
|
14
|
+
USE when: run job, execute job, run with parameters
|
|
15
|
+
DO NOT USE for: arbitrary SAS code (use run-sas-program), macros (use run-macro), list/find jobs
|
|
16
|
+
|
|
17
|
+
PARAMETERS
|
|
18
|
+
- name: string — job name (required)
|
|
19
|
+
- scenario: string | object — input parameters. Accepts: "x=1, y=2" or {x:1, y:2}
|
|
20
|
+
|
|
21
|
+
ROUTING RULES
|
|
22
|
+
- "run job xyz" → { name: "xyz" }
|
|
23
|
+
- "run job xyz with param1=10, param2=val2" → { name: "xyz", scenario: {param1:10, param2:"val2"} }
|
|
24
|
+
|
|
25
|
+
EXAMPLES
|
|
26
|
+
- "run job xyz" → { name: "xyz" }
|
|
27
|
+
- "run job monthly_etl with month=10, year=2025" → { name: "monthly_etl", scenario: {month:10, year:2025} }
|
|
28
|
+
|
|
29
|
+
NEGATIVE EXAMPLES (do not route here)
|
|
30
|
+
- "run SAS code" (use run-sas-program)
|
|
31
|
+
- "run macro X" (use run-macro)
|
|
32
|
+
- "list jobs" (use list-jobs)
|
|
33
|
+
- "find job X" (use find-job)
|
|
34
|
+
|
|
35
|
+
ERRORS
|
|
36
|
+
Returns log output, listings, tables from job. Error if job not found.
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
let spec = {
|
|
40
|
+
name: 'run-job',
|
|
41
|
+
description: description,
|
|
42
|
+
inputSchema: z.object({
|
|
43
|
+
name: z.string(),
|
|
44
|
+
scenario: z.string()
|
|
45
|
+
}),
|
|
46
|
+
handler: async (params) => {
|
|
47
|
+
let scenario = params.scenario;
|
|
48
|
+
let scenarioObj = {};
|
|
49
|
+
let count = 0;
|
|
50
|
+
//
|
|
51
|
+
if (scenario == null) {
|
|
52
|
+
scenarioObj = {};
|
|
53
|
+
} else if (typeof scenario === 'object') {
|
|
54
|
+
scenarioObj = scenario;
|
|
55
|
+
} else if (Array.isArray(scenario)) {
|
|
56
|
+
scenarioObj = scenario[0];
|
|
57
|
+
} else if (typeof scenario === 'string') {
|
|
58
|
+
if (scenario.trim() === '') {
|
|
59
|
+
scenarioObj = {};
|
|
60
|
+
} else {
|
|
61
|
+
// console.error('Incoming scenario', scenario);
|
|
62
|
+
scenarioObj = scenario.split(',').reduce((acc, pair) => {
|
|
63
|
+
let [key, value] = pair.split('=');
|
|
64
|
+
acc[key.trim()] = value;
|
|
65
|
+
count++;
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
params.type = 'job';
|
|
71
|
+
params.scenario = scenarioObj;
|
|
72
|
+
// Provide runtime context for auth and server settings
|
|
73
|
+
let r = await _jobSubmit(params);
|
|
74
|
+
return r;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return spec;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default runJob;
|
|
81
|
+
|
package/src/toolSet/runJobdef.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import _jobSubmit from '../toolHelpers/_jobSubmit.js';
|
|
8
|
-
|
|
9
|
-
function runJobdef(_appContext) {
|
|
10
|
-
// JSON object for LLM/tooling
|
|
11
|
-
|
|
12
|
-
let description = `
|
|
13
|
-
run-jobdef — execute a SAS Viya job definition.
|
|
14
|
-
|
|
15
|
-
USE when: run jobdef, execute jobdef, run with parameters
|
|
16
|
-
DO NOT USE for: arbitrary SAS code (use run-sas-program), macros (use run-macro), list/find jobdefs
|
|
17
|
-
|
|
18
|
-
PARAMETERS
|
|
19
|
-
- name: string — jobdef name (required)
|
|
20
|
-
- scenario: string | object — input parameters. Accepts: "x=1, y=2" or {x:1, y:2}
|
|
21
|
-
|
|
22
|
-
ROUTING RULES
|
|
23
|
-
- "run jobdef xyz" → { name: "xyz" }
|
|
24
|
-
- "run jobdef xyz with param1=10, param2=val2" → { name: "xyz", scenario: {param1:10, param2:"val2"} }
|
|
25
|
-
|
|
26
|
-
EXAMPLES
|
|
27
|
-
- "run jobdef xyz" → { name: "xyz" }
|
|
28
|
-
- "run jobdef monthly_report with month=10, year=2025" → { name: "monthly_report", scenario: {month:10, year:2025} }
|
|
29
|
-
|
|
30
|
-
NEGATIVE EXAMPLES (do not route here)
|
|
31
|
-
- "run SAS code" (use run-sas-program)
|
|
32
|
-
- "run macro X" (use run-macro)
|
|
33
|
-
- "list jobdefs" (use list-jobdefs)
|
|
34
|
-
- "find jobdef X" (use find-jobdef)
|
|
35
|
-
|
|
36
|
-
ERRORS
|
|
37
|
-
Returns log output, listings, tables from jobdef. Error if jobdef not found.
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
let spec = {
|
|
41
|
-
name: 'run-jobdef',
|
|
42
|
-
description: description,
|
|
43
|
-
inputSchema: z.object({
|
|
44
|
-
name: z.string(),
|
|
45
|
-
scenario: z.
|
|
46
|
-
}),
|
|
47
|
-
handler: async (params) => {
|
|
48
|
-
let scenario = params.scenario;
|
|
49
|
-
let scenarioObj = {};
|
|
50
|
-
let count = 0;
|
|
51
|
-
//
|
|
52
|
-
if (scenario == null) {
|
|
53
|
-
scenarioObj = {};
|
|
54
|
-
} else if (typeof scenario === 'object') {
|
|
55
|
-
scenarioObj = scenario;
|
|
56
|
-
} else if (Array.isArray(scenario)) {
|
|
57
|
-
scenarioObj = scenario[0];
|
|
58
|
-
} else if (typeof scenario === 'string') {
|
|
59
|
-
if (scenario.trim() === '') {
|
|
60
|
-
scenarioObj = {};
|
|
61
|
-
} else {
|
|
62
|
-
// console.error('Incoming scenario', scenario);
|
|
63
|
-
scenarioObj = scenario.split(',').reduce((acc, pair) => {
|
|
64
|
-
let [key, value] = pair.split('=');
|
|
65
|
-
acc[key.trim()] = value;
|
|
66
|
-
count++;
|
|
67
|
-
return acc;
|
|
68
|
-
}, {});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
params.type = 'def';
|
|
72
|
-
params.scenario = scenarioObj;
|
|
73
|
-
// Provide runtime context for auth and server settings
|
|
74
|
-
let r = await _jobSubmit(params);
|
|
75
|
-
return r;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
return spec;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export default runJobdef;
|
|
82
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import _jobSubmit from '../toolHelpers/_jobSubmit.js';
|
|
8
|
+
|
|
9
|
+
function runJobdef(_appContext) {
|
|
10
|
+
// JSON object for LLM/tooling
|
|
11
|
+
|
|
12
|
+
let description = `
|
|
13
|
+
run-jobdef — execute a SAS Viya job definition.
|
|
14
|
+
|
|
15
|
+
USE when: run jobdef, execute jobdef, run with parameters
|
|
16
|
+
DO NOT USE for: arbitrary SAS code (use run-sas-program), macros (use run-macro), list/find jobdefs
|
|
17
|
+
|
|
18
|
+
PARAMETERS
|
|
19
|
+
- name: string — jobdef name (required)
|
|
20
|
+
- scenario: string | object — input parameters. Accepts: "x=1, y=2" or {x:1, y:2}
|
|
21
|
+
|
|
22
|
+
ROUTING RULES
|
|
23
|
+
- "run jobdef xyz" → { name: "xyz" }
|
|
24
|
+
- "run jobdef xyz with param1=10, param2=val2" → { name: "xyz", scenario: {param1:10, param2:"val2"} }
|
|
25
|
+
|
|
26
|
+
EXAMPLES
|
|
27
|
+
- "run jobdef xyz" → { name: "xyz" }
|
|
28
|
+
- "run jobdef monthly_report with month=10, year=2025" → { name: "monthly_report", scenario: {month:10, year:2025} }
|
|
29
|
+
|
|
30
|
+
NEGATIVE EXAMPLES (do not route here)
|
|
31
|
+
- "run SAS code" (use run-sas-program)
|
|
32
|
+
- "run macro X" (use run-macro)
|
|
33
|
+
- "list jobdefs" (use list-jobdefs)
|
|
34
|
+
- "find jobdef X" (use find-jobdef)
|
|
35
|
+
|
|
36
|
+
ERRORS
|
|
37
|
+
Returns log output, listings, tables from jobdef. Error if jobdef not found.
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
let spec = {
|
|
41
|
+
name: 'run-jobdef',
|
|
42
|
+
description: description,
|
|
43
|
+
inputSchema: z.object({
|
|
44
|
+
name: z.string(),
|
|
45
|
+
scenario: z.string()
|
|
46
|
+
}),
|
|
47
|
+
handler: async (params) => {
|
|
48
|
+
let scenario = params.scenario;
|
|
49
|
+
let scenarioObj = {};
|
|
50
|
+
let count = 0;
|
|
51
|
+
//
|
|
52
|
+
if (scenario == null) {
|
|
53
|
+
scenarioObj = {};
|
|
54
|
+
} else if (typeof scenario === 'object') {
|
|
55
|
+
scenarioObj = scenario;
|
|
56
|
+
} else if (Array.isArray(scenario)) {
|
|
57
|
+
scenarioObj = scenario[0];
|
|
58
|
+
} else if (typeof scenario === 'string') {
|
|
59
|
+
if (scenario.trim() === '') {
|
|
60
|
+
scenarioObj = {};
|
|
61
|
+
} else {
|
|
62
|
+
// console.error('Incoming scenario', scenario);
|
|
63
|
+
scenarioObj = scenario.split(',').reduce((acc, pair) => {
|
|
64
|
+
let [key, value] = pair.split('=');
|
|
65
|
+
acc[key.trim()] = value;
|
|
66
|
+
count++;
|
|
67
|
+
return acc;
|
|
68
|
+
}, {});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
params.type = 'def';
|
|
72
|
+
params.scenario = scenarioObj;
|
|
73
|
+
// Provide runtime context for auth and server settings
|
|
74
|
+
let r = await _jobSubmit(params);
|
|
75
|
+
return r;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return spec;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default runJobdef;
|
|
82
|
+
|
package/src/toolSet/runMacro.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import _submitCode from '../toolHelpers/_submitCode.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function runMacro(_appContext) {
|
|
11
|
-
let description = `
|
|
12
|
-
run-macro — submit and execute a SAS macro on SAS Viya server.
|
|
13
|
-
|
|
14
|
-
USE when: run macro, execute macro with parameters
|
|
15
|
-
DO NOT USE for: arbitrary SAS code (use run-sas-program), jobs, jobdefs
|
|
16
|
-
|
|
17
|
-
PARAMETERS
|
|
18
|
-
- macro: string — macro name without "%" (required)
|
|
19
|
-
- scenario: string — parameters or setup code (optional). Accepts: "x=1, y=abc" or "%let x=1; %let y=abc;"
|
|
20
|
-
|
|
21
|
-
ROUTING RULES
|
|
22
|
-
- "run macro abc" → { macro: "abc", scenario: "" }
|
|
23
|
-
- "run macro abc with x=1, y=2" → { macro: "abc", scenario: "x=1, y=2" }
|
|
24
|
-
- "run macro xyz with %let a=1; %let b=2;" → { macro: "xyz", scenario: "%let a=1; %let b=2;" }
|
|
25
|
-
|
|
26
|
-
EXAMPLES
|
|
27
|
-
- "run macro abc" → { macro: "abc", scenario: "" }
|
|
28
|
-
- "run macro summarize with x=1, y=2" → { macro: "summarize", scenario: "x=1, y=2" }
|
|
29
|
-
|
|
30
|
-
NEGATIVE EXAMPLES (do not route here)
|
|
31
|
-
- "run SAS code" (use run-sas-program)
|
|
32
|
-
- "run job X" (use run-job)
|
|
33
|
-
- "run jobdef X" (use run-jobdef)
|
|
34
|
-
|
|
35
|
-
ERRORS
|
|
36
|
-
Returns log, ods, tables created by macro. Auto-converts "x=1, y=2" to "%let x=1; %let y=2;" format.
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
let spec = {
|
|
40
|
-
name: 'run-macro',
|
|
41
|
-
description: description,
|
|
42
|
-
|
|
43
|
-
inputSchema: z.object({
|
|
44
|
-
macro: z.string()
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
handler: async (params) => {
|
|
48
|
-
const scenarioRaw = (params.scenario || '').trim();
|
|
49
|
-
let setup = '';
|
|
50
|
-
if (scenarioRaw) {
|
|
51
|
-
// If the scenario already contains macro syntax, send it through unchanged
|
|
52
|
-
const hasMacroSyntax = /%let\b|%[a-zA-Z_]\w*\s*\(|%[a-zA-Z_]\w*\s*;/.test(scenarioRaw) || scenarioRaw.includes('%');
|
|
53
|
-
if (hasMacroSyntax) {
|
|
54
|
-
setup = scenarioRaw;
|
|
55
|
-
} else {
|
|
56
|
-
// Convert "x=1,y=abc" -> "%let x=1; %let y=abc;"
|
|
57
|
-
setup = scenarioRaw.split(',')
|
|
58
|
-
.map(p => p.trim())
|
|
59
|
-
.filter(Boolean)
|
|
60
|
-
.map(p => {
|
|
61
|
-
const [k, ...rest] = p.split('=');
|
|
62
|
-
if (!k) return '';
|
|
63
|
-
const key = k.trim();
|
|
64
|
-
const val = rest.join('=').trim();
|
|
65
|
-
return `%let ${key}=${val};`;
|
|
66
|
-
})
|
|
67
|
-
.filter(Boolean)
|
|
68
|
-
.join(' ');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const src = `${setup} %${params.macro};`;
|
|
72
|
-
params.src = src;
|
|
73
|
-
let r = await _submitCode(params);
|
|
74
|
-
return r;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return spec;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default runMacro;
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import _submitCode from '../toolHelpers/_submitCode.js';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function runMacro(_appContext) {
|
|
11
|
+
let description = `
|
|
12
|
+
run-macro — submit and execute a SAS macro on SAS Viya server.
|
|
13
|
+
|
|
14
|
+
USE when: run macro, execute macro with parameters
|
|
15
|
+
DO NOT USE for: arbitrary SAS code (use run-sas-program), jobs, jobdefs
|
|
16
|
+
|
|
17
|
+
PARAMETERS
|
|
18
|
+
- macro: string — macro name without "%" (required)
|
|
19
|
+
- scenario: string — parameters or setup code (optional). Accepts: "x=1, y=abc" or "%let x=1; %let y=abc;"
|
|
20
|
+
|
|
21
|
+
ROUTING RULES
|
|
22
|
+
- "run macro abc" → { macro: "abc", scenario: "" }
|
|
23
|
+
- "run macro abc with x=1, y=2" → { macro: "abc", scenario: "x=1, y=2" }
|
|
24
|
+
- "run macro xyz with %let a=1; %let b=2;" → { macro: "xyz", scenario: "%let a=1; %let b=2;" }
|
|
25
|
+
|
|
26
|
+
EXAMPLES
|
|
27
|
+
- "run macro abc" → { macro: "abc", scenario: "" }
|
|
28
|
+
- "run macro summarize with x=1, y=2" → { macro: "summarize", scenario: "x=1, y=2" }
|
|
29
|
+
|
|
30
|
+
NEGATIVE EXAMPLES (do not route here)
|
|
31
|
+
- "run SAS code" (use run-sas-program)
|
|
32
|
+
- "run job X" (use run-job)
|
|
33
|
+
- "run jobdef X" (use run-jobdef)
|
|
34
|
+
|
|
35
|
+
ERRORS
|
|
36
|
+
Returns log, ods, tables created by macro. Auto-converts "x=1, y=2" to "%let x=1; %let y=2;" format.
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
let spec = {
|
|
40
|
+
name: 'run-macro',
|
|
41
|
+
description: description,
|
|
42
|
+
|
|
43
|
+
inputSchema: z.object({
|
|
44
|
+
macro: z.string()
|
|
45
|
+
}),
|
|
46
|
+
|
|
47
|
+
handler: async (params) => {
|
|
48
|
+
const scenarioRaw = (params.scenario || '').trim();
|
|
49
|
+
let setup = '';
|
|
50
|
+
if (scenarioRaw) {
|
|
51
|
+
// If the scenario already contains macro syntax, send it through unchanged
|
|
52
|
+
const hasMacroSyntax = /%let\b|%[a-zA-Z_]\w*\s*\(|%[a-zA-Z_]\w*\s*;/.test(scenarioRaw) || scenarioRaw.includes('%');
|
|
53
|
+
if (hasMacroSyntax) {
|
|
54
|
+
setup = scenarioRaw;
|
|
55
|
+
} else {
|
|
56
|
+
// Convert "x=1,y=abc" -> "%let x=1; %let y=abc;"
|
|
57
|
+
setup = scenarioRaw.split(',')
|
|
58
|
+
.map(p => p.trim())
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.map(p => {
|
|
61
|
+
const [k, ...rest] = p.split('=');
|
|
62
|
+
if (!k) return '';
|
|
63
|
+
const key = k.trim();
|
|
64
|
+
const val = rest.join('=').trim();
|
|
65
|
+
return `%let ${key}=${val};`;
|
|
66
|
+
})
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join(' ');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const src = `${setup} %${params.macro};`;
|
|
72
|
+
params.src = src;
|
|
73
|
+
let r = await _submitCode(params);
|
|
74
|
+
return r;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return spec;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default runMacro;
|
|
81
81
|
|
|
@@ -44,11 +44,11 @@ Returns log, ods, tables array, data (if output specified). Error if execution f
|
|
|
44
44
|
name: 'run-program',
|
|
45
45
|
description: description,
|
|
46
46
|
inputSchema: z.object({
|
|
47
|
-
src: z.string(),
|
|
47
|
+
src: z.string().optional,
|
|
48
48
|
scenario: z.any(),
|
|
49
49
|
output: z.string(),
|
|
50
50
|
folder: z.string(),
|
|
51
|
-
limit: z.number()
|
|
51
|
+
limit: z.number().optional()
|
|
52
52
|
}),
|
|
53
53
|
// NOTE: Previously 'required' incorrectly listed 'program' which does not
|
|
54
54
|
// exist in the schema. This prevented execution in some orchestrators that
|
package/src/toolSet/sasQuery.js
CHANGED
|
@@ -1,78 +1,77 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import {z} from 'zod';
|
|
6
|
-
import _jobSubmit from '../toolHelpers/_jobSubmit.js';
|
|
7
|
-
|
|
8
|
-
function sasQuery() {
|
|
9
|
-
|
|
10
|
-
let description = `
|
|
11
|
-
sas-query — convert natural language questions into SQL queries and execute them.
|
|
12
|
-
|
|
13
|
-
USE when: how many/count/total/average by, aggregated analytics, complex filtering, statistical summaries
|
|
14
|
-
DO NOT USE for: raw reads without filtering (use read-table), table structure (use table-info), SAS programs (use run-sas-program), jobs/jobdefs
|
|
15
|
-
|
|
16
|
-
PARAMETERS
|
|
17
|
-
- table: string — table in lib.table format (required), e.g. "Public.cars" or "sashelp.class"
|
|
18
|
-
- query: string — natural language question (required)
|
|
19
|
-
- sql: string — pre-generated SQL SELECT (optional, LLM generates)
|
|
20
|
-
- job: string (default: 'program') — job name to execute
|
|
21
|
-
|
|
22
|
-
ROUTING RULES
|
|
23
|
-
- "how many cars by make in sashelp.cars" → { table: "sashelp.cars", query: "how many cars by make", sql: "SELECT make, COUNT(*) FROM sashelp.cars GROUP BY make" }
|
|
24
|
-
- "average salary by department in Public.employees" → { table: "Public.employees", query: "average salary by department", sql: "SELECT department, AVG(salary) FROM Public.employees GROUP BY department" }
|
|
25
|
-
|
|
26
|
-
EXAMPLES
|
|
27
|
-
- "how many cars by make in sashelp.cars" → { table: "sashelp.cars", query: "how many cars by make", sql: "SELECT make, COUNT(*) FROM sashelp.cars GROUP BY make" }
|
|
28
|
-
- "total sales by region from mylib.sales" → { table: "mylib.sales", query: "total sales by region", sql: "SELECT region, SUM(amount) FROM mylib.sales GROUP BY region" }
|
|
29
|
-
|
|
30
|
-
NEGATIVE EXAMPLES (do not route here)
|
|
31
|
-
- "read table cars" (use read-table)
|
|
32
|
-
- "show 10 rows" (use read-table)
|
|
33
|
-
- "table structure" (use table-info)
|
|
34
|
-
- "run SAS code" (use run-sas-program)
|
|
35
|
-
- "run job/macro" (use run-job/run-macro)
|
|
36
|
-
|
|
37
|
-
ERRORS
|
|
38
|
-
Returns rows array, columns metadata, log. Returns error if SQL invalid or table not found.
|
|
39
|
-
`;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let spec = {
|
|
43
|
-
name: 'sas-query',
|
|
44
|
-
description: description,
|
|
45
|
-
inputSchema: z.object({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import {z} from 'zod';
|
|
6
|
+
import _jobSubmit from '../toolHelpers/_jobSubmit.js';
|
|
7
|
+
|
|
8
|
+
function sasQuery() {
|
|
9
|
+
|
|
10
|
+
let description = `
|
|
11
|
+
sas-query — convert natural language questions into SQL queries and execute them.
|
|
12
|
+
|
|
13
|
+
USE when: how many/count/total/average by, aggregated analytics, complex filtering, statistical summaries
|
|
14
|
+
DO NOT USE for: raw reads without filtering (use read-table), table structure (use table-info), SAS programs (use run-sas-program), jobs/jobdefs
|
|
15
|
+
|
|
16
|
+
PARAMETERS
|
|
17
|
+
- table: string — table in lib.table format (required), e.g. "Public.cars" or "sashelp.class"
|
|
18
|
+
- query: string — natural language question (required)
|
|
19
|
+
- sql: string — pre-generated SQL SELECT (optional, LLM generates)
|
|
20
|
+
- job: string (default: 'program') — job name to execute
|
|
21
|
+
|
|
22
|
+
ROUTING RULES
|
|
23
|
+
- "how many cars by make in sashelp.cars" → { table: "sashelp.cars", query: "how many cars by make", sql: "SELECT make, COUNT(*) FROM sashelp.cars GROUP BY make" }
|
|
24
|
+
- "average salary by department in Public.employees" → { table: "Public.employees", query: "average salary by department", sql: "SELECT department, AVG(salary) FROM Public.employees GROUP BY department" }
|
|
25
|
+
|
|
26
|
+
EXAMPLES
|
|
27
|
+
- "how many cars by make in sashelp.cars" → { table: "sashelp.cars", query: "how many cars by make", sql: "SELECT make, COUNT(*) FROM sashelp.cars GROUP BY make" }
|
|
28
|
+
- "total sales by region from mylib.sales" → { table: "mylib.sales", query: "total sales by region", sql: "SELECT region, SUM(amount) FROM mylib.sales GROUP BY region" }
|
|
29
|
+
|
|
30
|
+
NEGATIVE EXAMPLES (do not route here)
|
|
31
|
+
- "read table cars" (use read-table)
|
|
32
|
+
- "show 10 rows" (use read-table)
|
|
33
|
+
- "table structure" (use table-info)
|
|
34
|
+
- "run SAS code" (use run-sas-program)
|
|
35
|
+
- "run job/macro" (use run-job/run-macro)
|
|
36
|
+
|
|
37
|
+
ERRORS
|
|
38
|
+
Returns rows array, columns metadata, log. Returns error if SQL invalid or table not found.
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
let spec = {
|
|
43
|
+
name: 'sas-query',
|
|
44
|
+
description: description,
|
|
45
|
+
inputSchema: z.object({
|
|
46
|
+
query: z.string(),
|
|
47
|
+
table: z.string(),
|
|
48
|
+
sql: z.string()
|
|
49
|
+
}),
|
|
50
|
+
handler: async (params) => {
|
|
51
|
+
let {table,query, sql, job, _appContext} = params;
|
|
52
|
+
let sqlinput = (sql == null) ? ' ' : sql.replaceAll(';', ' ').replaceAll('\n', ' ').replaceAll('\r', ' ');
|
|
53
|
+
|
|
54
|
+
let iparams = {
|
|
55
|
+
scenario: {
|
|
56
|
+
table: table,
|
|
57
|
+
prompt: query,
|
|
58
|
+
sql: sqlinput
|
|
59
|
+
},
|
|
60
|
+
name: (job == null) ? 'program' : job,
|
|
61
|
+
type: 'job',
|
|
62
|
+
query: true,
|
|
63
|
+
_appContext: _appContext
|
|
64
|
+
};
|
|
65
|
+
if (sql == null || sql.trim().length === 0) {
|
|
66
|
+
return { content: [{ type: 'text', text: 'Error: The SQL statement generated is blank. Please provide a valid natural language query that can be converted to SQL.' }] };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let r = await _jobSubmit(iparams);
|
|
70
|
+
return r;
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return spec;
|
|
75
|
+
}
|
|
76
|
+
export default sasQuery;
|
|
77
|
+
|