Implementation:20000419 Fauxnix startMcpServer
| Knowledge Sources | |
|---|---|
| Domains | MCP, Server, Agent_Integration |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
Concrete MCP stdio server that exposes bash execution tools (bash, bash_batch, fauxnix_translate, fauxnix_session) to AI agent harnesses over a persistent, prewarmed fauxnix session.
Description
The startMcpServer function (src/mcp.ts) boots a McpServer from the @modelcontextprotocol/sdk connected to a StdioServerTransport. It constructs a single FauxnixSession, prewarms it so the first tool call is warm, and registers four tools:
- bash (or FAUXNIX_TOOL_NAME): parse → translate (execute mode) → session.run with 256 KiB stdout / 64 KiB stderr caps; returns formatted text + structuredContent with stdout/stderr/exitCode/sessionId.
- 'bash_batch: compile all steps (pure mode preflight) → session.runBatch atomically; returns per-step status plus stopReason.
- 'fauxnix_translate: translate-only (pure mode, never executes); returns the PowerShell script.
- 'fauxnix_session: status (cwd, env keys, positional count, session id) or reset (kill + re-prewarm).
An idempotent shutdown closure disposes the session and closes the server on stdin end/close, SIGINT, SIGTERM, or transport close.
Usage
Run via fauxnix mcp (CLI verb) or the spawn-safe absolute launcher written by fauxnix install. Agent harnesses (Claude, Codex, OpenCode, Kimi, Qwen) connect over stdio and call the registered tools.
Code Reference
Source Location
- Repository: fauxnix
- File: src/mcp.ts
- Lines: startMcpServer L258-467; compileBatchSteps L90-98; bashToolResult L193-209; batchToolResult L109-154; formatSessionStatus L238-256; shutdown closure L267-288
Signature
export interface BatchStepInput {
id?: string;
command: string;
}
export function compileBatchSteps(steps: BatchStepInput[]): SegmentPlan[][];
export function bashToolResult(r: ExecResult, sessionId: string, infra: boolean): ToolResult;
export function batchToolResult(inputs: BatchStepInput[], batch: BatchExecResult, sessionId: string): ToolResult;
export function formatSessionStatus(session: { cwd: string | null; env: Record<string,string>; id: string }): string;
export async function startMcpServer(): Promise<void>;
Import
import { startMcpServer, compileBatchSteps, formatSessionStatus } from './mcp.js';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (stdio) | transport | Yes | MCP client connected over stdin/stdout |
| FAUXNIX_TOOL_NAME | env | No | Override the primary tool name (default bash) |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | McpServer | Registered tools available to the agent harness |
| bash result | ToolResult | content (formatted text) + structuredContent (stdout/stderr/exitCode/.../sessionId) |
| bash_batch result | ToolResult | Per-step text + structuredContent with stopReason and per-step status |
Usage Examples
Start from the CLI
import { startMcpServer } from './mcp.js';
await startMcpServer(); // blocks; serves until stdin closes or signal
Compile Batch Steps (Preflight)
import { compileBatchSteps } from './mcp.js';
const compiled = compileBatchSteps([
{ id: 'list', command: 'ls -la' },
{ id: 'count', command: 'wc -l *.txt' },
]);
// SegmentPlan[][] — all parsed + translated in PURE mode before execution
Related Pages
Implements Principle
- Principle:20000419_Fauxnix_MCP_Tool_Exposure
- Principle:20000419_Fauxnix_Atomic_Batch_Execution
- Principle:20000419_Fauxnix_Stateful_Session_Execution