@sassoftware/sas-score-mcp-serverjs 0.4.1-1 → 0.4.1-5

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.
@@ -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
- query: z.string(),
47
- table: z.string(),
48
- sql: z.string(),
49
- job: z.string()
50
- }),
51
- handler: async (params) => {
52
- let {table,query, sql, job, _appContext} = params;
53
- let sqlinput = (sql == null) ? ' ' : sql.replaceAll(';', ' ').replaceAll('\n', ' ').replaceAll('\r', ' ');
54
-
55
- let iparams = {
56
- scenario: {
57
- table: table,
58
- prompt: query,
59
- sql: sqlinput
60
- },
61
- name: (job == null) ? 'program' : job,
62
- type: 'job',
63
- query: true,
64
- _appContext: _appContext
65
- };
66
- if (sql == null || sql.trim().length === 0) {
67
- 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.' }] };
68
- }
69
-
70
- let r = await _jobSubmit(iparams);
71
- return r;
72
-
73
- }
74
- }
75
- return spec;
76
- }
77
- export default sasQuery;
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().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
+
@@ -35,7 +35,7 @@ Examples
35
35
  name: 'scr-info',
36
36
  description: description,
37
37
  inputSchema: z.object({
38
- url: z.string(),
38
+ url: z.string()
39
39
  }),
