conductor-node-mcp 12.42.0 → 12.43.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/src/code-tool.ts CHANGED
@@ -1,14 +1,9 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import path from 'node:path';
4
- import url from 'node:url';
5
- import Conductor, { ClientOptions } from 'conductor-node';
6
- import { ContentBlock, Endpoint, Metadata, ToolCallResult } from './tools/types';
7
-
3
+ import { Metadata, ToolCallResult, asTextContentResult } from './tools/types';
8
4
  import { Tool } from '@modelcontextprotocol/sdk/types.js';
9
-
10
- import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
11
-
5
+ import { readEnv } from './server';
6
+ import { WorkerSuccess } from './code-tool-types';
12
7
  /**
13
8
  * A tool that runs code against a copy of the SDK.
14
9
  *
@@ -18,156 +13,45 @@ import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
18
13
  *
19
14
  * @param endpoints - The endpoints to include in the list.
20
15
  */
21
- export async function codeTool(): Promise<Endpoint> {
16
+ export async function codeTool() {
22
17
  const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
23
18
  const tool: Tool = {
24
19
  name: 'execute',
25
20
  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 "conductor", and it will be run.\nWrite code within this template:\n\n```\nasync function run(conductor) {\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.',
21
+ '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 SDK 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.',
27
22
  inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
28
23
  };
29
-
30
- // Import dynamically to avoid failing at import time in cases where the environment is not well-supported.
31
- const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker');
32
- const { workerPath } = await import('./code-tool-paths.cjs');
33
-
34
- const handler = async (conductor: Conductor, args: unknown): Promise<ToolCallResult> => {
35
- const baseURLHostname = new URL(conductor.baseURL).hostname;
36
- const { code } = args as { code: string };
37
-
38
- const allowRead = [
39
- 'code-tool-worker.mjs',
40
- `${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
41
- path.resolve(path.dirname(workerPath), '..'),
42
- ].join(',');
43
-
44
- const worker = await newDenoHTTPWorker(url.pathToFileURL(workerPath), {
45
- runFlags: [
46
- `--node-modules-dir=manual`,
47
- `--allow-read=${allowRead}`,
48
- `--allow-net=${baseURLHostname}`,
49
- // Allow environment variables because instantiating the client will try to read from them,
50
- // even though they are not set.
51
- '--allow-env',
52
- ],
53
- printOutput: true,
54
- spawnOptions: {
55
- cwd: path.dirname(workerPath),
24
+ const handler = async (_: unknown, args: any): Promise<ToolCallResult> => {
25
+ const code = args.code as string;
26
+
27
+ // this is not required, but passing a Stainless API key for the matching project_name
28
+ // will allow you to run code-mode queries against non-published versions of your SDK.
29
+ const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
30
+ const codeModeEndpoint =
31
+ readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
32
+
33
+ const res = await fetch(codeModeEndpoint, {
34
+ method: 'POST',
35
+ headers: {
36
+ ...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
37
+ 'Content-Type': 'application/json',
38
+ client_envs: JSON.stringify({ CONDUCTOR_SECRET_KEY: readEnv('CONDUCTOR_SECRET_KEY') }),
56
39
  },
40
+ body: JSON.stringify({
41
+ project_name: 'conductor',
42
+ code,
43
+ }),
57
44
  });
58
45
 
59
- try {
60
- const resp = await new Promise<Response>((resolve, reject) => {
61
- worker.addEventListener('exit', (exitCode) => {
62
- reject(new Error(`Worker exited with code ${exitCode}`));
63
- });
64
-
65
- const opts: ClientOptions = {
66
- baseURL: conductor.baseURL,
67
- apiKey: conductor.apiKey,
68
- defaultHeaders: {
69
- 'X-Stainless-MCP': 'true',
70
- },
71
- };
72
-
73
- const req = worker.request(
74
- 'http://localhost',
75
- {
76
- headers: {
77
- 'content-type': 'application/json',
78
- },
79
- method: 'POST',
80
- },
81
- (resp) => {
82
- const body: Uint8Array[] = [];
83
- resp.on('error', (err) => {
84
- reject(err);
85
- });
86
- resp.on('data', (chunk) => {
87
- body.push(chunk);
88
- });
89
- resp.on('end', () => {
90
- resolve(
91
- new Response(Buffer.concat(body).toString(), {
92
- status: resp.statusCode ?? 200,
93
- headers: resp.headers as any,
94
- }),
95
- );
96
- });
97
- },
98
- );
99
-
100
- const body = JSON.stringify({
101
- opts,
102
- code,
103
- } satisfies WorkerInput);
104
-
105
- req.write(body, (err) => {
106
- if (err != null) {
107
- reject(err);
108
- }
109
- });
110
-
111
- req.end();
112
- });
113
-
114
- if (resp.status === 200) {
115
- const { result, logLines, errLines } = (await resp.json()) as WorkerSuccess;
116
- const returnOutput: ContentBlock | null =
117
- result == null ? null : (
118
- {
119
- type: 'text',
120
- text: typeof result === 'string' ? result : JSON.stringify(result),
121
- }
122
- );
123
- const logOutput: ContentBlock | null =
124
- logLines.length === 0 ?
125
- null
126
- : {
127
- type: 'text',
128
- text: logLines.join('\n'),
129
- };
130
- const errOutput: ContentBlock | null =
131
- errLines.length === 0 ?
132
- null
133
- : {
134
- type: 'text',
135
- text: 'Error output:\n' + errLines.join('\n'),
136
- };
137
- return {
138
- content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
139
- };
140
- } else {
141
- const { message, logLines, errLines } = (await resp.json()) as WorkerError;
142
- const messageOutput: ContentBlock | null =
143
- message == null ? null : (
144
- {
145
- type: 'text',
146
- text: message,
147
- }
148
- );
149
- const logOutput: ContentBlock | null =
150
- logLines.length === 0 ?
151
- null
152
- : {
153
- type: 'text',
154
- text: logLines.join('\n'),
155
- };
156
- const errOutput: ContentBlock | null =
157
- errLines.length === 0 ?
158
- null
159
- : {
160
- type: 'text',
161
- text: 'Error output:\n' + errLines.join('\n'),
162
- };
163
- return {
164
- content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
165
- isError: true,
166
- };
167
- }
168
- } finally {
169
- worker.terminate();
46
+ if (!res.ok) {
47
+ throw new Error(
48
+ `${res.status}: ${
49
+ res.statusText
50
+ } error when trying to contact Code Tool server. Details: ${await res.text()}`,
51
+ );
170
52
  }
53
+
54
+ return asTextContentResult((await res.json()) as WorkerSuccess);
171
55
  };
172
56
 
173
57
  return { metadata, tool, handler };
@@ -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/server.ts CHANGED
@@ -33,7 +33,7 @@ export const newMcpServer = () =>
33
33
  new McpServer(
34
34
  {
35
35
  name: 'conductor_node_api',
36
- version: '12.42.0',
36
+ version: '12.43.0',
37
37
  },
38
38
  { capabilities: { tools: {}, logging: {} } },
39
39
  );
@@ -1,6 +0,0 @@
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.workerPath = void 0;
5
- exports.workerPath = require.resolve('./code-tool-worker.mjs');
6
- //# sourceMappingURL=code-tool-paths.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-tool-paths.cjs","sourceRoot":"","sources":["src/code-tool-paths.cts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEzE,QAAA,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const workerPath: string;
2
- //# sourceMappingURL=code-tool-paths.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-tool-paths.d.cts","sourceRoot":"","sources":["src/code-tool-paths.cts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4C,CAAC"}
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- fetch: (req: Request) => Promise<Response>;
3
- };
4
- export default _default;
5
- //# sourceMappingURL=code-tool-worker.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-tool-worker.d.mts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBAqa0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAkErD,wBAAyB"}
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- fetch: (req: Request) => Promise<Response>;
3
- };
4
- export default _default;
5
- //# sourceMappingURL=code-tool-worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-tool-worker.d.ts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBAqa0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAkErD,wBAAyB"}