@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.
Files changed (53) hide show
  1. package/cli.js +112 -33
  2. package/package.json +5 -5
  3. package/skills/sas-list-tables-smart/SKILL.md +123 -0
  4. package/skills/sas-read-and-score/SKILL.md +54 -53
  5. package/skills/sas-read-strategy/SKILL.md +10 -10
  6. package/skills/sas-score-workflow/SKILL.md +19 -1
  7. package/skills/sas-spec-migration/SKILL.md +303 -0
  8. package/src/authpkce.js +219 -0
  9. package/src/createMcpServer.js +16 -6
  10. package/src/expressMcpServer.js +354 -338
  11. package/src/handleGetDelete.js +1 -1
  12. package/src/oauthHandlers/authorize.js +46 -0
  13. package/src/oauthHandlers/baseUrl.js +8 -0
  14. package/src/oauthHandlers/callback.js +93 -0
  15. package/src/oauthHandlers/getMetadata.js +27 -0
  16. package/src/oauthHandlers/index.js +7 -0
  17. package/src/oauthHandlers/token.js +37 -0
  18. package/src/processHeaders.js +88 -0
  19. package/src/toolHelpers/_listLibrary.js +0 -1
  20. package/src/toolHelpers/getLogonPayload.js +5 -1
  21. package/src/toolHelpers/readCerts.js +4 -4
  22. package/src/toolHelpers/refreshTokenOauth.js +3 -3
  23. package/src/toolSet/.claude/settings.local.json +13 -0
  24. package/src/toolSet/devaScore.js +61 -61
  25. package/src/toolSet/findJob.js +9 -16
  26. package/src/toolSet/findJobdef.js +4 -5
  27. package/src/toolSet/findLibrary.js +68 -68
  28. package/src/toolSet/findModel.js +4 -5
  29. package/src/toolSet/findTable.js +6 -6
  30. package/src/toolSet/getEnv.js +10 -7
  31. package/src/toolSet/listJobdefs.js +61 -62
  32. package/src/toolSet/listJobs.js +61 -62
  33. package/src/toolSet/listLibraries.js +78 -80
  34. package/src/toolSet/listModels.js +56 -56
  35. package/src/toolSet/listTables.js +66 -66
  36. package/src/toolSet/makeTools.js +1 -3
  37. package/src/toolSet/modelInfo.js +4 -5
  38. package/src/toolSet/modelScore.js +7 -7
  39. package/src/toolSet/readTable.js +63 -67
  40. package/src/toolSet/runCasProgram.js +9 -9
  41. package/src/toolSet/runJob.js +81 -82
  42. package/src/toolSet/runJobdef.js +82 -83
  43. package/src/toolSet/runMacro.js +82 -82
  44. package/src/toolSet/runProgram.js +8 -13
  45. package/src/toolSet/sasQuery.js +77 -79
  46. package/src/toolSet/sasQueryTemplate.js +4 -5
  47. package/src/toolSet/sasQueryTemplate2.js +4 -5
  48. package/src/toolSet/scrInfo.js +3 -5
  49. package/src/toolSet/scrScore.js +69 -70
  50. package/src/toolSet/searchAssets.js +5 -6
  51. package/src/toolSet/setContext.js +65 -66
  52. package/src/toolSet/superstat.js +61 -60
  53. package/src/toolSet/tableInfo.js +58 -59
