A mcp server for SAS Viya
npm install @sassoftware/mcp-hapi-serverjs> Note: scoring refers to executing any code that takes some input and returns results.
Some examples are:
- models created with SAS solutions like Model Studio, Intelligent Decisioning etc...
- user written SAS program
- SAS Studio Flow
- job Definitions
- jobs using SAS Studio or other interfaces
``env
MCPTYPE=http
PORT=8080
HTTPS=FALSE
AUTHFLOW=sascli
SAS_CLI_CONFIG=your-home-directory
SAS_CLI_PROFILE=your-sas-cli-profile
VIYA_SERVER= your Viya server url
SSLCERT=
VIYACERT=
`
> Note: To use this, set AUTHFLOW=sascli
This MCP server CLI works similar to SAS supplied sas-viya CLI commands.
Use the following command to create the necessary token and refresh token.
create a default auth Profile.sas-viya profile init
Issue this command and follow instruction:
create tokensas-viya auth loginCode
Issue this command and follow the instructions:
You need to do this once every 90 days or whenever the refresh token expires.
At this point the tools can make authenticated calls to SAS Viya.
> Note: To use this, set AUTHTYPE=password
Ths requires additional setup:
- Create a clientid and client password for Oauth password flow.
- Set these in the .env file or the mcp configuration file
> Note: To use this, set AUTHTYPE=token
Set the env TOKENFILE to a file containing the token.
There seems to be a pattern of using a long-lived token.
If this is your use case, set the TOKENFILE to a file containing this token.
In this approach, the mcp client does not participate in the Oauth authentication process. It is handled by the mcp server at startup.
> This is marked as experimental since there can be timing issues between the mcp client and server. This needs to be investigated further.
#### SAS viya setup.
Create a Oauth client with the following properties
`js
{
auth flow: authorization_code
clientid:
clientsecret:
redirect: https://localhost:8080/mcpserver
}
#### Use an .env file as follows(sample values shown)
`env
PORT=8080
HTTPS=true
MCPTYPE=http
USELOGON=FALSE
USETOKEN=TRUE
APPNAME=mcpserver
APPHOST=localhost
APPPORT=8080
CLIENTID=mcpserver
CLIENTSECRET=jellico
AUTHFLOW=code
SSLCERT=c:\Users\kumar\.tls
VIYACERT=c:\Users\kumar\viyaCert
CAS_SERVER=cas-shared-default
COMPUTECONTEXT=SAS Job Execution compute context
SAMESITE=Lax,false
`
#### Usage
Start the server with this command:
`sh`
npx @sassoftware/sas-score-mcp-serverjs@latest
Then visit this site on your browser:
`sh`
https://localhost:8080/mcpserver
You will be prompted to logon to SAS Viya.
A dialog will be displayed if the logon was successful.
Icon this window and proceed to your mcp client
The env variables can be specified in two ways:
1. As part of the mcp configuration as shown below.
2. Create a .env file and specify the env variables in that file.
> Note: You must set the MCPTYPE in the environment variable.
`json
"sasmcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@sassoftware/sas-score-mcp-serverjs@latest",
],
"env": {
"MCPTYPE": "stdio",
"AUTHFLOW": "sascli", // sascli|password|token|none
"SAS_CLI_PROFILE": "cli profile name or Default",
"SAS_CLI_CONFIG":"where sas-cli stores authentication information",
"SSLCERT": "where you have stored the tls information(see below)",
"VIYACERT": "where you have stored the viya server ssl certificates for calls to Viya server",
"VIYA_SERVER": "viya server if AUTHFLOW=password|token|refresh",
"PASSWORD": "password if AUTHFLOW is password",
"USERNAME": "username if AUTHFLOW is password",
"CLIENTID": "client password if AUTHFLOW is password",
"CLIENTSECRET": "client id if AUTHFLOW is password",
"TOKENFILE": "file if AUTHFLOW is token",
"COMPUTECONTEXT": "SAS Job Execution compute context",
"CASSERVER": "cas-shared-default",
}
}
`
This is an alternate to using stdio.
This requires the .env file, which has the necessary configuration values described earlier in this document.
It also requires the MCP server to be running (see step 2).
> Remote MCP servers: This is under development
#### Step 1: Configure the mcp client for localhost
The mcp configuration is show below
`json
"sasmcp": {
"type": "http",
"url": "http(s)//localhost:8080/mcp"`
}
Here is a typical .env file for http transport. Note the value of MCPTYPE.
`env
PORT=8080
HTTPS=FALSE
MCPTYPE=http
VIYA_SERVER=https://myviya.com
AUTHFLOW=sascli
SAS_CLI_PROFILE=00m
SAS_CLI_CONFIG=c:\Users\
SSLCERT=c:\Users\yourusername\.tls
VIYACERT=c:\Users\yourusername\viyaCert
CAS_SERVER=cas-shared-default
COMPUTECONTEXT=SAS Job Execution compute context
`
Use https if the environment variables HTTPS=TRUE
#### Step 2: Start the mcp server
If using stdio transport, most of the mcp clients will start the server automatically.
But this step is necessary of using http transport.
`sh`
npx @sassoftware/sas-score-mcp-serverjs@latest
Make sure that the .env file is in the current working directory
The mcp server caches information for each mcp session id(user).
However, cas and compute sessions are not cached in this release(TBD).
The implication of this design choice is felt most when the tool needs is creating compute session * the requests will take longer than when the compute session is cached.
`sh`
mkcert -install
The install also stores local root Certificate Authority (CA) on the system.
For windows the location is AppData/Local\mkcert.
Now go to the location where you want to store the certificates.
Then create the certificates:
`sh`
mkcert -key-file key.pem -cert-file crt.pem localhost 127:0.0.1 ::1
One last step for windows nodejs users.
Add this to the environment variable NODE_EXTRA_CA_CERTS:
`text``
NODE_EXTRA_CA_CERTS=c:\Users\
* Documentation on modelcontextprotocol(mcp)
* mcp sdk
* restaf
* mkcert
* SAS tokens
* Also see