@sassoftware/sas-score-mcp-serverjs 0.4.0 → 0.4.1-15
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/cli.js +112 -33
- package/package.json +5 -5
- package/skills/sas-list-tables-smart/SKILL.md +123 -0
- package/skills/sas-read-and-score/SKILL.md +54 -53
- package/skills/sas-read-strategy/SKILL.md +10 -10
- package/skills/sas-score-workflow/SKILL.md +19 -1
- package/skills/sas-spec-migration/SKILL.md +303 -0
- package/src/authpkce.js +219 -0
- package/src/createMcpServer.js +16 -6
- package/src/expressMcpServer.js +354 -338
- package/src/handleGetDelete.js +1 -1
- package/src/oauthHandlers/authorize.js +46 -0
- package/src/oauthHandlers/baseUrl.js +8 -0
- package/src/oauthHandlers/callback.js +93 -0
- package/src/oauthHandlers/getMetadata.js +27 -0
- package/src/oauthHandlers/index.js +7 -0
- package/src/oauthHandlers/token.js +37 -0
- package/src/processHeaders.js +88 -0
- package/src/toolHelpers/_listLibrary.js +0 -1
- package/src/toolHelpers/getLogonPayload.js +5 -1
- package/src/toolHelpers/readCerts.js +4 -4
- package/src/toolHelpers/refreshTokenOauth.js +3 -3
- package/src/toolSet/.claude/settings.local.json +13 -0
- package/src/toolSet/devaScore.js +61 -61
- package/src/toolSet/findJob.js +9 -16
- package/src/toolSet/findJobdef.js +4 -5
- package/src/toolSet/findLibrary.js +68 -68
- package/src/toolSet/findModel.js +4 -5
- package/src/toolSet/findTable.js +6 -6
- package/src/toolSet/getEnv.js +10 -7
- package/src/toolSet/listJobdefs.js +61 -62
- package/src/toolSet/listJobs.js +61 -62
- package/src/toolSet/listLibraries.js +78 -80
- package/src/toolSet/listModels.js +56 -56
- package/src/toolSet/listTables.js +66 -66
- package/src/toolSet/makeTools.js +1 -3
- package/src/toolSet/modelInfo.js +4 -5
- package/src/toolSet/modelScore.js +7 -7
- package/src/toolSet/readTable.js +63 -67
- package/src/toolSet/runCasProgram.js +9 -9
- package/src/toolSet/runJob.js +81 -82
- package/src/toolSet/runJobdef.js +82 -83
- package/src/toolSet/runMacro.js +82 -82
- package/src/toolSet/runProgram.js +8 -13
- package/src/toolSet/sasQuery.js +77 -79
- package/src/toolSet/sasQueryTemplate.js +4 -5
- package/src/toolSet/sasQueryTemplate2.js +4 -5
- package/src/toolSet/scrInfo.js +3 -5
- package/src/toolSet/scrScore.js +69 -70
- package/src/toolSet/searchAssets.js +5 -6
- package/src/toolSet/setContext.js +65 -66
- package/src/toolSet/superstat.js +61 -60
- package/src/toolSet/tableInfo.js +58 -59
package/src/toolSet/runJobdef.js
CHANGED
|
@@ -1,83 +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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (scenario
|
|
55
|
-
scenarioObj =
|
|
56
|
-
} else if (
|
|
57
|
-
scenarioObj = scenario;
|
|
58
|
-
} else if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
acc
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export default runJobdef;
|
|
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().optional()
|
|
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,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 _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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 _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
|
+
scenario: z.string().optional()
|
|
46
|
+
}),
|
|
47
|
+
|
|
48
|
+
handler: async (params) => {
|
|
49
|
+
const scenarioRaw = (params.scenario || '').trim();
|
|
50
|
+
let setup = '';
|
|
51
|
+
if (scenarioRaw) {
|
|
52
|
+
// If the scenario already contains macro syntax, send it through unchanged
|
|
53
|
+
const hasMacroSyntax = /%let\b|%[a-zA-Z_]\w*\s*\(|%[a-zA-Z_]\w*\s*;/.test(scenarioRaw) || scenarioRaw.includes('%');
|
|
54
|
+
if (hasMacroSyntax) {
|
|
55
|
+
setup = scenarioRaw;
|
|
56
|
+
} else {
|
|
57
|
+
// Convert "x=1,y=abc" -> "%let x=1; %let y=abc;"
|
|
58
|
+
setup = scenarioRaw.split(',')
|
|
59
|
+
.map(p => p.trim())
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.map(p => {
|
|
62
|
+
const [k, ...rest] = p.split('=');
|
|
63
|
+
if (!k) return '';
|
|
64
|
+
const key = k.trim();
|
|
65
|
+
const val = rest.join('=').trim();
|
|
66
|
+
return `%let ${key}=${val};`;
|
|
67
|
+
})
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.join(' ');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const src = `${setup} %${params.macro};`;
|
|
73
|
+
params.src = src;
|
|
74
|
+
let r = await _submitCode(params);
|
|
75
|
+
return r;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return spec;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default runMacro;
|
|
82
|
+
|
|
@@ -41,21 +41,15 @@ Returns log, ods, tables array, data (if output specified). Error if execution f
|
|
|
41
41
|
`;
|
|
42
42
|
|
|
43
43
|
let spec = {
|
|
44
|
-
name: 'run-
|
|
45
|
-
aliases: ['Program','run program'],
|
|
44
|
+
name: 'run-program',
|
|
46
45
|
description: description,
|
|
47
|
-
|
|
46
|
+
inputSchema: z.object({
|
|
48
47
|
src: z.string(),
|
|
49
|
-
scenario: z.
|
|
50
|
-
output: z.string().
|
|
51
|
-
folder: z.string().
|
|
52
|
-
limit: z.number().
|
|
53
|
-
},
|
|
54
|
-
// NOTE: Previously 'required' incorrectly listed 'program' which does not
|
|
55
|
-
// exist in the schema. This prevented execution in some orchestrators that
|
|
56
|
-
// enforce required parameter presence, causing only descriptions to appear.
|
|
57
|
-
// Corrected to 'src'.
|
|
58
|
-
required: ['src'],
|
|
48
|
+
scenario: z.string().optional(),
|
|
49
|
+
output: z.string().optional(),
|
|
50
|
+
folder: z.string().optional(),
|
|
51
|
+
limit: z.number().optional()
|
|
52
|
+
}),
|
|
59
53
|
handler: async (params) => {
|
|
60
54
|
let {src, folder, scenario, _appContext} = params;
|
|
61
55
|
// figure out src
|
|
@@ -96,3 +90,4 @@ Returns log, ods, tables array, data (if output specified). Error if execution f
|
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
export default runProgram;
|
|
93
|
+
|
package/src/toolSet/sasQuery.js
CHANGED
|
@@ -1,79 +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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
export default sasQuery;
|
|
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().optional()
|
|
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
|
+
|
|
@@ -108,13 +108,12 @@ async function sasQueryTemplate(uparams) {
|
|
|
108
108
|
name: toolname,
|
|
109
109
|
description: description,
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
inputSchema: z.object({
|
|
112
112
|
query: z.string(),
|
|
113
113
|
table: z.string().default(uTable),
|
|
114
|
-
sql: z.string()
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
handler: async (params) => {
|
|
114
|
+
sql: z.string()
|
|
115
|
+
}),
|
|
116
|
+
handler: async (params) => {
|
|
118
117
|
|
|
119
118
|
|
|
120
119
|
let { table, query, sql, _appContext} = params;
|
|
@@ -102,14 +102,13 @@ async function sasQueryTemplate2(uparams) {
|
|
|
102
102
|
name: toolname,
|
|
103
103
|
description: description,
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
inputSchema: z.object({
|
|
106
106
|
query: z.string(),
|
|
107
107
|
table: z.string().default(uTable),
|
|
108
|
-
sql: z.string()
|
|
108
|
+
sql: z.string(),
|
|
109
109
|
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
handler: async (params) => {
|
|
110
|
+
}),
|
|
111
|
+
handler: async (params) => {
|
|
113
112
|
|
|
114
113
|
let { table, query, sql } = params;
|
|
115
114
|
let sqlinput = (sql == null) ? ' ' : sql.replaceAll(';', ' ').replaceAll('\n', ' ').replaceAll('\r', ' ');
|
package/src/toolSet/scrInfo.js
CHANGED
|
@@ -33,12 +33,10 @@ Examples
|
|
|
33
33
|
|
|
34
34
|
let spec = {
|
|
35
35
|
name: 'scr-info',
|
|
36
|
-
aliases: ['scrInfo','scr info','scr_info'],
|
|
37
36
|
description: description,
|
|
38
|
-
|
|
39
|
-
url: z.string()
|
|
40
|
-
},
|
|
41
|
-
required: ['url'],
|
|
37
|
+
inputSchema: z.object({
|
|
38
|
+
url: z.string()
|
|
39
|
+
}),
|
|
42
40
|
handler: async (params) => {
|
|
43
41
|
let {url, _appContext} = params;
|
|
44
42
|
if (url === null) {
|