-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgateway.ts
More file actions
229 lines (201 loc) · 5.79 KB
/
Copy pathgateway.ts
File metadata and controls
229 lines (201 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import { invoke } from '@tauri-apps/api/core';
/**
* Gateway status.
*/
export interface GatewayStatus {
running: boolean;
url: string | null;
active_sessions: number;
connected_backends: number;
}
/**
* Config export format.
*/
export type ExportFormat = 'cursor' | 'vscode' | 'claude';
/**
* Get gateway status.
*/
export async function getGatewayStatus(spaceId?: string): Promise<GatewayStatus> {
return invoke('get_gateway_status', { spaceId });
}
/**
* Start the gateway server.
*/
export async function startGateway(port?: number): Promise<string> {
return invoke('start_gateway', { port });
}
/**
* Stop the gateway server.
*/
export async function stopGateway(): Promise<void> {
return invoke('stop_gateway');
}
/**
* Restart the gateway server.
*/
export async function restartGateway(): Promise<string> {
return invoke('restart_gateway');
}
/**
* Export config for a client.
*/
export async function exportConfig(
format: ExportFormat,
clientId?: string
): Promise<string> {
return invoke('export_config', { format, clientId });
}
/**
* Backend server status.
*/
export interface BackendStatus {
id: string;
name: string;
status: string;
tools_count: number;
}
/**
* Connect an installed server to the gateway.
*/
export async function connectServer(serverId: string): Promise<void> {
return invoke('connect_server', { serverId });
}
/**
* Disconnect a server from the gateway.
* @param serverId - The server ID to disconnect
* @param spaceId - The space ID (required for proper space isolation)
* @param logout - If true, also delete stored credentials (OAuth tokens)
*/
export async function disconnectServer(serverId: string, spaceId: string, logout?: boolean): Promise<void> {
return invoke('disconnect_server', { serverId, spaceId, logout });
}
/**
* List all connected backend servers.
*/
export async function listConnectedServers(): Promise<BackendStatus[]> {
return invoke('list_connected_servers');
}
/**
* Inbound client registration type (per MCP spec 2025-11-25)
*/
export type RegistrationType = 'cimd' | 'dcr' | 'preregistered';
/**
* Inbound client (unified OAuth + MCP model)
*
* Represents apps connecting TO McpMux (e.g., Cursor, VS Code, Claude Desktop).
* Supports three MCP registration approaches:
* - CIMD: Client ID Metadata Documents (client_id is a URL)
* - DCR: Dynamic Client Registration (server generates client_id)
* - Preregistered: Server pre-configures client_id
*
* Per RFC 7591, clients self-identify via metadata they provide.
* Use `logo_uri`, `software_id`, and `client_name` for client identification.
*/
export interface OAuthClient {
client_id: string;
registration_type: RegistrationType;
client_name: string;
client_alias: string | null;
redirect_uris: string[];
scope: string | null;
// Approval status - true if user has explicitly approved this client
approved: boolean;
// RFC 7591 Client Metadata (use these for client identification)
logo_uri?: string | null; // URL for client's logo
client_uri?: string | null; // URL of client's homepage
software_id?: string | null; // Unique identifier (e.g., "com.cursor.app")
software_version?: string | null; // Client software version
// CIMD-specific fields (only used when registration_type='cimd')
metadata_url?: string | null; // URL where metadata was fetched
metadata_cached_at?: string | null; // When we last fetched
metadata_cache_ttl?: number | null; // Cache duration in seconds
// MCP client preferences
connection_mode: string;
locked_space_id: string | null;
last_seen: string | null;
created_at: string;
}
/**
* Update client settings request.
*/
export interface UpdateClientRequest {
client_alias?: string;
connection_mode?: 'follow_active' | 'locked' | 'ask_on_change';
locked_space_id?: string | null;
}
/**
* List all registered OAuth clients (Cursor, Claude, etc.)
*/
export async function listOAuthClients(): Promise<OAuthClient[]> {
return invoke('get_oauth_clients');
}
/**
* Update an OAuth client's settings.
*/
export async function updateOAuthClient(
clientId: string,
settings: UpdateClientRequest
): Promise<OAuthClient> {
return invoke('update_oauth_client', { clientId, settings });
}
/**
* Delete an OAuth client.
*/
export async function deleteOAuthClient(clientId: string): Promise<void> {
return invoke('delete_oauth_client', { clientId });
}
/**
* Result of bulk server connection.
*/
export interface BulkConnectResult {
connected: number;
reused: number;
failed: number;
oauth_required: number;
errors: string[];
}
/**
* Connect all enabled servers from all spaces.
* This is typically called on gateway startup.
*/
export async function connectAllEnabledServers(): Promise<BulkConnectResult> {
return invoke('connect_all_enabled_servers');
}
/**
* Pool statistics.
*/
export interface PoolStats {
total_instances: number;
connected_instances: number;
total_space_server_mappings: number;
}
/**
* Get server pool statistics.
*/
export async function getPoolStats(): Promise<PoolStats> {
return invoke('get_pool_stats');
}
/**
* Result of OAuth token refresh operation.
*/
export interface RefreshResult {
servers_checked: number;
tokens_refreshed: number;
refresh_failed: number;
}
/**
* Refresh OAuth tokens on startup for all installed HTTP servers.
* This should be called during app initialization before connecting to servers.
*/
export async function refreshOAuthTokensOnStartup(): Promise<RefreshResult> {
return invoke('refresh_oauth_tokens_on_startup');
}
/**
* Open a URL using the system's default handler.
*
* This is needed for custom protocol URLs (like `cursor://`) that
* the webview's opener plugin may not be allowed to open directly.
*/
export async function openUrl(url: string): Promise<void> {
return invoke('open_url', { url });
}