Files
outline-mcp/src/tools/document.ts
Timo Behrendt e2081a19b5
All checks were successful
CD / test (push) Successful in 21s
CD / Check changes (push) Successful in 31s
CD / Build and push (amd64) (push) Successful in 47s
CD / Build and push (arm64) (push) Successful in 3m6s
CD / Create manifest (push) Successful in 55s
initial-commit (#1)
Reviewed-on: #1
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
2025-07-16 07:21:12 +02:00

69 lines
2.3 KiB
TypeScript

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { backlinkDocumentId, collectionId, direction, limit, offset, parentDocumentId, sort, userId } from "./common";
import { handleSuccess, handleError } from "./utils";
import type { ToolsFactory } from "./toolsFactory";
import type { DocumentsApi } from "../gen/api/outline";
import type { Logger } from "pino";
export const registerDocumentTools: ToolsFactory<DocumentsApi> = (server: McpServer, client: DocumentsApi, logger: Logger): void => {
server.registerTool(
"documents_info",
{
title: "Get Document Info",
description: "Retrieve a document by its UUID, urlId, or shareId. At least one of these parameters must be provided.",
inputSchema: {
id: z.string().optional().describe("Unique identifier for the document. Either the UUID or the urlId is acceptable."),
shareId: z.string().optional().describe("Unique identifier for a document share, a shareId may be used in place of a document UUID"),
},
},
async (args) => {
try {
const response = await client.documentsInfo({
documentsInfoRequest: {
id: args?.id,
shareId: args?.shareId,
},
});
return handleSuccess(response, logger.child({ tool: "documents_info" }));
} catch (error) {
return handleError(error, logger.child({ tool: "documents_info" }));
}
}
);
const documentsListSchema = z.object({
offset,
limit,
sort,
direction,
collectionId,
userId,
backlinkDocumentId,
parentDocumentId,
template: z.boolean().optional(),
});
server.registerTool(
"documents_list",
{
title: "List Documents",
description: "This method will list all published documents and draft documents belonging to the current user.",
inputSchema: documentsListSchema.shape,
},
async (args) => {
try {
const validatedArgs = documentsListSchema.parse(args);
const response = await client.documentsList({
documentsListRequest: validatedArgs,
});
return handleSuccess(response, logger.child({ tool: "documents_list" }));
} catch (error) {
return handleError(error, logger.child({ tool: "documents_list" }));
}
}
);
};