histoire
Version:
A fast story book powered by Vite
32 lines (31 loc) • 3.68 kB
JavaScript
import { observeMcpClientName } from '../observer/client-metadata.js';
import { projectMcpUiTarget } from '../observer/target.js';
import { errorResult, successResult } from '../protocol/results.js';
import { mcpToolInputSchemas, mcpToolOutputSchemas } from '../protocol/tool-schema.js';
/** Exactly the read milestone tools, shared by both serving transports. */
export const MCP_READ_TOOLS = ['histoire_get_project', 'histoire_list_stories', 'histoire_get_story', 'histoire_get_docs', 'histoire_get_source', 'histoire_get_preview'];
/** Read metadata never launches browsers or causes extra collection. */
const annotations = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
/** Project expected domain failures to one tool result adapter. */
export async function readToolResult(read) {
try {
return successResult(await read());
}
catch (error) {
return errorResult(error);
}
}
/** Register only implemented read services, with strict input/output schemas. */
export function registerReadTools(server, project, observeClientName, observeReadTool) {
/** Metadata comes from SDK context, outside public tool argument/result DTOs. */
function read(context, name, input, work) {
observeMcpClientName(server, context, observeClientName);
return readToolResult(() => observeReadTool ? observeReadTool(name, projectMcpUiTarget(input), work) : work());
}
server.registerTool('histoire_get_project', { description: 'Read served book lifecycle and available capabilities.', inputSchema: mcpToolInputSchemas.histoire_get_project, outputSchema: mcpToolOutputSchemas.histoire_get_project, annotations }, (input, context) => read(context, 'histoire_get_project', input, () => project.getProject(context.mcpReq.signal)));
server.registerTool('histoire_list_stories', { description: 'Search and page collected stories from a completed catalog snapshot.', inputSchema: mcpToolInputSchemas.histoire_list_stories, outputSchema: mcpToolOutputSchemas.histoire_list_stories, annotations }, (input, context) => read(context, 'histoire_list_stories', input, () => project.listStories(input, context.mcpReq.signal)));
server.registerTool('histoire_get_story', { description: 'Read exact story metadata and associated resource links.', inputSchema: mcpToolInputSchemas.histoire_get_story, outputSchema: mcpToolOutputSchemas.histoire_get_story, annotations }, (input, context) => read(context, 'histoire_get_story', input, () => project.getStory(input, context.mcpReq.signal)));
server.registerTool('histoire_get_docs', { description: 'Read original documentation by Unicode character page.', inputSchema: mcpToolInputSchemas.histoire_get_docs, outputSchema: mcpToolOutputSchemas.histoire_get_docs, annotations }, (input, context) => read(context, 'histoire_get_docs', input, () => project.getDocs(input, context.mcpReq.signal)));
server.registerTool('histoire_get_source', { description: 'Read raw registered source by original line page.', inputSchema: mcpToolInputSchemas.histoire_get_source, outputSchema: mcpToolOutputSchemas.histoire_get_source, annotations }, (input, context) => read(context, 'histoire_get_source', input, () => project.getSource(input, context.mcpReq.signal)));
server.registerTool('histoire_get_preview', { description: 'Resolve exact story/variant UI and sandbox links without opening a browser.', inputSchema: mcpToolInputSchemas.histoire_get_preview, outputSchema: mcpToolOutputSchemas.histoire_get_preview, annotations }, (input, context) => read(context, 'histoire_get_preview', input, () => project.getPreview(input, context.mcpReq.signal)));
}