bstracts client-specific quirks while preserving the underlying protocol requirements.
Architecture Decisions
- Transport Selection:
streamable-http is chosen over stdio or sse because it provides bidirectional capability discovery, supports header-based authentication, and maintains compatibility across desktop and IDE-based MCP clients.
- Credential Isolation: API keys are never hardcoded. They are injected via environment variables and validated before config generation to prevent runtime failures.
- Tool Tier Mapping: Free, keyed, and paid tools are categorized explicitly. This enables runtime routing logic that prevents accidental micro-transaction spend during development.
- Client Agnosticism: The configuration generator outputs a structure compatible with all major MCP hosts. Client-specific file paths are handled by the deployment environment, not the codebase.
Implementation
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
interface McpEndpointConfig {
url: string;
transport: 'streamable-http';
headers?: Record<string, string>;
}
interface CapabilityTier {
alwaysFree: string[];
keyedFree: string[];
microTransaction: Record<string, number>;
}
const TOOL_TIERS: CapabilityTier = {
alwaysFree: [
'web_search', 'price_feed', 'hive_read',
'tx_simulate', 'agent_reputation', 'x402_parse'
],
keyedFree: [
'llm_routing', 'hive_write', 'data_retrieval'
],
microTransaction: {
agent_see: 0.03,
agent_act: 0.05,
tx_broadcast: 0.05,
email_send: 0.05,
code_sandbox: 0.05,
swarm_broadcast: 0.05,
genesis_forge: 1.00
}
};
class McpConfigBuilder {
private readonly endpointUrl: string;
private readonly apiKey?: string;
constructor(env: NodeJS.ProcessEnv) {
this.endpointUrl = 'https://x711.io/mcp';
this.apiKey = env.X711_API_KEY;
}
public generateStandardConfig(): Record<string, McpEndpointConfig> {
const base: McpEndpointConfig = {
url: this.endpointUrl,
transport: 'streamable-http'
};
if (this.apiKey) {
base.headers = { 'X-API-Key': this.apiKey };
}
return { x711: base };
}
public generateZeroConfigVariant(): Record<string, McpEndpointConfig> {
return {
'x711-fm': {
url: 'https://x711.io/hivecast/mcp',
transport: 'streamable-http'
}
};
}
public validateToolAccess(toolName: string): { allowed: boolean; cost: number } {
if (TOOL_TIERS.alwaysFree.includes(toolName)) {
return { allowed: true, cost: 0 };
}
if (TOOL_TIERS.keyedFree.includes(toolName)) {
const hasKey = !!this.apiKey;
return { allowed: hasKey, cost: hasKey ? 0 : -1 };
}
const price = TOOL_TIERS.microTransaction[toolName];
if (price !== undefined) {
return { allowed: !!this.apiKey, cost: this.apiKey ? price : -1 };
}
return { allowed: false, cost: 0 };
}
public persistToDisk(outputPath: string, variant: 'standard' | 'hivecast' = 'standard'): void {
const config = variant === 'standard'
? this.generateStandardConfig()
: this.generateZeroConfigVariant();
const payload = { mcpServers: config };
writeFileSync(outputPath, JSON.stringify(payload, null, 2));
}
}
// Usage example
const builder = new McpConfigBuilder(process.env);
builder.persistToDisk(join(process.cwd(), '.mcp-runtime.json'), 'standard');
const accessCheck = builder.validateToolAccess('agent_see');
if (!accessCheck.allowed) {
console.warn('Micro-transaction tool requires authenticated endpoint.');
}
Rationale Behind Design Choices
- Explicit Tier Mapping: Hardcoding tool categories prevents runtime surprises. Agents can query
validateToolAccess before invoking expensive capabilities, enabling budget guards and dry-run modes.
- Environment-Driven Auth: Separating key injection from configuration generation ensures that local development, CI pipelines, and production deployments use identical logic with different credential sources.
- Variant Isolation: The zero-config variant (
hivecast) is deliberately separated. Mixing endpoints in a single configuration block causes client routing conflicts. Keeping them distinct allows teams to swap capabilities without rewriting agent prompts.
- File Persistence Abstraction: The
persistToDisk method decouples config generation from client-specific paths. Deployment scripts can route the output to ~/.windsurf/mcp.json, .cursor/mcp.json, or VS Code settings without modifying the core logic.
Pitfall Guide
1. Plaintext Credential Storage
Explanation: Embedding API keys directly in configuration files or version control exposes micro-transaction endpoints to unauthorized usage. Since paid tools charge per invocation, leaked keys can trigger unexpected billing.
Fix: Always inject credentials via environment variables or secret managers. Use the builder pattern above to validate key presence before generating configs. Rotate keys immediately if repository history is compromised.
2. Ignoring Free Tier Throttling
Explanation: The unauthenticated tier allows exactly 10 calls per day. Agents that retry failed requests or poll capabilities aggressively will exhaust this limit within minutes, causing silent failures.
Fix: Implement exponential backoff with jitter. Cache responses for idempotent tools like web_search and price_feed. Monitor daily call counts and switch to the keyed tier before hitting the ceiling.
Explanation: Tools like agent_act (browser automation) and tx_broadcast (transaction relay) execute asynchronously. Treating them as synchronous blocks the agent loop and causes timeout cascades.
Fix: Design agent orchestration layers to handle pending states. Use polling intervals or webhook callbacks for long-running capabilities. Never block the main execution thread waiting for micro-transaction confirmations.
4. Endpoint Confusion (Standard vs HiveCast)
Explanation: The standard endpoint and HiveCast variant share the same transport protocol but expose completely different tool sets. Mixing them in a single configuration block causes client routing errors and capability mismatches.
Fix: Maintain separate configuration profiles for each variant. Use environment flags to toggle between them during deployment. Validate tool availability against the active endpoint before agent initialization.
5. Unbounded Micro-Transaction Spend
Explanation: Paid tools charge in micro-USDC per invocation. Without spend limits, a misconfigured agent loop can trigger hundreds of agent_see or code_sandbox calls, accumulating costs rapidly.
Fix: Implement client-side spend caps. Track cumulative usage per session and pause execution when thresholds are reached. Use the validateToolAccess method to enforce budget guards before tool invocation.
6. Transport Fallback Neglect
Explanation: Relying exclusively on streamable-http without fallback mechanisms leaves agents vulnerable to network partitions or endpoint degradation.
Fix: Configure retry logic with circuit breakers. Log transport failures separately from tool errors. Consider implementing a local proxy that caches capability schemas and queues requests during outages.
Explanation: Developers often reach for paid capabilities like agent_see or tx_broadcast when free alternatives like hive_read or tx_simulate can satisfy the requirement during development or testing.
Fix: Establish a capability hierarchy. Route development and staging environments to free tiers. Reserve micro-transaction tools for production validation and user-facing workflows. Document the decision matrix in agent runbooks.
Production Bundle
Action Checklist
Decision Matrix
| Scenario | Recommended Approach | Why | Cost Impact |
|---|
| Local development & prototyping | Zero-config HiveCast variant | Instant setup, no auth overhead, 5 curated tools | $0 |
| Production agent swarm | Standard keyed endpoint | Full tool coverage, centralized auth, micro-transaction routing | Variable (pay-per-use) |
| Budget-constrained deployment | Free tier + response caching | Stays within 10-call daily limit, reduces redundant invocations | $0 (with strict caching) |
| High-throughput automation | Keyed tier + spend caps | Prevents accidental billing spikes, enables async tool orchestration | Predictable micro-USDC |
Configuration Template
{
"mcpServers": {
"x711-prod": {
"url": "https://x711.io/mcp",
"transport": "streamable-http",
"headers": {
"X-API-Key": "${X711_API_KEY}"
}
}
}
}
Note: Replace ${X711_API_KEY} with your environment variable reference. For HiveCast, swap the URL to https://x711.io/hivecast/mcp and remove the headers block entirely.
Quick Start Guide
- Generate an API key (optional for free tier): Execute
curl -X POST https://x711.io/api/onboard -d '{"name":"your-agent-id"}' and store the returned x711_... value in your environment.
- Select your variant: Use the standard endpoint for full capability access, or the HiveCast URL for zero-config deployment.
- Deploy the configuration: Place the JSON block in your client's designated path (e.g.,
.cursor/mcp.json, ~/.windsurf/mcp.json, or VS Code Cline settings).
- Validate tool access: Run a dry invocation of a free tool like
web_search to confirm transport connectivity and schema resolution.
- Enable spend monitoring: If using micro-transaction tools, implement session-level cost tracking before routing production traffic.
This architecture transforms capability injection from a fragmented integration challenge into a standardized, cost-aware routing layer. By treating tools as declarative capabilities rather than hardcoded dependencies, teams can iterate faster, control spend precisely, and maintain agent portability across the entire MCP ecosystem.