40
40
  handler: async (params) => {
41
41
  let {url, _appContext} = params;
@@ -1,69 +1,70 @@
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 _scrScore from '../toolHelpers/_scrScore.js';
8
-
9
- function scrScore(_appContext) {
10
- let description = `
11
- ## scr-score
12
-
13
- Purpose
14
- Score a scenario using a model deployed as a SCR container in Azure or another host).
15
-
16
- Inputs
17
- - url (string, required): SCR model identifier (URL)
18
- - scenario (string | object | array, optional): Input values to score. Accepts:
19
- - a comma-separated key=value string (e.g. "x=1, y=2"),
20
- - a JSON object with field names and values (recommended for typed inputs),
21
- - an array of objects for batch scoring. If omitted, the tool will return the model's input variable definitions.
22
-
23
- What it returns
24
- - When scoring: the SCR endpoint response (predictions, probabilities, scores) merged with or alongside the supplied inputs.
25
- - When \`scenario\` is omitted: metadata describing the model's input variables (names, types, required/optional).
26
-
27
- Usage notes
28
- - Run \`scr-info\` first to inspect the expected input variables and types.
29
- - Prefer structured objects for numeric/date values to avoid type ambiguity; the simple string parser keeps values as strings.
30
- - Ensure network connectivity and any required credentials for the target SCR service.
31
-
32
- Examples
33
- - scrScore with url="loan" and scenario="age=45, income=60000"
34
- - scrScore with url="https://scr-host/models/loan" and scenario={age:45, income:60000}
35
- `;
36
-
37
- let spec = {
38
- name: 'scr-score',
39
- description: description,
40
- inputSchema: z.object({
41
- url: z.string(),
42
- scenario: z.any()
43
- }),
44
- handler: async (params) => {
45
- let {url, scenario,_appContext} = params;
46
-
47
- if (url === null) {
48
- return { status: { statusCode: 2, msg: `SCR model ${url} was not specified` }, results: {} };
49
- }
50
-
51
- // Normalize simple string scenarios like "x=1, y=2" into an object
52
- if (typeof scenario === 'string' && scenario.includes('=')) {
53
- scenario = scenario.split(',').reduce((acc, pair) => {
54
- const [k, ...rest] = pair.split('=');
55
- if (!k) return acc;
56
- acc[k.trim()] = rest.join('=').trim();
57
- return acc;
58
- }, {});
59
- }
60
-
61
- let r = await _scrScore({ url: url, scenario: scenario , _appContext: _appContext});
62
- return r;
63
- }
64
- }
65
-
66
- return spec;
67
- }
68
-
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 _scrScore from '../toolHelpers/_scrScore.js';
8
+
9
+ function scrScore(_appContext) {
10
+ let description = `
11
+ ## scr-score
12
+
13
+ Purpose
14
+ Score a scenario using a model deployed as a SCR container in Azure or another host).
15
+
16
+ Inputs
17
+ - url (string, required): SCR model identifier (URL)
18
+ - scenario (string | object | array, optional): Input values to score. Accepts:
19
+ - a comma-separated key=value string (e.g. "x=1, y=2"),
20
+ - a JSON object with field names and values (recommended for typed inputs),
21
+ - an array of objects for batch scoring. If omitted, the tool will return the model's input variable definitions.
22
+
23
+ What it returns
24
+ - When scoring: the SCR endpoint response (predictions, probabilities, scores) merged with or alongside the supplied inputs.
25
+ - When \`scenario\` is omitted: metadata describing the model's input variables (names, types, required/optional).
26
+
27
+ Usage notes
28
+ - Run \`scr-info\` first to inspect the expected input variables and types.
29
+ - Prefer structured objects for numeric/date values to avoid type ambiguity; the simple string parser keeps values as strings.
30
+ - Ensure network connectivity and any required credentials for the target SCR service.
31
+
32
+ Examples
33
+ - scrScore with url="loan" and scenario="age=45, income=60000"
34
+ - scrScore with url="https://scr-host/models/loan" and scenario={age:45, income:60000}
35
+ `;
36
+
37
+ let spec = {
38
+ name: 'scr-score',
39
+ description: description,
40
+ inputSchema: z.object({
41
+ url: z.string(),
42
+ scenario: z.string().optional()
43
+ }),
44
+
45
+ handler: async (params) => {
46
+ let {url, scenario,_appContext} = params;
47
+
48
+ if (url === null) {
49
+ return { status: { statusCode: 2, msg: `SCR model ${url} was not specified` }, results: {} };
50
+ }
51
+
52
+ // Normalize simple string scenarios like "x=1, y=2" into an object
53
+ if (typeof scenario === 'string' && scenario.includes('=')) {
54
+ scenario = scenario.split(',').reduce((acc, pair) => {
55
+ const [k, ...rest] = pair.split('=');
56
+ if (!k) return acc;
57
+ acc[k.trim()] = rest.join('=').trim();
58
+ return acc;
59
+ }, {});
60
+ }
61
+
62
+ let r = await _scrScore({ url: url, scenario: scenario , _appContext: _appContext});
63
+ return r;
64
+ }
65
+ }
66
+
67
+ return spec;
68
+ }
69
+
69
70
  export default scrScore;
@@ -1,65 +1,65 @@
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
-
8
- function setContext(_appContext) {
9
- let description = `
10
- set-context — set the CAS and SAS server contexts for subsequent tool calls.
11
-
12
- USE when: switch to CAS server, change compute context, check current context, set both
13
- DO NOT USE for: get variables (use get-env), read data (use read-table), run programs (use run-sas-program)
14
-
15
- PARAMETERS
16
- - cas: string — CAS server name (optional), e.g. 'cas-shared-default', 'finance-cas-server'
17
- - sas: string — SAS compute context (optional), e.g. 'SAS Studio Compute Context', 'batch-compute'
18
-
19
- ROUTING RULES
20
- - "use finance-cas-server" → { cas: "finance-cas-server" }
21
- - "switch to SAS Studio Compute Context" → { sas: "SAS Studio Compute Context" }
22
- - "use finance-cas for CAS and batch-compute for SAS" → { cas: "finance-cas", sas: "batch-compute" }
23
- - "what context am I using" → { } (no params, returns current)
24
-
25
- EXAMPLES
26
- - "use finance-cas-server" → { cas: "finance-cas-server" }
27
- - "switch to batch-compute" → { sas: "batch-compute" }
28
- - "what's my current context" → { }
29
-
30
- NEGATIVE EXAMPLES (do not route here)
31
- - "read table cars" (use read-table)
32
- - "what's the value of X" (use get-env)
33
- - "run program" (use run-sas-program)
34
-
35
- ERRORS
36
- Returns current or updated context values {cas, sas}. Error if server not found or invalid name.
37
- `;
38
-
39
- let spec = {
40
- name: 'set-context',
41
- description: description,
42
- inputSchema: z.object({
43
- cas: z.string(),
44
- sas: z.string()
45
- }),
46
- handler: async (params) => {
47
-
48
- let {cas, sas} = params;
49
- if (typeof cas === 'string' && cas.trim().length > 0) {
50
- _appContext.contexts.cas = cas.trim();
51
- }
52
- if (typeof sas === 'string' && sas.trim().length > 0) {
53
- _appContext.contexts.sas = sas.trim();
54
- }
55
- // Return a structured response without extraneous keys
56
- return {
57
- content: [{ type: 'text', text: JSON.stringify(_appContext.contexts) }],
58
- structuredContent: _appContext.contexts
59
- };
60
- }
61
- }
62
- return spec;
63
- }
64
- export default setContext;
65
-
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
+
8
+ function setContext(_appContext) {
9
+ let description = `
10
+ set-context — set the CAS and SAS server contexts for subsequent tool calls.
11
+
12
+ USE when: switch to CAS server, change compute context, check current context, set both
13
+ DO NOT USE for: get variables (use get-env), read data (use read-table), run programs (use run-sas-program)
14
+
15
+ PARAMETERS
16
+ - cas: string — CAS server name (optional), e.g. 'cas-shared-default', 'finance-cas-server'
17
+ - sas: string — SAS compute context (optional), e.g. 'SAS Studio Compute Context', 'batch-compute'
18
+
19
+ ROUTING RULES
20
+ - "use finance-cas-server" → { cas: "finance-cas-server" }
21
+ - "switch to SAS Studio Compute Context" → { sas: "SAS Studio Compute Context" }
22
+ - "use finance-cas for CAS and batch-compute for SAS" → { cas: "finance-cas", sas: "batch-compute" }
23
+ - "what context am I using" → { } (no params, returns current)
24
+
25
+ EXAMPLES
26
+ - "use finance-cas-server" → { cas: "finance-cas-server" }
27
+ - "switch to batch-compute" → { sas: "batch-compute" }
28
+ - "what's my current context" → { }
29
+
30
+ NEGATIVE EXAMPLES (do not route here)
31
+ - "read table cars" (use read-table)
32
+ - "what's the value of X" (use get-env)
33
+ - "run program" (use run-sas-program)
34
+
35
+ ERRORS
36
+ Returns current or updated context values {cas, sas}. Error if server not found or invalid name.
37
+ `;
38
+
39
+ let spec = {
40
+ name: 'set-context',
41
+ description: description,
42
+ inputSchema: z.object({
43
+ cas: z.string().optional(),
44
+ sas: z.string().optional()
45
+ }),
46
+ handler: async (params) => {
47
+
48
+ let {cas, sas} = params;
49
+ if (typeof cas === 'string' && cas.trim().length > 0) {
50
+ _appContext.contexts.cas = cas.trim();
51
+ }
52
+ if (typeof sas === 'string' && sas.trim().length > 0) {
53
+ _appContext.contexts.sas = sas.trim();
54
+ }
55
+ // Return a structured response without extraneous keys
56
+ return {
57
+ content: [{ type: 'text', text: JSON.stringify(_appContext.contexts) }],
58
+ structuredContent: _appContext.contexts
59
+ };
60
+ }
61
+ }
62
+ return spec;
63
+ }
64
+ export default setContext;
65
+
@@ -1,59 +1,61 @@
1
- /*
2
- * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import _submitCode from '../toolHelpers/_submitCode.js';
6
- import { z } from 'zod';
7
-
8
- function superstat(_appContext) {
9
- let desc = `
10
- ## superstat: compute superstat for two numbers using SAS programming
11
-
12
- ## Details
13
- This is a tool to demonstrate using SAS programming to score. The SAS program for suprestat is
14
- below. In a real application this would be a more complex program that is
15
- available to the SAS server.
16
-
17
-
18
- ods html style=barrettsblue;
19
- data temp;
20
- superstat = (&a + &b) * 42;
21
- run;
22
- proc print data=temp;
23
- run;
24
- ods html close;
25
- run;
26
-
27
- ## Sample Prompt
28
-
29
- - compute superstat for 1 and 2
30
- - compute superstat for 3,5
31
-
32
- `;
33
- let spec = {
34
- name: 'superstat',
35
- description: desc,
36
- inputSchema: z.object({
37
- a: z.number(),
38
- b: z.number()
39
- }),
40
- handler: async (params) => {
41
- let src = `
42
- ods html style=barrettsblue;
43
- data temp;
44
- superstat = (&a + &b) * 42;
45
- run;
46
- proc print data=temp;
47
- run;
48
- ods html close;
49
- run;
50
- `;
51
- params.src = src;
52
- let r = await _submitCode(params);
53
- return r;
54
- }
55
-
56
- };
57
- return spec;
58
- }
59
- export default superstat;
1
+ /*
2
+ * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { type } from 'node:os';
6
+ import _submitCode from '../toolHelpers/_submitCode.js';
7
+ import { z } from 'zod';
8
+
9
+ function superstat(_appContext) {
10
+ let desc = `
11
+ ## superstat: compute superstat for two numbers using SAS programming
12
+
13
+ ## Details
14
+ This is a tool to demonstrate using SAS programming to score. The SAS program for suprestat is
15
+ below. In a real application this would be a more complex program that is
16
+ available to the SAS server.
17
+
18
+
19
+ ods html style=barrettsblue;
20
+ data temp;
21
+ superstat = (&a + &b) * 42;
22
+ run;
23
+ proc print data=temp;
24
+ run;
25
+ ods html close;
26
+ run;
27
+
28
+ ## Sample Prompt
29
+
30
+ - compute superstat for 1 and 2
31
+ - compute superstat for 3,5
32
+
33
+ `;
34
+ let spec = {
35
+ name: 'superstat',
36
+ description: desc,
37
+ inputSchema: z.object({
38
+ a: z.number().optional()
39
+ }),
40
+ required: ['a', 'b']
41
+ },
42
+ handler: async (params) => {
43
+ let src = `
44
+ ods html style=barrettsblue;
45
+ data temp;
46
+ superstat = (&a + &b) * 42;
47
+ run;
48
+ proc print data=temp;
49
+ run;
50
+ ods html close;
51
+ run;
52
+ `;
53
+ params.src = src;
54
+ let r = await _submitCode(params);
55
+ return r;
56
+ }
57
+
58
+ };
59
+ return spec;
60
+ }
61
+ export default superstat;