openloops 0.7.0 → 0.7.3

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/db/indexes/mcp-servers.js +2 -1
  3. package/dist/db/indexes/mcp-servers.mjs +2 -1
  4. package/dist/harness/agent.d.ts +1 -2
  5. package/dist/harness/agent.js +15 -9
  6. package/dist/harness/agent.mjs +15 -9
  7. package/dist/services/automations/runner/automation-runner.js +1 -3
  8. package/dist/services/automations/runner/automation-runner.mjs +1 -3
  9. package/dist/services/mcp-servers/admin/index.d.ts +1 -0
  10. package/dist/services/mcp-servers/admin/index.js +22 -0
  11. package/dist/services/mcp-servers/admin/index.mjs +1 -0
  12. package/dist/services/mcp-servers/admin/module.d.ts +10 -0
  13. package/dist/services/mcp-servers/admin/module.js +55 -0
  14. package/dist/services/mcp-servers/admin/module.mjs +27 -0
  15. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.d.ts +12 -0
  16. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.js +50 -0
  17. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.mjs +26 -0
  18. package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.d.ts +13 -0
  19. package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.js +44 -0
  20. package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.mjs +20 -0
  21. package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.d.ts +12 -0
  22. package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.js +41 -0
  23. package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.mjs +17 -0
  24. package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.d.ts +16 -0
  25. package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.js +42 -0
  26. package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.mjs +18 -0
  27. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.d.ts +13 -0
  28. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.js +59 -0
  29. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.mjs +35 -0
  30. package/dist/services/mcp-servers/entities/mcpserver.entity.d.ts +8 -1
  31. package/dist/services/mcp-servers/entities/mcpserver.entity.js +23 -3
  32. package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +23 -3
  33. package/dist/services/mcp-servers/internal.d.ts +6 -0
  34. package/dist/services/mcp-servers/internal.js +32 -0
  35. package/dist/services/mcp-servers/internal.mjs +8 -0
  36. package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +8 -0
  37. package/dist/services/mcp-servers/repositories/mcpserver.repository.js +23 -3
  38. package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +24 -4
  39. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +2 -0
  40. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +2 -0
  41. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +1 -1
  42. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +1 -1
  43. package/docs/agent.md +1 -1
  44. package/docs/automations.md +24 -6
  45. package/docs/configuration.md +0 -1
  46. package/docs/mcp-servers.md +83 -1
  47. package/examples/authentication/login.ts +5 -0
  48. package/examples/automations/create-automation.ts +5 -0
  49. package/examples/automations/create-event-automation.ts +5 -0
  50. package/examples/automations/list-automation-runs.ts +6 -0
  51. package/examples/automations/list-automations.ts +3 -0
  52. package/examples/automations/preview-automation-runs.ts +3 -0
  53. package/examples/automations/receive-automation-event.ts +5 -0
  54. package/examples/automations/revoke-automation-event-token.ts +6 -0
  55. package/examples/automations/run-automation-now.ts +3 -0
  56. package/examples/automations/run-automation-worker.ts +15 -0
  57. package/examples/automations/update-automation.ts +6 -0
  58. package/examples/chats/delete-chat.ts +6 -0
  59. package/examples/chats/get-chat-by-id.ts +6 -0
  60. package/examples/chats/list-autonomous-chats.ts +3 -0
  61. package/examples/chats/list-chats.ts +3 -0
  62. package/examples/guardrails/custom-guard.ts +5 -0
  63. package/examples/loops/custom-loop.ts +8 -0
  64. package/examples/mcps/create-mcp.ts +6 -0
  65. package/examples/mcps/decide-mcp.ts +6 -0
  66. package/examples/mcps/delete-mcp.ts +6 -0
  67. package/examples/mcps/get-mcp-by-id.ts +3 -0
  68. package/examples/mcps/internal-mcp-admin.ts +66 -0
  69. package/examples/mcps/internal-mcp.ts +28 -3
  70. package/examples/mcps/list-all-mcps.ts +3 -0
  71. package/examples/mcps/list-user-mcps.ts +3 -0
  72. package/examples/mcps/update-mcp.ts +6 -1
  73. package/examples/mcps/verify-mcp.ts +3 -0
  74. package/examples/run-agent/interrupt-agent.ts +3 -0
  75. package/examples/run-agent/run-agent-autonomous.ts +3 -0
  76. package/examples/run-agent/run-agent-strict-mode.ts +3 -0
  77. package/examples/run-agent/run-agent-with-confirmation.ts +6 -0
  78. package/examples/run-agent/run-agent-with-fallback-model.ts +3 -0
  79. package/examples/run-agent/run-agent-with-guards.ts +3 -0
  80. package/examples/run-agent/run-agent-with-hooks.ts +6 -0
  81. package/examples/run-agent/run-agent-with-identity.ts +3 -0
  82. package/examples/run-agent/run-agent-with-model.ts +3 -0
  83. package/examples/run-agent/run-agent-with-slack.ts +3 -0
  84. package/examples/run-agent/run-agent-with-tools.ts +3 -0
  85. package/examples/tools/basic-tool.ts +3 -0
  86. package/examples/tools/destructive-tool.ts +3 -0
  87. package/examples/tools/web-search-tool.ts +3 -0
  88. package/examples/usage/get-chat-usage.ts +3 -0
  89. package/examples/usage/get-message-usage.ts +3 -0
  90. package/examples/usage/get-usage-stats-by-range.ts +3 -0
  91. package/examples/usage/get-usage-stats.ts +3 -0
  92. package/examples/users/create-user.ts +3 -0
  93. package/examples/users/delete-user.ts +6 -0
  94. package/examples/users/get-user-by-id.ts +3 -0
  95. package/examples/users/list-users.ts +3 -0
  96. package/examples/users/set-default-model.ts +6 -0
  97. package/examples/users/update-user.ts +3 -0
  98. package/package.json +5 -1