@@ -17,7 +17,7 @@ async function handleGetDelete(mcpServer, cache, req, h) {
17
17
  if (req.method === "GET") {
18
18
  // You can customize the response as needed
19
19
  console.error("[Note] Payload:", req.payload);
20
- console.log("======================================================");
20
+ console.error("======================================================");
21
21
  await transport.handleRequest(req.raw.req, req.raw.res, req.payload);
22
22
  return h.abandon;
23
23
  }
@@ -0,0 +1,46 @@
1
+ //authorize
2
+ import { randomBytes, createHash } from "node:crypto";
3
+ import baseUrl from "./baseUrl.js";
4
+
5
+ function authorize(req, res, appContext, pkceStore, codeStore) {
6
+ const { response_type, redirect_uri, state, scope } = req.query;
7
+ console.error("===============================================================");
8
+ if (appContext.AUTHEXTERNAL === true) {
9
+ console.error('*************************************************************');
10
+ console.error("[Error] Received request for /authorize endpoint with external authorization expected");
11
+ console.error('*************************************************************');
12
+ }
13
+ console.error("[NOTE] query parameters:", { response_type, redirect_uri, state, scope });
14
+ if (response_type !== "code") {
15
+ return res.status(400).json({ error: "unsupported_response_type" });
16
+ }
17
+ if (!redirect_uri) {
18
+ return res.status(400).json({ error: "invalid_request", error_description: "redirect_uri is required" });
19
+ }
20
+
21
+ const codeVerifier = randomBytes(64).toString("base64url");
22
+ const codeChallenge = createHash("sha256").update(codeVerifier).digest("base64url");
23
+ const ourState = randomBytes(16).toString("hex");
24
+
25
+ pkceStore.set(ourState, { codeVerifier, clientRedirectUri: redirect_uri, clientState: state, codeChallenge });
26
+
27
+ const callbackUri = appContext.mcpHost + '/callback';
28
+ console.error("[Note] callbackUri:", callbackUri);
29
+ let urlConfig = {
30
+ response_type: "code",
31
+ client_id: appContext.CLIENTID,
32
+ redirect_uri: callbackUri,
33
+ scope: "openid",
34
+ state: ourState,
35
+ code_challenge: codeChallenge,
36
+ code_challenge_method: "S256"
37
+ }
38
+ if (appContext.PKCE !== "TRUE") {
39
+ urlConfig.client_secret = appContext.CLIENTSECRET;
40
+ }
41
+ console.error("[Note] Params for SAS Viya authorization request:", urlConfig);
42
+ const params = new URLSearchParams(urlConfig);
43
+ console.error("================================================================");
44
+ return res.redirect(`${appContext.VIYA_SERVER}/SASLogon/oauth/authorize?${params}`);
45
+ }
46
+ export default authorize;
@@ -0,0 +1,8 @@
1
+ function baseUrl(appContext) {
2
+ const protocol = appContext.HTTPS === "TRUE" ? "https" : "http";
3
+ //const host = "localhost";
4
+ const host = appContext.VIYA_SERVER;
5
+ return host;
6
+ return `${protocol}://${host}:${appContext.PORT}`;
7
+ }
8
+ export default baseUrl;
@@ -0,0 +1,93 @@
1
+ import baseUrl from "./baseUrl.js";
2
+ import { Agent, fetch as undiciFetch } from "undici";
3
+ import { randomUUID } from "node:crypto";
4
+ async function callback(req, res, pkceStore, codeStore, appContext) {
5
+ console.error("===============================================================");
6
+ console.error("[Note] OAuth callback");
7
+ console.error(req.query);
8
+ const {code, state} = req.query;
9
+
10
+ console.error("[Note] query parameters:", code, state);
11
+ if (!code) {
12
+ return res.status(400).send("Missing code parameter");
13
+ }
14
+
15
+ const pending = pkceStore.get(state);
16
+ if (!pending) {
17
+ return res.status(400).send("Invalid or expired state parameter");
18
+ }
19
+ pkceStore.delete(state);
20
+
21
+ // const callbackUri = `${baseUrl(appContext)}/callback`;
22
+ const callbackUri = appContext.mcpHost + '/callback';
23
+ console.error("[Note] callbackUri for token exchange:", callbackUri);
24
+ try {
25
+ const body = new URLSearchParams({
26
+ grant_type: "authorization_code",
27
+ client_id: appContext.CLIENTID,
28
+ code: code,
29
+ redirect_uri: callbackUri,
30
+ code_verifier: pending.codeVerifier
31
+ }).toString();
32
+
33
+ console.error("[Note] Token request body:", body.toString());
34
+ let connectOpts = {
35
+ ca: appContext.contexts.viyaCert.ca, // trust this CA
36
+ rejectUnauthorized: false // or false, if you really want to bypass checks
37
+ }
38
+ const agent = new Agent({ connect: connectOpts });
39
+ console.error("[Note] Initiating token exchange with SAS Viya");
40
+ let clientID= appContext.CLIENTID;
41
+ let h = buildBasicAuthFromClientId(clientID);
42
+ console.error("[Note] Authorization header for token request:", h);
43
+ const response = await undiciFetch(`${appContext.VIYA_SERVER}/SASLogon/oauth/token`, {
44
+ method: "POST",
45
+ headers: {
46
+ "Content-Type": "application/x-www-form-urlencoded",
47
+ "Accept": "application/json"
48
+ },
49
+ body: body,
50
+ dispatcher: agent,
51
+ });
52
+
53
+ if (!response.ok) {
54
+ const errText = await response.text();
55
+ console.error("[Error] SAS Viya token exchange failed:", errText);
56
+ return res.status(502).send("Token exchange with SAS Viya failed");
57
+ }
58
+
59
+ const tokens = await response.json();
60
+ console.error("[Note] Received tokens from SAS Viya:", tokens);
61
+ const ourCode = randomUUID();
62
+ codeStore.set(ourCode, {
63
+ access_token: tokens.access_token,
64
+ refresh_token: tokens.refresh_token,
65
+ expires_in: tokens.expires_in,
66
+ });
67
+
68
+ const redirectParams = new URLSearchParams({ code: ourCode , state: pending.clientState});
69
+ //pending.clientState is the original state from the MCP client, which we should pass back to it for correlation
70
+
71
+ // pending.clientRedirectUri is the original redirect URI from the MCP client,
72
+ // which was part of the payload from the client to /oauth/authorize
73
+ // we trust since it was associated with the valid PKCE state
74
+ console.error("[Note] OAuth callback complete, redirecting to MCP client");
75
+ console.log(pending.clientRedirectUri.toString())
76
+ return res.redirect(`${pending.clientRedirectUri}?${redirectParams}`);
77
+ } catch (err) {
78
+ console.error("[Error] OAuth callback handler error:", err);
79
+ return res.status(500).send("Internal server error during token exchange");
80
+ }
81
+
82
+ function buildBasicAuthFromClientId(clientId) {
83
+ const raw = `${clientId}:`; // empty client_secret
84
+ const encoded =
85
+ typeof btoa === "function"
86
+ ? btoa(raw)
87
+ : Buffer.from(raw).toString("base64");
88
+
89
+ return `Basic ${encoded}`;
90
+ }
91
+
92
+ }
93
+ export default callback;
@@ -0,0 +1,27 @@
1
+ import baseUrl from "./baseUrl.js";
2
+ function getMetadata(req, res, appEnvContext) {
3
+ let base = '';
4
+ let host = '';
5
+ if (appEnvContext.AUTHEXTERNAL === true) {
6
+ base = appEnvContext.VIYA_SERVER + '/SASLogon';
7
+ host = appEnvContext.VIYA_SERVER;
8
+ } else {
9
+ base = appEnvContext.mcpHost;
10
+ host = appEnvContext.mcpHost;
11
+ }
12
+ console.error(`[Note] Base URL for Authorization Server Metadata: ${base}`);
13
+ let metadata = {
14
+ "issuer": host,
15
+ "authorization_endpoint": `${base}/oauth/authorize`,
16
+ "token_endpoint": `${base}/oauth/token`,
17
+ "response_types_supported": ["code"],
18
+ "grant_types_supported": ["authorization_code", "refresh_token"],
19
+ "code_challenge_methods_supported": ["S256"],
20
+ "scopes_supported": ["openid"]
21
+ };
22
+ console.error("===============================================================");
23
+ console.error("[Note] Authorization Server Metadata:", metadata);
24
+ console.error("===============================================================");
25
+ return metadata;
26
+ };
27
+ export default getMetadata;
@@ -0,0 +1,7 @@
1
+ import authorize from "./authorize.js";
2
+ import callback from "./callback.js";
3
+ import token from "./token.js";
4
+ import getMetadata from "./getMetadata.js";
5
+ import baseUrl from "./baseUrl.js";
6
+
7
+ export { authorize, callback, token, getMetadata, baseUrl };
@@ -0,0 +1,37 @@
1
+ function token(req, res, appContext, codeStore, cache) {
2
+ console.error("===============================================================");
3
+ console.error("[Note] at /token endpoint");
4
+ console.error("[Note] Request headers:", req.headers);
5
+ console.error("[Note] Handling token request with body:", req.body);
6
+
7
+ const { grant_type, code } = req.body;
8
+ console.error("[Note] OAuth token request received for code:", code);
9
+ console.error("[Note] Grant type:", grant_type);
10
+
11
+ const tokenData = codeStore.get(code);
12
+ if (!tokenData) {
13
+ return res.status(400).json({ error: "Invalid_code", error_description: "Invalid or expired authorization code" });
14
+ }
15
+ console.error("[Note] Retrieved token data for code:", Object.keys(tokenData));
16
+
17
+ let payload = {
18
+ access_token: code, // tokenData.access_token,
19
+ token_type: "Bearer",
20
+ expires_in: tokenData.expires_in,
21
+ scope: "openid" // You can include scopes if you have them, e.g., tokenData.scope
22
+ // scope: tokenData.scope,
23
+ };
24
+ let tokenlist = cache.get("tokenlist");
25
+ tokenData.refreshAt = Date.now() + tokenData.expires_in * 1000; // Set refresh time based on expires_in
26
+ tokenlist[code] = tokenData;
27
+ cache.set("tokenlist", tokenlist);
28
+
29
+ codeStore.delete(code); // Invalidate the code after use
30
+ console.error("[Note] Returning token to client");
31
+ console.error("[Note] Token sent to client:", JSON.stringify(payload, null, 2));
32
+
33
+ console.error("============================================================")
34
+ return res.status(200).json(payload);
35
+ }
36
+
37
+ export default token;
@@ -0,0 +1,88 @@
1
+ import { start } from "node:repl";
2
+
3
+ /*
4
+ * Copyright © 2026, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+ import baseUrl from "./oauthHandlers/baseUrl.js";
8
+ function processHeaders(req, res, next, cache, appContext) {
9
+
10
+ // process any new header information
11
+ debugger;
12
+ console.error("=======================================================");
13
+ console.error("Processing headers for incoming request to /mcp endpoint");
14
+ // Allow different VIYA server per sessionid(user)
15
+ cache.del("headerCache");
16
+ let headerCache = {};
17
+ if (req.header("X-VIYA-SERVER") != null) {
18
+ console.error("[Note] Using user supplied VIYA server");
19
+ headerCache.VIYA_SERVER = req.header("X-VIYA-SERVER");
20
+ }
21
+
22
+ // fakeapi key since Viya does not support it
23
+ // not ideal for production, just for testing
24
+ const hdr2 = req.header("X-REFRESH-TOKEN");
25
+ if (hdr2 != null) {
26
+ headerCache.REFRESH_TOKEN = hdr2;
27
+ headerCache.AUTHFLOW = "refresh";
28
+ console.error("[Note] Using user supplied refresh token for authorization");
29
+ }
30
+
31
+ // Oauth flow
32
+ const hdr = req.header("Authorization");
33
+ //for now, ignore Authorization if authflow is not bearer
34
+ let token = (hdr != null) ? hdr.slice(7) : null;
35
+ //console.error("[Note] Authorization token", token);
36
+ debugger;
37
+ console.log('>>>',appContext.AUTHFLOW);
38
+ if (appContext.AUTHFLOW === 'bearer') {
39
+ debugger;
40
+ let startAuth = false;
41
+ console.error("[Note] appContext.AUTHEXTERNAL:", appContext.AUTHEXTERNAL);
42
+ if (appContext.AUTHEXTERNAL === true) {
43
+ console.error("[Note] Expecting external authorization");
44
+ if (token != null) {
45
+ console.error("[Note] Using user supplied token for authorization");
46
+ headerCache.bearerToken = token;
47
+ } else {
48
+ startAuth = true;
49
+ }
50
+ } else if (token == null) {
51
+ console.error("[Note] No Authorization token provided in header.");
52
+ startAuth = true;
53
+ } else {
54
+ console.error("[Note] Checking token against cache", token);
55
+ let tokenlist = cache.get("tokenlist");
56
+ let tokenData = tokenlist[token];
57
+ if (tokenData == null) {
58
+ return res.status(403).json({
59
+ error: "unauthorized",
60
+ error_description: "[Error] Expired token. Clear token and try again."
61
+ });
62
+ } else {
63
+ token = tokenData.access_token;
64
+ headerCache.bearerToken = token;
65
+ }
66
+ }
67
+ if (startAuth === true) {
68
+ // start oauth flow process
69
+ console.error(`[Note] No Authorization header provided.
70
+ Returning 401 to start the OAuth flow`);
71
+ const base = appContext.mcpHost;
72
+ res.set(
73
+ "WWW-Authenticate",
74
+ `Bearer resource_metadata="${base}/.well-known/oauth-authorization-server", scope="openid"`
75
+ );
76
+ return res.status(401).json({
77
+ error: "unauthorized",
78
+ error_description: "Bearer token required."
79
+ });
80
+ // start auth flow process since no token provided in header and we are not configured for external token
81
+ }
82
+ }
83
+ // console.error("Header cache after processing:", headerCache);
84
+ cache.set("headerCache", headerCache);
85
+ next();
86
+ }
87
+
88
+ export default processHeaders;
@@ -12,7 +12,6 @@ async function _listLibrary(params) {
12
12
 
13
13
  const _ilistLibrary = async (params) => {
14
14
  let { server, limit, start, name, _appContext } = params;
15
- console.error(_appContext);
16
15
  let config = {
17
16
  casServerName: _appContext.cas,
18
17
  computeContext: _appContext.sas,
@@ -53,7 +53,6 @@ async function igetLogonPayload(_appContext) {
53
53
  token: _appContext.bearerToken,
54
54
  tokenType: "Bearer",
55
55
  };
56
- console.error("[Note] Bearer token in logonPayload ", _appContext.bearerToken);
57
56
  return logonPayload;
58
57
  }
59
58
 
@@ -122,4 +121,9 @@ async function igetLogonPayload(_appContext) {
122
121
  return null;
123
122
  }
124
123
  }
124
+
125
+ function isExpired(expiresAt, skewSeconds = 60) {
126
+ return Date.now() >= (expiresAt - skewSeconds * 1000);
127
+ }
128
+
125
129
  export default getLogonPayload;
@@ -9,23 +9,23 @@ function getCerts(tlsdir) {
9
9
  return null;
10
10
  }
11
11
 
12
- console.log(`[Note] Reading certs from directory: ` + tlsdir);
12
+ console.error(`[Note] Reading certs from directory: ` + tlsdir);
13
13
  if (fs.existsSync(tlsdir) === false) {
14
14
  console.error("[Warning] Specified cert dir does not exist: " + tlsdir);
15
15
  return null;
16
16
  }
17
17
 
18
18
  let listOfFiles = fs.readdirSync(tlsdir);
19
- console.log("[Note] TLS/SSL files found: " + listOfFiles);
19
+ console.error("[Note] TLS/SSL files found: " + listOfFiles);
20
20
  let options = {};
21
21
  for(let i=0; i < listOfFiles.length; i++) {
22
22
  let fname = listOfFiles[i];
23
23
  let name = tlsdir + '/' + listOfFiles[i];
24
24
  let key = fname.split('.')[0];
25
- console.log('Reading TLS file: ' + name + ' as key: ' + key);
25
+ console.error('Reading TLS file: ' + name + ' as key: ' + key);
26
26
  options[key] = fs.readFileSync(name, { encoding: 'utf8' });
27
27
  }
28
- console.log('cert files', Object.keys(options));
28
+ console.error('cert files', Object.keys(options));
29
29
 
30
30
  return options;
31
31
 
@@ -6,7 +6,7 @@
6
6
  //import getOpts from './getOpts.js';
7
7
  async function refreshTokenOauth(_appContext, oauthInfo ){
8
8
 
9
- const url = `${process.env.VIYA_SERVER}/SASLogon/oauth/token`;
9
+ const url = `${_appContext.VIYA_SERVER}/SASLogon/oauth/token`;
10
10
  let opts = _appContext.contexts.appCert;
11
11
 
12
12
  const agent = new Agent({
@@ -23,10 +23,10 @@
23
23
  try {
24
24
  const response = await fetch(url, {
25
25
  method: 'POST',
26
+ dispatcher: agent,
26
27
  headers: {
27
28
  'Accept': 'application/json',
28
- 'Content-Type': 'application/x-www-form-urlencoded',
29
- dispatcher: agent
29
+ 'Content-Type': 'application/x-www-form-urlencoded'
30
30
  },
31
31
  body: body.toString()
32
32
  });
@@ -0,0 +1,13 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "mcp__sasmcp__sas-score-deva-score",
5
+ "mcp__sasmcp__sas-score-find-model",
6
+ "mcp__sasmcp__sas-score-model-info",
7
+ "Bash(cp \"C:/dev/github/7-skill-integration/.claude/skills/sas-read-and-score/SKILL.md\" \"C:/dev/github/7-skill-integration/skills/sas-read-and-score/SKILL.md\")",
8
+ "Bash(cp \"C:/dev/github/7-skill-integration/.claude/skills/sas-read-strategy/SKILL.md\" \"C:/dev/github/7-skill-integration/skills/sas-read-strategy/SKILL.md\")",
9
+ "Bash(cp \"C:/dev/github/7-skill-integration/.claude/skills/sas-score-workflow/SKILL.md\" \"C:/dev/github/7-skill-integration/skills/sas-score-workflow/SKILL.md\")",
10
+ "WebSearch"
11
+ ]
12
+ }
13
+ }
@@ -1,61 +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 {z} from 'zod';
6
-
7
- function devaScore(_appContext) {
8
-
9
- let description = `
10
- deva-score — compute a numeric score based on two input values.
11
-
12
- USE when: calculate deva score, score these values, compute score for numbers
13
- DO NOT USE for: model scoring (use model-score), statistical calculations, data lookup
14
-
15
- PARAMETERS
16
- - a: number (required) — first input value
17
- - b: number (required) — second input value
18
-
19
- FORMULA: (a + b) * 42
20
-
21
- ROUTING RULES
22
- - "calculate deva score for 5 and 10" → { a: 5, b: 10 }
23
- - "score 1 and 2" → { a: 1, b: 2 }
24
- - "deva score a=3, b=7" → { a: 3, b: 7 }
25
- - Multiple numbers → chain calls left-to-right: call(first, second), then call(result, third)
26
-
27
- EXAMPLES
28
- - "Calculate deva score for 5 and 10" → { a: 5, b: 10 } returns 630
29
- - "Score 1 and 2" → { a: 1, b: 2 } returns 126
30
- - "Deva score 20 and 30" → { a: 20, b: 30 } returns 2100
31
-
32
- NEGATIVE EXAMPLES (do not route here)
33
- - "Score this customer with credit model" (use model-score)
34
- - "Calculate the mean of these values" (use run-sas-program or sas-query)
35
- - "Statistical analysis of numbers" (use sas-query)
36
-
37
- RESPONSE
38
- Returns { score: (a + b) * 42 }
39
- `;
40
- let spec = {
41
- name: 'deva-score',
42
- aliases: ['devaScore','deva score','deva_score'],
43
- description: description,
44
- schema: {
45
- a: z.number(),
46
- b: z.number()
47
- },
48
- handler: async ({ a, b }) => {
49
- console.error( a, b);
50
- let r = {score: (a + b) * 42};
51
- console.error('deva score result', r);
52
- return {
53
- content: [{type: 'text', text: 'deva score result: ' + JSON.stringify(r)}],
54
- structuredContent: r
55
- };
56
- }
57
- }
58
-
59
- return spec;
60
- }
61
- export default devaScore;
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
+
7
+ function devaScore(_appContext) {
8
+
9
+ let description = `
10
+ deva-score — compute a numeric score based on two input values.
11
+
12
+ USE when: calculate deva score, score these values, compute score for numbers
13
+ DO NOT USE for: model scoring (use model-score), statistical calculations, data lookup
14
+
15
+ PARAMETERS
16
+ - a: number (required) — first input value
17
+ - b: number (required) — second input value
18
+
19
+ FORMULA: (a + b) * 42
20
+
21
+ ROUTING RULES
22
+ - "calculate deva score for 5 and 10" → { a: 5, b: 10 }
23
+ - "score 1 and 2" → { a: 1, b: 2 }
24
+ - "deva score a=3, b=7" → { a: 3, b: 7 }
25
+ - Multiple numbers → chain calls left-to-right: call(first, second), then call(result, third)
26
+
27
+ EXAMPLES
28
+ - "Calculate deva score for 5 and 10" → { a: 5, b: 10 } returns 630
29
+ - "Score 1 and 2" → { a: 1, b: 2 } returns 126
30
+ - "Deva score 20 and 30" → { a: 20, b: 30 } returns 2100
31
+
32
+ NEGATIVE EXAMPLES (do not route here)
33
+ - "Score this customer with credit model" (use model-score)
34
+ - "Calculate the mean of these values" (use run-sas-program or sas-query)
35
+ - "Statistical analysis of numbers" (use sas-query)
36
+
37
+ RESPONSE
38
+ Returns { score: (a + b) * 42 }
39
+ `;
40
+ let spec = {
41
+ name: 'deva-score',
42
+ description: description,
43
+ inputSchema: z.object({
44
+ a: z.number(),
45
+ b: z.number(),
46
+ }),
47
+ handler: async ({ a, b }) => {
48
+ console.error(a, b);
49
+ let r = { score: (a + b) * 42 };
50
+ console.error('deva score result', r);
51
+ return {
52
+ content: [{ type: 'text', text: 'deva score result: ' + JSON.stringify(r) }],
53
+ structuredContent: r
54
+ };
55
+ }
56
+ }
57
+
58
+ return spec;
59
+ }
60
+ export default devaScore;
61
+
@@ -5,16 +5,7 @@
5
5
  import { z } from 'zod';
6
6
  import _listJobs from '../toolHelpers/_listJobs.js';
7
7
  function findJob(_appContext) {
8
- let llmDescription= {
9
- "purpose": "Map natural language requests to find a job in SAS Viya and return structured results.",
10
- "param_mapping": {
11
- "name": "required - single name. If missing, ask 'Which job name would you like to find?'.",
12
- "_userPrompt": "the original user prompt that triggered this tool."
13
-
14
- },
15
- "response_schema": "{ jobs: Array<string|object> }",
16
- "behavior": "Return only JSON matching response_schema when invoked by an LLM. If no matches, return { jobs: [] }"
17
- };
8
+
18
9
  let description = `
19
10
  find-job — locate a specific SAS Viya job.
20
11
 
@@ -49,18 +40,20 @@ Returns { jobs: [] } if not found; { jobs: [name, ...] } if found. Never halluci
49
40
 
50
41
  let spec = {
51
42
  name: 'find-job',
52
- aliases: ['findJob','find job','find_job'],
53
43
  description: description,
54
- schema: {
55
- name: z.string(),
56
- _userPrompt: z.string()
57
- },
58
- required: ['name'],
44
+ inputSchema: z.object({
45
+ name: z.string()
46
+ }),
59
47
  handler: async (params) => {
60
48
  let r = await _listJobs(params);
61
49
  return r;
62
50
  }
63
51
  }
52
+
53
+
54
+ /* correct spec for registerTool with inputSchema */
55
+
64
56
  return spec;
65
57
  }
66
58
  export default findJob;
59
+
@@ -49,12 +49,10 @@ Returns { jobdefs: [] } if not found; { jobdefs: [name, ...] } if found. Never h
49
49
 
50
50
  let spec = {
51
51
  name: 'find-jobdef',
52
- aliases: ['findJobdef','find jobdef','find_jobdef'],
53
52
  description: description,
54
- schema: {
55
- name: z.string()
56
- },
57
- required: ['name'],
53
+ inputSchema: z.object({
54
+ name: z.string()
55
+ }),
58
56
  handler: async (params) => {
59
57
  let r = await _listJobdefs(params);
60
58
  return r;
@@ -63,3 +61,4 @@ Returns { jobdefs: [] } if not found; { jobdefs: [name, ...] } if found. Never h
63
61
  return spec;
64
62
  }
65
63
  export default findJobdef;
64
+