-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathapi.ts
More file actions
486 lines (429 loc) · 10.6 KB
/
Copy pathapi.ts
File metadata and controls
486 lines (429 loc) · 10.6 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
// Re-export common types from contracts (generated from Go constants)
export type { APIResponse, HealthStatus, HealthLevel, AdminState, HealthAction } from './contracts'
export {
HealthLevelHealthy,
HealthLevelDegraded,
HealthLevelUnhealthy,
AdminStateEnabled,
AdminStateDisabled,
AdminStateQuarantined,
HealthActionNone,
HealthActionLogin,
HealthActionRestart,
HealthActionEnable,
HealthActionApprove,
HealthActionViewLogs,
HealthActionSetSecret,
HealthActionConfigure,
} from './contracts'
// Import HealthStatus for use in this file
import type { HealthStatus } from './contracts'
// Server types
export interface Server {
name: string
url?: string
command?: string
protocol: 'http' | 'stdio' | 'streamable-http'
enabled: boolean
quarantined: boolean
connected: boolean
connecting: boolean
authenticated?: boolean
tool_count: number
last_error?: string
tool_list_token_size?: number
oauth?: {
client_id: string
auth_url: string
token_url: string
}
oauth_status?: 'authenticated' | 'expired' | 'error' | 'none'
token_expires_at?: string
user_logged_out?: boolean // True if user explicitly logged out (prevents auto-reconnection)
health?: HealthStatus // Unified health status calculated by the backend
}
// Tool Annotation types
export interface ToolAnnotation {
title?: string
readOnlyHint?: boolean
destructiveHint?: boolean
idempotentHint?: boolean
openWorldHint?: boolean
}
// MCP Session types
export interface MCPSession {
id: string
client_name?: string
client_version?: string
status: 'active' | 'closed'
start_time: string // ISO 8601
end_time?: string // ISO 8601
last_activity: string // ISO 8601
tool_call_count: number
total_tokens: number
// MCP Client Capabilities
has_roots?: boolean
has_sampling?: boolean
experimental?: string[]
}
// Tool types
export interface Tool {
name: string
description: string
server: string
input_schema?: Record<string, any>
annotations?: ToolAnnotation
}
// Tool approval types (Spec 032)
export interface ToolApproval {
server_name: string
tool_name: string
status: 'pending' | 'approved' | 'changed'
hash: string
description: string
schema?: string
approved_hash?: string
current_hash?: string
previous_description?: string
current_description?: string
previous_schema?: string
current_schema?: string
}
// Search result types
export interface SearchResult {
tool: {
name: string
description: string
server_name: string
input_schema?: Record<string, any>
usage?: number
last_used?: string
}
score: number
snippet?: string
matches: number
}
// Status types
export interface StatusUpdate {
running: boolean
listen_addr: string
routing_mode?: string
upstream_stats: {
connected_servers: number
total_servers: number
total_tools: number
}
status: Record<string, any>
timestamp: number
}
// Routing mode types
export interface RoutingInfo {
routing_mode: string
description: string
endpoints: {
default: string
direct: string
code_execution: string
retrieve_tools: string
}
available_modes: string[]
}
// Dashboard stats
export interface DashboardStats {
servers: {
total: number
connected: number
enabled: number
quarantined: number
}
tools: {
total: number
available: number
}
system: {
uptime: string
version: string
memory_usage?: string
}
}
// Secret management types
export interface SecretRef {
type: string // "env", "keyring", etc.
name: string // The secret name/key
original: string // Original reference string like "${env:API_KEY}"
}
export interface MigrationCandidate {
field: string // Field path in configuration
value: string // Masked value for display
suggested: string // Suggested secret reference
confidence: number // Confidence score (0.0 to 1.0)
migrating?: boolean // UI state for migration in progress
}
export interface MigrationAnalysis {
candidates: MigrationCandidate[]
total_found: number
}
export interface EnvVarStatus {
secret_ref: SecretRef
is_set: boolean
}
export interface KeyringSecretStatus {
secret_ref: SecretRef
is_set: boolean
}
export interface ConfigSecretsResponse {
secrets: KeyringSecretStatus[]
environment_vars: EnvVarStatus[]
total_secrets: number
total_env_vars: number
}
// Tool Call History types
export interface TokenMetrics {
input_tokens: number // Tokens in the request
output_tokens: number // Tokens in the response
total_tokens: number // Total tokens (input + output)
model: string // Model used for tokenization
encoding: string // Encoding used (e.g., cl100k_base)
estimated_cost?: number // Optional cost estimate
truncated_tokens?: number // Tokens removed by truncation
was_truncated: boolean // Whether response was truncated
}
export interface ServerTokenMetrics {
total_server_tool_list_size: number
average_query_result_size: number
saved_tokens: number
saved_tokens_percentage: number
per_server_tool_list_sizes: Record<string, number>
}
export interface ToolCallRecord {
id: string
server_id: string
server_name: string
tool_name: string
arguments: Record<string, any>
response?: any
error?: string
duration: number // nanoseconds
timestamp: string // ISO 8601 date string
config_path: string
request_id?: string
metrics?: TokenMetrics // Token usage metrics (optional for older records)
parent_call_id?: string // Links nested calls to parent code_execution
execution_type?: string // "direct" or "code_execution"
mcp_session_id?: string // MCP session identifier
mcp_client_name?: string // MCP client name from InitializeRequest
mcp_client_version?: string // MCP client version
annotations?: ToolAnnotation // Tool behavior hints snapshot
}
export interface GetToolCallsResponse {
tool_calls: ToolCallRecord[]
total: number
limit: number
offset: number
}
export interface GetToolCallDetailResponse {
tool_call: ToolCallRecord
}
export interface GetServerToolCallsResponse {
server_name: string
tool_calls: ToolCallRecord[]
total: number
}
// Session response types
export interface GetSessionsResponse {
sessions: MCPSession[]
total: number
limit: number
offset: number
}
export interface GetSessionDetailResponse {
session: MCPSession
}
// Configuration management types
export interface ValidationError {
field: string
message: string
}
export interface ConfigApplyResult {
success: boolean
applied_immediately: boolean
requires_restart: boolean
restart_reason?: string
validation_errors?: ValidationError[]
changed_fields?: string[]
}
export interface GetConfigResponse {
config: any // The full configuration object
config_path: string
}
export interface ValidateConfigRequest {
config: any
}
export interface ValidateConfigResponse {
valid: boolean
errors?: ValidationError[]
}
export interface ApplyConfigRequest {
config: any
}
// Registry browsing types (Phase 7)
export interface Registry {
id: string
name: string
description: string
url: string
servers_url?: string
tags?: string[]
protocol?: string
count?: number | string
}
export interface NPMPackageInfo {
exists: boolean
install_cmd: string
}
export interface RepositoryInfo {
npm?: NPMPackageInfo
// Future: pypi, docker_hub, etc.
}
export interface RepositoryServer {
id: string
name: string
description: string
url?: string // MCP endpoint for remote servers only
source_code_url?: string // Source repository URL
installCmd?: string // Installation command
connectUrl?: string // Alternative connection URL
updatedAt?: string
createdAt?: string
registry?: string // Which registry this came from
repository_info?: RepositoryInfo // Detected package info
}
export interface GetRegistriesResponse {
registries: Registry[]
total: number
}
export interface SearchRegistryServersResponse {
registry_id: string
servers: RepositoryServer[]
total: number
query?: string
tag?: string
}
// Activity Log types (RFC-003)
export type ActivityType =
| 'tool_call'
| 'policy_decision'
| 'quarantine_change'
| 'server_change'
export type ActivitySource = 'mcp' | 'cli' | 'api'
export type ActivityStatus = 'success' | 'error' | 'blocked'
export interface ActivityRecord {
id: string
type: ActivityType
source?: ActivitySource
server_name?: string
tool_name?: string
arguments?: Record<string, any>
response?: string
response_truncated?: boolean
status: ActivityStatus
error_message?: string
duration_ms?: number
timestamp: string
session_id?: string
request_id?: string
metadata?: Record<string, any>
// Spec 026: Sensitive data detection fields
has_sensitive_data?: boolean
detection_types?: string[]
max_severity?: 'critical' | 'high' | 'medium' | 'low'
}
export interface ActivityListResponse {
activities: ActivityRecord[]
total: number
limit: number
offset: number
}
export interface ActivityDetailResponse {
activity: ActivityRecord
}
export interface ActivityTopServer {
name: string
count: number
}
export interface ActivityTopTool {
server: string
tool: string
count: number
}
export interface ActivitySummaryResponse {
period: string
total_count: number
success_count: number
error_count: number
blocked_count: number
top_servers?: ActivityTopServer[]
top_tools?: ActivityTopTool[]
start_time: string
end_time: string
}
// Agent Token types (Spec 028)
export interface AgentTokenInfo {
name: string
token_prefix: string
allowed_servers: string[]
permissions: string[]
expires_at: string
created_at: string
last_used_at: string | null
revoked: boolean
}
export interface CreateAgentTokenRequest {
name: string
allowed_servers: string[]
permissions: string[]
expires_in?: string
}
export interface CreateAgentTokenResponse {
name: string
token: string
allowed_servers: string[]
permissions: string[]
expires_at: string
created_at: string
}
// Import server configuration types
export interface ImportSummary {
total: number
imported: number
skipped: number
failed: number
}
export interface ImportedServer {
name: string
protocol: string
url?: string
command?: string
args?: string[]
source_format: string
original_name: string
fields_skipped?: string[]
warnings?: string[]
}
export interface SkippedServer {
name: string
reason: string
}
export interface FailedServer {
name: string
error: string
}
export interface ImportResponse {
format: string
format_name: string
summary: ImportSummary
imported: ImportedServer[]
skipped: SkippedServer[]
failed: FailedServer[]
warnings: string[]
}