@sassoftware/sas-score-mcp-serverjs 0.3.9 → 0.3.12
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/expressMcpServer.js +15 -10
- package/src/openAPIJson.js +16 -12
package/package.json
CHANGED
package/src/expressMcpServer.js
CHANGED
|
@@ -23,7 +23,7 @@ import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
|
23
23
|
|
|
24
24
|
async function expressMcpServer(mcpServer, cache, baseAppEnvContext) {
|
|
25
25
|
// setup for change to persistence session
|
|
26
|
-
|
|
26
|
+
cache.set("headerCache", {});
|
|
27
27
|
|
|
28
28
|
const app = express();
|
|
29
29
|
|
|
@@ -120,7 +120,7 @@ function requireBearer(req, res, next) {
|
|
|
120
120
|
headerCache.refreshToken = hdr2;
|
|
121
121
|
headerCache.AUTHFLOW = "refresh";
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
cache.set("headerCache", headerCache);
|
|
124
124
|
next();
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -128,15 +128,17 @@ function requireBearer(req, res, next) {
|
|
|
128
128
|
const handleRequest = async (req, res) => {
|
|
129
129
|
let transport;
|
|
130
130
|
let transports = cache.get("transports");
|
|
131
|
+
console.error("current transports in cache:", Object.keys(transports));
|
|
131
132
|
try {
|
|
132
133
|
|
|
133
134
|
let sessionId = req.headers["mcp-session-id"];
|
|
134
135
|
|
|
135
136
|
// we have session id, get existing transport
|
|
136
|
-
|
|
137
|
+
console.error('>>>>>>>>>>>>>> Received request for MCP endpoint with session ID:', req.method, sessionId);
|
|
137
138
|
if (sessionId != null) {
|
|
138
|
-
|
|
139
|
+
console.error("Looking for transport with session ID:", sessionId);
|
|
139
140
|
transport = transports[sessionId];
|
|
141
|
+
console.error("Found transport:", transport != null);
|
|
140
142
|
if (transport == null) {
|
|
141
143
|
throw new Error(`No transport found for session ID: ${sessionId}`);
|
|
142
144
|
}
|
|
@@ -151,6 +153,7 @@ const handleRequest = async (req, res) => {
|
|
|
151
153
|
if (_appContext == null) {
|
|
152
154
|
|
|
153
155
|
let appEnvTemplate = cache.get("appEnvTemplate");
|
|
156
|
+
let headerCache = cache.get("headerCache");
|
|
154
157
|
_appContext = Object.assign({}, appEnvTemplate, headerCache);
|
|
155
158
|
cache.set(sessionId, _appContext);
|
|
156
159
|
}
|
|
@@ -162,7 +165,7 @@ const handleRequest = async (req, res) => {
|
|
|
162
165
|
// initialize request
|
|
163
166
|
else if (!sessionId && isInitializeRequest(req.body)) {
|
|
164
167
|
// create transport
|
|
165
|
-
|
|
168
|
+
console.error("[Note] Initializing new transport for MCP session...");
|
|
166
169
|
transport = new StreamableHTTPServerTransport({
|
|
167
170
|
sessionIdGenerator: () => randomUUID(),
|
|
168
171
|
enableJsonResponse: true,
|
|
@@ -178,14 +181,16 @@ const handleRequest = async (req, res) => {
|
|
|
178
181
|
}
|
|
179
182
|
};
|
|
180
183
|
console.error("[Note] Connecting mcpServer to new transport...");
|
|
184
|
+
console.error('connecting mcp Server with session ID:', transport.sessionId);
|
|
185
|
+
console.error('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> connecting mcp Server with session ID:', transport.sessionId);
|
|
181
186
|
await mcpServer.connect(transport);
|
|
182
187
|
|
|
183
188
|
// Save transport data and app context for use in tools
|
|
184
|
-
|
|
189
|
+
console.error('connected mcpServe with session ID:', transport.sessionId);
|
|
190
|
+
cache.set("transports", transports);
|
|
185
191
|
await transport.handleRequest(req, res, req.body);
|
|
186
192
|
// cache transport
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
196
|
catch (error) {
|
|
@@ -208,13 +213,13 @@ const handleGetDelete = async (req, res) => {
|
|
|
208
213
|
const sessionId = req.headers["mcp-session-id"];
|
|
209
214
|
console.error("Handling GET/DELETE for session ID:", sessionId);
|
|
210
215
|
let transports = cache.get("transports");
|
|
211
|
-
let transport = transports[sessionId];
|
|
216
|
+
let transport = (sessionId == null) ? null : transports[sessionId];
|
|
212
217
|
if (!sessionId || transport == null) {
|
|
213
218
|
res.status(400).send(`[Error] In ${req.method}: Invalid or missing session ID ${sessionId}`);
|
|
214
219
|
return;
|
|
215
220
|
}
|
|
216
221
|
await transport.handleRequest(req, res);
|
|
217
|
-
if (req.method === "DELETE") {
|
|
222
|
+
if (req.method === "DELETE" && sessionId != null) {
|
|
218
223
|
console.error("Deleting transport and cache for session ID:", sessionId);
|
|
219
224
|
delete transports[sessionId];
|
|
220
225
|
cache.del(sessionId);
|
package/src/openAPIJson.js
CHANGED
|
@@ -17,8 +17,9 @@ function openAPIJson(version) {
|
|
|
17
17
|
"produces": ["application/json"],
|
|
18
18
|
"paths": {
|
|
19
19
|
"/health": {
|
|
20
|
-
"
|
|
20
|
+
"GET": {
|
|
21
21
|
"summary": "Health check",
|
|
22
|
+
"operationId": "GetHealth",
|
|
22
23
|
"description": "Returns health and version information.",
|
|
23
24
|
"responses": {
|
|
24
25
|
"200": {
|
|
@@ -38,9 +39,9 @@ function openAPIJson(version) {
|
|
|
38
39
|
}
|
|
39
40
|
},
|
|
40
41
|
"/apiMeta": {
|
|
41
|
-
"
|
|
42
|
-
"summary": "API metadata",
|
|
43
|
-
"
|
|
42
|
+
"GET": {
|
|
43
|
+
"summary": "API metadata using apiMeta",
|
|
44
|
+
"operationId": "GetApiMeta",
|
|
44
45
|
"responses": {
|
|
45
46
|
"200": {
|
|
46
47
|
"description": "OpenAPI document",
|
|
@@ -50,8 +51,9 @@ function openAPIJson(version) {
|
|
|
50
51
|
}
|
|
51
52
|
},
|
|
52
53
|
"/openapi.json": {
|
|
53
|
-
"
|
|
54
|
-
"summary": "API metadata",
|
|
54
|
+
"GET": {
|
|
55
|
+
"summary": "API metadata using openapi.json",
|
|
56
|
+
"operationId": "GetOpenApiJson",
|
|
55
57
|
"description": "Returns the OpenAPI specification for this server.",
|
|
56
58
|
"responses": {
|
|
57
59
|
"200": {
|
|
@@ -62,16 +64,17 @@ function openAPIJson(version) {
|
|
|
62
64
|
}
|
|
63
65
|
},
|
|
64
66
|
"/mcp": {
|
|
65
|
-
"
|
|
67
|
+
"OPTIONS": {
|
|
66
68
|
"summary": "CORS preflight",
|
|
69
|
+
"operationId": "OptionsMcp",
|
|
67
70
|
"description": "CORS preflight endpoint.",
|
|
68
71
|
"responses": {
|
|
69
72
|
"204": { "description": "No Content" }
|
|
70
73
|
}
|
|
71
74
|
},
|
|
72
|
-
"
|
|
75
|
+
"POST": {
|
|
73
76
|
"summary": "MCP request",
|
|
74
|
-
"
|
|
77
|
+
"operationId": "PostMcp",
|
|
75
78
|
"parameters": [
|
|
76
79
|
{
|
|
77
80
|
"name": "body",
|
|
@@ -119,8 +122,9 @@ function openAPIJson(version) {
|
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
},
|
|
122
|
-
"
|
|
125
|
+
"GET": {
|
|
123
126
|
"summary": "Get MCP session",
|
|
127
|
+
"operationId": "GetMcp",
|
|
124
128
|
"description": "Retrieves information for an MCP session.",
|
|
125
129
|
"parameters": [
|
|
126
130
|
{
|
|
@@ -141,9 +145,9 @@ function openAPIJson(version) {
|
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
},
|
|
144
|
-
"
|
|
148
|
+
"DELETE": {
|
|
145
149
|
"summary": "Delete MCP session",
|
|
146
|
-
"
|
|
150
|
+
"operationId": "DeleteMcp",
|
|
147
151
|
"parameters": [
|
|
148
152
|
{
|
|
149
153
|
"name": "mcp-session-id",
|