Skip to content

[front] mcp(remote): create remote server model #11409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions front/admin/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
AgentReasoningAction,
AgentReasoningConfiguration,
} from "@app/lib/models/assistant/actions/reasoning";
import { RemoteMCPServer } from "@app/lib/models/assistant/actions/remote_mcp_server";
import {
AgentRetrievalAction,
AgentRetrievalConfiguration,
Expand Down Expand Up @@ -147,6 +148,8 @@ async function main() {
await AgentUserRelation.sync({ alter: true });
await GlobalAgentSettings.sync({ alter: true });

await RemoteMCPServer.sync({ alter: true });

await AgentRetrievalConfiguration.sync({ alter: true });
await AgentDustAppRunConfiguration.sync({ alter: true });
await AgentTablesQueryConfiguration.sync({ alter: true });
Expand Down
22 changes: 20 additions & 2 deletions front/lib/models/assistant/actions/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CreationOptional, ForeignKey } from "sequelize";
import { DataTypes } from "sequelize";
import type { z } from "zod";

import { RemoteMCPServer } from "@app/lib/models/assistant/actions/remote_mcp_server";
import { AgentConfiguration } from "@app/lib/models/assistant/agent";
import { AgentMessage } from "@app/lib/models/assistant/conversation";
import { frontSequelize } from "@app/lib/resources/storage";
Expand All @@ -24,8 +25,7 @@ export class AgentMCPServerConfiguration extends WorkspaceAwareModel<AgentMCPSer

declare serverType: "internal" | "remote";
declare internalMCPServerId: string | null;

//TODO(mcp): Add a reference to the MCP server in case of remote host type.
declare remoteMCPServerId: ForeignKey<RemoteMCPServer["id"]> | null;
}

AgentMCPServerConfiguration.init(
Expand Down Expand Up @@ -79,8 +79,18 @@ AgentMCPServerConfiguration.init(
"internalMCPServerId is required for serverType internal"
);
}
if (config.remoteMCPServerId) {
throw new Error(
"remoteMCPServerId is not allowed for serverType internal"
);
}
break;
case "remote":
if (!config.remoteMCPServerId) {
throw new Error(
"remoteMCPServerId is required for serverType remote"
);
}
if (config.internalMCPServerId) {
throw new Error(
"internalMCPServerId is not allowed for serverType remote"
Expand All @@ -102,6 +112,14 @@ AgentMCPServerConfiguration.belongsTo(AgentConfiguration, {
foreignKey: { name: "agentConfigurationId", allowNull: false },
});

RemoteMCPServer.hasMany(AgentMCPServerConfiguration, {
foreignKey: { name: "remoteMCPServerId", allowNull: true },
onDelete: "RESTRICT",
});
AgentMCPServerConfiguration.belongsTo(RemoteMCPServer, {
foreignKey: { name: "remoteMCPServerId", allowNull: true },
});

export class AgentMCPAction extends WorkspaceAwareModel<AgentMCPAction> {
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;
Expand Down
81 changes: 81 additions & 0 deletions front/lib/models/assistant/actions/remote_mcp_server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { CreationOptional, ForeignKey, NonAttribute } from "sequelize";
import { DataTypes } from "sequelize";

import { frontSequelize } from "@app/lib/resources/storage";
import { SpaceModel } from "@app/lib/resources/storage/models/spaces";
import { WorkspaceAwareModel } from "@app/lib/resources/storage/wrappers/workspace_models";

export class RemoteMCPServer extends WorkspaceAwareModel<RemoteMCPServer> {
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;

declare sId: string;

declare spaceId: ForeignKey<SpaceModel["id"]>;
declare space: NonAttribute<SpaceModel>;

declare name: string;
declare url: string;

declare description: string | null;
declare cachedTools: string[];

declare lastSyncAt: Date | null;
declare sharedSecret: string;
}

RemoteMCPServer.init(
{
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
sId: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
url: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
cachedTools: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true,
defaultValue: [],
},
lastSyncAt: {
type: DataTypes.DATE,
allowNull: true,
},
sharedSecret: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
sequelize: frontSequelize,
modelName: "remote_mcp_server",
}
);

SpaceModel.hasMany(RemoteMCPServer, {
foreignKey: { allowNull: false, name: "spaceId" },
onDelete: "RESTRICT",
});
RemoteMCPServer.belongsTo(SpaceModel, {
foreignKey: { allowNull: false, name: "spaceId" },
});
20 changes: 20 additions & 0 deletions front/migrations/db/migration_185.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Migration created on Mar 19, 2025
CREATE TABLE IF NOT EXISTS "remote_mcp_servers" (
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"sId" varchar(255) NOT NULL,
"name" varchar(255) NOT NULL,
"url" varchar(255) NOT NULL,
"description" text,
"cachedTools" varchar(255)[] DEFAULT ARRAY[] ::varchar(255)[],
"lastSyncAt" timestamp with time zone,
"sharedSecret" varchar(255) NOT NULL,
"workspaceId" bigint NOT NULL REFERENCES "workspaces" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
"id" bigserial,
"spaceId" bigint NOT NULL REFERENCES "vaults" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
PRIMARY KEY ("id")
);

ALTER TABLE "public"."agent_mcp_server_configurations"
ADD COLUMN "remoteMCPServerId" bigint REFERENCES "remote_mcp_servers" ("id") ON DELETE RESTRICT ON UPDATE CASCADE;

Loading