init_plan
Sets up revision-bound planning context metadata for multi-agent collaboration on DOCX files.
Instructions
Initialize revision-bound context metadata for coordinated multi-agent planning.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the DOCX file. | |
| plan_name | No | ||
| orchestrator_id | No |
Implementation Reference
- The main handler function for the init_plan tool. Resolves the session for the given file_path, creates a unique plan_context_id (plctx_*), and returns plan metadata including session info, base revision, edit count, and optional plan_name/orchestrator_id.
export async function initPlan( manager: SessionManager, params: { file_path?: string; plan_name?: string; orchestrator_id?: string; }, ): Promise<ToolResponse> { try { const resolved = await resolveSessionForTool(manager, params, { toolName: 'init_plan' }); if (!resolved.ok) return resolved.response; const { session, metadata } = resolved; return ok(mergeSessionResolutionMetadata({ plan_context_id: createPlanContextId(), file_path: manager.normalizePath(session.originalPath), session_epoch: session.createdAt.getTime(), base_revision: session.editRevision, edit_count: session.editCount, created_at: new Date().toISOString(), plan_context: { plan_name: optionalString(params.plan_name) ?? null, orchestrator_id: optionalString(params.orchestrator_id) ?? null, document_filename: session.filename, }, }, metadata)); } catch (e: unknown) { const msg = errorMessage(e); return err('PLAN_INIT_ERROR', `Failed to initialize plan context: ${msg}`); } } - Schema registration for the init_plan tool: defines input schema (file_path required, plan_name and orchestrator_id optional), description, and readOnlyHint=true annotation.
{ name: 'init_plan', description: 'Initialize revision-bound context metadata for coordinated multi-agent planning.', input: z.object({ ...FILE_FIELD, plan_name: z.string().optional(), orchestrator_id: z.string().optional(), }), annotations: { readOnlyHint: true, destructiveHint: false }, }, - packages/docx-mcp/src/server.ts:97-98 (registration)Dispatch routing in server.ts that maps the 'init_plan' tool name to the initPlan handler function.
case 'init_plan': return await initPlan(sessions, args as Parameters<typeof initPlan>[1]); - packages/docx-mcp/src/server.ts:9-9 (registration)Import of the initPlan handler from the init_plan.ts module.
import { initPlan } from './tools/init_plan.js'; - Helper function that generates a unique plan context ID with a 'plctx_' prefix using 12 random alphanumeric characters.
function createPlanContextId(): string { const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; const bytes = randomBytes(12); let suffix = ''; for (let i = 0; i < 12; i += 1) { suffix += alphabet[bytes[i]! % alphabet.length]; } return `plctx_${suffix}`; }