Skip to content
Draft
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

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

13 changes: 13 additions & 0 deletions apps/api/src/handlers/discord/routing-confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getAvailableEnvironments,
getRoutingAutoConfirmDelayMs,
getTaskUrl,
recordRoutingPreference,
resolveRoutingFollowUp,
ROUTING_AUTO_CONFIRM_TIMEOUT_MS,
type RoutingDecision,
Expand Down Expand Up @@ -777,6 +778,7 @@ export async function handleDiscordRoutingReply(input: {
: null,
userResponse: input.queuedMessage.text,
userId: input.launchOwnerUserId,
apiBaseUrl: routingContext.routingActor?.apiBaseUrl,
correctionMessage: {
user: input.queuedMessage.user,
text: input.queuedMessage.text,
Expand Down Expand Up @@ -1110,6 +1112,17 @@ export async function handleDiscordRoutingCallback(input: {
});
return;
}
if (option.workspace.type === 'environment') {
await recordRoutingPreference({
userId: pending.launchOwnerUserId,
apiBaseUrl: pending.routingContext?.routingActor?.apiBaseUrl,
environmentId: option.workspace.id,
signal:
input.callback.selection === pending.suggestedIndex
? 'accepted'
: 'corrected',
});
}
// The launch already answered a card that lived in the task thread.
if (pending.cardChannel) return;
await replyToDiscordEvent({
Expand Down

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

90 changes: 89 additions & 1 deletion apps/api/src/handlers/mcp/roomote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
MCP_INTEGRATIONS,
isUserToken,
PRODUCT_NAME,
ROUTING_PREFERENCE_GET_TOOL,
ROUTING_PREFERENCE_RECORD_TOOL,
} from '@roomote/types';
import { Env, getDefaultDocsUrl } from '@roomote/env';
import {
Expand Down Expand Up @@ -49,6 +51,10 @@ import {
import { requireCommunicationLookupTaskRun } from './communication-lookup-run-context';
import type { McpAuth } from './middleware';
import { registerRoomoteMemberTools } from './roomote-member-tools';
import {
getRoutingPreferenceMemory,
recordRoutingPreferenceMemory,
} from './routing-preference-memory';

const ROOMOTE_MCP_SERVER_INFO = {
name: 'roomote-router-mcp',
Expand Down Expand Up @@ -371,6 +377,7 @@ function createRoomoteMcpServer(
auth: McpAuthContext,
actingUserId: string | null,
memberAuth?: McpAuth,
routerTools = false,
) {
const server = new McpServer(ROOMOTE_MCP_SERVER_INFO, {
instructions: `Use get_about_me for Roomote platform, integration, and getting-started context. Use ${CHAT_MESSAGE_CONTEXT_TOOL.name} for surrounding context from the task communication channel or a referenced Slack/Discord message. Use ${CHAT_CHANNEL_MESSAGES_TOOL.name} for readable history from the task communication channel or an explicitly linked channel.`,
Expand All @@ -380,6 +387,79 @@ function createRoomoteMcpServer(
registerRoomoteMemberTools(server, memberAuth);
}

if (routerTools) {
server.registerTool(
ROUTING_PREFERENCE_GET_TOOL,
{
title: 'Get Routing Preference',
description:
'Get the current user routing preference from the Brain by exact key.',
inputSchema: {},
outputSchema: z.object({
preference: z
.object({
environmentId: z.string(),
acceptedCount: z.number(),
correctionCount: z.number(),
lastSelectedAt: z.string(),
})
.nullable(),
}),
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
},
async () =>
toMcpToolResult({
preference: actingUserId
? await getRoutingPreferenceMemory(actingUserId)
: null,
}),
);

server.registerTool(
ROUTING_PREFERENCE_RECORD_TOOL,
{
title: 'Record Routing Preference',
description:
'Record an accepted or corrected environment choice in the current user routing preference page.',
inputSchema: {
environmentId: z.string().min(1),
signal: z.enum(['accepted', 'corrected']),
},
outputSchema: z.object({
preference: z
.object({
environmentId: z.string(),
acceptedCount: z.number(),
correctionCount: z.number(),
lastSelectedAt: z.string(),
})
.nullable(),
}),
annotations: {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: false,
openWorldHint: false,
},
},
async ({ environmentId, signal }) =>
toMcpToolResult({
preference: actingUserId
? await recordRoutingPreferenceMemory({
userId: actingUserId,
environmentId,
signal,
})
: null,
}),
);
}

server.registerTool(
'get_about_me',
{
Expand Down Expand Up @@ -509,6 +589,7 @@ function createRoomoteMcpServer(
function createRoomoteMcpRouter(options: {
memberTools: boolean;
allowLegacyAudience: boolean;
routerTools: boolean;
}) {
const router = new Hono<{ Variables: Variables }>();

Expand Down Expand Up @@ -536,7 +617,12 @@ function createRoomoteMcpRouter(options: {
: rawAuth,
}
: undefined;
const server = createRoomoteMcpServer(auth, actingUserId, memberAuth);
const server = createRoomoteMcpServer(
auth,
actingUserId,
memberAuth,
options.routerTools,
);

await server.connect(transport);
return await transport.handleRequest(c.req.raw);
Expand Down Expand Up @@ -578,8 +664,10 @@ function createRoomoteMcpRouter(options: {
export const roomoteMcp = createRoomoteMcpRouter({
memberTools: false,
allowLegacyAudience: true,
routerTools: true,
});
export const publicRoomoteMcp = createRoomoteMcpRouter({
memberTools: true,
allowLegacyAudience: false,
routerTools: false,
});
Loading
Loading