profound-mcp 0.14.0 → 0.17.0
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/LICENSE +1 -1
- package/README.md +14 -184
- package/code-tool-types.d.mts +6 -9
- package/code-tool-types.d.mts.map +1 -1
- package/code-tool-types.d.ts +6 -9
- package/code-tool-types.d.ts.map +1 -1
- package/code-tool.d.mts +2 -2
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +2 -2
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +53 -145
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +53 -112
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +15 -9
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +15 -9
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +4 -1
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +4 -1
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts.map +1 -1
- package/http.d.ts.map +1 -1
- package/http.js +1 -18
- package/http.js.map +1 -1
- package/http.mjs +1 -18
- package/http.mjs.map +1 -1
- package/index.js +4 -40
- package/index.js.map +1 -1
- package/index.mjs +4 -40
- package/index.mjs.map +1 -1
- package/options.d.mts +0 -9
- package/options.d.mts.map +1 -1
- package/options.d.ts +0 -9
- package/options.d.ts.map +1 -1
- package/options.js +6 -361
- package/options.js.map +1 -1
- package/options.mjs +6 -361
- package/options.mjs.map +1 -1
- package/package.json +10 -66
- package/server.d.mts +3 -8
- package/server.d.mts.map +1 -1
- package/server.d.ts +3 -8
- package/server.d.ts.map +1 -1
- package/server.js +12 -65
- package/server.js.map +1 -1
- package/server.mjs +11 -62
- package/server.mjs.map +1 -1
- package/src/code-tool-types.ts +6 -9
- package/src/code-tool.ts +60 -138
- package/src/docs-search-tool.ts +8 -1
- package/src/http.ts +1 -19
- package/src/index.ts +5 -52
- package/src/options.ts +7 -388
- package/src/server.ts +12 -72
- package/src/stdio.ts +2 -3
- package/src/{tools/types.ts → types.ts} +1 -1
- package/stdio.d.mts +1 -2
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts +1 -2
- package/stdio.d.ts.map +1 -1
- package/stdio.js +2 -2
- package/stdio.js.map +1 -1
- package/stdio.mjs +2 -2
- package/stdio.mjs.map +1 -1
- package/{tools/types.d.mts → types.d.mts} +1 -1
- package/types.d.mts.map +1 -0
- package/{tools/types.d.ts → types.d.ts} +1 -1
- package/types.d.ts.map +1 -0
- package/types.js.map +1 -0
- package/types.mjs.map +1 -0
- package/code-tool-paths.cjs +0 -6
- package/code-tool-paths.cjs.map +0 -1
- package/code-tool-paths.d.cts +0 -2
- package/code-tool-paths.d.cts.map +0 -1
- package/code-tool-worker.d.mts +0 -5
- package/code-tool-worker.d.mts.map +0 -1
- package/code-tool-worker.d.ts +0 -5
- package/code-tool-worker.d.ts.map +0 -1
- package/code-tool-worker.js +0 -169
- package/code-tool-worker.js.map +0 -1
- package/code-tool-worker.mjs +0 -164
- package/code-tool-worker.mjs.map +0 -1
- package/compat.d.mts +0 -58
- package/compat.d.mts.map +0 -1
- package/compat.d.ts +0 -58
- package/compat.d.ts.map +0 -1
- package/compat.js +0 -387
- package/compat.js.map +0 -1
- package/compat.mjs +0 -378
- package/compat.mjs.map +0 -1
- package/dynamic-tools.d.mts +0 -12
- package/dynamic-tools.d.mts.map +0 -1
- package/dynamic-tools.d.ts +0 -12
- package/dynamic-tools.d.ts.map +0 -1
- package/dynamic-tools.js +0 -135
- package/dynamic-tools.js.map +0 -1
- package/dynamic-tools.mjs +0 -132
- package/dynamic-tools.mjs.map +0 -1
- package/filtering.d.mts +0 -3
- package/filtering.d.mts.map +0 -1
- package/filtering.d.ts +0 -3
- package/filtering.d.ts.map +0 -1
- package/filtering.js +0 -24
- package/filtering.js.map +0 -1
- package/filtering.mjs +0 -16
- package/filtering.mjs.map +0 -1
- package/src/code-tool-paths.cts +0 -3
- package/src/code-tool-worker.ts +0 -215
- package/src/compat.ts +0 -483
- package/src/dynamic-tools.ts +0 -153
- package/src/filtering.ts +0 -18
- package/src/tools/index.ts +0 -99
- package/src/tools/logs/raw/bots-logs-raw.ts +0 -544
- package/src/tools/logs/raw/logs-logs-raw.ts +0 -565
- package/src/tools/organizations/categories/assets-organizations-categories.ts +0 -57
- package/src/tools/organizations/categories/list-organizations-categories.ts +0 -51
- package/src/tools/organizations/categories/prompts-organizations-categories.ts +0 -57
- package/src/tools/organizations/categories/tags-organizations-categories.ts +0 -57
- package/src/tools/organizations/categories/topics-organizations-categories.ts +0 -57
- package/src/tools/organizations/domains-organizations.ts +0 -51
- package/src/tools/organizations/list-assets-organizations.ts +0 -51
- package/src/tools/organizations/models-organizations.ts +0 -51
- package/src/tools/organizations/regions-organizations.ts +0 -51
- package/src/tools/prompts/answers-prompts.ts +0 -370
- package/src/tools/reports/citations-reports.ts +0 -504
- package/src/tools/reports/sentiment-reports.ts +0 -418
- package/src/tools/reports/visibility-reports.ts +0 -364
- package/src/tools.ts +0 -1
- package/tools/index.d.mts +0 -10
- package/tools/index.d.mts.map +0 -1
- package/tools/index.d.ts +0 -10
- package/tools/index.d.ts.map +0 -1
- package/tools/index.js +0 -83
- package/tools/index.js.map +0 -1
- package/tools/index.mjs +0 -76
- package/tools/index.mjs.map +0 -1
- package/tools/logs/raw/bots-logs-raw.d.mts +0 -45
- package/tools/logs/raw/bots-logs-raw.d.mts.map +0 -1
- package/tools/logs/raw/bots-logs-raw.d.ts +0 -45
- package/tools/logs/raw/bots-logs-raw.d.ts.map +0 -1
- package/tools/logs/raw/bots-logs-raw.js +0 -544
- package/tools/logs/raw/bots-logs-raw.js.map +0 -1
- package/tools/logs/raw/bots-logs-raw.mjs +0 -537
- package/tools/logs/raw/bots-logs-raw.mjs.map +0 -1
- package/tools/logs/raw/logs-logs-raw.d.mts +0 -45
- package/tools/logs/raw/logs-logs-raw.d.mts.map +0 -1
- package/tools/logs/raw/logs-logs-raw.d.ts +0 -45
- package/tools/logs/raw/logs-logs-raw.d.ts.map +0 -1
- package/tools/logs/raw/logs-logs-raw.js +0 -565
- package/tools/logs/raw/logs-logs-raw.js.map +0 -1
- package/tools/logs/raw/logs-logs-raw.mjs +0 -558
- package/tools/logs/raw/logs-logs-raw.mjs.map +0 -1
- package/tools/organizations/categories/assets-organizations-categories.d.mts +0 -45
- package/tools/organizations/categories/assets-organizations-categories.d.mts.map +0 -1
- package/tools/organizations/categories/assets-organizations-categories.d.ts +0 -45
- package/tools/organizations/categories/assets-organizations-categories.d.ts.map +0 -1
- package/tools/organizations/categories/assets-organizations-categories.js +0 -55
- package/tools/organizations/categories/assets-organizations-categories.js.map +0 -1
- package/tools/organizations/categories/assets-organizations-categories.mjs +0 -48
- package/tools/organizations/categories/assets-organizations-categories.mjs.map +0 -1
- package/tools/organizations/categories/list-organizations-categories.d.mts +0 -45
- package/tools/organizations/categories/list-organizations-categories.d.mts.map +0 -1
- package/tools/organizations/categories/list-organizations-categories.d.ts +0 -45
- package/tools/organizations/categories/list-organizations-categories.d.ts.map +0 -1
- package/tools/organizations/categories/list-organizations-categories.js +0 -51
- package/tools/organizations/categories/list-organizations-categories.js.map +0 -1
- package/tools/organizations/categories/list-organizations-categories.mjs +0 -44
- package/tools/organizations/categories/list-organizations-categories.mjs.map +0 -1
- package/tools/organizations/categories/prompts-organizations-categories.d.mts +0 -45
- package/tools/organizations/categories/prompts-organizations-categories.d.mts.map +0 -1
- package/tools/organizations/categories/prompts-organizations-categories.d.ts +0 -45
- package/tools/organizations/categories/prompts-organizations-categories.d.ts.map +0 -1
- package/tools/organizations/categories/prompts-organizations-categories.js +0 -55
- package/tools/organizations/categories/prompts-organizations-categories.js.map +0 -1
- package/tools/organizations/categories/prompts-organizations-categories.mjs +0 -48
- package/tools/organizations/categories/prompts-organizations-categories.mjs.map +0 -1
- package/tools/organizations/categories/tags-organizations-categories.d.mts +0 -45
- package/tools/organizations/categories/tags-organizations-categories.d.mts.map +0 -1
- package/tools/organizations/categories/tags-organizations-categories.d.ts +0 -45
- package/tools/organizations/categories/tags-organizations-categories.d.ts.map +0 -1
- package/tools/organizations/categories/tags-organizations-categories.js +0 -55
- package/tools/organizations/categories/tags-organizations-categories.js.map +0 -1
- package/tools/organizations/categories/tags-organizations-categories.mjs +0 -48
- package/tools/organizations/categories/tags-organizations-categories.mjs.map +0 -1
- package/tools/organizations/categories/topics-organizations-categories.d.mts +0 -45
- package/tools/organizations/categories/topics-organizations-categories.d.mts.map +0 -1
- package/tools/organizations/categories/topics-organizations-categories.d.ts +0 -45
- package/tools/organizations/categories/topics-organizations-categories.d.ts.map +0 -1
- package/tools/organizations/categories/topics-organizations-categories.js +0 -55
- package/tools/organizations/categories/topics-organizations-categories.js.map +0 -1
- package/tools/organizations/categories/topics-organizations-categories.mjs +0 -48
- package/tools/organizations/categories/topics-organizations-categories.mjs.map +0 -1
- package/tools/organizations/domains-organizations.d.mts +0 -45
- package/tools/organizations/domains-organizations.d.mts.map +0 -1
- package/tools/organizations/domains-organizations.d.ts +0 -45
- package/tools/organizations/domains-organizations.d.ts.map +0 -1
- package/tools/organizations/domains-organizations.js +0 -51
- package/tools/organizations/domains-organizations.js.map +0 -1
- package/tools/organizations/domains-organizations.mjs +0 -44
- package/tools/organizations/domains-organizations.mjs.map +0 -1
- package/tools/organizations/list-assets-organizations.d.mts +0 -45
- package/tools/organizations/list-assets-organizations.d.mts.map +0 -1
- package/tools/organizations/list-assets-organizations.d.ts +0 -45
- package/tools/organizations/list-assets-organizations.d.ts.map +0 -1
- package/tools/organizations/list-assets-organizations.js +0 -51
- package/tools/organizations/list-assets-organizations.js.map +0 -1
- package/tools/organizations/list-assets-organizations.mjs +0 -44
- package/tools/organizations/list-assets-organizations.mjs.map +0 -1
- package/tools/organizations/models-organizations.d.mts +0 -45
- package/tools/organizations/models-organizations.d.mts.map +0 -1
- package/tools/organizations/models-organizations.d.ts +0 -45
- package/tools/organizations/models-organizations.d.ts.map +0 -1
- package/tools/organizations/models-organizations.js +0 -51
- package/tools/organizations/models-organizations.js.map +0 -1
- package/tools/organizations/models-organizations.mjs +0 -44
- package/tools/organizations/models-organizations.mjs.map +0 -1
- package/tools/organizations/regions-organizations.d.mts +0 -45
- package/tools/organizations/regions-organizations.d.mts.map +0 -1
- package/tools/organizations/regions-organizations.d.ts +0 -45
- package/tools/organizations/regions-organizations.d.ts.map +0 -1
- package/tools/organizations/regions-organizations.js +0 -51
- package/tools/organizations/regions-organizations.js.map +0 -1
- package/tools/organizations/regions-organizations.mjs +0 -44
- package/tools/organizations/regions-organizations.mjs.map +0 -1
- package/tools/prompts/answers-prompts.d.mts +0 -45
- package/tools/prompts/answers-prompts.d.mts.map +0 -1
- package/tools/prompts/answers-prompts.d.ts +0 -45
- package/tools/prompts/answers-prompts.d.ts.map +0 -1
- package/tools/prompts/answers-prompts.js +0 -372
- package/tools/prompts/answers-prompts.js.map +0 -1
- package/tools/prompts/answers-prompts.mjs +0 -365
- package/tools/prompts/answers-prompts.mjs.map +0 -1
- package/tools/reports/citations-reports.d.mts +0 -45
- package/tools/reports/citations-reports.d.mts.map +0 -1
- package/tools/reports/citations-reports.d.ts +0 -45
- package/tools/reports/citations-reports.d.ts.map +0 -1
- package/tools/reports/citations-reports.js +0 -503
- package/tools/reports/citations-reports.js.map +0 -1
- package/tools/reports/citations-reports.mjs +0 -496
- package/tools/reports/citations-reports.mjs.map +0 -1
- package/tools/reports/sentiment-reports.d.mts +0 -45
- package/tools/reports/sentiment-reports.d.mts.map +0 -1
- package/tools/reports/sentiment-reports.d.ts +0 -45
- package/tools/reports/sentiment-reports.d.ts.map +0 -1
- package/tools/reports/sentiment-reports.js +0 -417
- package/tools/reports/sentiment-reports.js.map +0 -1
- package/tools/reports/sentiment-reports.mjs +0 -410
- package/tools/reports/sentiment-reports.mjs.map +0 -1
- package/tools/reports/visibility-reports.d.mts +0 -45
- package/tools/reports/visibility-reports.d.mts.map +0 -1
- package/tools/reports/visibility-reports.d.ts +0 -45
- package/tools/reports/visibility-reports.d.ts.map +0 -1
- package/tools/reports/visibility-reports.js +0 -363
- package/tools/reports/visibility-reports.js.map +0 -1
- package/tools/reports/visibility-reports.mjs +0 -356
- package/tools/reports/visibility-reports.mjs.map +0 -1
- package/tools/types.d.mts.map +0 -1
- package/tools/types.d.ts.map +0 -1
- package/tools/types.js.map +0 -1
- package/tools/types.mjs.map +0 -1
- package/tools.d.mts +0 -2
- package/tools.d.mts.map +0 -1
- package/tools.d.ts +0 -2
- package/tools.d.ts.map +0 -1
- package/tools.js +0 -18
- package/tools.js.map +0 -1
- package/tools.mjs +0 -2
- package/tools.mjs.map +0 -1
- /package/{tools/types.js → types.js} +0 -0
- /package/{tools/types.mjs → types.mjs} +0 -0
package/server.js
CHANGED
|
@@ -4,25 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.readEnvOrError = exports.readEnv = exports.server = exports.newMcpServer =
|
|
7
|
+
exports.readEnvOrError = exports.readEnv = exports.server = exports.newMcpServer = void 0;
|
|
8
8
|
exports.initMcpServer = initMcpServer;
|
|
9
9
|
exports.selectTools = selectTools;
|
|
10
10
|
exports.executeHandler = executeHandler;
|
|
11
11
|
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
12
|
-
const tools_1 = require("./tools.js");
|
|
13
12
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
14
13
|
const profoundai_1 = __importDefault(require("profoundai"));
|
|
15
|
-
const compat_1 = require("./compat.js");
|
|
16
|
-
const dynamic_tools_1 = require("./dynamic-tools.js");
|
|
17
14
|
const code_tool_1 = require("./code-tool.js");
|
|
18
15
|
const docs_search_tool_1 = __importDefault(require("./docs-search-tool.js"));
|
|
19
|
-
var compat_2 = require("./compat.js");
|
|
20
|
-
Object.defineProperty(exports, "ClientType", { enumerable: true, get: function () { return compat_2.ClientType; } });
|
|
21
|
-
var tools_2 = require("./tools.js");
|
|
22
|
-
Object.defineProperty(exports, "endpoints", { enumerable: true, get: function () { return tools_2.endpoints; } });
|
|
23
16
|
const newMcpServer = () => new mcp_js_1.McpServer({
|
|
24
17
|
name: 'profoundai_api',
|
|
25
|
-
version: '0.
|
|
18
|
+
version: '0.17.0',
|
|
26
19
|
}, { capabilities: { tools: {}, logging: {} } });
|
|
27
20
|
exports.newMcpServer = newMcpServer;
|
|
28
21
|
// Create server instance
|
|
@@ -33,23 +26,6 @@ exports.server = (0, exports.newMcpServer)();
|
|
|
33
26
|
*/
|
|
34
27
|
function initMcpServer(params) {
|
|
35
28
|
const server = params.server instanceof mcp_js_1.McpServer ? params.server.server : params.server;
|
|
36
|
-
const mcpOptions = params.mcpOptions ?? {};
|
|
37
|
-
let providedEndpoints = null;
|
|
38
|
-
let endpointMap = null;
|
|
39
|
-
const initTools = async (implementation) => {
|
|
40
|
-
if (implementation && (!mcpOptions.client || mcpOptions.client === 'infer')) {
|
|
41
|
-
mcpOptions.client =
|
|
42
|
-
implementation.name.toLowerCase().includes('claude') ? 'claude'
|
|
43
|
-
: implementation.name.toLowerCase().includes('cursor') ? 'cursor'
|
|
44
|
-
: undefined;
|
|
45
|
-
mcpOptions.capabilities = {
|
|
46
|
-
...(mcpOptions.client && compat_1.knownClients[mcpOptions.client]),
|
|
47
|
-
...mcpOptions.capabilities,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
providedEndpoints ?? (providedEndpoints = await selectTools(tools_1.endpoints, mcpOptions));
|
|
51
|
-
endpointMap ?? (endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint])));
|
|
52
|
-
};
|
|
53
29
|
const logAtLevel = (level) => (message, ...rest) => {
|
|
54
30
|
void server.sendLoggingMessage({
|
|
55
31
|
level,
|
|
@@ -70,24 +46,20 @@ function initMcpServer(params) {
|
|
|
70
46
|
'X-Stainless-MCP': 'true',
|
|
71
47
|
},
|
|
72
48
|
});
|
|
49
|
+
const providedTools = selectTools(params.mcpOptions);
|
|
50
|
+
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
73
51
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
74
|
-
if (providedEndpoints === null) {
|
|
75
|
-
await initTools(server.getClientVersion());
|
|
76
|
-
}
|
|
77
52
|
return {
|
|
78
|
-
tools:
|
|
53
|
+
tools: providedTools.map((mcpTool) => mcpTool.tool),
|
|
79
54
|
};
|
|
80
55
|
});
|
|
81
56
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
82
|
-
if (endpointMap === null) {
|
|
83
|
-
await initTools(server.getClientVersion());
|
|
84
|
-
}
|
|
85
57
|
const { name, arguments: args } = request.params;
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
58
|
+
const mcpTool = toolMap[name];
|
|
59
|
+
if (!mcpTool) {
|
|
88
60
|
throw new Error(`Unknown tool: ${name}`);
|
|
89
61
|
}
|
|
90
|
-
return executeHandler(
|
|
62
|
+
return executeHandler(mcpTool.handler, client, args);
|
|
91
63
|
});
|
|
92
64
|
server.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request) => {
|
|
93
65
|
const { level } = request.params;
|
|
@@ -115,42 +87,17 @@ function initMcpServer(params) {
|
|
|
115
87
|
/**
|
|
116
88
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
117
89
|
*/
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
let includedTools = filteredEndpoints.slice();
|
|
121
|
-
if (includedTools.length > 0) {
|
|
122
|
-
if (options?.includeDynamicTools) {
|
|
123
|
-
includedTools = (0, dynamic_tools_1.dynamicTools)(includedTools);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
if (options?.includeAllTools) {
|
|
128
|
-
includedTools = endpoints.slice();
|
|
129
|
-
}
|
|
130
|
-
else if (options?.includeDynamicTools) {
|
|
131
|
-
includedTools = (0, dynamic_tools_1.dynamicTools)(endpoints);
|
|
132
|
-
}
|
|
133
|
-
else if (options?.includeCodeTools) {
|
|
134
|
-
includedTools = [await (0, code_tool_1.codeTool)()];
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
includedTools = endpoints.slice();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
90
|
+
function selectTools(options) {
|
|
91
|
+
const includedTools = [(0, code_tool_1.codeTool)()];
|
|
140
92
|
if (options?.includeDocsTools ?? true) {
|
|
141
93
|
includedTools.push(docs_search_tool_1.default);
|
|
142
94
|
}
|
|
143
|
-
|
|
144
|
-
return (0, compat_1.applyCompatibilityTransformations)(includedTools, capabilities);
|
|
95
|
+
return includedTools;
|
|
145
96
|
}
|
|
146
97
|
/**
|
|
147
98
|
* Runs the provided handler with the given client and arguments.
|
|
148
99
|
*/
|
|
149
|
-
async function executeHandler(
|
|
150
|
-
const options = { ...compat_1.defaultClientCapabilities, ...compatibilityOptions };
|
|
151
|
-
if (!options.validJson && args) {
|
|
152
|
-
args = (0, compat_1.parseEmbeddedJSON)(args, tool.inputSchema);
|
|
153
|
-
}
|
|
100
|
+
async function executeHandler(handler, client, args) {
|
|
154
101
|
return await handler(client, args || {});
|
|
155
102
|
}
|
|
156
103
|
const readEnv = (env) => {
|
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","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAmCtF,sCAwEC;AAKD,kCAMC;AAKD,wCAMC;AA9HD,oEAAoE;AACpE,iEAI4C;AAE5C,4DAAkC;AAClC,8CAAuC;AACvC,6EAAgD;AAOzC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,IAAI,kBAAS,CACX;IACE,IAAI,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QAAQ,GAAG,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB"}
|
package/server.mjs
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { endpoints, query } from "./tools.mjs";
|
|
4
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
4
|
import Profound from 'profoundai';
|
|
6
|
-
import { applyCompatibilityTransformations, defaultClientCapabilities, knownClients, parseEmbeddedJSON, } from "./compat.mjs";
|
|
7
|
-
import { dynamicTools } from "./dynamic-tools.mjs";
|
|
8
5
|
import { codeTool } from "./code-tool.mjs";
|
|
9
6
|
import docsSearchTool from "./docs-search-tool.mjs";
|
|
10
|
-
export { ClientType } from "./compat.mjs";
|
|
11
|
-
export { endpoints } from "./tools.mjs";
|
|
12
7
|
export const newMcpServer = () => new McpServer({
|
|
13
8
|
name: 'profoundai_api',
|
|
14
|
-
version: '0.
|
|
9
|
+
version: '0.17.0',
|
|
15
10
|
}, { capabilities: { tools: {}, logging: {} } });
|
|
16
11
|
// Create server instance
|
|
17
12
|
export const server = newMcpServer();
|
|
@@ -21,23 +16,6 @@ export const server = newMcpServer();
|
|
|
21
16
|
*/
|
|
22
17
|
export function initMcpServer(params) {
|
|
23
18
|
const server = params.server instanceof McpServer ? params.server.server : params.server;
|
|
24
|
-
const mcpOptions = params.mcpOptions ?? {};
|
|
25
|
-
let providedEndpoints = null;
|
|
26
|
-
let endpointMap = null;
|
|
27
|
-
const initTools = async (implementation) => {
|
|
28
|
-
if (implementation && (!mcpOptions.client || mcpOptions.client === 'infer')) {
|
|
29
|
-
mcpOptions.client =
|
|
30
|
-
implementation.name.toLowerCase().includes('claude') ? 'claude'
|
|
31
|
-
: implementation.name.toLowerCase().includes('cursor') ? 'cursor'
|
|
32
|
-
: undefined;
|
|
33
|
-
mcpOptions.capabilities = {
|
|
34
|
-
...(mcpOptions.client && knownClients[mcpOptions.client]),
|
|
35
|
-
...mcpOptions.capabilities,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
providedEndpoints ?? (providedEndpoints = await selectTools(endpoints, mcpOptions));
|
|
39
|
-
endpointMap ?? (endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint])));
|
|
40
|
-
};
|
|
41
19
|
const logAtLevel = (level) => (message, ...rest) => {
|
|
42
20
|
void server.sendLoggingMessage({
|
|
43
21
|
level,
|
|
@@ -58,24 +36,20 @@ export function initMcpServer(params) {
|
|
|
58
36
|
'X-Stainless-MCP': 'true',
|
|
59
37
|
},
|
|
60
38
|
});
|
|
39
|
+
const providedTools = selectTools(params.mcpOptions);
|
|
40
|
+
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
61
41
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
62
|
-
if (providedEndpoints === null) {
|
|
63
|
-
await initTools(server.getClientVersion());
|
|
64
|
-
}
|
|
65
42
|
return {
|
|
66
|
-
tools:
|
|
43
|
+
tools: providedTools.map((mcpTool) => mcpTool.tool),
|
|
67
44
|
};
|
|
68
45
|
});
|
|
69
46
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
70
|
-
if (endpointMap === null) {
|
|
71
|
-
await initTools(server.getClientVersion());
|
|
72
|
-
}
|
|
73
47
|
const { name, arguments: args } = request.params;
|
|
74
|
-
const
|
|
75
|
-
if (!
|
|
48
|
+
const mcpTool = toolMap[name];
|
|
49
|
+
if (!mcpTool) {
|
|
76
50
|
throw new Error(`Unknown tool: ${name}`);
|
|
77
51
|
}
|
|
78
|
-
return executeHandler(
|
|
52
|
+
return executeHandler(mcpTool.handler, client, args);
|
|
79
53
|
});
|
|
80
54
|
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
81
55
|
const { level } = request.params;
|
|
@@ -103,42 +77,17 @@ export function initMcpServer(params) {
|
|
|
103
77
|
/**
|
|
104
78
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
105
79
|
*/
|
|
106
|
-
export
|
|
107
|
-
const
|
|
108
|
-
let includedTools = filteredEndpoints.slice();
|
|
109
|
-
if (includedTools.length > 0) {
|
|
110
|
-
if (options?.includeDynamicTools) {
|
|
111
|
-
includedTools = dynamicTools(includedTools);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
if (options?.includeAllTools) {
|
|
116
|
-
includedTools = endpoints.slice();
|
|
117
|
-
}
|
|
118
|
-
else if (options?.includeDynamicTools) {
|
|
119
|
-
includedTools = dynamicTools(endpoints);
|
|
120
|
-
}
|
|
121
|
-
else if (options?.includeCodeTools) {
|
|
122
|
-
includedTools = [await codeTool()];
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
includedTools = endpoints.slice();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
80
|
+
export function selectTools(options) {
|
|
81
|
+
const includedTools = [codeTool()];
|
|
128
82
|
if (options?.includeDocsTools ?? true) {
|
|
129
83
|
includedTools.push(docsSearchTool);
|
|
130
84
|
}
|
|
131
|
-
|
|
132
|
-
return applyCompatibilityTransformations(includedTools, capabilities);
|
|
85
|
+
return includedTools;
|
|
133
86
|
}
|
|
134
87
|
/**
|
|
135
88
|
* Runs the provided handler with the given client and arguments.
|
|
136
89
|
*/
|
|
137
|
-
export async function executeHandler(
|
|
138
|
-
const options = { ...defaultClientCapabilities, ...compatibilityOptions };
|
|
139
|
-
if (!options.validJson && args) {
|
|
140
|
-
args = parseEmbeddedJSON(args, tool.inputSchema);
|
|
141
|
-
}
|
|
90
|
+
export async function executeHandler(handler, client, args) {
|
|
142
91
|
return await handler(client, args || {});
|
|
143
92
|
}
|
|
144
93
|
export const readEnv = (env) => {
|
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,
|
|
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;AAOrB,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,IAAI,SAAS,CACX;IACE,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,QAAQ;CAClB,EACD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC7C,CAAC;AAEJ,yBAAyB;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAI7B;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,YAAY,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAEzF,MAAM,UAAU,GACd,CAAC,KAA6C,EAAE,EAAE,CAClD,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QACtC,KAAK,MAAM,CAAC,kBAAkB,CAAC;YAC7B,KAAK;YACL,IAAI,EAAE,EAAE,OAA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c,CAClC,OAAwB,EACxB,MAAgB,EAChB,IAAyC;IAEzC,OAAO,MAAM,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;SAAM,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3D,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO;AACT,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;IACpD,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
package/src/code-tool-types.ts
CHANGED
|
@@ -3,16 +3,13 @@
|
|
|
3
3
|
import { ClientOptions } from 'profoundai';
|
|
4
4
|
|
|
5
5
|
export type WorkerInput = {
|
|
6
|
-
|
|
6
|
+
project_name: string;
|
|
7
7
|
code: string;
|
|
8
|
+
client_opts: ClientOptions;
|
|
8
9
|
};
|
|
9
|
-
export type
|
|
10
|
+
export type WorkerOutput = {
|
|
11
|
+
is_error: boolean;
|
|
10
12
|
result: unknown | null;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export type WorkerError = {
|
|
15
|
-
message: string | undefined;
|
|
16
|
-
logLines: string[];
|
|
17
|
-
errLines: string[];
|
|
13
|
+
log_lines: string[];
|
|
14
|
+
err_lines: string[];
|
|
18
15
|
};
|
package/src/code-tool.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import Profound, { ClientOptions } from 'profoundai';
|
|
6
|
-
import { ContentBlock, Endpoint, Metadata, ToolCallResult } from './tools/types';
|
|
7
|
-
|
|
3
|
+
import { McpTool, Metadata, ToolCallResult, asErrorResult, asTextContentResult } from './types';
|
|
8
4
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { readEnv, readEnvOrError } from './server';
|
|
6
|
+
import { WorkerInput, WorkerOutput } from './code-tool-types';
|
|
7
|
+
|
|
8
|
+
const prompt = `Runs JavaScript code to interact with the Profound API.
|
|
9
|
+
|
|
10
|
+
You are a skilled programmer writing code to interface with the service.
|
|
11
|
+
Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
|
|
12
|
+
For example:
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
\`\`\`
|
|
15
|
+
async function run(client) {
|
|
16
|
+
const orgItems = await client.organizations.categories.list();
|
|
17
|
+
}
|
|
18
|
+
\`\`\`
|
|
19
|
+
|
|
20
|
+
You will be returned anything that your function returns, plus the results of any console.log statements.
|
|
21
|
+
Do not add try-catch blocks for single API calls. The tool will handle errors for you.
|
|
22
|
+
Do not add comments unless necessary for generating better code.
|
|
23
|
+
Code will run in a container, and cannot interact with the network outside of the given SDK client.
|
|
24
|
+
Variables will not persist between calls, so make sure to return or log any data you might need later.`;
|
|
11
25
|
|
|
12
26
|
/**
|
|
13
27
|
* A tool that runs code against a copy of the SDK.
|
|
@@ -18,150 +32,58 @@ import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
|
|
|
18
32
|
*
|
|
19
33
|
* @param endpoints - The endpoints to include in the list.
|
|
20
34
|
*/
|
|
21
|
-
export
|
|
35
|
+
export function codeTool(): McpTool {
|
|
22
36
|
const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
|
|
23
37
|
const tool: Tool = {
|
|
24
38
|
name: 'execute',
|
|
25
|
-
description:
|
|
26
|
-
'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
|
|
39
|
+
description: prompt,
|
|
27
40
|
inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
|
|
28
41
|
};
|
|
42
|
+
const handler = async (_: unknown, args: any): Promise<ToolCallResult> => {
|
|
43
|
+
const code = args.code as string;
|
|
29
44
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const baseURLHostname = new URL(client.baseURL).hostname;
|
|
36
|
-
const { code } = args as { code: string };
|
|
45
|
+
// this is not required, but passing a Stainless API key for the matching project_name
|
|
46
|
+
// will allow you to run code-mode queries against non-published versions of your SDK.
|
|
47
|
+
const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
|
|
48
|
+
const codeModeEndpoint =
|
|
49
|
+
readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
|
|
37
50
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
printOutput: true,
|
|
48
|
-
spawnOptions: {
|
|
49
|
-
cwd: dirname(workerPath),
|
|
51
|
+
const res = await fetch(codeModeEndpoint, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: {
|
|
54
|
+
...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
client_envs: JSON.stringify({
|
|
57
|
+
PROFOUND_API_KEY: readEnvOrError('PROFOUND_API_KEY'),
|
|
58
|
+
PROFOUND_BASE_URL: readEnv('PROFOUND_BASE_URL'),
|
|
59
|
+
}),
|
|
50
60
|
},
|
|
61
|
+
body: JSON.stringify({
|
|
62
|
+
project_name: 'profound',
|
|
63
|
+
code,
|
|
64
|
+
client_opts: {},
|
|
65
|
+
} satisfies WorkerInput),
|
|
51
66
|
});
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
baseURL: client.baseURL,
|
|
61
|
-
apiKey: client.apiKey,
|
|
62
|
-
defaultHeaders: {
|
|
63
|
-
'X-Stainless-MCP': 'true',
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const req = worker.request(
|
|
68
|
-
'http://localhost',
|
|
69
|
-
{
|
|
70
|
-
headers: {
|
|
71
|
-
'content-type': 'application/json',
|
|
72
|
-
},
|
|
73
|
-
method: 'POST',
|
|
74
|
-
},
|
|
75
|
-
(resp) => {
|
|
76
|
-
const body: Uint8Array[] = [];
|
|
77
|
-
resp.on('error', (err) => {
|
|
78
|
-
reject(err);
|
|
79
|
-
});
|
|
80
|
-
resp.on('data', (chunk) => {
|
|
81
|
-
body.push(chunk);
|
|
82
|
-
});
|
|
83
|
-
resp.on('end', () => {
|
|
84
|
-
resolve(
|
|
85
|
-
new Response(Buffer.concat(body).toString(), {
|
|
86
|
-
status: resp.statusCode ?? 200,
|
|
87
|
-
headers: resp.headers as any,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const body = JSON.stringify({
|
|
95
|
-
opts,
|
|
96
|
-
code,
|
|
97
|
-
} satisfies WorkerInput);
|
|
98
|
-
|
|
99
|
-
req.write(body, (err) => {
|
|
100
|
-
if (err != null) {
|
|
101
|
-
reject(err);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
req.end();
|
|
106
|
-
});
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`${res.status}: ${
|
|
71
|
+
res.statusText
|
|
72
|
+
} error when trying to contact Code Tool server. Details: ${await res.text()}`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
107
75
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const logOutput: ContentBlock | null =
|
|
118
|
-
logLines.length === 0 ?
|
|
119
|
-
null
|
|
120
|
-
: {
|
|
121
|
-
type: 'text',
|
|
122
|
-
text: logLines.join('\n'),
|
|
123
|
-
};
|
|
124
|
-
const errOutput: ContentBlock | null =
|
|
125
|
-
errLines.length === 0 ?
|
|
126
|
-
null
|
|
127
|
-
: {
|
|
128
|
-
type: 'text',
|
|
129
|
-
text: 'Error output:\n' + errLines.join('\n'),
|
|
130
|
-
};
|
|
131
|
-
return {
|
|
132
|
-
content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
|
|
133
|
-
};
|
|
134
|
-
} else {
|
|
135
|
-
const { message, logLines, errLines } = (await resp.json()) as WorkerError;
|
|
136
|
-
const messageOutput: ContentBlock | null =
|
|
137
|
-
message == null ? null : (
|
|
138
|
-
{
|
|
139
|
-
type: 'text',
|
|
140
|
-
text: message,
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
|
-
const logOutput: ContentBlock | null =
|
|
144
|
-
logLines.length === 0 ?
|
|
145
|
-
null
|
|
146
|
-
: {
|
|
147
|
-
type: 'text',
|
|
148
|
-
text: logLines.join('\n'),
|
|
149
|
-
};
|
|
150
|
-
const errOutput: ContentBlock | null =
|
|
151
|
-
errLines.length === 0 ?
|
|
152
|
-
null
|
|
153
|
-
: {
|
|
154
|
-
type: 'text',
|
|
155
|
-
text: 'Error output:\n' + errLines.join('\n'),
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
|
|
159
|
-
isError: true,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
} finally {
|
|
163
|
-
worker.terminate();
|
|
76
|
+
const { is_error, result, log_lines, err_lines } = (await res.json()) as WorkerOutput;
|
|
77
|
+
const hasLogs = log_lines.length > 0 || err_lines.length > 0;
|
|
78
|
+
const output = {
|
|
79
|
+
result,
|
|
80
|
+
...(log_lines.length > 0 && { log_lines }),
|
|
81
|
+
...(err_lines.length > 0 && { err_lines }),
|
|
82
|
+
};
|
|
83
|
+
if (is_error) {
|
|
84
|
+
return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
|
|
164
85
|
}
|
|
86
|
+
return asTextContentResult(output);
|
|
165
87
|
};
|
|
166
88
|
|
|
167
89
|
return { metadata, tool, handler };
|
package/src/docs-search-tool.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { Metadata, asTextContentResult } from './
|
|
3
|
+
import { Metadata, asTextContentResult } from './types';
|
|
4
4
|
|
|
5
5
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
|
|
@@ -46,6 +46,13 @@ export const handler = async (_: unknown, args: Record<string, unknown> | undefi
|
|
|
46
46
|
const body = args as any;
|
|
47
47
|
const query = new URLSearchParams(body).toString();
|
|
48
48
|
const result = await fetch(`${docsSearchURL}?${query}`);
|
|
49
|
+
|
|
50
|
+
if (!result.ok) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`${result.status}: ${result.statusText} when using doc search tool. Details: ${await result.text()}`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
return asTextContentResult(await result.json());
|
|
50
57
|
};
|
|
51
58
|
|
package/src/http.ts
CHANGED
|
@@ -4,38 +4,21 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
|
4
4
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
5
|
|
|
6
6
|
import express from 'express';
|
|
7
|
-
import {
|
|
8
|
-
import { McpOptions, parseQueryOptions } from './options';
|
|
7
|
+
import { McpOptions } from './options';
|
|
9
8
|
import { ClientOptions, initMcpServer, newMcpServer } from './server';
|
|
10
9
|
import { parseAuthHeaders } from './headers';
|
|
11
10
|
|
|
12
11
|
const newServer = ({
|
|
13
12
|
clientOptions,
|
|
14
|
-
mcpOptions: defaultMcpOptions,
|
|
15
13
|
req,
|
|
16
14
|
res,
|
|
17
15
|
}: {
|
|
18
16
|
clientOptions: ClientOptions;
|
|
19
|
-
mcpOptions: McpOptions;
|
|
20
17
|
req: express.Request;
|
|
21
18
|
res: express.Response;
|
|
22
19
|
}): McpServer | null => {
|
|
23
20
|
const server = newMcpServer();
|
|
24
21
|
|
|
25
|
-
let mcpOptions: McpOptions;
|
|
26
|
-
try {
|
|
27
|
-
mcpOptions = parseQueryOptions(defaultMcpOptions, req.query);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
res.status(400).json({
|
|
30
|
-
jsonrpc: '2.0',
|
|
31
|
-
error: {
|
|
32
|
-
code: -32000,
|
|
33
|
-
message: `Invalid request: ${fromError(error)}`,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
22
|
try {
|
|
40
23
|
const authOptions = parseAuthHeaders(req);
|
|
41
24
|
initMcpServer({
|
|
@@ -44,7 +27,6 @@ const newServer = ({
|
|
|
44
27
|
...clientOptions,
|
|
45
28
|
...authOptions,
|
|
46
29
|
},
|
|
47
|
-
mcpOptions,
|
|
48
30
|
});
|
|
49
31
|
} catch (error) {
|
|
50
32
|
res.status(401).json({
|