@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)
encodeFrame
Encode a JSON-RPC message as a single newline-terminated frame.
declare function encodeFrame(message: JsonRpcMessage): string;isJsonRpcNotification
declare function isJsonRpcNotification(m: unknown): m is JsonRpcNotification;isJsonRpcRequest
declare function isJsonRpcRequest(m: unknown): m is JsonRpcRequest;makeError
declare function makeError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcError;makeSuccess
declare function makeSuccess(id: JsonRpcId, result: unknown): JsonRpcSuccess;parseFrames
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;runStdioServer
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)
McpServer
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. |
Interfaces(13)
JsonRpcError
interface JsonRpcError| Member | Type | Summary |
|---|---|---|
| error | {
code: number;
message: string;
data?: unknown;
} | |
| id | JsonRpcId | |
| jsonrpc | '2.0' |
JsonRpcNotification
interface JsonRpcNotification| Member | Type | Summary |
|---|---|---|
| jsonrpc | '2.0' | |
| method | string | |
| params? | unknown |
JsonRpcRequest
interface JsonRpcRequest| Member | Type | Summary |
|---|---|---|
| id | JsonRpcId | |
| jsonrpc | '2.0' | |
| method | string | |
| params? | unknown |
JsonRpcSuccess
interface JsonRpcSuccess| Member | Type | Summary |
|---|---|---|
| id | JsonRpcId | |
| jsonrpc | '2.0' | |
| result | unknown |
McpContent
interface McpContent| Member | Type | Summary |
|---|---|---|
| text | string | |
| type | 'text' |
McpInitializeResult
interface McpInitializeResult| Member | Type | Summary |
|---|---|---|
| capabilities | {
tools?: Record<string, unknown>;
} | |
| protocolVersion | string | |
| serverInfo | {
name: string;
version: string;
} |
McpServerOptions
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). |
McpToolDescriptor
interface McpToolDescriptor| Member | Type | Summary |
|---|---|---|
| description | string | |
| inputSchema | Record<string, unknown> | |
| name | string |
McpToolsCallParams
interface McpToolsCallParams| Member | Type | Summary |
|---|---|---|
| arguments? | Record<string, unknown> | |
| name | string |
McpToolsCallResult
interface McpToolsCallResult| Member | Type | Summary |
|---|---|---|
| content | McpContent[] | |
| isError? | boolean |
McpToolsListResult
interface McpToolsListResult| Member | Type | Summary |
|---|---|---|
| tools | McpToolDescriptor[] |
StdioServerHandle
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). |
StdioServerOptions
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 |
Type aliases(3)
JsonRpcId
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;JsonRpcMessage
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;JsonRpcResponse
type JsonRpcResponse = JsonRpcSuccess | JsonRpcError;Variables(1)
ErrorCode
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;
}