@@ -0,0 +1,17 @@
1
+ import { BaseUseCase } from "../../../../common/base/base.use-case.js";
2
+ import { Scope } from "../../../../common/repositories/index.js";
3
+ import { McpServerRepository } from "../../repositories";
4
+ class GetInternalMcpByIdUseCase extends BaseUseCase {
5
+ constructor(mcpServerRepository = new McpServerRepository()) {
6
+ super();
7
+ this.mcpServerRepository = mcpServerRepository;
8
+ }
9
+ mcpServerRepository;
10
+ async execute(params) {
11
+ const { id, currentUser } = params;
12
+ return await this.mcpServerRepository.findInternalById(id, params.scope ?? Scope.asAdmin(currentUser));
13
+ }
14
+ }
15
+ export {
16
+ GetInternalMcpByIdUseCase
17
+ };
@@ -0,0 +1,16 @@
1
+ import { QueryOptions } from '../../../../common/repositories/index.js';
2
+ import { BaseUseCase, BaseUseCaseParams } from '../../../../common/base/base.use-case.js';
3
+ import { McpServerProps } from '../../entities';
4
+ import { McpServerRepository } from '../../repositories';
5
+ export interface Params extends BaseUseCaseParams {
6
+ options?: QueryOptions;
7
+ }
8
+ export interface Output {
9
+ items: McpServerProps[];
10
+ hasMore: boolean;
11
+ }
12
+ export declare class ListInternalMcpsUseCase extends BaseUseCase<Params, Output> {
13
+ private readonly mcpServerRepository;
14
+ constructor(mcpServerRepository?: McpServerRepository);
15
+ execute(params: Params): Promise<Output>;
16
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var list_internal_mcps_use_case_exports = {};
20
+ __export(list_internal_mcps_use_case_exports, {
21
+ ListInternalMcpsUseCase: () => ListInternalMcpsUseCase
22
+ });
23
+ module.exports = __toCommonJS(list_internal_mcps_use_case_exports);
24
+ var import_base = require("../../../../common/base/base.use-case.js");
25
+ var import_repositories2 = require("../../../../common/repositories/index.js");
26
+ var import_repositories3 = require("../../repositories");
27
+ class ListInternalMcpsUseCase extends import_base.BaseUseCase {
28
+ constructor(mcpServerRepository = new import_repositories3.McpServerRepository()) {
29
+ super();
30
+ this.mcpServerRepository = mcpServerRepository;
31
+ }
32
+ mcpServerRepository;
33
+ async execute(params) {
34
+ const { options, currentUser } = params;
35
+ const { page = 1, limit = 10 } = options || {};
36
+ return await this.mcpServerRepository.findInternalPage(params.scope ?? import_repositories2.Scope.asAdmin(currentUser), { page, limit, sortBy: { updatedAt: -1 } });
37
+ }
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ ListInternalMcpsUseCase
42
+ });
@@ -0,0 +1,18 @@
1
+ import { BaseUseCase } from "../../../../common/base/base.use-case.js";
2
+ import { Scope } from "../../../../common/repositories/index.js";
3
+ import { McpServerRepository } from "../../repositories";
4
+ class ListInternalMcpsUseCase extends BaseUseCase {
5
+ constructor(mcpServerRepository = new McpServerRepository()) {
6
+ super();
7
+ this.mcpServerRepository = mcpServerRepository;
8
+ }
9
+ mcpServerRepository;
10
+ async execute(params) {
11
+ const { options, currentUser } = params;
12
+ const { page = 1, limit = 10 } = options || {};
13
+ return await this.mcpServerRepository.findInternalPage(params.scope ?? Scope.asAdmin(currentUser), { page, limit, sortBy: { updatedAt: -1 } });
14
+ }
15
+ }
16
+ export {
17
+ ListInternalMcpsUseCase
18
+ };
@@ -0,0 +1,13 @@
1
+ import { BaseUseCase, BaseUseCaseParams } from '../../../../common/base/base.use-case.js';
2
+ import { McpServerProps } from '../../entities';
3
+ import { McpServerRepository } from '../../repositories';
4
+ export interface Params extends BaseUseCaseParams {
5
+ id: string;
6
+ payload?: Pick<McpServerProps, 'name' | 'url' | 'headers' | 'enabled' | 'environment' | '__v'>;
7
+ }
8
+ export type Output = McpServerProps;
9
+ export declare class UpdateInternalMcpUseCase extends BaseUseCase<Params, Output> {
10
+ private readonly mcpServerRepository;
11
+ constructor(mcpServerRepository?: McpServerRepository);
12
+ execute(params: Params): Promise<Output>;
13
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var update_internal_mcp_use_case_exports = {};
20
+ __export(update_internal_mcp_use_case_exports, {
21
+ UpdateInternalMcpUseCase: () => UpdateInternalMcpUseCase
22
+ });
23
+ module.exports = __toCommonJS(update_internal_mcp_use_case_exports);
24
+ var import_base = require("../../../../common/base/base.use-case.js");
25
+ var import_repositories = require("../../../../common/repositories/index.js");
26
+ var import_mongo_db = require("../../../../common/repositories/mongo-db.repository.js");
27
+ var import_entities = require("../../entities");
28
+ var import_repositories2 = require("../../repositories");
29
+ class UpdateInternalMcpUseCase extends import_base.BaseUseCase {
30
+ constructor(mcpServerRepository = new import_repositories2.McpServerRepository()) {
31
+ super();
32
+ this.mcpServerRepository = mcpServerRepository;
33
+ }
34
+ mcpServerRepository;
35
+ async execute(params) {
36
+ const { id, payload, currentUser } = params;
37
+ const scope = params.scope ?? import_repositories.Scope.asAdmin(currentUser);
38
+ if (!payload || Object.keys(payload).length === 0) this.throwHttpError({ statusCode: 400, errorMessage: "Payload is required for updating an internal MCP" });
39
+ const existing = await this.mcpServerRepository.findInternalById(id, scope);
40
+ if (!existing) this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
41
+ if (payload.__v !== void 0 && payload.__v !== existing.__v) throw new import_mongo_db.VersionConflictError();
42
+ if (payload.name !== void 0 && payload.name !== existing.name) {
43
+ if (!payload.name) this.throwHttpError({ statusCode: 400, errorMessage: "An internal MCP needs a name and a url" });
44
+ if (await this.mcpServerRepository.findInternalByName(payload.name, scope)) {
45
+ this.throwHttpError({ statusCode: 409, errorMessage: `There is already an internal MCP named "${payload.name}"` });
46
+ }
47
+ }
48
+ if (payload.url !== void 0 && !payload.url) this.throwHttpError({ statusCode: 400, errorMessage: "An internal MCP needs a name and a url" });
49
+ const { name, url, headers, enabled, environment } = payload;
50
+ const mcpServer = import_entities.McpServer.fromJSON({ ...existing, ...name !== void 0 && { name }, ...url !== void 0 && { url }, ...headers !== void 0 && { headers }, ...enabled !== void 0 && { enabled }, ...environment !== void 0 && { environment }, _id: id, internal: true });
51
+ const result = await this.mcpServerRepository.update(mcpServer, scope, { expectedVersion: existing.__v });
52
+ if (!result) this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
53
+ return result;
54
+ }
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ UpdateInternalMcpUseCase
59
+ });
@@ -0,0 +1,35 @@
1
+ import { BaseUseCase } from "../../../../common/base/base.use-case.js";
2
+ import { Scope } from "../../../../common/repositories/index.js";
3
+ import { VersionConflictError } from "../../../../common/repositories/mongo-db.repository.js";
4
+ import { McpServer } from "../../entities";
5
+ import { McpServerRepository } from "../../repositories";
6
+ class UpdateInternalMcpUseCase extends BaseUseCase {
7
+ constructor(mcpServerRepository = new McpServerRepository()) {
8
+ super();
9
+ this.mcpServerRepository = mcpServerRepository;
10
+ }
11
+ mcpServerRepository;
12
+ async execute(params) {
13
+ const { id, payload, currentUser } = params;
14
+ const scope = params.scope ?? Scope.asAdmin(currentUser);
15
+ if (!payload || Object.keys(payload).length === 0) this.throwHttpError({ statusCode: 400, errorMessage: "Payload is required for updating an internal MCP" });
16
+ const existing = await this.mcpServerRepository.findInternalById(id, scope);
17
+ if (!existing) this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
18
+ if (payload.__v !== void 0 && payload.__v !== existing.__v) throw new VersionConflictError();
19
+ if (payload.name !== void 0 && payload.name !== existing.name) {
20
+ if (!payload.name) this.throwHttpError({ statusCode: 400, errorMessage: "An internal MCP needs a name and a url" });
21
+ if (await this.mcpServerRepository.findInternalByName(payload.name, scope)) {
22
+ this.throwHttpError({ statusCode: 409, errorMessage: `There is already an internal MCP named "${payload.name}"` });
23
+ }
24
+ }
25
+ if (payload.url !== void 0 && !payload.url) this.throwHttpError({ statusCode: 400, errorMessage: "An internal MCP needs a name and a url" });
26
+ const { name, url, headers, enabled, environment } = payload;
27
+ const mcpServer = McpServer.fromJSON({ ...existing, ...name !== void 0 && { name }, ...url !== void 0 && { url }, ...headers !== void 0 && { headers }, ...enabled !== void 0 && { enabled }, ...environment !== void 0 && { environment }, _id: id, internal: true });
28
+ const result = await this.mcpServerRepository.update(mcpServer, scope, { expectedVersion: existing.__v });
29
+ if (!result) this.throwHttpError({ statusCode: 404, errorMessage: "{{resource_not_found}}" });
30
+ return result;
31
+ }
32
+ }
33
+ export {
34
+ UpdateInternalMcpUseCase
35
+ };
@@ -14,6 +14,9 @@ export interface McpServerProps extends BaseEntityProps {
14
14
  history?: McpManifest[];
15
15
  status?: McpStatus;
16
16
  lastError?: string | null;
17
+ internal?: boolean;
18
+ enabled?: boolean;
19
+ environment?: string;
17
20
  }
