Chat
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data โ all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v1192View latest version
Reviewed and updated clientTools.ts
and affordanceManager.ts
to ensure that mcpClientPool
dependency is passed directly instead of relying on global variables.
Removed:
- Global window interface declaration for
mcpClientPool
- Optional
mcpClientPool
parameters in key functions
Updated:
getAllAvailableTools()
: MademcpClientPool
parameter requiredgetAllToolHandlers()
: MademcpClientPool
parameter requiredexecuteTool()
: MademcpClientPool
parameter requiredjsExecHandler
: Added proper null check formcpClientPool
before usinggetAffordanceManager()
: Now requiresmcpClientPool
parameter and creates instance with it- All affordance tool handlers: Added proper error handling when
mcpClientPool
is missing
Updated:
- Constructor: Added proper TypeScript typing for
mcpClientPool
parameter - Added
mcpClientPool
as a private class property with proper typing registerAffordance()
: Uses passedmcpClientPool
or falls back to instance poolloadAndMountComponent()
: MademcpClientPool
parameter required- Removed global instance export (commented out with explanation)
Updated:
buildBody()
: MadeclientPool
parameter requiredexecuteToolCall()
: MadeclientPool
parameter requireduseAnthropicStream()
: MadeclientPool
parameter required- All internal calls properly pass the
clientPool
parameter
- No Global Dependencies: Eliminates reliance on global variables
- Explicit Dependencies: All dependencies are explicitly passed through function parameters
- Better Testability: Functions can be tested in isolation with mock dependencies
- Type Safety: Proper TypeScript typing ensures compile-time error detection
- Clearer API: Function signatures clearly indicate required dependencies
- All functions that need
mcpClientPool
now require it as a parameter - No global variable access remains in the codebase
- Proper error handling when required dependencies are missing
- Type safety maintained throughout the dependency chain
// Before (using globals)
const tools = await getAllAvailableTools(); // Used window.mcpClientPool
// After (explicit dependency injection)
const tools = await getAllAvailableTools(mcpClientPool); // Explicit parameter
The codebase now follows proper dependency injection patterns with no reliance on global state.