New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@eigenpal/docx-editor-agents/mcp

Model Context Protocol (MCP) server for the docx editor agent bridge.

Two transports, same core: - `stdio`: classic MCP transport. Use `runStdioServer(bridge)` from a Node subprocess that Claude Desktop, Cursor, or any MCP-aware client will spawn. Newline-delimited JSON-RPC. - `direct`: call `new McpServer(bridge).handle(message)` if you have your own transport (WebSocket, `postMessage`, HTTP long-poll, etc.).

The server is transport-agnostic and zero-dep. The stdio module reaches for `process.stdin` / `process.stdout` only when you call `runStdioServer` without explicit streams.

Functions(7)

Encode a JSON-RPC message as a single newline-terminated frame.

declare function encodeFrame(message: JsonRpcMessage): string;
declare function isJsonRpcNotification(m: unknown): m is JsonRpcNotification;
declare function isJsonRpcRequest(m: unknown): m is JsonRpcRequest;
declare function makeError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcError;
declare function makeSuccess(id: JsonRpcId, result: unknown): JsonRpcSuccess;

Parse newline-delimited JSON-RPC frames out of a buffer. Returns parsed messages plus any leftover bytes. Tolerates blank lines.

declare function parseFrames(buffer: string): ParseResult;

Wire an EditorBridge to a JSON-RPC stdio loop. Returns immediately; reading happens via the stream listeners. Designed to be testable: pass in fake streams, call `feed(...)` directly, then assert on what was written.

declare function runStdioServer(bridge: EditorBridge, options?: StdioServerOptions): StdioServerHandle;

Classes(1)

declare class McpServer
MemberTypeSummary
(constructor)Constructs a new instance of the `McpServer` class
handleHandle one inbound message. Returns the response to send back, or `null` for notifications and other no-reply messages. Never throws.

Interfaces(13)

interface JsonRpcError
MemberTypeSummary
error{ code: number; message: string; data?: unknown; }
idJsonRpcId
jsonrpc'2.0'
interface

JsonRpcNotification

packages/agents/src/mcp/protocol.ts:26
interface JsonRpcNotification
MemberTypeSummary
jsonrpc'2.0'
methodstring
params?unknown
interface JsonRpcRequest
MemberTypeSummary
idJsonRpcId
jsonrpc'2.0'
methodstring
params?unknown
interface JsonRpcSuccess
MemberTypeSummary
idJsonRpcId
jsonrpc'2.0'
resultunknown
interface McpContent
MemberTypeSummary
textstring
type'text'
interface

McpInitializeResult

packages/agents/src/mcp/protocol.ts:66
interface McpInitializeResult
MemberTypeSummary
capabilities{ tools?: Record<string, unknown>; }
protocolVersionstring
serverInfo{ name: string; version: string; }

MCP server core. Transport-agnostic — accepts a JsonRpcRequest, returns either a JsonRpcResponse or `null` (for notifications, which never reply).

Wraps an EditorBridge: tools/list returns the bridge's tool schemas in MCP shape; tools/call dispatches via executeToolCall and converts the AgentToolResult into MCP CallToolResult content.

interface McpServerOptions
MemberTypeSummary
name?stringServer name reported in `initialize` response. Default: `@eigenpal/docx-editor-agents`.
protocolVersion?stringMCP protocol version we claim to speak. Default: `2025-06-18`.
version?stringServer version. Default: `0.0.0` (override at build time).
interface McpToolDescriptor
MemberTypeSummary
descriptionstring
inputSchemaRecord<string, unknown>
namestring
interface McpToolsCallParams
MemberTypeSummary
arguments?Record<string, unknown>
namestring
interface McpToolsCallResult
MemberTypeSummary
contentMcpContent[]
isError?boolean
interface McpToolsListResult
MemberTypeSummary
toolsMcpToolDescriptor[]
interface

StdioServerHandle

packages/agents/src/mcp/stdio.ts:44
interface StdioServerHandle
MemberTypeSummary
close() => voidStop accepting input and reject further writes. Idempotent.
feed(chunk: string | Buffer) => voidManually feed a raw chunk (used by tests; the live transport calls this internally).
serverMcpServerUnderlying server (for tests / introspection).
interface

StdioServerOptions

packages/agents/src/mcp/stdio.ts:37
interface StdioServerOptions extends McpServerOptions
MemberTypeSummary
input?InputStream
log?(msg: string) => voidCalled with diagnostic strings (e.g. parse errors). Default: stderr.
output?OutputStream

Type aliases(3)

MCP wire protocol (subset) — JSON-RPC 2.0 framing + the message types we actually implement. Zero dependencies. Pure functions; everything is unit- testable without a transport.

This is NOT a full MCP SDK. We implement only what the server needs: - initialize / initialized - tools/list - tools/call - notifications/cancelled (no-op, accepted)

Spec reference: https://spec.modelcontextprotocol.io

type JsonRpcId = string | number | null;
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
type JsonRpcResponse = JsonRpcSuccess | JsonRpcError;

Variables(1)

Standard JSON-RPC error codes. We only ever emit JSON-RPC errors for protocol-level problems; tool execution failures use MCP's `isError` envelope inside a successful response, per spec.

ErrorCode: {
    readonly ParseError: -32700;
    readonly InvalidRequest: -32600;
    readonly MethodNotFound: -32601;
    readonly InvalidParams: -32602;
    readonly InternalError: -32603;
}