@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.
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;
declare class McpServer
| Member | Type | Summary |
|---|
| (constructor) | | Constructs a new instance of the `McpServer` class |
| handle | | Handle one inbound message. Returns the response to send back, or `null` for notifications and other no-reply messages. Never throws. |
interface JsonRpcError
| Member | Type | Summary |
|---|
| error | {
code: number;
message: string;
data?: unknown;
} | |
| id | JsonRpcId | |
| jsonrpc | '2.0' | |
interface JsonRpcNotification
| Member | Type | Summary |
|---|
| jsonrpc | '2.0' | |
| method | string | |
| params? | unknown | |
interface JsonRpcRequest
| Member | Type | Summary |
|---|
| id | JsonRpcId | |
| jsonrpc | '2.0' | |
| method | string | |
| params? | unknown | |
interface JsonRpcSuccess
| Member | Type | Summary |
|---|
| id | JsonRpcId | |
| jsonrpc | '2.0' | |
| result | unknown | |
McpContentinterfaceSource ↗
interface McpContent
| Member | Type | Summary |
|---|
| text | string | |
| type | 'text' | |
interface McpInitializeResult
| Member | Type | Summary |
|---|
| capabilities | {
tools?: Record<string, unknown>;
} | |
| protocolVersion | string | |
| 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
| Member | Type | Summary |
|---|
| name? | string | Server name reported in `initialize` response. Default: `@eigenpal/docx-editor-agents`. |
| protocolVersion? | string | MCP protocol version we claim to speak. Default: `2025-06-18`. |
| version? | string | Server version. Default: `0.0.0` (override at build time). |
interface McpToolDescriptor
| Member | Type | Summary |
|---|
| description | string | |
| inputSchema | Record<string, unknown> | |
| name | string | |
interface McpToolsCallParams
| Member | Type | Summary |
|---|
| arguments? | Record<string, unknown> | |
| name | string | |
interface McpToolsCallResult
| Member | Type | Summary |
|---|
| content | McpContent[] | |
| isError? | boolean | |
interface McpToolsListResult
| Member | Type | Summary |
|---|
| tools | McpToolDescriptor[] | |
interface StdioServerHandle
| Member | Type | Summary |
|---|
| close | () => void | Stop accepting input and reject further writes. Idempotent. |
| feed | (chunk: string | Buffer) => void | Manually feed a raw chunk (used by tests; the live transport calls this internally). |
| server | McpServer | Underlying server (for tests / introspection). |
interface StdioServerOptions extends McpServerOptions
| Member | Type | Summary |
|---|
| input? | InputStream | |
| log? | (msg: string) => void | Called with diagnostic strings (e.g. parse errors). Default: stderr. |
| output? | OutputStream | |
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;
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;
}