diff --git a/app/models/Team.ts b/app/models/Team.ts index 47363c7f60..0d142fc6ee 100644 --- a/app/models/Team.ts +++ b/app/models/Team.ts @@ -64,6 +64,10 @@ class Team extends Model { @observable defaultUserRole: UserRole; + @Field + @observable + guidanceMCP: string | null; + @Field @observable preferences: TeamPreferences | null; diff --git a/app/scenes/Settings/Features.tsx b/app/scenes/Settings/Features.tsx index d3651f636a..2386145e8c 100644 --- a/app/scenes/Settings/Features.tsx +++ b/app/scenes/Settings/Features.tsx @@ -4,6 +4,7 @@ import * as React from "react"; import { useTranslation, Trans } from "react-i18next"; import { toast } from "sonner"; import { TeamPreference } from "@shared/types"; +import { TeamValidation } from "@shared/validations"; import Heading from "~/components/Heading"; import Scene from "~/components/Scene"; import Switch from "~/components/Switch"; @@ -30,6 +31,18 @@ function Features() { [team, t] ); + const handleGuidanceMCPChange = React.useCallback( + async (ev: React.ChangeEvent) => { + team.guidanceMCP = ev.target.value || null; + }, + [team] + ); + + const handleGuidanceMCPBlur = React.useCallback(async () => { + await team.save(); + toast.success(t("Settings saved")); + }, [team, t]); + const handleCopied = React.useCallback(() => { toast.success(t("Copied to clipboard")); }, [t]); @@ -46,6 +59,7 @@ function Features() { @@ -97,6 +111,31 @@ function Features() { /> + {team.getPreference(TeamPreference.MCP) && ( + +
+ {t( + "You can use these optional instructions to tell MCP clients how to use your knowledge base." + )} +
+ + + } + /> + )} + { + return queryInterface.addColumn("teams", "guidanceMCP", { + type: Sequelize.TEXT, + allowNull: true, + }); + }, + + down: async (queryInterface) => { + return queryInterface.removeColumn("teams", "guidanceMCP"); + }, +}; diff --git a/server/models/Team.ts b/server/models/Team.ts index 9b18711b18..80849d9856 100644 --- a/server/models/Team.ts +++ b/server/models/Team.ts @@ -187,6 +187,14 @@ class Team extends ParanoidModel< @SkipChangeset approximateTotalAttachmentsSize: number; + @AllowNull + @Length({ + max: TeamValidation.maxGuidanceMCPLength, + msg: `MCP guidance must be ${TeamValidation.maxGuidanceMCPLength} characters or less`, + }) + @Column(DataType.TEXT) + guidanceMCP: string | null; + @AllowNull @Column(DataType.JSONB) preferences: TeamPreferences | null; diff --git a/server/presenters/team.ts b/server/presenters/team.ts index d5ffc771a8..cee6df9194 100644 --- a/server/presenters/team.ts +++ b/server/presenters/team.ts @@ -20,5 +20,6 @@ export default function presentTeam(team: Team) { inviteRequired: team.inviteRequired, allowedDomains: team.allowedDomains?.map((d) => d.name), preferences: team.preferences, + guidanceMCP: team.guidanceMCP, }; } diff --git a/server/routes/api/teams/schema.ts b/server/routes/api/teams/schema.ts index 9d8d97a942..394a5076a7 100644 --- a/server/routes/api/teams/schema.ts +++ b/server/routes/api/teams/schema.ts @@ -1,5 +1,6 @@ import { z } from "zod"; import { EmailDisplay, TOCPosition, UserRole } from "@shared/types"; +import { TeamValidation } from "@shared/validations"; import { BaseSchema } from "@server/routes/api/schema"; export const TeamsUpdateSchema = BaseSchema.extend({ @@ -32,6 +33,8 @@ export const TeamsUpdateSchema = BaseSchema.extend({ inviteRequired: z.boolean().optional(), /** Domains allowed to sign-in with SSO */ allowedDomains: z.array(z.string()).optional(), + /** Workspace guidance provided to MCP clients on connection */ + guidanceMCP: z.string().max(TeamValidation.maxGuidanceMCPLength).nullish(), /** Team preferences */ preferences: z .object({ diff --git a/server/routes/mcp/index.ts b/server/routes/mcp/index.ts index 6fa3023ef6..deb5afc67f 100644 --- a/server/routes/mcp/index.ts +++ b/server/routes/mcp/index.ts @@ -27,9 +27,10 @@ const router = new Router(); * scopes granted to the current token. * * @param scopes - the OAuth scopes granted to the access token. + * @param instructions - optional workspace guidance to send to clients. * @returns a configured McpServer ready to be connected to a transport. */ -function createMcpServer(scopes: string[]): McpServer { +function createMcpServer(scopes: string[], instructions?: string): McpServer { const server = new McpServer( { name: "outline", @@ -39,6 +40,7 @@ function createMcpServer(scopes: string[]): McpServer { capabilities: { tools: {}, }, + ...(instructions ? { instructions } : {}), } ); @@ -68,7 +70,10 @@ router.post( throw NotFoundError(); } - const server = createMcpServer(scope ?? []); + const server = createMcpServer( + scope ?? [], + user.team.guidanceMCP ?? undefined + ); const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, }); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index de5ac5b256..cb03a58f0e 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -1250,6 +1250,8 @@ "Allow members to connect to this workspace with MCP to read and write data.": "Allow members to connect to this workspace with MCP to read and write data.", "Use the following endpoint to connect to the MCP server from your app. Find out more about setup in the docs.": "Use the following endpoint to connect to the MCP server from your app. Find out more about setup in the docs.", "Copy URL": "Copy URL", + "Additional guidance": "Additional guidance", + "You can use these optional instructions to tell MCP clients how to use your knowledge base.": "You can use these optional instructions to tell MCP clients how to use your knowledge base.", "AI answers": "AI answers", "Use AI to get direct answers to questions in search. This feature requires a paid license.": "Use AI to get direct answers to questions in search. This feature requires a paid license.", "Add people to {{groupName}}": "Add people to {{groupName}}", diff --git a/shared/validations.ts b/shared/validations.ts index 2653b782fb..d3c61ab7ee 100644 --- a/shared/validations.ts +++ b/shared/validations.ts @@ -132,6 +132,9 @@ export const TeamValidation = { /** The maximum length of the team subdomain for self-hosted */ maxSubdomainSelfHostedLength: 255, + + /** The maximum length of MCP workspace guidance */ + maxGuidanceMCPLength: 2000, }; export const UserValidation = {