profound-mcp 0.26.1 → 0.26.3
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/http.d.mts.map +1 -1
- package/http.d.ts.map +1 -1
- package/http.js +10 -22
- package/http.js.map +1 -1
- package/http.mjs +10 -22
- package/http.mjs.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/instructions.d.mts +2 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +2 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +55 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +52 -0
- package/instructions.mjs.map +1 -0
- package/package.json +12 -2
- package/server.d.mts.map +1 -1
- package/server.d.ts.map +1 -1
- package/server.js +55 -42
- package/server.js.map +1 -1
- package/server.mjs +54 -41
- package/server.mjs.map +1 -1
- package/src/http.ts +10 -21
- package/src/index.ts +1 -1
- package/src/instructions.ts +74 -0
- package/src/server.ts +53 -51
package/http.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.mts","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"OAIO,EAAE,aAAa,EAAE,MAAM,YAAY;OACnC,OAAO,MAAM,SAAS;OAItB,EAAE,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"http.d.mts","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"OAIO,EAAE,aAAa,EAAE,MAAM,YAAY;OACnC,OAAO,MAAM,SAAS;OAItB,EAAE,UAAU,EAAE;AA+DrB,eAAO,MAAM,iBAAiB,GAAI,uCAI/B;IACD,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;CAChB,KAAG,OAAO,CAAC,OAwBX,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAU,8BAI9C;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC,kBAYA,CAAC"}
|
package/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"OAIO,EAAE,aAAa,EAAE,MAAM,YAAY;OACnC,OAAO,MAAM,SAAS;OAItB,EAAE,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"OAIO,EAAE,aAAa,EAAE,MAAM,YAAY;OACnC,OAAO,MAAM,SAAS;OAItB,EAAE,UAAU,EAAE;AA+DrB,eAAO,MAAM,iBAAiB,GAAI,uCAI/B;IACD,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;CAChB,KAAG,OAAO,CAAC,OAwBX,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAU,8BAI9C;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC,kBAYA,CAAC"}
|
package/http.js
CHANGED
|
@@ -14,28 +14,16 @@ const server_1 = require("./server.js");
|
|
|
14
14
|
const newServer = async ({ clientOptions, mcpOptions, req, res, }) => {
|
|
15
15
|
const stainlessApiKey = (0, auth_1.getStainlessApiKey)(req, mcpOptions);
|
|
16
16
|
const server = await (0, server_1.newMcpServer)(stainlessApiKey);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clientOptions
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
res.status(401).json({
|
|
31
|
-
jsonrpc: '2.0',
|
|
32
|
-
error: {
|
|
33
|
-
code: -32000,
|
|
34
|
-
message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
17
|
+
const authOptions = (0, auth_1.parseClientAuthHeaders)(req, false);
|
|
18
|
+
await (0, server_1.initMcpServer)({
|
|
19
|
+
server: server,
|
|
20
|
+
mcpOptions: mcpOptions,
|
|
21
|
+
clientOptions: {
|
|
22
|
+
...clientOptions,
|
|
23
|
+
...authOptions,
|
|
24
|
+
},
|
|
25
|
+
stainlessApiKey: stainlessApiKey,
|
|
26
|
+
});
|
|
39
27
|
return server;
|
|
40
28
|
};
|
|
41
29
|
const post = (options) => async (req, res) => {
|
package/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAGtF,0FAAmG;AAEnG,sDAA8B;AAC9B,oDAA4B;AAC5B,8DAAqC;AACrC,oCAAoE;AAEpE,wCAAuD;AAEvD,MAAM,SAAS,GAAG,KAAK,EAAE,EACvB,aAAa,EACb,UAAU,EACV,GAAG,EACH,GAAG,GAMJ,EAA6B,EAAE;IAC9B,MAAM,eAAe,GAAG,IAAA,yBAAkB,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,eAAe,CAAC,CAAC;IAEnD,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAGtF,0FAAmG;AAEnG,sDAA8B;AAC9B,oDAA4B;AAC5B,8DAAqC;AACrC,oCAAoE;AAEpE,wCAAuD;AAEvD,MAAM,SAAS,GAAG,KAAK,EAAE,EACvB,aAAa,EACb,UAAU,EACV,GAAG,EACH,GAAG,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ACb,CAAC,CAAC;AAhCW,QAAA,iBAAiB,qBAgC5B;AAEK,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAC/C,UAAU,EACV,KAAK,EACL,IAAI,GAKL,EAAE,EAAE;IACH,MAAM,GAAG,GAAG,IAAA,yBAAiB,EAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,4CAA4C,OAAO,EAAE,CAAC,CAAC;IACvE,CAAC;SAAM,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC,iDAAiD,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,iDAAiD,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;AACH,CAAC,CAAC;AApBW,QAAA,0BAA0B,8BAoBrC"}
|
package/http.mjs
CHANGED
|
@@ -8,28 +8,16 @@ import { initMcpServer, newMcpServer } from "./server.mjs";
|
|
|
8
8
|
const newServer = async ({ clientOptions, mcpOptions, req, res, }) => {
|
|
9
9
|
const stainlessApiKey = getStainlessApiKey(req, mcpOptions);
|
|
10
10
|
const server = await newMcpServer(stainlessApiKey);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
clientOptions
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
res.status(401).json({
|
|
25
|
-
jsonrpc: '2.0',
|
|
26
|
-
error: {
|
|
27
|
-
code: -32000,
|
|
28
|
-
message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
11
|
+
const authOptions = parseClientAuthHeaders(req, false);
|
|
12
|
+
await initMcpServer({
|
|
13
|
+
server: server,
|
|
14
|
+
mcpOptions: mcpOptions,
|
|
15
|
+
clientOptions: {
|
|
16
|
+
...clientOptions,
|
|
17
|
+
...authOptions,
|
|
18
|
+
},
|
|
19
|
+
stainlessApiKey: stainlessApiKey,
|
|
20
|
+
});
|
|
33
21
|
return server;
|
|
34
22
|
};
|
|
35
23
|
const post = (options) => async (req, res) => {
|
package/http.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.mjs","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,6BAA6B,EAAE,MAAM,oDAAoD;OAE3F,OAAO,MAAM,SAAS;OACtB,MAAM,MAAM,QAAQ;OACpB,UAAU,MAAM,aAAa;OAC7B,EAAE,kBAAkB,EAAE,sBAAsB,EAAE;OAE9C,EAAE,aAAa,EAAE,YAAY,EAAE;AAEtC,MAAM,SAAS,GAAG,KAAK,EAAE,EACvB,aAAa,EACb,UAAU,EACV,GAAG,EACH,GAAG,GAMJ,EAA6B,EAAE;IAC9B,MAAM,eAAe,GAAG,kBAAkB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC,CAAC;IAEnD,
|
|
1
|
+
{"version":3,"file":"http.mjs","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,6BAA6B,EAAE,MAAM,oDAAoD;OAE3F,OAAO,MAAM,SAAS;OACtB,MAAM,MAAM,QAAQ;OACpB,UAAU,MAAM,aAAa;OAC7B,EAAE,kBAAkB,EAAE,sBAAsB,EAAE;OAE9C,EAAE,aAAa,EAAE,YAAY,EAAE;AAE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1
|
+
{"version":3,"file":"instructions.d.mts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AA0BA,wBAAsB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAW1F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AA0BA,wBAAsB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAW1F"}
|
package/instructions.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getInstructions = getInstructions;
|
|
5
|
+
const util_1 = require("./util.js");
|
|
6
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
7
|
+
const instructionsCache = new Map();
|
|
8
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
9
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
10
|
+
const now = Date.now();
|
|
11
|
+
for (const [key, entry] of instructionsCache) {
|
|
12
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
13
|
+
instructionsCache.delete(key);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
17
|
+
// Don't keep the process alive just for cleanup.
|
|
18
|
+
_cacheCleanupInterval.unref();
|
|
19
|
+
async function getInstructions(stainlessApiKey) {
|
|
20
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
21
|
+
const cached = instructionsCache.get(cacheKey);
|
|
22
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
23
|
+
return cached.fetchedInstructions;
|
|
24
|
+
}
|
|
25
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
26
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
27
|
+
return fetchedInstructions;
|
|
28
|
+
}
|
|
29
|
+
async function fetchLatestInstructions(stainlessApiKey) {
|
|
30
|
+
// Setting the stainless API key is optional, but may be required
|
|
31
|
+
// to authenticate requests to the Stainless API.
|
|
32
|
+
const response = await fetch((0, util_1.readEnv)('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/profound', {
|
|
33
|
+
method: 'GET',
|
|
34
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
35
|
+
});
|
|
36
|
+
let instructions;
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
39
|
+
instructions = `
|
|
40
|
+
This is the profound MCP server. You will use Code Mode to help the user perform
|
|
41
|
+
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
42
|
+
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
43
|
+
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
44
|
+
block: it can be as long as you need to get the job done!
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
instructions ??= (await response.json()).instructions;
|
|
48
|
+
instructions = `
|
|
49
|
+
If needed, you can get the current time by executing Date.now().
|
|
50
|
+
|
|
51
|
+
${instructions}
|
|
52
|
+
`;
|
|
53
|
+
return instructions;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;AA0BtF,0CAWC;AAnCD,oCAAiC;AAEjC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,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AK;QACb,OAAO,EAAE,EAAE,GAAG,CAAC,eAAe,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC,EAAE;KACxE,CACF,CAAC;IAEF,IAAI,YAAgC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CACV,8FAA8F,CAC/F,CAAC;QAEF,YAAY,GAAG;;;;;;KAMd,CAAC;IACJ,CAAC;IAED,YAAY,KAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA8B,CAAC,YAAY,CAAC;IACpF,YAAY,GAAG;;;MAGX,YAAY;GACf,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/instructions.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
import { readEnv } from "./util.mjs";
|
|
3
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
4
|
+
const instructionsCache = new Map();
|
|
5
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
6
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
7
|
+
const now = Date.now();
|
|
8
|
+
for (const [key, entry] of instructionsCache) {
|
|
9
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
10
|
+
instructionsCache.delete(key);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
14
|
+
// Don't keep the process alive just for cleanup.
|
|
15
|
+
_cacheCleanupInterval.unref();
|
|
16
|
+
export async function getInstructions(stainlessApiKey) {
|
|
17
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
18
|
+
const cached = instructionsCache.get(cacheKey);
|
|
19
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
20
|
+
return cached.fetchedInstructions;
|
|
21
|
+
}
|
|
22
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
23
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
24
|
+
return fetchedInstructions;
|
|
25
|
+
}
|
|
26
|
+
async function fetchLatestInstructions(stainlessApiKey) {
|
|
27
|
+
// Setting the stainless API key is optional, but may be required
|
|
28
|
+
// to authenticate requests to the Stainless API.
|
|
29
|
+
const response = await fetch(readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/profound', {
|
|
30
|
+
method: 'GET',
|
|
31
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
32
|
+
});
|
|
33
|
+
let instructions;
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
36
|
+
instructions = `
|
|
37
|
+
This is the profound MCP server. You will use Code Mode to help the user perform
|
|
38
|
+
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
39
|
+
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
40
|
+
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
41
|
+
block: it can be as long as you need to get the job done!
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
instructions ??= (await response.json()).instructions;
|
|
45
|
+
instructions = `
|
|
46
|
+
If needed, you can get the current time by executing Date.now().
|
|
47
|
+
|
|
48
|
+
${instructions}
|
|
49
|
+
`;
|
|
50
|
+
return instructions;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=instructions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.mjs","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,OAAO,EAAE;AAElB,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,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O,EAAE,EAAE,GAAG,CAAC,eAAe,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC,EAAE;KACxE,CACF,CAAC;IAEF,IAAI,YAAgC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CACV,8FAA8F,CAC/F,CAAC;QAEF,YAAY,GAAG;;;;;;KAMd,CAAC;IACJ,CAAC;IAED,YAAY,KAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA8B,CAAC,YAAY,CAAC;IACpF,YAAY,GAAG;;;MAGX,YAAY;GACf,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "profound-mcp",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.3",
|
|
4
4
|
"description": "The official MCP Server for the Profound API",
|
|
5
5
|
"author": "Profound <support@tryprofound.com>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"fix": "eslint --fix --ext ts,js ."
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"profoundai": "^0.26.
|
|
30
|
+
"profoundai": "^0.26.3",
|
|
31
31
|
"@cloudflare/cabidela": "^0.2.4",
|
|
32
32
|
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
33
33
|
"@valtown/deno-http-worker": "^0.0.21",
|
|
@@ -121,6 +121,16 @@
|
|
|
121
121
|
"./index.mjs": {
|
|
122
122
|
"default": "./index.mjs"
|
|
123
123
|
},
|
|
124
|
+
"./instructions": {
|
|
125
|
+
"import": "./instructions.mjs",
|
|
126
|
+
"require": "./instructions.js"
|
|
127
|
+
},
|
|
128
|
+
"./instructions.js": {
|
|
129
|
+
"default": "./instructions.js"
|
|
130
|
+
},
|
|
131
|
+
"./instructions.mjs": {
|
|
132
|
+
"default": "./instructions.mjs"
|
|
133
|
+
},
|
|
124
134
|
"./methods": {
|
|
125
135
|
"import": "./methods.mjs",
|
|
126
136
|
"require": "./methods.js"
|
package/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,YAAY;OAKnC,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,iBAAiB,MAAM,GAAG,SAAS,uBAUnE,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,iBAiHA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAU3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GACL,EAAE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1B"}
|
package/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,YAAY;OAKnC,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,iBAAiB,MAAM,GAAG,SAAS,uBAUnE,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,iBAiHA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAU3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GACL,EAAE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1B"}
|
package/server.js
CHANGED
|
@@ -13,39 +13,13 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
13
13
|
const profoundai_1 = __importDefault(require("profoundai"));
|
|
14
14
|
const code_tool_1 = require("./code-tool.js");
|
|
15
15
|
const docs_search_tool_1 = __importDefault(require("./docs-search-tool.js"));
|
|
16
|
+
const instructions_1 = require("./instructions.js");
|
|
16
17
|
const methods_1 = require("./methods.js");
|
|
17
|
-
const util_1 = require("./util.js");
|
|
18
|
-
async function getInstructions(stainlessApiKey) {
|
|
19
|
-
// Setting the stainless API key is optional, but may be required
|
|
20
|
-
// to authenticate requests to the Stainless API.
|
|
21
|
-
const response = await fetch((0, util_1.readEnv)('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/profound', {
|
|
22
|
-
method: 'GET',
|
|
23
|
-
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
24
|
-
});
|
|
25
|
-
let instructions;
|
|
26
|
-
if (!response.ok) {
|
|
27
|
-
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
28
|
-
instructions = `
|
|
29
|
-
This is the profound MCP server. You will use Code Mode to help the user perform
|
|
30
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
31
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
32
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
33
|
-
block: it can be as long as you need to get the job done!
|
|
34
|
-
`;
|
|
35
|
-
}
|
|
36
|
-
instructions ??= (await response.json()).instructions;
|
|
37
|
-
instructions = `
|
|
38
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
39
|
-
|
|
40
|
-
${instructions}
|
|
41
|
-
`;
|
|
42
|
-
return instructions;
|
|
43
|
-
}
|
|
44
18
|
const newMcpServer = async (stainlessApiKey) => new mcp_js_1.McpServer({
|
|
45
19
|
name: 'profoundai_api',
|
|
46
|
-
version: '0.26.
|
|
20
|
+
version: '0.26.3',
|
|
47
21
|
}, {
|
|
48
|
-
instructions: await getInstructions(stainlessApiKey),
|
|
22
|
+
instructions: await (0, instructions_1.getInstructions)(stainlessApiKey),
|
|
49
23
|
capabilities: { tools: {}, logging: {} },
|
|
50
24
|
});
|
|
51
25
|
exports.newMcpServer = newMcpServer;
|
|
@@ -67,14 +41,33 @@ async function initMcpServer(params) {
|
|
|
67
41
|
warn: logAtLevel('warning'),
|
|
68
42
|
error: logAtLevel('error'),
|
|
69
43
|
};
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
44
|
+
let _client;
|
|
45
|
+
let _clientError;
|
|
46
|
+
let _logLevel;
|
|
47
|
+
const getClient = () => {
|
|
48
|
+
if (_clientError)
|
|
49
|
+
throw _clientError;
|
|
50
|
+
if (!_client) {
|
|
51
|
+
try {
|
|
52
|
+
_client = new profoundai_1.default({
|
|
53
|
+
logger,
|
|
54
|
+
...params.clientOptions,
|
|
55
|
+
defaultHeaders: {
|
|
56
|
+
...params.clientOptions?.defaultHeaders,
|
|
57
|
+
'X-Stainless-MCP': 'true',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
if (_logLevel) {
|
|
61
|
+
_client = _client.withOptions({ logLevel: _logLevel });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
_clientError = e instanceof Error ? e : new Error(String(e));
|
|
66
|
+
throw _clientError;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return _client;
|
|
70
|
+
};
|
|
78
71
|
const providedTools = selectTools(params.mcpOptions);
|
|
79
72
|
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
80
73
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
@@ -88,6 +81,21 @@ async function initMcpServer(params) {
|
|
|
88
81
|
if (!mcpTool) {
|
|
89
82
|
throw new Error(`Unknown tool: ${name}`);
|
|
90
83
|
}
|
|
84
|
+
let client;
|
|
85
|
+
try {
|
|
86
|
+
client = getClient();
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: 'text',
|
|
93
|
+
text: `Failed to initialize client: ${error instanceof Error ? error.message : String(error)}`,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
isError: true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
91
99
|
return executeHandler({
|
|
92
100
|
handler: mcpTool.handler,
|
|
93
101
|
reqContext: {
|
|
@@ -99,24 +107,29 @@ async function initMcpServer(params) {
|
|
|
99
107
|
});
|
|
100
108
|
server.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request) => {
|
|
101
109
|
const { level } = request.params;
|
|
110
|
+
let logLevel;
|
|
102
111
|
switch (level) {
|
|
103
112
|
case 'debug':
|
|
104
|
-
|
|
113
|
+
logLevel = 'debug';
|
|
105
114
|
break;
|
|
106
115
|
case 'info':
|
|
107
|
-
|
|
116
|
+
logLevel = 'info';
|
|
108
117
|
break;
|
|
109
118
|
case 'notice':
|
|
110
119
|
case 'warning':
|
|
111
|
-
|
|
120
|
+
logLevel = 'warn';
|
|
112
121
|
break;
|
|
113
122
|
case 'error':
|
|
114
|
-
|
|
123
|
+
logLevel = 'error';
|
|
115
124
|
break;
|
|
116
125
|
default:
|
|
117
|
-
|
|
126
|
+
logLevel = 'off';
|
|
118
127
|
break;
|
|
119
128
|
}
|
|
129
|
+
_logLevel = logLevel;
|
|
130
|
+
if (_client) {
|
|
131
|
+
_client = _client.withOptions({ logLevel });
|
|
132
|
+
}
|
|
120
133
|
return {};
|
|
121
134
|
});
|
|
122
135
|
}
|
package/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;
|
|
1
|
+
{"version":3,"file":"server.js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G,MAAM,CAAC;gBAClB,MAAM;YACR,KAAK,OAAO;gBACV,QAAQ,GAAG,OAAO,CAAC;gBACnB,MAAM;YACR;gBACE,QAAQ,GAAG,KAAK,CAAC;gBACjB,MAAM;QACV,CAAC;QACD,SAAS,GAAG,QAAQ,CAAC;QACrB,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,OAAoB;IAC9C,MAAM,aAAa,GAAG;QACpB,IAAA,oBAAQ,EAAC;YACP,cAAc,EAAE,IAAA,mCAAyB,EAAC,OAAO,CAAC;SACnD,CAAC;KACH,CAAC;IACF,IAAI,OAAO,EAAE,gBAAgB,IAAI,IAAI,EAAE,CAAC;QACtC,aAAa,CAAC,IAAI,CAAC,0BAAc,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/server.mjs
CHANGED
|
@@ -4,37 +4,11 @@ import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema, }
|
|
|
4
4
|
import Profound from 'profoundai';
|
|
5
5
|
import { codeTool } from "./code-tool.mjs";
|
|
6
6
|
import docsSearchTool from "./docs-search-tool.mjs";
|
|
7
|
+
import { getInstructions } from "./instructions.mjs";
|
|
7
8
|
import { blockedMethodsForCodeTool } from "./methods.mjs";
|
|
8
|
-
import { readEnv } from "./util.mjs";
|
|
9
|
-
async function getInstructions(stainlessApiKey) {
|
|
10
|
-
// Setting the stainless API key is optional, but may be required
|
|
11
|
-
// to authenticate requests to the Stainless API.
|
|
12
|
-
const response = await fetch(readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/profound', {
|
|
13
|
-
method: 'GET',
|
|
14
|
-
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
15
|
-
});
|
|
16
|
-
let instructions;
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
19
|
-
instructions = `
|
|
20
|
-
This is the profound MCP server. You will use Code Mode to help the user perform
|
|
21
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
22
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
23
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
24
|
-
block: it can be as long as you need to get the job done!
|
|
25
|
-
`;
|
|
26
|
-
}
|
|
27
|
-
instructions ??= (await response.json()).instructions;
|
|
28
|
-
instructions = `
|
|
29
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
30
|
-
|
|
31
|
-
${instructions}
|
|
32
|
-
`;
|
|
33
|
-
return instructions;
|
|
34
|
-
}
|
|
35
9
|
export const newMcpServer = async (stainlessApiKey) => new McpServer({
|
|
36
10
|
name: 'profoundai_api',
|
|
37
|
-
version: '0.26.
|
|
11
|
+
version: '0.26.3',
|
|
38
12
|
}, {
|
|
39
13
|
instructions: await getInstructions(stainlessApiKey),
|
|
40
14
|
capabilities: { tools: {}, logging: {} },
|
|
@@ -57,14 +31,33 @@ export async function initMcpServer(params) {
|
|
|
57
31
|
warn: logAtLevel('warning'),
|
|
58
32
|
error: logAtLevel('error'),
|
|
59
33
|
};
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
34
|
+
let _client;
|
|
35
|
+
let _clientError;
|
|
36
|
+
let _logLevel;
|
|
37
|
+
const getClient = () => {
|
|
38
|
+
if (_clientError)
|
|
39
|
+
throw _clientError;
|
|
40
|
+
if (!_client) {
|
|
41
|
+
try {
|
|
42
|
+
_client = new Profound({
|
|
43
|
+
logger,
|
|
44
|
+
...params.clientOptions,
|
|
45
|
+
defaultHeaders: {
|
|
46
|
+
...params.clientOptions?.defaultHeaders,
|
|
47
|
+
'X-Stainless-MCP': 'true',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (_logLevel) {
|
|
51
|
+
_client = _client.withOptions({ logLevel: _logLevel });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
_clientError = e instanceof Error ? e : new Error(String(e));
|
|
56
|
+
throw _clientError;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return _client;
|
|
60
|
+
};
|
|
68
61
|
const providedTools = selectTools(params.mcpOptions);
|
|
69
62
|
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
70
63
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
@@ -78,6 +71,21 @@ export async function initMcpServer(params) {
|
|
|
78
71
|
if (!mcpTool) {
|
|
79
72
|
throw new Error(`Unknown tool: ${name}`);
|
|
80
73
|
}
|
|
74
|
+
let client;
|
|
75
|
+
try {
|
|
76
|
+
client = getClient();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: 'text',
|
|
83
|
+
text: `Failed to initialize client: ${error instanceof Error ? error.message : String(error)}`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
isError: true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
81
89
|
return executeHandler({
|
|
82
90
|
handler: mcpTool.handler,
|
|
83
91
|
reqContext: {
|
|
@@ -89,24 +97,29 @@ export async function initMcpServer(params) {
|
|
|
89
97
|
});
|
|
90
98
|
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
91
99
|
const { level } = request.params;
|
|
100
|
+
let logLevel;
|
|
92
101
|
switch (level) {
|
|
93
102
|
case 'debug':
|
|
94
|
-
|
|
103
|
+
logLevel = 'debug';
|
|
95
104
|
break;
|
|
96
105
|
case 'info':
|
|
97
|
-
|
|
106
|
+
logLevel = 'info';
|
|
98
107
|
break;
|
|
99
108
|
case 'notice':
|
|
100
109
|
case 'warning':
|
|
101
|
-
|
|
110
|
+
logLevel = 'warn';
|
|
102
111
|
break;
|
|
103
112
|
case 'error':
|
|
104
|
-
|
|
113
|
+
logLevel = 'error';
|
|
105
114
|
break;
|
|
106
115
|
default:
|
|
107
|
-
|
|
116
|
+
logLevel = 'off';
|
|
108
117
|
break;
|
|
109
118
|
}
|
|
119
|
+
_logLevel = logLevel;
|
|
120
|
+
if (_client) {
|
|
121
|
+
_client = _client.withOptions({ logLevel });
|
|
122
|
+
}
|
|
110
123
|
return {};
|
|
111
124
|
});
|
|
112
125
|
}
|
package/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC;OAEpC,QAAQ,MAAM,YAAY;OAC1B,EAAE,QAAQ,EAAE;OACZ,cAAc;
|
|
1
|
+
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC;OAEpC,QAAQ,MAAM,YAAY;OAC1B,EAAE,QAAQ,EAAE;OACZ,cAAc;OACd,EAAE,eAAe,EAAE;OAEnB,EAAE,yBAA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Z,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAoB;IAC9C,MAAM,aAAa,GAAG;QACpB,QAAQ,CAAC;YACP,cAAc,EAAE,yBAAyB,CAAC,OAAO,CAAC;SACnD,CAAC;KACH,CAAC;IACF,IAAI,OAAO,EAAE,gBAAgB,IAAI,IAAI,EAAE,CAAC;QACtC,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/src/http.ts
CHANGED
|
@@ -24,28 +24,17 @@ const newServer = async ({
|
|
|
24
24
|
const stainlessApiKey = getStainlessApiKey(req, mcpOptions);
|
|
25
25
|
const server = await newMcpServer(stainlessApiKey);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
const authOptions = parseClientAuthHeaders(req, false);
|
|
27
|
+
const authOptions = parseClientAuthHeaders(req, false);
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} catch (error) {
|
|
40
|
-
res.status(401).json({
|
|
41
|
-
jsonrpc: '2.0',
|
|
42
|
-
error: {
|
|
43
|
-
code: -32000,
|
|
44
|
-
message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
29
|
+
await initMcpServer({
|
|
30
|
+
server: server,
|
|
31
|
+
mcpOptions: mcpOptions,
|
|
32
|
+
clientOptions: {
|
|
33
|
+
...clientOptions,
|
|
34
|
+
...authOptions,
|
|
35
|
+
},
|
|
36
|
+
stainlessApiKey: stainlessApiKey,
|
|
37
|
+
});
|
|
49
38
|
|
|
50
39
|
return server;
|
|
51
40
|
};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { readEnv } from './util';
|
|
4
|
+
|
|
5
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
6
|
+
|
|
7
|
+
interface InstructionsCacheEntry {
|
|
8
|
+
fetchedInstructions: string;
|
|
9
|
+
fetchedAt: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const instructionsCache = new Map<string, InstructionsCacheEntry>();
|
|
13
|
+
|
|
14
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
15
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
for (const [key, entry] of instructionsCache) {
|
|
18
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
19
|
+
instructionsCache.delete(key);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
23
|
+
|
|
24
|
+
// Don't keep the process alive just for cleanup.
|
|
25
|
+
_cacheCleanupInterval.unref();
|
|
26
|
+
|
|
27
|
+
export async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
28
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
29
|
+
const cached = instructionsCache.get(cacheKey);
|
|
30
|
+
|
|
31
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
32
|
+
return cached.fetchedInstructions;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
36
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
37
|
+
return fetchedInstructions;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function fetchLatestInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
41
|
+
// Setting the stainless API key is optional, but may be required
|
|
42
|
+
// to authenticate requests to the Stainless API.
|
|
43
|
+
const response = await fetch(
|
|
44
|
+
readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/profound',
|
|
45
|
+
{
|
|
46
|
+
method: 'GET',
|
|
47
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let instructions: string | undefined;
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
console.warn(
|
|
54
|
+
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
instructions = `
|
|
58
|
+
This is the profound MCP server. You will use Code Mode to help the user perform
|
|
59
|
+
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
60
|
+
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
61
|
+
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
62
|
+
block: it can be as long as you need to get the job done!
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
67
|
+
instructions = `
|
|
68
|
+
If needed, you can get the current time by executing Date.now().
|
|
69
|
+
|
|
70
|
+
${instructions}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
return instructions;
|
|
74
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -11,52 +11,16 @@ import { ClientOptions } from 'profoundai';
|
|
|
11
11
|
import Profound from 'profoundai';
|
|
12
12
|
import { codeTool } from './code-tool';
|
|
13
13
|
import docsSearchTool from './docs-search-tool';
|
|
14
|
+
import { getInstructions } from './instructions';
|
|
14
15
|
import { McpOptions } from './options';
|
|
15
16
|
import { blockedMethodsForCodeTool } from './methods';
|
|
16
17
|
import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from './types';
|
|
17
|
-
import { readEnv } from './util';
|
|
18
|
-
|
|
19
|
-
async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
20
|
-
// Setting the stainless API key is optional, but may be required
|
|
21
|
-
// to authenticate requests to the Stainless API.
|
|
22
|
-
const response = await fetch(
|
|
23
|
-
readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/profound',
|
|
24
|
-
{
|
|
25
|
-
method: 'GET',
|
|
26
|
-
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
27
|
-
},
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
let instructions: string | undefined;
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
console.warn(
|
|
33
|
-
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
instructions = `
|
|
37
|
-
This is the profound MCP server. You will use Code Mode to help the user perform
|
|
38
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
39
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
40
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
41
|
-
block: it can be as long as you need to get the job done!
|
|
42
|
-
`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
46
|
-
instructions = `
|
|
47
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
48
|
-
|
|
49
|
-
${instructions}
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
return instructions;
|
|
53
|
-
}
|
|
54
18
|
|
|
55
19
|
export const newMcpServer = async (stainlessApiKey: string | undefined) =>
|
|
56
20
|
new McpServer(
|
|
57
21
|
{
|
|
58
22
|
name: 'profoundai_api',
|
|
59
|
-
version: '0.26.
|
|
23
|
+
version: '0.26.3',
|
|
60
24
|
},
|
|
61
25
|
{
|
|
62
26
|
instructions: await getInstructions(stainlessApiKey),
|
|
@@ -91,14 +55,32 @@ export async function initMcpServer(params: {
|
|
|
91
55
|
error: logAtLevel('error'),
|
|
92
56
|
};
|
|
93
57
|
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
58
|
+
let _client: Profound | undefined;
|
|
59
|
+
let _clientError: Error | undefined;
|
|
60
|
+
let _logLevel: 'debug' | 'info' | 'warn' | 'error' | 'off' | undefined;
|
|
61
|
+
|
|
62
|
+
const getClient = (): Profound => {
|
|
63
|
+
if (_clientError) throw _clientError;
|
|
64
|
+
if (!_client) {
|
|
65
|
+
try {
|
|
66
|
+
_client = new Profound({
|
|
67
|
+
logger,
|
|
68
|
+
...params.clientOptions,
|
|
69
|
+
defaultHeaders: {
|
|
70
|
+
...params.clientOptions?.defaultHeaders,
|
|
71
|
+
'X-Stainless-MCP': 'true',
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
if (_logLevel) {
|
|
75
|
+
_client = _client.withOptions({ logLevel: _logLevel });
|
|
76
|
+
}
|
|
77
|
+
} catch (e) {
|
|
78
|
+
_clientError = e instanceof Error ? e : new Error(String(e));
|
|
79
|
+
throw _clientError;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return _client;
|
|
83
|
+
};
|
|
102
84
|
|
|
103
85
|
const providedTools = selectTools(params.mcpOptions);
|
|
104
86
|
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
@@ -116,6 +98,21 @@ export async function initMcpServer(params: {
|
|
|
116
98
|
throw new Error(`Unknown tool: ${name}`);
|
|
117
99
|
}
|
|
118
100
|
|
|
101
|
+
let client: Profound;
|
|
102
|
+
try {
|
|
103
|
+
client = getClient();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return {
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: 'text' as const,
|
|
109
|
+
text: `Failed to initialize client: ${error instanceof Error ? error.message : String(error)}`,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
isError: true,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
119
116
|
return executeHandler({
|
|
120
117
|
handler: mcpTool.handler,
|
|
121
118
|
reqContext: {
|
|
@@ -128,24 +125,29 @@ export async function initMcpServer(params: {
|
|
|
128
125
|
|
|
129
126
|
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
130
127
|
const { level } = request.params;
|
|
128
|
+
let logLevel: 'debug' | 'info' | 'warn' | 'error' | 'off';
|
|
131
129
|
switch (level) {
|
|
132
130
|
case 'debug':
|
|
133
|
-
|
|
131
|
+
logLevel = 'debug';
|
|
134
132
|
break;
|
|
135
133
|
case 'info':
|
|
136
|
-
|
|
134
|
+
logLevel = 'info';
|
|
137
135
|
break;
|
|
138
136
|
case 'notice':
|
|
139
137
|
case 'warning':
|
|
140
|
-
|
|
138
|
+
logLevel = 'warn';
|
|
141
139
|
break;
|
|
142
140
|
case 'error':
|
|
143
|
-
|
|
141
|
+
logLevel = 'error';
|
|
144
142
|
break;
|
|
145
143
|
default:
|
|
146
|
-
|
|
144
|
+
logLevel = 'off';
|
|
147
145
|
break;
|
|
148
146
|
}
|
|
147
|
+
_logLevel = logLevel;
|
|
148
|
+
if (_client) {
|
|
149
|
+
_client = _client.withOptions({ logLevel });
|
|
150
|
+
}
|
|
149
151
|
return {};
|
|
150
152
|
});
|
|
151
153
|
}
|