11// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22
3+ import fs from 'node:fs' ;
4+ import path from 'node:path' ;
5+ import url from 'node:url' ;
6+ import { newDenoHTTPWorker } from '@valtown/deno-http-worker' ;
7+ import { workerPath } from './code-tool-paths.cjs' ;
38import {
49 ContentBlock ,
510 McpRequestContext ,
@@ -144,23 +149,19 @@ const remoteStainlessHandler = async ({
144149
145150 const codeModeEndpoint = readEnv ( 'CODE_MODE_ENDPOINT_URL' ) ?? 'https://api.stainless.com/api/ai/code-tool' ;
146151
147- const localClientEnvs = {
148- RUNLOOP_API_KEY : requireValue (
149- readEnv ( 'RUNLOOP_API_KEY' ) ?? client . bearerToken ,
150- 'set RUNLOOP_API_KEY environment variable or provide bearerToken client option' ,
151- ) ,
152- RUNLOOP_BASE_URL : readEnv ( 'RUNLOOP_BASE_URL' ) ?? client . baseURL ?? undefined ,
153- } ;
154- // Merge any upstream client envs from the request header, with upstream values taking precedence.
155- const mergedClientEnvs = { ...localClientEnvs , ...reqContext . upstreamClientEnvs } ;
156-
157152 // Setting a Stainless API key authenticates requests to the code tool endpoint.
158153 const res = await fetch ( codeModeEndpoint , {
159154 method : 'POST' ,
160155 headers : {
161156 ...( reqContext . stainlessApiKey && { Authorization : reqContext . stainlessApiKey } ) ,
162157 'Content-Type' : 'application/json' ,
163- 'x-stainless-mcp-client-envs' : JSON . stringify ( mergedClientEnvs ) ,
158+ 'x-stainless-mcp-client-envs' : JSON . stringify ( {
159+ RUNLOOP_API_KEY : requireValue (
160+ readEnv ( 'RUNLOOP_API_KEY' ) ?? client . bearerToken ,
161+ 'set RUNLOOP_API_KEY environment variable or provide bearerToken client option' ,
162+ ) ,
163+ RUNLOOP_BASE_URL : readEnv ( 'RUNLOOP_BASE_URL' ) ?? client . baseURL ?? undefined ,
164+ } ) ,
164165 } ,
165166 body : JSON . stringify ( {
166167 project_name : 'runloop' ,
@@ -203,13 +204,6 @@ const localDenoHandler = async ({
203204 reqContext : McpRequestContext ;
204205 args : unknown ;
205206} ) : Promise < ToolCallResult > => {
206- const fs = await import ( 'node:fs' ) ;
207- const path = await import ( 'node:path' ) ;
208- const url = await import ( 'node:url' ) ;
209- const { newDenoHTTPWorker } = await import ( '@valtown/deno-http-worker' ) ;
210- const { getWorkerPath } = await import ( './code-tool-paths.cjs' ) ;
211- const workerPath = getWorkerPath ( ) ;
212-
213207 const client = reqContext . client ;
214208 const baseURLHostname = new URL ( client . baseURL ) . hostname ;
215209 const { code } = args as { code : string } ;
@@ -271,9 +265,6 @@ const localDenoHandler = async ({
271265 printOutput : true ,
272266 spawnOptions : {
273267 cwd : path . dirname ( workerPath ) ,
274- // Merge any upstream client envs into the Deno subprocess environment,
275- // with the upstream env vars taking precedence.
276- env : { ...process . env , ...reqContext . upstreamClientEnvs } ,
277268 } ,
278269 } ) ;
279270
@@ -283,17 +274,13 @@ const localDenoHandler = async ({
283274 reject ( new Error ( `Worker exited with code ${ exitCode } ` ) ) ;
284275 } ) ;
285276
286- // Strip null/undefined values so that the worker SDK client can fall back to
287- // reading from environment variables (including any upstreamClientEnvs).
288- const opts : ClientOptions = Object . fromEntries (
289- Object . entries ( {
290- baseURL : client . baseURL ,
291- bearerToken : client . bearerToken ,
292- defaultHeaders : {
293- 'X-Stainless-MCP' : 'true' ,
294- } ,
295- } ) . filter ( ( [ _ , v ] ) => v != null ) ,
296- ) as ClientOptions ;
277+ const opts : ClientOptions = {
278+ baseURL : client . baseURL ,
279+ bearerToken : client . bearerToken ,
280+ defaultHeaders : {
281+ 'X-Stainless-MCP' : 'true' ,
282+ } ,
283+ } ;
297284
298285 const req = worker . request (
299286 'http://localhost' ,
0 commit comments