Expose exact source documents through MCP

This commit is contained in:
Meta Vens 2026-08-16 21:30:21 +02:00
commit c88c71909d
9 changed files with 110 additions and 2 deletions

View file

@ -105,6 +105,10 @@ export const sourceContextInputSchema = {
after: z.number().int().min(0).max(20).optional(),
};
export const exactSourceDocumentInputSchema = {
sourceId: z.string().min(1),
};
export interface SearchHistoryArgs {
query: string;
limit?: number;
@ -210,6 +214,10 @@ export interface SourceContextArgs {
after?: number;
}
export interface ExactSourceDocumentArgs {
sourceId: string;
}
export function formatArchivedMessage(
message: ArchivedMessageRecord,
anchorMessageId: string,

View file

@ -46,6 +46,7 @@ import {
type SearchHistoryArgs,
type SearchSourcesArgs,
type SourceContextArgs,
type ExactSourceDocumentArgs,
type UpdateSharedDocumentArgs,
formatArchivedMessage,
formatHistoryResults,
@ -67,6 +68,7 @@ import {
searchHistoryInputSchema,
searchSourcesInputSchema,
sourceContextInputSchema,
exactSourceDocumentInputSchema,
updateSharedDocumentInputSchema,
} from "./mcp-server-shared";
@ -554,6 +556,45 @@ export function registerVoidbotTools(
},
);
registerIfAllowed(
"get_exact_source_document",
{
title: "Get Exact Source Document",
description:
"Fetch one complete indexed source document by its exact sourceId. This is the canonical read-only witness path for consumers that must hash and receipt the full source rather than a retrieval chunk.",
inputSchema: exactSourceDocumentInputSchema,
annotations: READ_ONLY_ANNOTATIONS,
},
async (input: ExactSourceDocumentArgs): Promise<CallToolResult> => {
const document = await context.sourceArchiveRepository.get(input.sourceId);
if (!document) {
return {
content: [{ type: "text", text: `No indexed source document with ID ${input.sourceId} was found.` }],
structuredContent: { found: false, sourceId: input.sourceId },
isError: true,
};
}
const exactDocument = {
found: true,
sourceId: document.id,
repoName: document.repoName,
path: document.path,
language: document.language,
title: document.title,
content: document.content,
lastModifiedAt: document.lastModifiedAt,
indexedAt: document.indexedAt,
metadata: document.metadata ?? {},
};
return {
content: [{ type: "text", text: renderJsonBlock(exactDocument) }],
structuredContent: exactDocument,
};
},
);
registerIfAllowed(
"get_message_context",
{