MCP Tools Reference
Complete reference for Orchex's Model Context Protocol (MCP) tools.
Overview
Orchex exposes five MCP tools that enable AI assistants to execute multi-step orchestrations:
orchex_init— Initialize a new orchestration sessionorchex_add_stream— Add execution streams to the sessionorchex_status— Check orchestration progressorchex_execute— Execute the orchestrationorchex_complete— Finalize and clean up the session
These tools support a session-based workflow where you build up an orchestration plan before executing it.
Tool: `orchex_init`
Initialize a new orchestration session.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
task |
string | Yes | Natural language description of the overall task |
files |
string[] | No | Array of file paths to include in context |
maxSteps |
number | No | Maximum execution steps (default: 10) |
dryRun |
boolean | No | Preview mode without actual execution (default: false) |
Returns
{
sessionId: string; // Unique session identifier
status: "initialized"; // Session status
task: string; // Confirmed task description
context: {
files: string[]; // Files included in context
fileCount: number; // Number of context files
};
options: {
maxSteps: number; // Maximum execution steps
dryRun: boolean; // Dry run mode enabled
};
}Example
const session = await orchex_init({
task: "Add user authentication to the API",
files: [
"src/server.ts",
"src/routes/",
"src/models/user.ts"
],
maxSteps: 15,
dryRun: false
});
console.log(session.sessionId);
// => "sess_abc123def456"Usage Notes
- Session ID is required for all subsequent tool calls
- Context files are analyzed to understand project structure
- Dry run mode generates execution plan without making changes
- Sessions expire after 1 hour of inactivity
Tool: `orchex_add_stream`
Add an execution stream to an initialized session.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId |
string | Yes | Session ID from orchex_init |
streamId |
string | Yes | Unique identifier for this stream |
description |
string | Yes | What this stream accomplishes |
plan |
string | Yes | Step-by-step execution plan |
context |
object | No | Context configuration for this stream |
commands |
array | No | Validation commands to run |
constraints |
object | No | Stream-specific constraints |
Context Object
{
files?: string[]; // Additional files for this stream
depth?: "minimal" | "moderate" | "comprehensive";
}Commands Array
[
{
command: string; // Command to execute
critical: boolean; // Fail on error if true
}
]Constraints Object
{
maxSteps?: number; // Override session maxSteps
timeout?: number; // Timeout in milliseconds
requireTests?: boolean; // Require test validation
}Returns
{
sessionId: string; // Session identifier
streamId: string; // Added stream identifier
status: "stream_added"; // Confirmation status
streamCount: number; // Total streams in session
plan: {
steps: number; // Estimated execution steps
files: string[]; // Files this stream will modify
};
}Example
const result = await orchex_add_stream({
sessionId: "sess_abc123def456",
streamId: "api-auth-routes",
description: "Create authentication API routes",
plan: `
1. Create src/routes/auth.ts with login/logout endpoints
2. Add JWT token generation and validation
3. Integrate with existing Express server
4. Add authentication middleware
`,
context: {
files: ["src/middleware/", "src/utils/jwt.ts"],
depth: "moderate"
},
commands: [
{ command: "npm test", critical: true },
{ command: "npm run lint", critical: false }
],
constraints: {
maxSteps: 8,
requireTests: true
}
});
console.log(result.streamCount);
// => 1Usage Notes
- Multiple streams can be added to build complex orchestrations
- Stream order determines execution sequence
- Context depth controls how much related code is analyzed:
minimal: Only specified files (~5-10 files)moderate: Files + dependencies (~20-30 files)comprehensive: Full project context (~50+ files)
- Commands run after stream execution completes
Tool: `orchex_status`
Check the status of an orchestration session or execution.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId |
string | Yes | Session ID to check |
Returns
{
sessionId: string; // Session identifier
status: "initialized" | // Current session status
"planning" |
"executing" |
"completed" |
"failed" |
"cancelled";
progress?: { // Present during execution
currentStream: string; // Active stream ID
currentStep: number; // Current step number
totalSteps: number; // Total estimated steps
percentage: number; // Completion percentage (0-100)
};
streams: Array<{ // All streams in session
streamId: string;
status: "pending" | "running" | "completed" | "failed";
steps?: number; // Steps executed
duration?: number; // Execution time (ms)
}>;
metrics?: { // Present after execution
totalDuration: number; // Total execution time (ms)
tokensUsed: number; // Total tokens consumed
filesModified: number; // Number of files changed
};
error?: { // Present on failure
message: string; // Error description
stream: string; // Stream where error occurred
step: number; // Step where error occurred
};
}Example
const status = await orchex_status({
sessionId: "sess_abc123def456"
});
if (status.status === "executing") {
console.log(`Progress: ${status.progress.percentage}%`);
console.log(`Current: ${status.progress.currentStream}`);
}
if (status.status === "completed") {
console.log(`Completed in ${status.metrics.totalDuration}ms`);
console.log(`Modified ${status.metrics.filesModified} files`);
}
if (status.status === "failed") {
console.error(`Error: ${status.error.message}`);
console.error(`Failed at: ${status.error.stream} step ${status.error.step}`);
}Usage Notes
- Poll periodically during execution to monitor progress
- Status transitions: initialized → planning → executing → completed/failed
- Metrics are only available after execution completes
- Session persistence: Status available for 24 hours after completion
Tool: `orchex_execute`
Execute the orchestration with all added streams.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId |
string | Yes | Session ID from orchex_init |
confirm |
boolean | No | Explicit execution confirmation (default: true) |
parallel |
boolean | No | Execute independent streams in parallel (default: false) |
Returns
{
sessionId: string; // Session identifier
executionId: string; // Unique execution identifier
status: "executing"; // Initial execution status
startedAt: string; // ISO 8601 timestamp
plan: { // Execution plan overview
streams: number; // Number of streams
estimatedSteps: number; // Total estimated steps
estimatedDuration: number; // Estimated duration (ms)
};
options: { // Execution configuration
dryRun: boolean; // Dry run mode
parallel: boolean; // Parallel execution
maxSteps: number; // Maximum steps
};
}Example
// Execute the orchestration
const execution = await orchex_execute({
sessionId: "sess_abc123def456",
confirm: true,
parallel: false
});
console.log(`Execution started: ${execution.executionId}`);
console.log(`Estimated duration: ${execution.plan.estimatedDuration}ms`);
// Poll for status
let status;
do {
await new Promise(resolve => setTimeout(resolve, 2000));
status = await orchex_status({ sessionId: execution.sessionId });
console.log(`Progress: ${status.progress?.percentage}%`);
} while (status.status === "executing");
if (status.status === "completed") {
console.log("Orchestration completed successfully!");
}Usage Notes
- At least one stream must be added before execution
- Parallel execution runs independent streams concurrently
- Dry run mode (from
orchex_init) generates plan without changes - Execution is asynchronous — use
orchex_statusto monitor - Cannot modify session after execution starts
Tool: `orchex_complete`
Finalize and clean up an orchestration session.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId |
string | Yes | Session ID to complete |
saveResults |
boolean | No | Save execution results (default: true) |
Returns
{
sessionId: string; // Session identifier
status: "completed" | "failed"; // Final session status
summary: { // Execution summary
task: string; // Original task description
streamsExecuted: number; // Number of streams executed
stepsExecuted: number; // Total steps executed
duration: number; // Total duration (ms)
};
results: { // Execution results
filesCreated: string[]; // New files created
filesModified: string[]; // Existing files modified
filesDeleted: string[]; // Files deleted
artifacts: Array<{ // Generated artifacts
path: string; // File path
type: string; // Artifact type
description: string; // What it contains
}>;
};
metrics: { // Performance metrics
totalDuration: number; // Total time (ms)
tokensUsed: number; // Total tokens consumed
averageStepTime: number; // Average step duration (ms)
efficiency: number; // Efficiency score (0-100)
};
validation: { // Validation results
commandsPassed: number; // Successful commands
commandsFailed: number; // Failed commands
testsPassed: boolean; // Overall test status
lintPassed: boolean; // Lint status
};
saved?: { // Present if saveResults=true
historyId: string; // Execution history ID
url: string; // View URL (if cloud enabled)
};
}Example
const result = await orchex_complete({
sessionId: "sess_abc123def456",
saveResults: true
});
console.log("Orchestration Summary:");
console.log(`- Task: ${result.summary.task}`);
console.log(`- Streams: ${result.summary.streamsExecuted}`);
console.log(`- Duration: ${result.summary.duration}ms`);
console.log(`\nFiles Changed:`);
console.log(`- Created: ${result.results.filesCreated.length}`);
console.log(`- Modified: ${result.results.filesModified.length}`);
console.log(`- Deleted: ${result.results.filesDeleted.length}`);
console.log(`\nValidation:`);
console.log(`- Tests: ${result.validation.testsPassed ? 'PASSED' : 'FAILED'}`);
console.log(`- Lint: ${result.validation.lintPassed ? 'PASSED' : 'FAILED'}`);
if (result.saved) {
console.log(`\nView results: ${result.saved.url}`);
}Usage Notes
- Always call
orchex_completeto clean up resources - Results are preserved for 24 hours if
saveResults=true - Metrics include token usage for cost tracking
- Validation summary shows command execution results
- Can be called even if execution failed
Workflow Example
Complete workflow using all five tools:
// 1. Initialize session
const session = await orchex_init({
task: "Add user authentication to the API",
files: ["src/server.ts", "src/routes/"],
maxSteps: 20
});
// 2. Add streams
await orchex_add_stream({
sessionId: session.sessionId,
streamId: "api-auth-routes",
description: "Create authentication routes",
plan: `
1. Create src/routes/auth.ts with login/logout
2. Add JWT token generation
3. Integrate with Express server
`,
commands: [
{ command: "npm test", critical: true }
]
});
await orchex_add_stream({
sessionId: session.sessionId,
streamId: "api-auth-middleware",
description: "Add authentication middleware",
plan: `
1. Create src/middleware/auth.ts
2. Add token validation
3. Protect existing routes
`
});
// 3. Execute
const execution = await orchex_execute({
sessionId: session.sessionId,
confirm: true
});
// 4. Monitor progress
let status;
do {
await new Promise(resolve => setTimeout(resolve, 3000));
status = await orchex_status({
sessionId: session.sessionId
});
if (status.progress) {
console.log(
`Progress: ${status.progress.percentage}% ` +
`(${status.progress.currentStream})`
);
}
} while (status.status === "executing");
// 5. Complete and get results
const result = await orchex_complete({
sessionId: session.sessionId,
saveResults: true
});
if (result.status === "completed") {
console.log("✓ Authentication added successfully!");
console.log(`Modified ${result.results.filesModified.length} files`);
} else {
console.error("✗ Orchestration failed");
}Error Handling
Common Errors
Invalid Session:
{
error: "SESSION_NOT_FOUND",
message: "Session sess_abc123 does not exist or has expired",
code: 404
}Session Already Executing:
{
error: "SESSION_LOCKED",
message: "Cannot modify session during execution",
code: 409
}Missing Required Streams:
{
error: "NO_STREAMS",
message: "At least one stream must be added before execution",
code: 400
}Execution Failed:
{
error: "EXECUTION_FAILED",
message: "Stream 'api-auth-routes' failed at step 3",
details: {
stream: "api-auth-routes",
step: 3,
reason: "Test command failed"
},
code: 500
}Error Recovery
try {
const execution = await orchex_execute({
sessionId: session.sessionId
});
// Monitor execution...
} catch (error) {
if (error.code === 409) {
// Session already executing - get status
const status = await orchex_status({
sessionId: session.sessionId
});
console.log("Execution already in progress:", status);
} else if (error.code === 404) {
// Session expired - create new one
console.log("Session expired, creating new session...");
} else {
// Other error - complete and inspect
const result = await orchex_complete({
sessionId: session.sessionId
});
console.error("Execution failed:", result);
}
}MCP Server Configuration
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"orchex": {
"command": "npx",
"args": ["-y", "@wundam/orchex", "mcp"]
}
}
}Cline / Other MCP Clients
{
"mcpServers": {
"orchex": {
"command": "node",
"args": ["/path/to/orchex/bin/orchex-server.js"],
"env": {
"ORCHEX_API_KEY": "orchex_sk_..."
}
}
}
}Environment Variables
ORCHEX_API_KEY— Cloud API key (optional)ORCHEX_CLOUD_URL— Cloud API URL (default: https://api.orchex.dev)ORCHEX_LOCAL— Force local execution (default: false)ORCHEX_DEBUG— Enable debug logging (default: false)
Best Practices
Session Management
✓ Always complete sessions to free resources
try {
// ... orchestration workflow
} finally {
await orchex_complete({ sessionId });
}✓ Reuse sessions for related tasks
// One session, multiple streams
const session = await orchex_init({ task: "Feature X" });
await orchex_add_stream({ sessionId, streamId: "backend", ... });
await orchex_add_stream({ sessionId, streamId: "frontend", ... });
await orchex_execute({ sessionId });✗ Don't create sessions for single simple tasks
// Overkill for simple tasks
const session = await orchex_init({ task: "Fix typo" });
// Just use orchex_run() or CLI insteadStream Design
✓ Break complex tasks into logical streams
// Good: Clear separation of concerns
await orchex_add_stream({ streamId: "api-routes", ... });
await orchex_add_stream({ streamId: "api-middleware", ... });
await orchex_add_stream({ streamId: "api-tests", ... });✓ Include validation commands
commands: [
{ command: "npm test", critical: true },
{ command: "npm run lint", critical: false },
{ command: "npm run typecheck", critical: true }
]✓ Specify appropriate context depth
// Minimal for isolated changes
context: { depth: "minimal" }
// Moderate for feature development
context: { depth: "moderate" }
// Comprehensive for refactoring
context: { depth: "comprehensive" }Progress Monitoring
✓ Poll with backoff during execution
let pollInterval = 2000;
while (status.status === "executing") {
await new Promise(resolve => setTimeout(resolve, pollInterval));
status = await orchex_status({ sessionId });
pollInterval = Math.min(pollInterval * 1.5, 10000);
}✓ Show meaningful progress
if (status.progress) {
console.log(
`[${status.progress.percentage}%] ` +
`${status.progress.currentStream} ` +
`(${status.progress.currentStep}/${status.progress.totalSteps})`
);
}Advanced Usage
Parallel Stream Execution
// Independent streams can run in parallel
await orchex_add_stream({
streamId: "backend-tests",
// ... backend test stream
});
await orchex_add_stream({
streamId: "frontend-tests",
// ... frontend test stream
});
// Execute in parallel
await orchex_execute({
sessionId,
parallel: true // Faster for independent streams
});Dry Run Planning
// Preview changes without executing
const session = await orchex_init({
task: "Refactor authentication",
dryRun: true
});
await orchex_add_stream({ ... });
const execution = await orchex_execute({ sessionId });
// Get plan details
const result = await orchex_complete({ sessionId });
console.log("Planned changes:", result.results);Progressive Context
// Start with minimal context
await orchex_add_stream({
streamId: "core-changes",
context: {
files: ["src/auth.ts"],
depth: "minimal"
},
// ...
});
// Expand context for dependent changes
await orchex_add_stream({
streamId: "integration",
context: {
files: ["src/auth.ts", "src/routes/"],
depth: "moderate"
},
// ...
});See Also
- API Overview — Complete API reference
- Cloud API — REST API for cloud orchestrations
- Stream Manifests — YAML manifest format
- CLI Reference — Command-line interface
- Getting Started — Quick start tutorial
Last updated: February 2026 • MCP Protocol Version: 2024-11-05