Skip to content
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
2 changes: 1 addition & 1 deletion .changeset/calm-notion-automations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@roomote/web": minor
---

Add a deployment-wide Notion internal integration for tasks and automations. Notion restricts it to explicitly shared content, while admins choose read-only or read-write tool access in Roomote.
Add a deployment-wide Notion internal integration for tasks and automations. Notion controls the connection's capabilities and restricts it to explicitly shared content.
2 changes: 0 additions & 2 deletions apps/api/src/handlers/mcp/__tests__/integration-mcp.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 2 additions & 44 deletions apps/api/src/handlers/mcp/__tests__/notion-auth.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions apps/api/src/handlers/mcp/integration-mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ async function resolveDeploymentToolPolicy(mcpId: string) {
),
columns: {
disabledTools: true,
toolAccessMode: true,
},
});

return {
disabledToolNames: enablement?.disabledTools ?? null,
allowedToolNames:
getAllowedIntegrationMcpToolNames(mcpId, enablement?.toolAccessMode) ??
null,
allowedToolNames: getAllowedIntegrationMcpToolNames(mcpId) ?? null,
};
}

Expand Down
32 changes: 8 additions & 24 deletions apps/api/src/handlers/mcp/notion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
mcpConnections,
taskRuns,
} from '@roomote/db/server';
import {
getAllowedIntegrationMcpToolNames,
isMcpConnectionNotionConfig,
} from '@roomote/types';
import { isMcpConnectionNotionConfig } from '@roomote/types';

import type { Variables } from '../../../types';

Expand Down Expand Up @@ -62,7 +59,7 @@ async function resolveNotionMcpAuth(
);
}

async function resolveNotionConnectionAndPolicy() {
async function resolveNotionConnection() {
const [connection, enablement] = await Promise.all([
db.query.mcpConnections.findFirst({
where: and(
Expand All @@ -77,10 +74,7 @@ async function resolveNotionConnectionAndPolicy() {
eq(deploymentMcpEnablements.mcpId, 'notion'),
eq(deploymentMcpEnablements.enabled, true),
),
columns: {
disabledTools: true,
toolAccessMode: true,
},
columns: { mcpId: true },
}),
]);

Expand All @@ -98,28 +92,18 @@ async function resolveNotionConnectionAndPolicy() {
);
}

return {
config: connection.authConfig,
policy: {
allowedToolNames:
getAllowedIntegrationMcpToolNames(
'notion',
enablement.toolAccessMode,
) ?? undefined,
disabledToolNames: enablement.disabledTools,
},
};
return connection.authConfig;
}

function createNotionMcpServer(
resolved: Awaited<ReturnType<typeof resolveNotionConnectionAndPolicy>>,
config: Awaited<ReturnType<typeof resolveNotionConnection>>,
) {
const server = new McpServer(NOTION_MCP_SERVER_INFO, {
instructions:
'Use these Notion tools only for content explicitly shared with the deployment internal integration. Unshared pages, including private pages, are inaccessible to the stored token.',
});

registerNotionTools(server, resolved.config, resolved.policy);
registerNotionTools(server, config);
return server;
}

Expand All @@ -132,8 +116,8 @@ notionMcp.on(['POST', 'GET', 'DELETE'], '/', async (c) => {

try {
await resolveNotionMcpAuth(c.get('authContext'));
const connectionAndPolicy = await resolveNotionConnectionAndPolicy();
const server = createNotionMcpServer(connectionAndPolicy);
const connection = await resolveNotionConnection();
const server = createNotionMcpServer(connection);

await server.connect(transport);
return await transport.handleRequest(c.req.raw);
Expand Down
Loading
Loading