18
21
  export declare class McpServer extends BaseEntity {
19
22
  private readonly props;
@@ -26,14 +29,18 @@ export declare class McpServer extends BaseEntity {
26
29
  history?: McpManifest[] | undefined;
27
30
  status?: McpStatus | undefined;
28
31
  lastError?: string | null | undefined;
32
+ internal?: boolean | undefined;
33
+ enabled?: boolean | undefined;
34
+ environment?: string | undefined;
29
35
  mcpClient?: Client;
30
36
  static fromJSON(props: McpServerProps): McpServer;
31
- constructor(props: McpServerProps, name?: string | undefined, url?: string | undefined, type?: McpType | undefined, headers?: Record<string, string> | undefined, trust?: McpTrust | undefined, approvedHash?: string | null | undefined, history?: McpManifest[] | undefined, status?: McpStatus | undefined, lastError?: string | null | undefined);
37
+ constructor(props: McpServerProps, name?: string | undefined, url?: string | undefined, type?: McpType | undefined, headers?: Record<string, string> | undefined, trust?: McpTrust | undefined, approvedHash?: string | null | undefined, history?: McpManifest[] | undefined, status?: McpStatus | undefined, lastError?: string | null | undefined, internal?: boolean | undefined, enabled?: boolean | undefined, environment?: string | undefined);
32
38
  toJSON(): McpServerProps;
33
39
  get latest(): McpManifest | undefined;
34
40
  get approved(): McpManifest | undefined;
35
41
  diffAgainst(manifest: McpManifest): McpManifestDiff;
36
42
  initialize(): this;
43
+ initializeInternal(): this;
37
44
  lockForNewEndpoint(): this;
38
45
  approve(hash: string): this;
39
46
  block(): this;
@@ -30,7 +30,7 @@ __reExport(mcpserver_entity_exports, require("./mcp-manifest"), module.exports);
30
30
  const MAX_HISTORY = 5;
31
31
  const MAX_ERROR_CHARS = 300;
32
32
  class McpServer extends import_base.BaseEntity {
33
- constructor(props, name, url, type, headers, trust, approvedHash, history, status, lastError) {
33
+ constructor(props, name, url, type, headers, trust, approvedHash, history, status, lastError, internal, enabled, environment) {
34
34
  super(props);
35
35
  this.props = props;
36
36
  this.name = name;
@@ -42,6 +42,9 @@ class McpServer extends import_base.BaseEntity {
42
42
  this.history = history;
43
43
  this.status = status;
44
44
  this.lastError = lastError;
45
+ this.internal = internal;
46
+ this.enabled = enabled;
47
+ this.environment = environment;
45
48
  }
46
49
  props;
47
50
  name;
@@ -53,6 +56,9 @@ class McpServer extends import_base.BaseEntity {
53
56
  history;
54
57
  status;
55
58
  lastError;
59
+ internal;
60
+ enabled;
61
+ environment;
56
62
  mcpClient;
57
63
  static fromJSON(props) {
58
64
  return new McpServer(
@@ -65,7 +71,10 @@ class McpServer extends import_base.BaseEntity {
65
71
  props.approvedHash,
66
72
  props.history,
67
73
  props.status || void 0,
68
- props.lastError
74
+ props.lastError,
75
+ props.internal,
76
+ props.enabled,
77
+ props.environment
69
78
  );
70
79
  }
71
80
  toJSON() {
@@ -79,7 +88,10 @@ class McpServer extends import_base.BaseEntity {
79
88
  approvedHash: this.approvedHash,
80
89
  history: this.history,
81
90
  status: this.status,
82
- lastError: this.lastError
91
+ lastError: this.lastError,
92
+ internal: this.internal,
93
+ enabled: this.enabled,
94
+ environment: this.environment
83
95
  };
84
96
  }
85
97
  get latest() {
@@ -97,6 +109,14 @@ class McpServer extends import_base.BaseEntity {
97
109
  this.history = [];
98
110
  this.status = "unknown";
99
111
  this.lastError = null;
112
+ this.internal = void 0;
113
+ this.enabled = void 0;
114
+ return this;
115
+ }
116
+ initializeInternal() {
117
+ this.internal = true;
118
+ this.enabled = this.enabled ?? true;
119
+ this.type = this.type ?? "http";
100
120
  return this;
101
121
  }
102
122
  lockForNewEndpoint() {
@@ -6,7 +6,7 @@ export * from "./mcp-manifest";
6
6
  const MAX_HISTORY = 5;
7
7
  const MAX_ERROR_CHARS = 300;
8
8
  class McpServer extends BaseEntity {
9
- constructor(props, name, url, type, headers, trust, approvedHash, history, status, lastError) {
9
+ constructor(props, name, url, type, headers, trust, approvedHash, history, status, lastError, internal, enabled, environment) {
10
10
  super(props);
11
11
  this.props = props;
12
12
  this.name = name;
@@ -18,6 +18,9 @@ class McpServer extends BaseEntity {
18
18
  this.history = history;
19
19
  this.status = status;
20
20
  this.lastError = lastError;
21
+ this.internal = internal;
22
+ this.enabled = enabled;
23
+ this.environment = environment;
21
24
  }
22
25
  props;
23
26
  name;
@@ -29,6 +32,9 @@ class McpServer extends BaseEntity {
29
32
  history;
30
33
  status;
31
34
  lastError;
35
+ internal;
36
+ enabled;
37
+ environment;
32
38
  mcpClient;
33
39
  static fromJSON(props) {
34
40
  return new McpServer(
@@ -41,7 +47,10 @@ class McpServer extends BaseEntity {
41
47
  props.approvedHash,
42
48
  props.history,
43
49
  props.status || void 0,
44
- props.lastError
50
+ props.lastError,
51
+ props.internal,
52
+ props.enabled,
53
+ props.environment
45
54
  );
46
55
  }
47
56
  toJSON() {
@@ -55,7 +64,10 @@ class McpServer extends BaseEntity {
55
64
  approvedHash: this.approvedHash,
56
65
  history: this.history,
57
66
  status: this.status,
58
- lastError: this.lastError
67
+ lastError: this.lastError,
68
+ internal: this.internal,
69
+ enabled: this.enabled,
70
+ environment: this.environment
59
71
  };
60
72
  }
61
73
  get latest() {
@@ -73,6 +85,14 @@ class McpServer extends BaseEntity {
73
85
  this.history = [];
74
86
  this.status = "unknown";
75
87
  this.lastError = null;
88
+ this.internal = void 0;
89
+ this.enabled = void 0;
90
+ return this;
91
+ }
92
+ initializeInternal() {
93
+ this.internal = true;
94
+ this.enabled = this.enabled ?? true;
95
+ this.type = this.type ?? "http";
76
96
  return this;
77
97
  }
78
98
  lockForNewEndpoint() {
@@ -0,0 +1,6 @@
1
+ export interface StoredInternalMcp {
2
+ name: string;
3
+ url: string;
4
+ headers?: Record<string, string>;
5
+ }
6
+ export declare function listActiveInternalMcps(): Promise<StoredInternalMcp[]>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var internal_exports = {};
20
+ __export(internal_exports, {
21
+ listActiveInternalMcps: () => listActiveInternalMcps
22
+ });
23
+ module.exports = __toCommonJS(internal_exports);
24
+ var import_repositories = require("./repositories");
25
+ async function listActiveInternalMcps() {
26
+ const items = await new import_repositories.McpServerRepository().findActiveInternals();
27
+ return items.flatMap((item) => item.name && item.url ? [{ name: item.name, url: item.url, ...item.headers ? { headers: item.headers } : {} }] : []);
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ listActiveInternalMcps
32
+ });
@@ -0,0 +1,8 @@
1
+ import { McpServerRepository } from "./repositories";
2
+ async function listActiveInternalMcps() {
3
+ const items = await new McpServerRepository().findActiveInternals();
4
+ return items.flatMap((item) => item.name && item.url ? [{ name: item.name, url: item.url, ...item.headers ? { headers: item.headers } : {} }] : []);
5
+ }
6
+ export {
7
+ listActiveInternalMcps
8
+ };
@@ -11,4 +11,12 @@ export declare class McpServerRepository {
11
11
  softDeleteById(id: string, scope: Scope): Promise<McpServerProps | null>;
12
12
  deleteById(id: string, scope: Scope): Promise<number>;
13
13
  findByProps(where: McpServerProps, scope: Scope, options?: QueryOptions): Promise<McpServerProps[]>;
14
+ findInternalById(id: string, scope: Scope): Promise<McpServerProps | null>;
15
+ findInternalByName(name: string, scope: Scope): Promise<McpServerProps | null>;
16
+ findInternalPage(scope: Scope, options: QueryOptions): Promise<{
17
+ items: McpServerProps[];
18
+ hasMore: boolean;
19
+ }>;
20
+ findActiveInternals(): Promise<McpServerProps[]>;
21
+ deleteInternalById(id: string, scope: Scope): Promise<number>;
14
22
  }
@@ -25,6 +25,7 @@ var import_mongodb = require("mongodb");
25
25
  var import_utils = require("../../../common/base/utils/index.js");
26
26
  var import_repositories = require("../../../common/repositories/index.js");
27
27
  var import_database_name = require("../../../common/utils/database-name.js");
28
+ const external = (where) => ({ ...where, internal: { $ne: true } });
28
29
  class McpServerRepository {
29
30
  _ = new import_repositories.MongoRepository({
30
31
  database: (0, import_database_name.getDatabaseName)(),
@@ -41,7 +42,7 @@ class McpServerRepository {
41
42
  return await this._.patchOne({ scope, where: { _id: mcpServer._id }, ...(0, import_utils.entityPatch)(mcpServer), expectedVersion: options?.expectedVersion });
42
43
  }
43
44
  async findById(id, scope) {
44
- return await this._.findOne({ scope, where: { _id: this._.parseId(id) } });
45
+ return await this._.findOne({ scope, where: external({ _id: this._.parseId(id) }) });
45
46
  }
46
47
  async findAllByOwner(ownerId, scope) {
47
48
  return await this._.findAll({
@@ -51,14 +52,33 @@ class McpServerRepository {
51
52
  });
52
53
  }
53
54
  async softDeleteById(id, scope) {
54
- return await this._.softDelete({ scope, where: { _id: this._.parseId(id) } });
55
+ return await this._.softDelete({ scope, where: external({ _id: this._.parseId(id) }) });
55
56
  }
56
57
  async deleteById(id, scope) {
57
- return await this._.deleteOne({ scope, where: { _id: this._.parseId(id) } });
58
+ return await this._.deleteOne({ scope, where: external({ _id: this._.parseId(id) }) });
58
59
  }
59
60
  async findByProps(where, scope, options) {
60
61
  return await this._.findMany({ scope, where, options });
61
62
  }
63
+ async findInternalById(id, scope) {
64
+ return await this._.findOne({ scope, where: { _id: this._.parseId(id), internal: true } });
65
+ }
66
+ async findInternalByName(name, scope) {
67
+ return await this._.findOne({ scope, where: { name, internal: true } });
68
+ }
69
+ async findInternalPage(scope, options) {
70
+ return await this._.findManyPaginated({ scope, where: { internal: true }, options });
71
+ }
72
+ async findActiveInternals() {
73
+ return await this._.findAll({
74
+ scope: import_repositories.Scope.system("Load the internal MCP servers of the solution"),
75
+ where: { internal: true, enabled: true },
76
+ options: { sortBy: { createdAt: 1, _id: 1 } }
77
+ });
78
+ }
79
+ async deleteInternalById(id, scope) {
80
+ return await this._.deleteOne({ scope, where: { _id: this._.parseId(id), internal: true } });
81
+ }
62
82
  }
63
83
  // Annotate the CommonJS export names for ESM import in node:
64
84
  0 && (module.exports = {
@@ -1,7 +1,8 @@
1
1
  import { ObjectId } from "mongodb";
2
2
  import { entityPatch } from "../../../common/base/utils/index.js";
3
- import { MongoRepository } from "../../../common/repositories/index.js";
3
+ import { MongoRepository, Scope } from "../../../common/repositories/index.js";
4
4
  import { getDatabaseName } from "../../../common/utils/database-name.js";
5
+ const external = (where) => ({ ...where, internal: { $ne: true } });
5
6
  class McpServerRepository {
6
7
  _ = new MongoRepository({
7
8
  database: getDatabaseName(),
@@ -18,7 +19,7 @@ class McpServerRepository {
18
19
  return await this._.patchOne({ scope, where: { _id: mcpServer._id }, ...entityPatch(mcpServer), expectedVersion: options?.expectedVersion });
19
20
  }
20
21
  async findById(id, scope) {
21
- return await this._.findOne({ scope, where: { _id: this._.parseId(id) } });
22
+ return await this._.findOne({ scope, where: external({ _id: this._.parseId(id) }) });
22
23
  }
23
24
  async findAllByOwner(ownerId, scope) {
24
25
  return await this._.findAll({
@@ -28,14 +29,33 @@ class McpServerRepository {
28
29
  });
29
30
  }
30
31
  async softDeleteById(id, scope) {
31
- return await this._.softDelete({ scope, where: { _id: this._.parseId(id) } });
32
+ return await this._.softDelete({ scope, where: external({ _id: this._.parseId(id) }) });
32
33
  }
33
34
  async deleteById(id, scope) {
34
- return await this._.deleteOne({ scope, where: { _id: this._.parseId(id) } });
35
+ return await this._.deleteOne({ scope, where: external({ _id: this._.parseId(id) }) });
35
36
  }
36
37
  async findByProps(where, scope, options) {
37
38
  return await this._.findMany({ scope, where, options });
38
39
  }
40
+ async findInternalById(id, scope) {
41
+ return await this._.findOne({ scope, where: { _id: this._.parseId(id), internal: true } });
42
+ }
43
+ async findInternalByName(name, scope) {
44
+ return await this._.findOne({ scope, where: { name, internal: true } });
45
+ }
46
+ async findInternalPage(scope, options) {
47
+ return await this._.findManyPaginated({ scope, where: { internal: true }, options });
48
+ }
49
+ async findActiveInternals() {
50
+ return await this._.findAll({
51
+ scope: Scope.system("Load the internal MCP servers of the solution"),
52
+ where: { internal: true, enabled: true },
53
+ options: { sortBy: { createdAt: 1, _id: 1 } }
54
+ });
55
+ }
56
+ async deleteInternalById(id, scope) {
57
+ return await this._.deleteOne({ scope, where: { _id: this._.parseId(id), internal: true } });
58
+ }
39
59
  }
40
60
  export {
41
61
  McpServerRepository
@@ -22,6 +22,7 @@ __export(list_mcpservers_by_user_use_case_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(list_mcpservers_by_user_use_case_exports);
24
24
  var import_mongodb = require("mongodb");
25
+ var import_repositories = require("../../../common/repositories/index.js");
25
26
  var import_base = require("../../../common/base/base.use-case.js");
26
27
  var import_repositories2 = require("../repositories");
27
28
  class ListMcpServersByUserUseCase extends import_base.BaseUseCase {
@@ -34,6 +35,7 @@ class ListMcpServersByUserUseCase extends import_base.BaseUseCase {
34
35
  const { options, currentUser } = params;
35
36
  const { page = 1, limit: pageSize = 10 } = options || {};
36
37
  const result = await this.mcpServerRepository._.findManyPaginated({
38
+ scope: params.scope ?? import_repositories.Scope.canView(currentUser),
37
39
  where: {
38
40
  ownerId: new import_mongodb.ObjectId(currentUser?.userId)
39
41
  },
@@ -1,4 +1,5 @@
1
1
  import { ObjectId } from "mongodb";
2
+ import { Scope } from "../../../common/repositories/index.js";
2
3
  import { BaseUseCase } from "../../../common/base/base.use-case.js";
3
4
  import { McpServerRepository } from "../repositories";
4
5
  class ListMcpServersByUserUseCase extends BaseUseCase {
@@ -11,6 +12,7 @@ class ListMcpServersByUserUseCase extends BaseUseCase {
11
12
  const { options, currentUser } = params;
12
13
  const { page = 1, limit: pageSize = 10 } = options || {};
13
14
  const result = await this.mcpServerRepository._.findManyPaginated({
15
+ scope: params.scope ?? Scope.canView(currentUser),
14
16
  where: {
15
17
  ownerId: new ObjectId(currentUser?.userId)
16
18
  },
@@ -48,7 +48,7 @@ class UpdateMcpServerUseCase extends import_base.BaseUseCase {
48
48
  }
49
49
  const endpointChanged = payload.url !== void 0 && payload.url !== existing.url || payload.type !== void 0 && payload.type !== existing.type;
50
50
  const headersChanged = payload.headers !== void 0 && JSON.stringify(payload.headers) !== JSON.stringify(existing.headers);
51
- const mcpServer = import_entities.McpServer.fromJSON({ ...existing, ...payload, _id: id, trust: existing.trust, approvedHash: existing.approvedHash, status: existing.status, lastError: existing.lastError, history: existing.history });
51
+ const mcpServer = import_entities.McpServer.fromJSON({ ...existing, ...payload, _id: id, trust: existing.trust, approvedHash: existing.approvedHash, status: existing.status, lastError: existing.lastError, history: existing.history, internal: existing.internal, enabled: existing.enabled });
52
52
  if (endpointChanged) {
53
53
  mcpServer.lockForNewEndpoint();
54
54
  }
@@ -25,7 +25,7 @@ class UpdateMcpServerUseCase extends BaseUseCase {
25
25
  }
26
26
  const endpointChanged = payload.url !== void 0 && payload.url !== existing.url || payload.type !== void 0 && payload.type !== existing.type;
27
27
  const headersChanged = payload.headers !== void 0 && JSON.stringify(payload.headers) !== JSON.stringify(existing.headers);
28
- const mcpServer = McpServer.fromJSON({ ...existing, ...payload, _id: id, trust: existing.trust, approvedHash: existing.approvedHash, status: existing.status, lastError: existing.lastError, history: existing.history });
28
+ const mcpServer = McpServer.fromJSON({ ...existing, ...payload, _id: id, trust: existing.trust, approvedHash: existing.approvedHash, status: existing.status, lastError: existing.lastError, history: existing.history, internal: existing.internal, enabled: existing.enabled });
29
29
  if (endpointChanged) {
30
30
  mcpServer.lockForNewEndpoint();
31
31
  }
package/docs/agent.md CHANGED
@@ -72,7 +72,7 @@ Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a
72
72
 
73
73
  `currentSession` is optional. It carries device, location and locale, which skills use to answer in the right time zone and language.
74
74
 
75
- `mcpTokens` is optional. It gives the token of the user to each [internal MCP server](mcp-servers.md#internal-mcp-servers), by name. It is never saved. `serviceToken` is the token that the runner of [automations](automations.md#internal-mcp-servers-in-a-automation) passes when there is no session of the user. You do not need it unless you write your own scheduler.
75
+ `mcpTokens` is optional. It gives the token of the user to each [internal MCP server](mcp-servers.md#internal-mcp-servers), by name. It is never saved. In an [autonomous run](#autonomous-mode) with no token for a server, the `autonomousToken` of that server is used, see [automations](automations.md#internal-mcp-servers-in-an-automation).
76
76
 
77
77
  ## Autonomous mode
78
78
 
@@ -320,13 +320,31 @@ A new `Agent` is created for every run, so the options are the same but nothing
320
320
 
321
321
  ### Internal MCP servers in an automation
322
322
 
323
- An automation runs without the session of its owner, so there is no token of theirs to send to your [internal MCP servers](mcp-servers.md#internal-mcp-servers). For automations, the runner uses one token for the whole deployment, taken from `INTERNAL_MCP_TOKEN`. It replaces `{{token}}` in the headers of every internal server, and the runner also sends the id of the owner of the automation in the header `X-User-Id`, so your MCP server knows on whose behalf it acts.
323
+ An automation runs without the session of its owner, so there is no token of theirs to send to your [internal MCP servers](mcp-servers.md#internal-mcp-servers). Each internal server can declare an `autonomousToken`, the token of a service account that is used only in autonomous runs, such as the ones of the runner, when the run brings no token for that server:
324
324
 
325
- - Your MCP server must accept `X-User-Id` only together with this service token. Never trust it on a request that carries the token of a user.
326
- - The header is added only in automations and only to internal servers that use `{{token}}`. It replaces any `X-User-Id` you configured. It is never sent to the servers added by the user.
327
- - Without `INTERNAL_MCP_TOKEN`, the internal servers that need a token are unavailable in the automations, and the run continues without them.
328
- - The value is read with the secret manager, so it can be encrypted with the `ENC:` prefix.
329
- - One variable serves all the internal servers. If two of them need different credentials, that is not supported yet.
325
+ ```typescript
326
+ const runner = createAutomationRunner({
327
+ agent: {
328
+ loop: new AgiLoop(),
329
+ internalMcps: [
330
+ {
331
+ name: 'budget',
332
+ url: 'https://api.example.com/mcp',
333
+ headers: { Authorization: 'Bearer {{token}}' },
334
+ autonomousToken: process.env.BUDGET_SERVICE_TOKEN,
335
+ },
336
+ ],
337
+ },
338
+ })
339
+ ```
340
+
341
+ - `{{token}}` is replaced with the `autonomousToken` and the agent sends the id of the owner of the automation in the header `X-User-Id`, so your MCP server knows on whose behalf it acts.
342
+ - Your MCP server must accept `X-User-Id` only together with that service token. Never trust it on a request that carries the token of a user.
343
+ - The header is added only in autonomous runs and only to internal servers that use `{{token}}`. It replaces any `X-User-Id` you configured. It is never sent to the servers added by the user.
344
+ - An interactive run never uses the `autonomousToken`. A server without one is unavailable in the automations that need a token, and the run continues without it.
345
+ - Each server has its own token, so two servers can use different service accounts. A server that must use a service account in every run, also in chats, does not need this: write the token in the header (for example `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjcm0uZXhhbXBsZS5jb20iLCJzdWIiOiJzdmMtb3Blbmxvb3BzLWNybSIsImF1ZCI6ImNybS1tY3AiLCJzY29wZSI6ImNybTpyZWFkIGNybTp3cml0ZSIsImlhdCI6MTc2MjIxNDQwMCwiZXhwIjoxNzkzNzUwNDAwfQ.YCtd8mv7RZpaZb3Z1aSl25MGP2QRWHc8RtA82MJOH7U`).
346
+ - `autonomousToken` exists only in the servers declared in code. A server stored with the back office is [available in an automation](mcp-servers.md#internal-servers-stored-in-the-database) only if its header has the token written in it.
347
+ - This field is temporary. It will go away when the integrations let the runner get the token of the owner.
330
348
 
331
349
  ### Running by hand
332
350