FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
c15r
c15rChat
Public
Like
Chat
Home
Code
18
backend
1
frontend
6
shared
2
test
4
AFFORDANCE-COMPONENT-GUIDE.md
AFFORDANCE-FRAMEWORK.md
AFFORDANCE-IMPLEMENTATION-SUMMARY.md
COMMAND-PALETTE-REVIEW.md
DEPENDENCY-INJECTION-REVIEW.md
IMPLEMENTATION-SUMMARY-AFFORDANCES.md
IMPLEMENTATION-SUMMARY.md
NextSteps-Examples.md
NextSteps-README.md
README.md
ResourceViewer-README.md
TESTING.md
package.json
H
test-runner.ts
Branches
1
Pull requests
Remixes
1
History
Environment variables
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.
Sign up now
Code
/
DEPENDENCY-INJECTION-REVIEW.md
Code
/
DEPENDENCY-INJECTION-REVIEW.md
Search
6/28/2025
Viewing readonly version of main branch: v1192
View latest version
DEPENDENCY-INJECTION-REVIEW.md

MCP Client Pool Dependency Injection Review

Summary

Reviewed and updated clientTools.ts and affordanceManager.ts to ensure that mcpClientPool dependency is passed directly instead of relying on global variables.

Changes Made

1. clientTools.ts

Removed:

  • Global window interface declaration for mcpClientPool
  • Optional mcpClientPool parameters in key functions

Updated:

  • getAllAvailableTools(): Made mcpClientPool parameter required
  • getAllToolHandlers(): Made mcpClientPool parameter required
  • executeTool(): Made mcpClientPool parameter required
  • jsExecHandler: Added proper null check for mcpClientPool before using
  • getAffordanceManager(): Now requires mcpClientPool parameter and creates instance with it
  • All affordance tool handlers: Added proper error handling when mcpClientPool is missing

2. affordanceManager.ts

Updated:

  • Constructor: Added proper TypeScript typing for mcpClientPool parameter
  • Added mcpClientPool as a private class property with proper typing
  • registerAffordance(): Uses passed mcpClientPool or falls back to instance pool
  • loadAndMountComponent(): Made mcpClientPool parameter required
  • Removed global instance export (commented out with explanation)

3. useAnthropicStream.tsx

Updated:

  • buildBody(): Made clientPool parameter required
  • executeToolCall(): Made clientPool parameter required
  • useAnthropicStream(): Made clientPool parameter required
  • All internal calls properly pass the clientPool parameter

Benefits

  1. No Global Dependencies: Eliminates reliance on global variables
  2. Explicit Dependencies: All dependencies are explicitly passed through function parameters
  3. Better Testability: Functions can be tested in isolation with mock dependencies
  4. Type Safety: Proper TypeScript typing ensures compile-time error detection
  5. Clearer API: Function signatures clearly indicate required dependencies

Verification

  • 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

Usage Pattern

// 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.

Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
ยฉ 2025 Val Town, Inc.