@univerjs-pro/mcp 0.10.6-experimental.20250904-44da50e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/lib/cjs/facade.js +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/es/facade.js +1 -0
- package/lib/es/index.js +1 -0
- package/lib/facade.js +1 -0
- package/lib/index.js +1 -0
- package/lib/types/controllers/config.schema.d.ts +56 -0
- package/lib/types/controllers/mcp-connection.controller.d.ts +118 -0
- package/lib/types/controllers/mcp-message.controller.d.ts +111 -0
- package/lib/types/controllers/mcp-tool-registry.controller.d.ts +75 -0
- package/lib/types/facade/f-univer.d.ts +41 -0
- package/lib/types/facade/index.d.ts +1 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/plugin.d.ts +28 -0
- package/lib/types/services/mcp-ui-event.service.d.ts +84 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { IMCPMessage, MCPConnectionController } from './mcp-connection.controller';
|
|
2
|
+
import { Disposable, ILogService } from '@univerjs/core';
|
|
3
|
+
import { IMCPToolRegistry } from './mcp-tool-registry.controller';
|
|
4
|
+
/**
|
|
5
|
+
* MCP Protocol message types
|
|
6
|
+
*/
|
|
7
|
+
export declare enum MCPMessageType {
|
|
8
|
+
REQUEST = "request",
|
|
9
|
+
RESPONSE = "response",
|
|
10
|
+
NOTIFICATION = "notification"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* MCP Request message interface
|
|
14
|
+
*/
|
|
15
|
+
export interface IMCPRequest extends IMCPMessage {
|
|
16
|
+
id: string | number;
|
|
17
|
+
method: string;
|
|
18
|
+
params?: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* MCP Response message interface
|
|
22
|
+
*/
|
|
23
|
+
export interface IMCPResponse extends IMCPMessage {
|
|
24
|
+
id: string | number;
|
|
25
|
+
result?: unknown;
|
|
26
|
+
error?: {
|
|
27
|
+
code: number;
|
|
28
|
+
message: string;
|
|
29
|
+
data?: unknown;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* MCP Notification message interface (no response expected)
|
|
34
|
+
*/
|
|
35
|
+
export interface IMCPNotification extends IMCPMessage {
|
|
36
|
+
method: string;
|
|
37
|
+
params?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Tool call parameters interface
|
|
41
|
+
*/
|
|
42
|
+
export interface IToolCallParams {
|
|
43
|
+
name: string;
|
|
44
|
+
arguments?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* MCP Message Controller
|
|
48
|
+
*
|
|
49
|
+
* Handles MCP protocol message processing:
|
|
50
|
+
* - Receives messages from MCP Server via WebSocket
|
|
51
|
+
* - Routes tool-call requests to appropriate tools
|
|
52
|
+
* - Validates message format and parameters
|
|
53
|
+
* - Sends responses back through WebSocket
|
|
54
|
+
* - Manages JSON-RPC 2.0 protocol compliance
|
|
55
|
+
*/
|
|
56
|
+
export declare class MCPMessageController extends Disposable {
|
|
57
|
+
private readonly _logService;
|
|
58
|
+
private readonly _connectionController;
|
|
59
|
+
private readonly _toolRegistry;
|
|
60
|
+
private readonly _destroy$;
|
|
61
|
+
constructor(_logService: ILogService, _connectionController: MCPConnectionController, _toolRegistry: IMCPToolRegistry);
|
|
62
|
+
/**
|
|
63
|
+
* Initialize message listener for incoming MCP messages
|
|
64
|
+
*/
|
|
65
|
+
private _initMessageListener;
|
|
66
|
+
/**
|
|
67
|
+
* Handle incoming MCP messages
|
|
68
|
+
*/
|
|
69
|
+
private _handleIncomingMessage;
|
|
70
|
+
/**
|
|
71
|
+
* Handle MCP request messages (expect response)
|
|
72
|
+
*/
|
|
73
|
+
private _handleRequest;
|
|
74
|
+
/**
|
|
75
|
+
* Handle tool call request
|
|
76
|
+
*/
|
|
77
|
+
private _handleToolCall;
|
|
78
|
+
/**
|
|
79
|
+
* Handle MCP response messages
|
|
80
|
+
*/
|
|
81
|
+
private _handleResponse;
|
|
82
|
+
/**
|
|
83
|
+
* Handle MCP notification messages (no response expected)
|
|
84
|
+
*/
|
|
85
|
+
private _handleNotification;
|
|
86
|
+
/**
|
|
87
|
+
* Send success response
|
|
88
|
+
*/
|
|
89
|
+
private _sendSuccessResponse;
|
|
90
|
+
/**
|
|
91
|
+
* Send error response
|
|
92
|
+
*/
|
|
93
|
+
private _sendErrorResponse;
|
|
94
|
+
/**
|
|
95
|
+
* Check if message is a request
|
|
96
|
+
*/
|
|
97
|
+
private _isRequest;
|
|
98
|
+
/**
|
|
99
|
+
* Check if message is a response
|
|
100
|
+
*/
|
|
101
|
+
private _isResponse;
|
|
102
|
+
/**
|
|
103
|
+
* Check if message is a notification
|
|
104
|
+
*/
|
|
105
|
+
private _isNotification;
|
|
106
|
+
/**
|
|
107
|
+
* Convert Zod schema to JSON Schema (simplified)
|
|
108
|
+
* This is a basic implementation - a more robust solution would use a dedicated library
|
|
109
|
+
*/
|
|
110
|
+
private _zodSchemaToJsonSchema;
|
|
111
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Disposable, ILogService } from '@univerjs/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { MCPUIEventService } from '../services/mcp-ui-event.service';
|
|
4
|
+
/**
|
|
5
|
+
* MCP Tool definition interface
|
|
6
|
+
*/
|
|
7
|
+
export interface IMCPTool {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
inputSchema: z.ZodSchema<any>;
|
|
11
|
+
execute: (params: any) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* MCP Tool Registry interface
|
|
15
|
+
*/
|
|
16
|
+
export interface IMCPToolRegistry {
|
|
17
|
+
registerTool: (tool: IMCPTool) => void;
|
|
18
|
+
unregisterTool: (toolName: string) => void;
|
|
19
|
+
getTool: (toolName: string) => IMCPTool | undefined;
|
|
20
|
+
getAllTools: () => IMCPTool[];
|
|
21
|
+
validateToolCall: (toolName: string, params: unknown) => {
|
|
22
|
+
isValid: boolean;
|
|
23
|
+
error?: string;
|
|
24
|
+
validatedParams?: any;
|
|
25
|
+
};
|
|
26
|
+
executeTool: (toolName: string, params: any, callId?: string) => Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
export declare const IMCPToolRegistry: import('@wendellhu/redi').IdentifierDecorator<IMCPToolRegistry>;
|
|
29
|
+
/**
|
|
30
|
+
* MCP Tool Registry Controller
|
|
31
|
+
*
|
|
32
|
+
* Manages tool registration and execution for Univer MCP:
|
|
33
|
+
* - Provides API for registering and unregistering tools
|
|
34
|
+
* - Includes built-in eval_js tool for debugging
|
|
35
|
+
* - Validates tool call parameters using Zod schemas
|
|
36
|
+
* - Executes tool calls and handles errors
|
|
37
|
+
*/
|
|
38
|
+
export declare class MCPToolRegistryController extends Disposable implements IMCPToolRegistry {
|
|
39
|
+
private readonly _logService;
|
|
40
|
+
private readonly _mcpUIEventService;
|
|
41
|
+
private readonly _tools;
|
|
42
|
+
constructor(_logService: ILogService, _mcpUIEventService: MCPUIEventService);
|
|
43
|
+
/**
|
|
44
|
+
* Register a tool for MCP calls
|
|
45
|
+
*/
|
|
46
|
+
registerTool(tool: IMCPTool): void;
|
|
47
|
+
/**
|
|
48
|
+
* Unregister a tool
|
|
49
|
+
*/
|
|
50
|
+
unregisterTool(toolName: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get a specific tool by name
|
|
53
|
+
*/
|
|
54
|
+
getTool(toolName: string): IMCPTool | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Get all registered tools
|
|
57
|
+
*/
|
|
58
|
+
getAllTools(): IMCPTool[];
|
|
59
|
+
/**
|
|
60
|
+
* Validate tool call parameters using Zod schema
|
|
61
|
+
*/
|
|
62
|
+
validateToolCall(toolName: string, params: unknown): {
|
|
63
|
+
isValid: boolean;
|
|
64
|
+
error?: string;
|
|
65
|
+
validatedParams?: any;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Execute a tool call with parameter validation
|
|
69
|
+
*/
|
|
70
|
+
executeTool(toolName: string, params: any, callId?: string): Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Register built-in tools
|
|
73
|
+
*/
|
|
74
|
+
private _registerBuiltInTools;
|
|
75
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IMCPTool } from '@univerjs-pro/mcp';
|
|
2
|
+
import { FUniver } from '@univerjs/core/facade';
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
interface IFUniverMCP {
|
|
7
|
+
/**
|
|
8
|
+
* Validate a tool call.
|
|
9
|
+
* @param toolName The name of the tool.
|
|
10
|
+
* @param params The parameters for the tool.
|
|
11
|
+
*/
|
|
12
|
+
validateMCPToolCall(toolName: string, params: unknown): {
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
validatedParams?: any;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Get all registered MCP tools.
|
|
19
|
+
*/
|
|
20
|
+
getAllMCPTools(): IMCPTool[];
|
|
21
|
+
/**
|
|
22
|
+
* Call a registered MCP tool.
|
|
23
|
+
* @param toolName The name of the tool.
|
|
24
|
+
* @param params The parameters for the tool.
|
|
25
|
+
*/
|
|
26
|
+
callMCPTool(toolName: string, params: unknown): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
export declare class FUniverMCPMixin extends FUniver implements IFUniverMCP {
|
|
29
|
+
validateMCPToolCall(toolName: string, params: unknown): {
|
|
30
|
+
isValid: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
validatedParams?: any;
|
|
33
|
+
};
|
|
34
|
+
getAllMCPTools(): IMCPTool[];
|
|
35
|
+
callMCPTool(toolName: string, params: unknown): Promise<any>;
|
|
36
|
+
}
|
|
37
|
+
declare module '@univerjs/core/facade' {
|
|
38
|
+
interface FUniver extends IFUniverMCP {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './f-univer';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { IUniverMCPConfig } from './controllers/config.schema';
|
|
2
|
+
export { MCP_PLUGIN_CONFIG_KEY, MCPConnectionError, MCPConnectionStatus } from './controllers/config.schema';
|
|
3
|
+
export { MCPConnectionController } from './controllers/mcp-connection.controller';
|
|
4
|
+
export { MCPMessageController } from './controllers/mcp-message.controller';
|
|
5
|
+
export { type IMCPTool, IMCPToolRegistry, MCPToolRegistryController } from './controllers/mcp-tool-registry.controller';
|
|
6
|
+
export { UniverMCPPlugin } from './plugin';
|
|
7
|
+
export { type IConfigUpdateEvent, type IConnectionStatusEvent, type IMCPUIEvent, type IToolCallEvent, type IToolExecutionEvent, MCPUIEventId, MCPUIEventService } from './services/mcp-ui-event.service';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IUniverMCPConfig } from './controllers/config.schema';
|
|
2
|
+
import { IConfigService, Injector, Plugin } from '@univerjs/core';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Agent (MCP Client / MCP Host) <-> Univer MCP Server Cloud <-> Univer MCP Plugin <-> Univer Instance
|
|
6
|
+
*
|
|
7
|
+
* Univer MCP Plugin is a bridge between Univer Instance and Univer MCP Server Cloud.
|
|
8
|
+
*
|
|
9
|
+
* What does this plugin do?
|
|
10
|
+
* 本插件为无UI部分,可以在node、browser等环节允许
|
|
11
|
+
* 业务逻辑在controllers实现
|
|
12
|
+
*
|
|
13
|
+
* 1. 开启安全校验时, 根据 api-key(从local-storage配置读取) /universer-api/user/session-ticket+(Authorization Bearer + api-key) 获取session-ticket
|
|
14
|
+
* 2. 根据session-ticket与Univer MCP Server Cloud /mcp-server-api/ws 建立连接
|
|
15
|
+
* 3. 意外断线时触发自动重连,最大重连次数3(成功清零),重复上述步骤
|
|
16
|
+
* 4. 提供管理(注册,注销) tool 的API, 本插件自身注册有一个 eval_js 的调试tool,使用Zod (已安装),参数是字符串,返回值描述Any。
|
|
17
|
+
* 其它插件如果需要注册自己的 tool,可以通过调用 API 来注册
|
|
18
|
+
* 4. 接收来自Univer MCP Server Cloud的 tool-call 消息并执行,校验tool-call消息是否合法,并将执行结果通过 websocket 返回
|
|
19
|
+
* 合法包括是否存在该名称的key,参数定义是否匹配。
|
|
20
|
+
*/
|
|
21
|
+
export declare class UniverMCPPlugin extends Plugin {
|
|
22
|
+
private readonly _config;
|
|
23
|
+
protected readonly _injector: Injector;
|
|
24
|
+
private readonly _configService;
|
|
25
|
+
static pluginName: string;
|
|
26
|
+
constructor(_config: IUniverMCPConfig | undefined, _injector: Injector, _configService: IConfigService);
|
|
27
|
+
onStarting(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MCPConnectionError, MCPConnectionStatus } from '../controllers/config.schema';
|
|
2
|
+
/**
|
|
3
|
+
* MCP UI event interface
|
|
4
|
+
*/
|
|
5
|
+
export interface IMCPUIEvent {
|
|
6
|
+
id: MCPUIEventId;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* MCP UI event IDs for communication between MCP and MCP UI
|
|
11
|
+
*/
|
|
12
|
+
export declare enum MCPUIEventId {
|
|
13
|
+
CONNECTION_STATUS_CHANGED = "CONNECTION_STATUS_CHANGED",
|
|
14
|
+
CONNECTION_ERROR = "CONNECTION_ERROR",
|
|
15
|
+
AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED",
|
|
16
|
+
SESSION_TICKET_EXPIRED = "SESSION_TICKET_EXPIRED",
|
|
17
|
+
TOOL_CALL_RECEIVED = "TOOL_CALL_RECEIVED",
|
|
18
|
+
TOOL_CALL_EXECUTED = "TOOL_CALL_EXECUTED",
|
|
19
|
+
TOOL_CALL_FAILED = "TOOL_CALL_FAILED",
|
|
20
|
+
CONFIG_UPDATED = "CONFIG_UPDATED",
|
|
21
|
+
API_KEY_UPDATED = "API_KEY_UPDATED"
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Connection status change event data
|
|
25
|
+
*/
|
|
26
|
+
export interface IConnectionStatusEvent {
|
|
27
|
+
status: MCPConnectionStatus;
|
|
28
|
+
error?: MCPConnectionError;
|
|
29
|
+
message?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tool call event data
|
|
33
|
+
*/
|
|
34
|
+
export interface IToolCallEvent {
|
|
35
|
+
toolName: string;
|
|
36
|
+
parameters: unknown;
|
|
37
|
+
callId?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Tool execution result event data
|
|
41
|
+
*/
|
|
42
|
+
export interface IToolExecutionEvent {
|
|
43
|
+
toolName: string;
|
|
44
|
+
callId?: string;
|
|
45
|
+
result?: unknown;
|
|
46
|
+
error?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Configuration update event data
|
|
50
|
+
*/
|
|
51
|
+
export interface IConfigUpdateEvent {
|
|
52
|
+
key: string;
|
|
53
|
+
value: unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* MCP UI Event Service
|
|
57
|
+
*
|
|
58
|
+
* This service provides event communication between MCP core plugin
|
|
59
|
+
* and MCP UI plugin, similar to CollaborationUIEventService.
|
|
60
|
+
*/
|
|
61
|
+
export declare class MCPUIEventService {
|
|
62
|
+
private readonly _event$;
|
|
63
|
+
readonly event$: import('rxjs').Observable<IMCPUIEvent>;
|
|
64
|
+
/**
|
|
65
|
+
* Emit an MCP UI event
|
|
66
|
+
*/
|
|
67
|
+
emitEvent(event: IMCPUIEvent): void;
|
|
68
|
+
/**
|
|
69
|
+
* Emit connection status change event
|
|
70
|
+
*/
|
|
71
|
+
emitConnectionStatus(status: MCPConnectionStatus, error?: MCPConnectionError, message?: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Emit tool call received event
|
|
74
|
+
*/
|
|
75
|
+
emitToolCallReceived(toolName: string, parameters: unknown, callId?: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Emit tool execution result event
|
|
78
|
+
*/
|
|
79
|
+
emitToolExecuted(toolName: string, callId?: string, result?: unknown, error?: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Emit configuration update event
|
|
82
|
+
*/
|
|
83
|
+
emitConfigUpdate(key: string, value: unknown): void;
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function _0x479a(_0x3989b9,_0x221fce){var _0x2273bf=_0x2273();return _0x479a=function(_0x479aa7,_0x4c5d82){_0x479aa7=_0x479aa7-0x187;var _0x1fc34d=_0x2273bf[_0x479aa7];return _0x1fc34d;},_0x479a(_0x3989b9,_0x221fce);}function _0x2273(){var _0x5c479e=['29264ffFKne','651EFcqzo','UniverCoreFacade','87831BWfGIy','getAllTools','301913NEsHDL','validateToolCall','executeTool','IMCPToolRegistry','4160732WUNkJW','59075196pCMjPu','UniverProMcp','@univerjs/core/facade','callMCPTool','_injector','3TQRuIF','12142174OvvsRO','extend','7497295ZEngwO','6eooRbl','function','10gyHxKs','object','FUniver','13vdlrfd','get','validateMCPToolCall','890uVsOAB'];_0x2273=function(){return _0x5c479e;};return _0x2273();}(function(_0x1c8db1,_0x163068){var _0x35afe6=_0x479a,_0x1977bb=_0x1c8db1();while(!![]){try{var _0x459683=-parseInt(_0x35afe6(0x199))/0x1*(parseInt(_0x35afe6(0x18d))/0x2)+-parseInt(_0x35afe6(0x187))/0x3*(parseInt(_0x35afe6(0x19d))/0x4)+parseInt(_0x35afe6(0x18a))/0x5*(-parseInt(_0x35afe6(0x18b))/0x6)+parseInt(_0x35afe6(0x195))/0x7*(-parseInt(_0x35afe6(0x194))/0x8)+parseInt(_0x35afe6(0x197))/0x9*(-parseInt(_0x35afe6(0x193))/0xa)+parseInt(_0x35afe6(0x188))/0xb+-parseInt(_0x35afe6(0x19e))/0xc*(-parseInt(_0x35afe6(0x190))/0xd);if(_0x459683===_0x163068)break;else _0x1977bb['push'](_0x1977bb['shift']());}catch(_0x471a6e){_0x1977bb['push'](_0x1977bb['shift']());}}}(_0x2273,0xbbb2f),function(_0x19607d,_0x577561){var _0x347f77=_0x479a;typeof exports==_0x347f77(0x18e)&&typeof module<'u'?_0x577561(require('@univerjs-pro/mcp'),require('@univerjs/core/facade')):typeof define==_0x347f77(0x18c)&&define['amd']?define(['@univerjs-pro/mcp',_0x347f77(0x1a0)],_0x577561):(_0x19607d=typeof globalThis<'u'?globalThis:_0x19607d||self,_0x577561(_0x19607d[_0x347f77(0x19f)],_0x19607d[_0x347f77(0x196)]));}(this,function(_0x39785b,_0x2ee111){'use strict';var _0x4c1b5b=_0x479a;class _0x1f1cda extends _0x2ee111[_0x4c1b5b(0x18f)]{[_0x4c1b5b(0x192)](_0x3fbed1,_0x75d419){var _0x232be7=_0x4c1b5b;return this[_0x232be7(0x1a2)][_0x232be7(0x191)](_0x39785b['IMCPToolRegistry'])[_0x232be7(0x19a)](_0x3fbed1,_0x75d419);}['getAllMCPTools'](){var _0x435467=_0x4c1b5b;return this['_injector'][_0x435467(0x191)](_0x39785b[_0x435467(0x19c)])[_0x435467(0x198)]();}[_0x4c1b5b(0x1a1)](_0x42ff63,_0x4c80fa){var _0xe7865e=_0x4c1b5b;return this[_0xe7865e(0x1a2)][_0xe7865e(0x191)](_0x39785b['IMCPToolRegistry'])[_0xe7865e(0x19b)](_0x42ff63,_0x4c80fa);}}_0x2ee111['FUniver'][_0x4c1b5b(0x189)](_0x1f1cda);}));
|