driftos_get_context
Retrieve focused conversation context for LLMs by extracting relevant messages and accumulated facts from specific branches, reducing history overload.
Instructions
Get assembled context for a conversation branch, including messages and facts from related branches.
This is what you pass to an LLM instead of the entire conversation history. Returns only the relevant messages from the current branch plus accumulated facts.
Args:
branch_id (string): The branch ID to get context for (returned from route_message)
Returns: { "branchId": string, "branchTopic": string, "messages": [ { "role": "user" | "assistant", "content": string } ], "allFacts": [ { "branchTopic": string, "isCurrent": boolean, "facts": [{ "key": string, "value": string, "confidence": number }] } ] }
Use this to build focused LLM context windows instead of dumping entire conversation history.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch_id | Yes | Branch ID to get context for |
Implementation Reference
- src/tools/context.ts:44-68 (handler)Executes the tool logic: calls driftClient.getContext(branch_id), stringifies the result as JSON text response, or returns error if failed.async (params) => { try { const result = await driftClient.getContext(params.branch_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 getting context: ${message}`, }, ], isError: true, }; } }
- src/tools/context.ts:34-36 (schema)Zod input schema validating the branch_id parameter.inputSchema: z.object({ branch_id: z.string().min(1).describe('Branch ID to get context for'), }).strict(),
- src/tools/context.ts:6-69 (registration)Direct registration of the 'driftos_get_context' tool on the MCP server, including title, description, input schema, annotations, and inline handler function.server.registerTool( 'driftos_get_context', { title: 'Get Conversation Context', description: `Get assembled context for a conversation branch, including messages and facts from related branches. This is what you pass to an LLM instead of the entire conversation history. Returns only the relevant messages from the current branch plus accumulated facts. Args: - branch_id (string): The branch ID to get context for (returned from route_message) Returns: { "branchId": string, "branchTopic": string, "messages": [ { "role": "user" | "assistant", "content": string } ], "allFacts": [ { "branchTopic": string, "isCurrent": boolean, "facts": [{ "key": string, "value": string, "confidence": number }] } ] } Use this to build focused LLM context windows instead of dumping entire conversation history.`, inputSchema: z.object({ branch_id: z.string().min(1).describe('Branch ID to get context for'), }).strict(), annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, async (params) => { try { const result = await driftClient.getContext(params.branch_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 getting context: ${message}`, }, ], isError: true, }; } } );
- src/services/drift-client.ts:4-4 (helper)Creation of the driftClient instance used in the tool handler to perform the getContext call.export const driftClient = createDriftClient(DRIFTOS_API_URL);
- src/index.ts:18-18 (registration)Top-level call to registerContextTools during MCP server initialization, which includes registration of driftos_get_context.registerContextTools(server);