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: v1131View 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
mcpClientPoolparameters in key functions
Updated:
getAllAvailableTools(): MademcpClientPoolparameter requiredgetAllToolHandlers(): MademcpClientPoolparameter requiredexecuteTool(): MademcpClientPoolparameter requiredjsExecHandler: Added proper null check formcpClientPoolbefore usinggetAffordanceManager(): Now requiresmcpClientPoolparameter and creates instance with it- All affordance tool handlers: Added proper error handling when
mcpClientPoolis missing
Updated:
- Constructor: Added proper TypeScript typing for
mcpClientPoolparameter - Added
mcpClientPoolas a private class property with proper typing registerAffordance(): Uses passedmcpClientPoolor falls back to instance poolloadAndMountComponent(): MademcpClientPoolparameter required- Removed global instance export (commented out with explanation)
Updated:
buildBody(): MadeclientPoolparameter requiredexecuteToolCall(): MadeclientPoolparameter requireduseAnthropicStream(): MadeclientPoolparameter required- All internal calls properly pass the
clientPoolparameter
- 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
mcpClientPoolnow 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.