@1mcp/agent 0.35.0-beta.4 → 0.35.0
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/build/admin/assets/{admin-AboutRuntimeWorkspace-CM2ZafTJ.js → admin-AboutRuntimeWorkspace-DH2QC2nJ.js} +1 -1
- package/build/admin/assets/admin-BackendLogsWorkspace-BKavXT9B.js +1 -0
- package/build/admin/assets/admin-InstructionTemplatesWorkspace-CvG4EPdZ.js +1 -0
- package/build/admin/assets/admin-OAuthServicesWorkspace-B8y2weAX.js +1 -0
- package/build/admin/assets/admin-PresetAuthoringWorkspace-BboJVBFl.js +1 -0
- package/build/admin/assets/admin-console-D6jyI73o.css +1 -0
- package/build/admin/assets/admin-console-HJH52xGP.js +3 -0
- package/build/admin/assets/admin-icons-CYGTDZA5.js +1 -0
- package/build/admin/assets/admin-mantine-xwbfu5Gd.js +53 -0
- package/build/admin/index.html +4 -4
- package/build/auth/sdkOAuthClientProvider.d.ts +4 -0
- package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -1
- package/build/auth/sdkOAuthClientProvider.js +29 -0
- package/build/auth/sdkOAuthClientProvider.js.map +1 -1
- package/build/commands/instructions/instructions.d.ts.map +1 -1
- package/build/commands/instructions/instructions.js +56 -1
- package/build/commands/instructions/instructions.js.map +1 -1
- package/build/commands/mcp/add.js +2 -2
- package/build/commands/mcp/add.js.map +1 -1
- package/build/commands/mcp/list.js +1 -1
- package/build/commands/mcp/list.js.map +1 -1
- package/build/commands/mcp/update.js +1 -1
- package/build/commands/mcp/update.js.map +1 -1
- package/build/commands/shared/serveTargetResolver.d.ts.map +1 -1
- package/build/commands/shared/serveTargetResolver.js +17 -22
- package/build/commands/shared/serveTargetResolver.js.map +1 -1
- package/build/config/configManager.d.ts +11 -1
- package/build/config/configManager.d.ts.map +1 -1
- package/build/config/configManager.js +13 -0
- package/build/config/configManager.js.map +1 -1
- package/build/config/configuredServerTargets.d.ts +3 -0
- package/build/config/configuredServerTargets.d.ts.map +1 -0
- package/build/config/configuredServerTargets.js +8 -0
- package/build/config/configuredServerTargets.js.map +1 -0
- package/build/config/mcpConfigManager.d.ts +3 -0
- package/build/config/mcpConfigManager.d.ts.map +1 -1
- package/build/config/mcpConfigManager.js +15 -0
- package/build/config/mcpConfigManager.js.map +1 -1
- package/build/constants/api.d.ts +1 -0
- package/build/constants/api.d.ts.map +1 -1
- package/build/constants/api.js +1 -0
- package/build/constants/api.js.map +1 -1
- package/build/constants/mcp.d.ts +1 -1
- package/build/constants/mcp.d.ts.map +1 -1
- package/build/constants/mcp.js +1 -1
- package/build/constants/mcp.js.map +1 -1
- package/build/core/capabilities/capabilityAggregator.d.ts.map +1 -1
- package/build/core/capabilities/capabilityAggregator.js +33 -14
- package/build/core/capabilities/capabilityAggregator.js.map +1 -1
- package/build/core/capabilities/capabilityCatalog.d.ts +1 -1
- package/build/core/capabilities/capabilityCatalog.d.ts.map +1 -1
- package/build/core/capabilities/capabilityCatalog.js +19 -7
- package/build/core/capabilities/capabilityCatalog.js.map +1 -1
- package/build/core/capabilities/capabilityPagination.d.ts.map +1 -1
- package/build/core/capabilities/capabilityPagination.js +2 -0
- package/build/core/capabilities/capabilityPagination.js.map +1 -1
- package/build/core/capabilities/configuredToolSnapshot.d.ts +12 -0
- package/build/core/capabilities/configuredToolSnapshot.d.ts.map +1 -0
- package/build/core/capabilities/configuredToolSnapshot.js +98 -0
- package/build/core/capabilities/configuredToolSnapshot.js.map +1 -0
- package/build/core/capabilities/lazyLoadingOrchestrator.d.ts.map +1 -1
- package/build/core/capabilities/lazyLoadingOrchestrator.js +8 -4
- package/build/core/capabilities/lazyLoadingOrchestrator.js.map +1 -1
- package/build/core/capabilities/metaToolProvider.js +3 -3
- package/build/core/capabilities/metaToolProvider.js.map +1 -1
- package/build/core/client/clientManager.js +6 -6
- package/build/core/client/clientManager.js.map +1 -1
- package/build/core/client/postAuthOAuthRecovery.d.ts +6 -0
- package/build/core/client/postAuthOAuthRecovery.d.ts.map +1 -0
- package/build/core/client/postAuthOAuthRecovery.js +74 -0
- package/build/core/client/postAuthOAuthRecovery.js.map +1 -0
- package/build/core/configChangeHandler.d.ts +2 -0
- package/build/core/configChangeHandler.d.ts.map +1 -1
- package/build/core/configChangeHandler.js +38 -11
- package/build/core/configChangeHandler.js.map +1 -1
- package/build/core/instructions/effectiveServerInstructions.d.ts +17 -0
- package/build/core/instructions/effectiveServerInstructions.d.ts.map +1 -0
- package/build/core/instructions/effectiveServerInstructions.js +12 -0
- package/build/core/instructions/effectiveServerInstructions.js.map +1 -0
- package/build/core/instructions/instructionAggregator.d.ts +51 -2
- package/build/core/instructions/instructionAggregator.d.ts.map +1 -1
- package/build/core/instructions/instructionAggregator.js +191 -30
- package/build/core/instructions/instructionAggregator.js.map +1 -1
- package/build/core/instructions/instructionsDistribution.d.ts +53 -0
- package/build/core/instructions/instructionsDistribution.d.ts.map +1 -1
- package/build/core/instructions/instructionsDistribution.js +25 -0
- package/build/core/instructions/instructionsDistribution.js.map +1 -1
- package/build/core/instructions/templateTypes.d.ts +25 -3
- package/build/core/instructions/templateTypes.d.ts.map +1 -1
- package/build/core/instructions/templateTypes.js +45 -0
- package/build/core/instructions/templateTypes.js.map +1 -1
- package/build/core/protocol/requestHandlerUtils.d.ts.map +1 -1
- package/build/core/protocol/requestHandlerUtils.js +3 -3
- package/build/core/protocol/requestHandlerUtils.js.map +1 -1
- package/build/core/protocol/toolRequestHandlers.d.ts.map +1 -1
- package/build/core/protocol/toolRequestHandlers.js +18 -5
- package/build/core/protocol/toolRequestHandlers.js.map +1 -1
- package/build/core/server/clientInstancePool.js +2 -2
- package/build/core/server/clientInstancePool.js.map +1 -1
- package/build/core/server/disabledTools.d.ts +2 -0
- package/build/core/server/disabledTools.d.ts.map +1 -1
- package/build/core/server/disabledTools.js +7 -4
- package/build/core/server/disabledTools.js.map +1 -1
- package/build/core/server/serverManager.d.ts.map +1 -1
- package/build/core/server/serverManager.js +1 -0
- package/build/core/server/serverManager.js.map +1 -1
- package/build/core/server/templateIdentity.d.ts +1 -0
- package/build/core/server/templateIdentity.d.ts.map +1 -1
- package/build/core/server/templateIdentity.js +11 -1
- package/build/core/server/templateIdentity.js.map +1 -1
- package/build/core/server/templateServerManager.d.ts +5 -1
- package/build/core/server/templateServerManager.d.ts.map +1 -1
- package/build/core/server/templateServerManager.js +26 -10
- package/build/core/server/templateServerManager.js.map +1 -1
- package/build/core/server/toolDescriptionOverrides.d.ts +9 -0
- package/build/core/server/toolDescriptionOverrides.d.ts.map +1 -0
- package/build/core/server/toolDescriptionOverrides.js +44 -0
- package/build/core/server/toolDescriptionOverrides.js.map +1 -0
- package/build/core/tools/handlers/serverManagementHandler.d.ts +15 -1
- package/build/core/tools/handlers/serverManagementHandler.d.ts.map +1 -1
- package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts +2 -0
- package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts.map +1 -1
- package/build/core/tools/internal/schemas/discovery.d.ts +1 -1
- package/build/core/tools/internal/schemas/index.d.ts +2 -2
- package/build/core/tools/internal/schemas/management.d.ts +1 -1
- package/build/core/types/transport.d.ts +33 -0
- package/build/core/types/transport.d.ts.map +1 -1
- package/build/core/types/transport.js +55 -1
- package/build/core/types/transport.js.map +1 -1
- package/build/domains/admin/adminConfiguredServerService.d.ts +51 -4
- package/build/domains/admin/adminConfiguredServerService.d.ts.map +1 -1
- package/build/domains/admin/adminConfiguredServerService.js +259 -38
- package/build/domains/admin/adminConfiguredServerService.js.map +1 -1
- package/build/domains/admin/adminDomain.d.ts +13 -0
- package/build/domains/admin/adminDomain.d.ts.map +1 -1
- package/build/domains/admin/adminDomain.js +16 -0
- package/build/domains/admin/adminDomain.js.map +1 -1
- package/build/domains/admin/adminInstructionPreviewRuntime.d.ts +7 -0
- package/build/domains/admin/adminInstructionPreviewRuntime.d.ts.map +1 -0
- package/build/domains/admin/adminInstructionPreviewRuntime.js +154 -0
- package/build/domains/admin/adminInstructionPreviewRuntime.js.map +1 -0
- package/build/domains/admin/adminInstructionTemplateService.d.ts +169 -0
- package/build/domains/admin/adminInstructionTemplateService.d.ts.map +1 -0
- package/build/domains/admin/adminInstructionTemplateService.js +181 -0
- package/build/domains/admin/adminInstructionTemplateService.js.map +1 -0
- package/build/domains/admin/configuredToolInventory.d.ts +46 -0
- package/build/domains/admin/configuredToolInventory.d.ts.map +1 -0
- package/build/domains/admin/configuredToolInventory.js +135 -0
- package/build/domains/admin/configuredToolInventory.js.map +1 -0
- package/build/domains/config-change/configChange.d.ts +1 -1
- package/build/domains/config-change/configChange.d.ts.map +1 -1
- package/build/domains/config-change/configChange.js +153 -13
- package/build/domains/config-change/configChange.js.map +1 -1
- package/build/domains/config-change/types.d.ts +30 -2
- package/build/domains/config-change/types.d.ts.map +1 -1
- package/build/domains/instruction-template/instructionTemplateManager.d.ts +58 -0
- package/build/domains/instruction-template/instructionTemplateManager.d.ts.map +1 -0
- package/build/domains/instruction-template/instructionTemplateManager.js +167 -0
- package/build/domains/instruction-template/instructionTemplateManager.js.map +1 -0
- package/build/domains/runtime-targets/runtimeIdentityVerification.d.ts +1 -0
- package/build/domains/runtime-targets/runtimeIdentityVerification.d.ts.map +1 -1
- package/build/domains/runtime-targets/runtimeIdentityVerification.js +6 -5
- package/build/domains/runtime-targets/runtimeIdentityVerification.js.map +1 -1
- package/build/transport/http/routes/adminRoutes.d.ts +2 -0
- package/build/transport/http/routes/adminRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/adminRoutes.js +293 -9
- package/build/transport/http/routes/adminRoutes.js.map +1 -1
- package/build/transport/http/routes/apiRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/apiRoutes.js +2 -0
- package/build/transport/http/routes/apiRoutes.js.map +1 -1
- package/build/transport/http/routes/inspectRequestContext.d.ts +2 -0
- package/build/transport/http/routes/inspectRequestContext.d.ts.map +1 -1
- package/build/transport/http/routes/inspectRequestContext.js +2 -2
- package/build/transport/http/routes/inspectRequestContext.js.map +1 -1
- package/build/transport/http/routes/inspectRoutes.d.ts +9 -0
- package/build/transport/http/routes/inspectRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/inspectRoutes.js +15 -10
- package/build/transport/http/routes/inspectRoutes.js.map +1 -1
- package/build/transport/http/routes/instructionsRoutes.d.ts +4 -0
- package/build/transport/http/routes/instructionsRoutes.d.ts.map +1 -0
- package/build/transport/http/routes/instructionsRoutes.js +147 -0
- package/build/transport/http/routes/instructionsRoutes.js.map +1 -0
- package/build/transport/http/routes/toolRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/toolRoutes.js +5 -4
- package/build/transport/http/routes/toolRoutes.js.map +1 -1
- package/build/transport/http/server.d.ts.map +1 -1
- package/build/transport/http/server.js +17 -0
- package/build/transport/http/server.js.map +1 -1
- package/build/utils/validation/discoveredServer.d.ts +15 -0
- package/build/utils/validation/discoveredServer.d.ts.map +1 -0
- package/build/utils/validation/discoveredServer.js +2 -0
- package/build/utils/validation/discoveredServer.js.map +1 -0
- package/build/utils/validation/urlDetection.d.ts +4 -5
- package/build/utils/validation/urlDetection.d.ts.map +1 -1
- package/build/utils/validation/urlDetection.js +94 -25
- package/build/utils/validation/urlDetection.js.map +1 -1
- package/package.json +2 -2
- package/build/admin/assets/admin-BackendLogsWorkspace-CvJs1npx.js +0 -1
- package/build/admin/assets/admin-OAuthServicesWorkspace-BswG57Gm.js +0 -1
- package/build/admin/assets/admin-PresetAuthoringWorkspace-BIIRs_EN.js +0 -1
- package/build/admin/assets/admin-console-Brz9bnhv.css +0 -1
- package/build/admin/assets/admin-console-MT8QZmIC.js +0 -3
- package/build/admin/assets/admin-icons-D-JtMXSq.js +0 -1
- package/build/admin/assets/admin-mantine-DSFdoMaN.js +0 -53
|
@@ -6,6 +6,7 @@ import { MCP_PROJECT_METADATA } from '../../../constants.js';
|
|
|
6
6
|
import { parseTemplateConnectionKey } from '../../../core/server/templateIdentity.js';
|
|
7
7
|
import { AdminConfiguredServerApplyError, AdminConfiguredServerNotFoundError, } from '../../../domains/admin/adminConfiguredServerService.js';
|
|
8
8
|
import { ADMIN_SESSION_COOKIE_NAME, AdminIdentityError, } from '../../../domains/admin/adminIdentityService.js';
|
|
9
|
+
import { AdminInstructionTemplateNotFoundError, } from '../../../domains/admin/adminInstructionTemplateService.js';
|
|
9
10
|
import { AdminPresetConflictError, AdminPresetNotFoundError, } from '../../../domains/admin/adminPresetService.js';
|
|
10
11
|
import { sensitiveOperationLimiter } from '../../../transport/http/middlewares/securityMiddleware.js';
|
|
11
12
|
import { sanitizeErrorMessage } from '../../../utils/validation/sanitization.js';
|
|
@@ -40,6 +41,7 @@ const adminOAuthServiceParamsSchema = z.object({
|
|
|
40
41
|
const backendLogSnapshotQuerySchema = z.object({
|
|
41
42
|
sourceId: z.string().trim().min(1).max(256).optional(),
|
|
42
43
|
});
|
|
44
|
+
const configuredServerModelSchema = z.string().trim().min(1).max(64);
|
|
43
45
|
const cliConfiguredServerMutationBodySchema = z.object({
|
|
44
46
|
targetName: z.string().trim().min(1).max(256),
|
|
45
47
|
dryRun: z.boolean().optional(),
|
|
@@ -53,6 +55,67 @@ const cliBackendRestartBodySchema = z
|
|
|
53
55
|
.refine((value) => !(value.instance !== undefined && value.allInstances === true), {
|
|
54
56
|
message: 'instance and allInstances are mutually exclusive',
|
|
55
57
|
});
|
|
58
|
+
const instructionTemplateIdentitySchema = z.string().trim().min(1).max(128);
|
|
59
|
+
const instructionTemplateVariantsSchema = z.object({ initialization: z.string(), cli: z.string() }).strict();
|
|
60
|
+
const instructionPreviewSelectionSchema = z.discriminatedUnion('mode', [
|
|
61
|
+
z.object({ mode: z.literal('all') }).strict(),
|
|
62
|
+
z.object({ mode: z.literal('preset'), preset: z.string().trim().min(1).max(128) }).strict(),
|
|
63
|
+
z.object({ mode: z.literal('tags'), tags: z.array(z.string().trim().min(1).max(128)).max(256) }).strict(),
|
|
64
|
+
z.object({ mode: z.literal('tag-filter'), expression: z.string().trim().min(1).max(4096) }).strict(),
|
|
65
|
+
]);
|
|
66
|
+
const requestContextSchema = z
|
|
67
|
+
.object({
|
|
68
|
+
project: z
|
|
69
|
+
.object({
|
|
70
|
+
path: z.string().optional(),
|
|
71
|
+
cwd: z.string().optional(),
|
|
72
|
+
name: z.string().optional(),
|
|
73
|
+
environment: z.string().optional(),
|
|
74
|
+
custom: z.record(z.string(), z.unknown()).optional(),
|
|
75
|
+
git: z
|
|
76
|
+
.object({
|
|
77
|
+
branch: z.string().optional(),
|
|
78
|
+
commit: z.string().optional(),
|
|
79
|
+
repository: z.string().optional(),
|
|
80
|
+
isRepo: z.boolean().optional(),
|
|
81
|
+
})
|
|
82
|
+
.strict()
|
|
83
|
+
.optional(),
|
|
84
|
+
})
|
|
85
|
+
.strict(),
|
|
86
|
+
user: z
|
|
87
|
+
.object({
|
|
88
|
+
name: z.string().optional(),
|
|
89
|
+
email: z.string().optional(),
|
|
90
|
+
home: z.string().optional(),
|
|
91
|
+
username: z.string().optional(),
|
|
92
|
+
uid: z.string().optional(),
|
|
93
|
+
gid: z.string().optional(),
|
|
94
|
+
shell: z.string().optional(),
|
|
95
|
+
})
|
|
96
|
+
.strict(),
|
|
97
|
+
environment: z
|
|
98
|
+
.object({
|
|
99
|
+
variables: z.record(z.string(), z.string()).optional(),
|
|
100
|
+
prefixes: z.array(z.string()).optional(),
|
|
101
|
+
})
|
|
102
|
+
.strict(),
|
|
103
|
+
timestamp: z.string().optional(),
|
|
104
|
+
sessionId: z.string().optional(),
|
|
105
|
+
version: z.string().optional(),
|
|
106
|
+
transport: z
|
|
107
|
+
.object({
|
|
108
|
+
type: z.string(),
|
|
109
|
+
url: z.string().optional(),
|
|
110
|
+
connectionId: z.string().optional(),
|
|
111
|
+
connectionTimestamp: z.string().optional(),
|
|
112
|
+
client: z.object({ name: z.string(), version: z.string(), title: z.string().optional() }).strict().optional(),
|
|
113
|
+
})
|
|
114
|
+
.strict()
|
|
115
|
+
.optional(),
|
|
116
|
+
})
|
|
117
|
+
.strict();
|
|
118
|
+
const configuredServerSourceSchema = z.enum(['mcpServers', 'mcpTemplates']);
|
|
56
119
|
export function createAdminRoutes(options) {
|
|
57
120
|
if (!options.adminEnabled) {
|
|
58
121
|
options.adminService.revokeAllSessions();
|
|
@@ -421,8 +484,47 @@ export function createAdminRoutes(options) {
|
|
|
421
484
|
ok: true,
|
|
422
485
|
operationId: result.operationId,
|
|
423
486
|
servers: result.result.servers,
|
|
487
|
+
configFingerprint: result.result.configFingerprint,
|
|
424
488
|
});
|
|
425
489
|
});
|
|
490
|
+
router.get('/api/instruction-templates', async (req, res) => {
|
|
491
|
+
const service = options.instructionTemplateService;
|
|
492
|
+
if (!service)
|
|
493
|
+
return void res.status(404).json({ error: 'admin_instruction_templates_unavailable' });
|
|
494
|
+
sendAdminOperationResult(res, await service.listTemplates({
|
|
495
|
+
context: buildAdminOperationContext(req, options, { type: 'instruction_template_collection' }),
|
|
496
|
+
}));
|
|
497
|
+
});
|
|
498
|
+
router.get('/api/instruction-templates/:identity', async (req, res) => {
|
|
499
|
+
await handleInstructionTemplateRequest(req, res, options, 'get');
|
|
500
|
+
});
|
|
501
|
+
router.post('/api/instruction-templates', async (req, res) => {
|
|
502
|
+
await handleInstructionTemplateRequest(req, res, options, 'create');
|
|
503
|
+
});
|
|
504
|
+
router.post('/api/instruction-templates/import-legacy', async (req, res) => {
|
|
505
|
+
await handleInstructionTemplateRequest(req, res, options, 'import');
|
|
506
|
+
});
|
|
507
|
+
router.post('/api/instruction-templates/:identity/clone', async (req, res) => {
|
|
508
|
+
await handleInstructionTemplateRequest(req, res, options, 'clone');
|
|
509
|
+
});
|
|
510
|
+
router.post('/api/instruction-templates/:identity/update', async (req, res) => {
|
|
511
|
+
await handleInstructionTemplateRequest(req, res, options, 'update');
|
|
512
|
+
});
|
|
513
|
+
router.post('/api/instruction-templates/:identity/validate', async (req, res) => {
|
|
514
|
+
await handleInstructionTemplateRequest(req, res, options, 'validate');
|
|
515
|
+
});
|
|
516
|
+
router.post('/api/instruction-templates/:identity/preview', async (req, res) => {
|
|
517
|
+
await handleInstructionTemplateRequest(req, res, options, 'preview');
|
|
518
|
+
});
|
|
519
|
+
router.post('/api/instruction-templates/:identity/activate', async (req, res) => {
|
|
520
|
+
await handleInstructionTemplateRequest(req, res, options, 'activate');
|
|
521
|
+
});
|
|
522
|
+
router.post('/api/instruction-templates/:identity/delete-preview', async (req, res) => {
|
|
523
|
+
await handleInstructionTemplateRequest(req, res, options, 'delete-preview');
|
|
524
|
+
});
|
|
525
|
+
router.delete('/api/instruction-templates/:identity', async (req, res) => {
|
|
526
|
+
await handleInstructionTemplateRequest(req, res, options, 'delete');
|
|
527
|
+
});
|
|
426
528
|
router.get('/api/configured-servers/create-contract', async (req, res) => {
|
|
427
529
|
await handleConfiguredServerCreateContract(req, res, options);
|
|
428
530
|
});
|
|
@@ -432,9 +534,33 @@ export function createAdminRoutes(options) {
|
|
|
432
534
|
router.post('/api/configured-servers', async (req, res) => {
|
|
433
535
|
await handleConfiguredServerCreateApply(req, res, options);
|
|
434
536
|
});
|
|
537
|
+
router.get('/api/configured-servers/:source/:name', async (req, res) => {
|
|
538
|
+
const source = configuredServerSourceSchema.safeParse(req.params.source);
|
|
539
|
+
if (!source.success)
|
|
540
|
+
return void res.status(400).json({ error: 'configured_server_source_invalid' });
|
|
541
|
+
await handleConfiguredServerDetail(req, res, options, source.data);
|
|
542
|
+
});
|
|
435
543
|
router.get('/api/configured-servers/:name', async (req, res) => {
|
|
436
544
|
await handleConfiguredServerDetail(req, res, options);
|
|
437
545
|
});
|
|
546
|
+
router.post('/api/configured-servers/:source/:name/preview', async (req, res) => {
|
|
547
|
+
const source = configuredServerSourceSchema.safeParse(req.params.source);
|
|
548
|
+
if (!source.success)
|
|
549
|
+
return void res.status(400).json({ error: 'configured_server_source_invalid' });
|
|
550
|
+
await handleConfiguredServerPreview(req, res, options, source.data);
|
|
551
|
+
});
|
|
552
|
+
router.post('/api/configured-servers/:source/:name/apply', async (req, res) => {
|
|
553
|
+
const source = configuredServerSourceSchema.safeParse(req.params.source);
|
|
554
|
+
if (!source.success)
|
|
555
|
+
return void res.status(400).json({ error: 'configured_server_source_invalid' });
|
|
556
|
+
await handleConfiguredServerApply(req, res, options, source.data);
|
|
557
|
+
});
|
|
558
|
+
router.post('/api/configured-servers/mcpServers/:name/enable', async (req, res) => {
|
|
559
|
+
await handleConfiguredServerMutation(req, res, options, 'enableConfiguredServer', 'mcpServers');
|
|
560
|
+
});
|
|
561
|
+
router.post('/api/configured-servers/mcpServers/:name/disable', async (req, res) => {
|
|
562
|
+
await handleConfiguredServerMutation(req, res, options, 'disableConfiguredServer', 'mcpServers');
|
|
563
|
+
});
|
|
438
564
|
router.post('/api/configured-servers/:name/preview', async (req, res) => {
|
|
439
565
|
await handleConfiguredServerPreview(req, res, options);
|
|
440
566
|
});
|
|
@@ -480,6 +606,113 @@ export function createAdminRoutes(options) {
|
|
|
480
606
|
});
|
|
481
607
|
return router;
|
|
482
608
|
}
|
|
609
|
+
async function handleInstructionTemplateRequest(req, res, options, action) {
|
|
610
|
+
const service = options.instructionTemplateService;
|
|
611
|
+
if (!service)
|
|
612
|
+
return void res.status(404).json({ error: 'admin_instruction_templates_unavailable' });
|
|
613
|
+
const body = req.body && typeof req.body === 'object' ? req.body : {};
|
|
614
|
+
const identityValue = action === 'create' || action === 'import' ? body.identity : req.params.identity;
|
|
615
|
+
const identity = instructionTemplateIdentitySchema.safeParse(identityValue);
|
|
616
|
+
if (!identity.success)
|
|
617
|
+
return void res.status(400).json({ error: 'instruction_template_identity_invalid' });
|
|
618
|
+
const context = buildAdminOperationContext(req, options, { type: 'instruction_template', id: identity.data });
|
|
619
|
+
const expectedConfigFingerprint = typeof body.expectedConfigFingerprint === 'string' ? body.expectedConfigFingerprint : '';
|
|
620
|
+
try {
|
|
621
|
+
switch (action) {
|
|
622
|
+
case 'get':
|
|
623
|
+
return sendAdminOperationResult(res, await service.getTemplate({ context, identity: identity.data }));
|
|
624
|
+
case 'create':
|
|
625
|
+
case 'update': {
|
|
626
|
+
const variants = instructionTemplateVariantsSchema.safeParse(body.variants);
|
|
627
|
+
if (!variants.success || !expectedConfigFingerprint) {
|
|
628
|
+
return void res.status(400).json({ error: 'instruction_template_request_invalid' });
|
|
629
|
+
}
|
|
630
|
+
return sendInstructionTemplateResult(res, await (action === 'create' ? service.createTemplate : service.updateTemplate).call(service, {
|
|
631
|
+
context,
|
|
632
|
+
identity: identity.data,
|
|
633
|
+
variants: variants.data,
|
|
634
|
+
expectedConfigFingerprint,
|
|
635
|
+
}));
|
|
636
|
+
}
|
|
637
|
+
case 'clone': {
|
|
638
|
+
const destination = instructionTemplateIdentitySchema.safeParse(body.identity);
|
|
639
|
+
if (!destination.success || !expectedConfigFingerprint) {
|
|
640
|
+
return void res.status(400).json({ error: 'instruction_template_request_invalid' });
|
|
641
|
+
}
|
|
642
|
+
return sendInstructionTemplateResult(res, await service.cloneTemplate({
|
|
643
|
+
context,
|
|
644
|
+
sourceIdentity: identity.data,
|
|
645
|
+
identity: destination.data,
|
|
646
|
+
expectedConfigFingerprint,
|
|
647
|
+
}));
|
|
648
|
+
}
|
|
649
|
+
case 'validate':
|
|
650
|
+
return sendAdminOperationResult(res, await service.validateTemplate({ context, identity: identity.data, expectedConfigFingerprint }));
|
|
651
|
+
case 'preview': {
|
|
652
|
+
const preview = z
|
|
653
|
+
.object({
|
|
654
|
+
surface: z.enum(['initialize', 'cli']),
|
|
655
|
+
selection: instructionPreviewSelectionSchema,
|
|
656
|
+
requestContext: requestContextSchema.optional(),
|
|
657
|
+
})
|
|
658
|
+
.strict()
|
|
659
|
+
.safeParse(body);
|
|
660
|
+
if (!preview.success)
|
|
661
|
+
return void res.status(400).json({ error: 'instruction_template_preview_invalid' });
|
|
662
|
+
return sendAdminOperationResult(res, await service.previewTemplate({ context, identity: identity.data, ...preview.data }));
|
|
663
|
+
}
|
|
664
|
+
case 'activate':
|
|
665
|
+
case 'delete': {
|
|
666
|
+
const previewFingerprint = typeof body.previewFingerprint === 'string' ? body.previewFingerprint : '';
|
|
667
|
+
if (!expectedConfigFingerprint || !previewFingerprint) {
|
|
668
|
+
return void res.status(400).json({ error: 'instruction_template_request_invalid' });
|
|
669
|
+
}
|
|
670
|
+
return sendInstructionTemplateResult(res, await (action === 'activate' ? service.activateTemplate : service.deleteTemplate).call(service, {
|
|
671
|
+
context,
|
|
672
|
+
identity: identity.data,
|
|
673
|
+
expectedConfigFingerprint,
|
|
674
|
+
previewFingerprint,
|
|
675
|
+
}));
|
|
676
|
+
}
|
|
677
|
+
case 'import':
|
|
678
|
+
if (!expectedConfigFingerprint) {
|
|
679
|
+
return void res.status(400).json({ error: 'instruction_template_request_invalid' });
|
|
680
|
+
}
|
|
681
|
+
return sendInstructionTemplateResult(res, await service.importLegacyTemplate({ context, identity: identity.data, expectedConfigFingerprint }));
|
|
682
|
+
case 'delete-preview':
|
|
683
|
+
return sendAdminOperationResult(res, await service.previewDeleteTemplate({ context, identity: identity.data, expectedConfigFingerprint }));
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
catch (error) {
|
|
687
|
+
if (error instanceof AdminInstructionTemplateNotFoundError) {
|
|
688
|
+
res.status(404).json({ error: error.code });
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
throw error;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function sendInstructionTemplateResult(res, result) {
|
|
695
|
+
if (!result.ok)
|
|
696
|
+
return sendAdminOperationResult(res, result);
|
|
697
|
+
const status = result.result?.status;
|
|
698
|
+
if (status === 'not_found')
|
|
699
|
+
return void res.status(404).json({ ok: false, error: 'instruction_template_not_found' });
|
|
700
|
+
if (status === 'invalid') {
|
|
701
|
+
return void res
|
|
702
|
+
.status(422)
|
|
703
|
+
.json({ ok: false, error: 'instruction_template_invalid', validation: result.result.validation });
|
|
704
|
+
}
|
|
705
|
+
if (status === 'legacy_unavailable') {
|
|
706
|
+
return void res.status(409).json({ ok: false, error: 'legacy_instruction_template_unavailable' });
|
|
707
|
+
}
|
|
708
|
+
if (status === 'conflict' ||
|
|
709
|
+
status === 'identity_conflict' ||
|
|
710
|
+
status === 'protected' ||
|
|
711
|
+
status === 'active_conflict') {
|
|
712
|
+
return void res.status(409).json({ ok: false, error: `instruction_template_${status}` });
|
|
713
|
+
}
|
|
714
|
+
sendAdminOperationResult(res, result);
|
|
715
|
+
}
|
|
483
716
|
function streamBackendLogs(req, res, broker, adminService) {
|
|
484
717
|
const sessionToken = getAdminSessionCookie(req);
|
|
485
718
|
let closed = false;
|
|
@@ -786,16 +1019,22 @@ function backendRestartFailure(outcome) {
|
|
|
786
1019
|
};
|
|
787
1020
|
}
|
|
788
1021
|
}
|
|
789
|
-
async function handleConfiguredServerDetail(req, res, options) {
|
|
1022
|
+
async function handleConfiguredServerDetail(req, res, options, targetSource) {
|
|
790
1023
|
if (!options.configuredServerService) {
|
|
791
1024
|
res.status(404).json({ error: 'admin_configured_servers_unavailable' });
|
|
792
1025
|
return;
|
|
793
1026
|
}
|
|
794
1027
|
const targetName = req.params.name;
|
|
795
1028
|
try {
|
|
1029
|
+
const model = configuredServerModelSchema.safeParse(req.query.model);
|
|
796
1030
|
const result = await options.configuredServerService.getConfiguredServerDetail({
|
|
797
|
-
context: buildAdminOperationContext(req, options, {
|
|
1031
|
+
context: buildAdminOperationContext(req, options, {
|
|
1032
|
+
type: 'configured_server',
|
|
1033
|
+
id: `${targetSource ?? 'mcpServers'}:${targetName}`,
|
|
1034
|
+
}),
|
|
798
1035
|
targetName,
|
|
1036
|
+
...(targetSource ? { targetSource } : {}),
|
|
1037
|
+
...(model.success ? { model: model.data } : {}),
|
|
799
1038
|
});
|
|
800
1039
|
if (!result.ok) {
|
|
801
1040
|
sendAdminOperationResult(res, result);
|
|
@@ -806,6 +1045,7 @@ async function handleConfiguredServerDetail(req, res, options) {
|
|
|
806
1045
|
operationId: result.operationId,
|
|
807
1046
|
server: result.result.server,
|
|
808
1047
|
editContract: result.result.editContract,
|
|
1048
|
+
...(result.result.toolInventory ? { toolInventory: result.result.toolInventory } : {}),
|
|
809
1049
|
});
|
|
810
1050
|
}
|
|
811
1051
|
catch (error) {
|
|
@@ -906,7 +1146,7 @@ function configuredServerCreateDraftName(draft) {
|
|
|
906
1146
|
const name = draft.name;
|
|
907
1147
|
return typeof name === 'string' ? name : '';
|
|
908
1148
|
}
|
|
909
|
-
async function handleConfiguredServerPreview(req, res, options) {
|
|
1149
|
+
async function handleConfiguredServerPreview(req, res, options, targetSource) {
|
|
910
1150
|
if (!options.configuredServerService) {
|
|
911
1151
|
res.status(404).json({ error: 'admin_configured_servers_unavailable' });
|
|
912
1152
|
return;
|
|
@@ -914,11 +1154,17 @@ async function handleConfiguredServerPreview(req, res, options) {
|
|
|
914
1154
|
const targetName = req.params.name;
|
|
915
1155
|
const edit = getBodyValue(req.body, 'edit');
|
|
916
1156
|
try {
|
|
1157
|
+
const model = configuredServerModelSchema.safeParse(getBodyString(req.body, 'model'));
|
|
917
1158
|
const result = await options.configuredServerService.previewConfiguredServerEdit({
|
|
918
|
-
context: buildAdminOperationContext(req, options, {
|
|
1159
|
+
context: buildAdminOperationContext(req, options, {
|
|
1160
|
+
type: 'configured_server',
|
|
1161
|
+
id: `${targetSource ?? 'mcpServers'}:${targetName}`,
|
|
1162
|
+
}),
|
|
919
1163
|
targetName,
|
|
1164
|
+
...(targetSource ? { targetSource } : {}),
|
|
920
1165
|
edit: edit === undefined ? {} : edit,
|
|
921
1166
|
connectivityCheck: getBodyString(req.body, 'connectivityCheck') === 'manual' ? 'manual' : 'auto',
|
|
1167
|
+
...(model.success ? { model: model.data } : {}),
|
|
922
1168
|
});
|
|
923
1169
|
if (!result.ok) {
|
|
924
1170
|
sendAdminOperationResult(res, result);
|
|
@@ -944,7 +1190,7 @@ async function handleConfiguredServerPreview(req, res, options) {
|
|
|
944
1190
|
throw error;
|
|
945
1191
|
}
|
|
946
1192
|
}
|
|
947
|
-
async function handleConfiguredServerApply(req, res, options) {
|
|
1193
|
+
async function handleConfiguredServerApply(req, res, options, targetSource) {
|
|
948
1194
|
if (!options.configuredServerService) {
|
|
949
1195
|
res.status(404).json({ error: 'admin_configured_servers_unavailable' });
|
|
950
1196
|
return;
|
|
@@ -962,11 +1208,17 @@ async function handleConfiguredServerApply(req, res, options) {
|
|
|
962
1208
|
}
|
|
963
1209
|
const targetName = req.params.name;
|
|
964
1210
|
try {
|
|
1211
|
+
const model = configuredServerModelSchema.safeParse(getBodyString(req.body, 'model'));
|
|
965
1212
|
const result = await options.configuredServerService.applyConfiguredServerEdit({
|
|
966
|
-
context: buildAdminOperationContext(req, options, {
|
|
1213
|
+
context: buildAdminOperationContext(req, options, {
|
|
1214
|
+
type: 'configured_server',
|
|
1215
|
+
id: `${targetSource ?? 'mcpServers'}:${targetName}`,
|
|
1216
|
+
}),
|
|
967
1217
|
targetName,
|
|
1218
|
+
...(targetSource ? { targetSource } : {}),
|
|
968
1219
|
edit: getBodyValue(req.body, 'edit') ?? {},
|
|
969
1220
|
previewFingerprint: getBodyString(req.body, 'previewFingerprint'),
|
|
1221
|
+
...(model.success ? { model: model.data } : {}),
|
|
970
1222
|
});
|
|
971
1223
|
if (!result.ok && result.status === 'mutation_failed' && isConfiguredServerApplyErrorCode(result.error)) {
|
|
972
1224
|
sendConfiguredServerApplyError(res, result.error);
|
|
@@ -1020,7 +1272,7 @@ function configuredServerApplyErrorMessage(code) {
|
|
|
1020
1272
|
return 'The configured server edit could not be applied.';
|
|
1021
1273
|
}
|
|
1022
1274
|
}
|
|
1023
|
-
async function handleConfiguredServerMutation(req, res, options, operationName) {
|
|
1275
|
+
async function handleConfiguredServerMutation(req, res, options, operationName, targetSource) {
|
|
1024
1276
|
if (!options.configuredServerService) {
|
|
1025
1277
|
res.status(404).json({ error: 'admin_configured_servers_unavailable' });
|
|
1026
1278
|
return;
|
|
@@ -1037,8 +1289,11 @@ async function handleConfiguredServerMutation(req, res, options, operationName)
|
|
|
1037
1289
|
return;
|
|
1038
1290
|
}
|
|
1039
1291
|
const targetName = req.params.name;
|
|
1040
|
-
const context = buildAdminOperationContext(req, options, {
|
|
1041
|
-
|
|
1292
|
+
const context = buildAdminOperationContext(req, options, {
|
|
1293
|
+
type: 'configured_server',
|
|
1294
|
+
id: `${targetSource ?? 'mcpServers'}:${targetName}`,
|
|
1295
|
+
});
|
|
1296
|
+
const input = { context, targetName, ...(targetSource ? { targetSource } : {}) };
|
|
1042
1297
|
const result = operationName === 'enableConfiguredServer'
|
|
1043
1298
|
? await options.configuredServerService.enableConfiguredServer(input)
|
|
1044
1299
|
: await options.configuredServerService.disableConfiguredServer(input);
|
|
@@ -1531,6 +1786,11 @@ function configuredServerRequestFingerprint(operationName, targetName, body) {
|
|
|
1531
1786
|
},
|
|
1532
1787
|
}
|
|
1533
1788
|
: {}),
|
|
1789
|
+
...(operationName.includes('InstructionTemplate') || operationName === 'applyConfiguredServerInstructionOverride'
|
|
1790
|
+
? {
|
|
1791
|
+
bodyDigest: keyedRequestFingerprint(previewFingerprint || getBodyString(body, 'expectedConfigFingerprint') || operationName, 'admin-instruction-operation', stableJsonStringify(body ?? {})),
|
|
1792
|
+
}
|
|
1793
|
+
: {}),
|
|
1534
1794
|
});
|
|
1535
1795
|
if (operationName === 'applyConfiguredServerCreate') {
|
|
1536
1796
|
return `configured_server_create_${keyedRequestFingerprint(previewFingerprint, 'configured-server-create', normalized)}`;
|
|
@@ -1621,6 +1881,30 @@ function cliOperationErrorDetails(result) {
|
|
|
1621
1881
|
return details;
|
|
1622
1882
|
}
|
|
1623
1883
|
function operationNameForRequest(req) {
|
|
1884
|
+
if (req.path.startsWith('/api/instruction-templates')) {
|
|
1885
|
+
if (req.path.endsWith('/clone'))
|
|
1886
|
+
return 'cloneInstructionTemplate';
|
|
1887
|
+
if (req.path.endsWith('/update'))
|
|
1888
|
+
return 'updateInstructionTemplate';
|
|
1889
|
+
if (req.path.endsWith('/validate'))
|
|
1890
|
+
return 'validateInstructionTemplate';
|
|
1891
|
+
if (req.path.endsWith('/preview'))
|
|
1892
|
+
return 'previewInstructionTemplate';
|
|
1893
|
+
if (req.path.endsWith('/activate'))
|
|
1894
|
+
return 'activateInstructionTemplate';
|
|
1895
|
+
if (req.path.endsWith('/delete-preview'))
|
|
1896
|
+
return 'previewDeleteInstructionTemplate';
|
|
1897
|
+
if (req.path.endsWith('/import-legacy'))
|
|
1898
|
+
return 'importLegacyInstructionTemplate';
|
|
1899
|
+
if (req.method === 'DELETE')
|
|
1900
|
+
return 'deleteInstructionTemplate';
|
|
1901
|
+
if (req.method === 'POST')
|
|
1902
|
+
return 'createInstructionTemplate';
|
|
1903
|
+
return req.path === '/api/instruction-templates' ? 'listInstructionTemplates' : 'getInstructionTemplate';
|
|
1904
|
+
}
|
|
1905
|
+
if (req.path.endsWith('/instruction-override')) {
|
|
1906
|
+
return 'applyConfiguredServerInstructionOverride';
|
|
1907
|
+
}
|
|
1624
1908
|
if (req.path.startsWith('/api/oauth/')) {
|
|
1625
1909
|
return req.path.endsWith('/restart') ? 'restartBackendOAuth' : 'authorizeBackendOAuth';
|
|
1626
1910
|
}
|