import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import { driftClient } from '../services/drift-client.js';
export function registerBranchTools(server: McpServer): void {
server.registerTool(
'driftos_list_branches',
{
title: 'List Conversation Branches',
description: `List all branches in a conversation with their topics and message counts.
Use this to understand the structure of a conversation and see what topics have been discussed.
Args:
- conversation_id (string): Unique identifier for the conversation
Returns:
[
{
"id": string,
"topic": string,
"messageCount": number,
"isActive": boolean
}
]`,
inputSchema: z.object({
conversation_id: z.string().min(1).describe('Unique identifier for the conversation'),
}).strict(),
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
},
async (params) => {
try {
const result = await driftClient.getBranches(params.conversation_id);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(result, null, 2),
},
],
};
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error';
return {
content: [
{
type: 'text' as const,
text: `Error listing branches: ${message}`,
},
],
isError: true,
};
}
}
);
}