-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add ai_mcp_servers_js for dynamic MCP server selection #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for dynamically computing MCP servers in AI checks via JavaScript
expressions. This enables conditional loading of MCP servers based on routing
tags, outputs, or other runtime context.
Key changes:
- Add ai_mcp_servers_js property to CheckConfig interface
- Implement evaluateMcpServersJs() in AiCheckProvider using sandbox evaluation
- Add environment variable resolution for ${VAR} placeholders in MCP server
env configs, enabling secure credential injection
- Update config schema to include the new property
- Add comprehensive tests for the feature
This feature allows workflows to conditionally load expensive MCP servers
(like Jira, Confluence, Zendesk) only when needed based on intent routing tags.
Example usage:
```yaml
ai_mcp_servers_js: |
const servers = {};
const tags = outputs['route-intent']?.tags || [];
if (tags.includes('jira')) {
servers.jira = {
command: "npx",
args: ["-y", "@aashari/mcp-server-atlassian-jira"],
env: { ATLASSIAN_API_TOKEN: "${ATLASSIAN_API_TOKEN}" }
};
}
return servers;
```
Co-Authored-By: Claude Opus 4.5 <[email protected]>
PR Overview: Dynamic MCP Server Selection with JavaScript ExpressionsSummaryThis PR introduces Files ChangedCore Implementation:
Supporting Changes:
Testing:
Dependencies:
Architecture & Impact AssessmentWhat This PR Accomplishes
Key Technical Changes
Affected System Componentsgraph TD
A[AI Check Provider] --> B[evaluateMcpServersJs]
A --> C[evaluateCustomToolsJs]
B --> D[Sandbox Evaluation]
C --> D
D --> E[Context: outputs, inputs, pr, files, env, memory]
B --> F[Environment Variable Resolution]
F --> G[MCP Server Config]
C --> H[Custom Tools Array]
G --> I[MCP Server Initialization]
H --> J[Custom Tools SSE Server]
K[Existing Sandbox Usage] --> D
K --> L[Failure Conditions]
K --> M[Routing Logic]
K --> N[Script Provider]
O[env-exposure.ts] --> P[buildSandboxEnv]
P --> D
Component Relationships
Scope Discovery & Context ExpansionDirect Impact
Related Components
Testing CoverageUnit tests verify:
Integration Points
Use Case Examplechecks:
ai-review:
type: ai
prompt: "Review this PR"
ai_mcp_servers_js: |
const servers = {};
const tags = outputs['route-intent']?.tags || [];
if (tags.includes('jira')) {
servers.jira = {
command: "npx",
args: ["-y", "@aashari/mcp-server-atlassian-jira"],
env: {
ATLASSIAN_SITE_NAME: "${ATLASSIAN_SITE_NAME}",
ATLASSIAN_API_TOKEN: "${ATLASSIAN_API_TOKEN}"
}
};
}
return servers;Security Considerations
Performance Impact
Migration Notes
Review Focus Areas
Metadata
Powered by Visor from Probelabs Last updated: 2026-02-02T14:11:13.786Z | Triggered by: pr_updated | Commit: 710def7 💡 TIP: You can chat with Visor using |
Security Issues (8)
Architecture Issues (8)
Performance Issues (8)
Quality Issues (13)
Powered by Visor from Probelabs Last updated: 2026-02-02T14:11:17.462Z | Triggered by: pr_updated | Commit: 710def7 💡 TIP: You can chat with Visor using |
The worktree tests (.visor/worktrees/) run against historical code versions that have singleton state leakage issues (MemoryStore). Tests pass individually but fail when run in sequence due to shared state. This change explicitly specifies test directories (defaults/, tests/, examples/) rather than running all tests recursively, ensuring pre-commit hooks are reliable. Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Update validation to accept entries with 'workflow' property
- Add Option 4 to extract workflow entries from ai_mcp_servers
- Update McpServerConfig type to support unified flat detection:
- command → stdio MCP server
- url → SSE/HTTP MCP server
- workflow → workflow tool reference
- empty {} → auto-detect from tools: section
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Workflow tools like tyk-code-talk can run complex operations (code search, AI analysis) that take several minutes. The default 30-second MCP timeout was causing these calls to fail. Set 10-minute (600000ms) timeout for the __tools__ SSE server that hosts workflow tools. Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix sandbox parallel execution errors by passing `log` through scope instead of declaring in code header (prevents "already declared" errors) - Only inject `log` when injectLog=true, allowing callers to define their own - Fix wrapFunction default to handle partial options correctly - Add detailed logging for MCP SSE communication and workflow tool execution - Make worktree IDs deterministic for reuse across multiple calls - Reuse existing project paths in workspace manager to prevent duplicates - Update @probelabs/probe to v0.6.0-rc210 - Add enableTasks option propagation to ProbeAgent Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary
ai_mcp_servers_jsproperty to AI checks that allows dynamic computation of MCP servers at runtime@nyariv/sandboxjs${VAR}placeholders in MCP server env configsai_mcp_servers_js(returns{workflow: "workflow-id", ...})logthrough scope instead of header declarationenableTasksand MCP method filtering (allowedMethods/blockedMethods) optionsUse Case
This feature supports the OEL Bot simplification effort where we want MCP servers to load conditionally based on tags from intent routing:
jiratag → loads Atlassian Jira MCP serverconfluencetag → loads Atlassian Confluence MCP serverzendesktag → loads Zendesk MCP serverExample Usage
Test plan
evaluateMcpServersJs()method${VAR}placeholders🤖 Generated with Claude Code