coda_get_page_content
Retrieve the content of a specific page in markdown format from a Coda document using its document ID and page identifier. Integrates with the Coda MCP Server for streamlined document interactions.
Instructions
Get the content of a page as markdown
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| docId | Yes | The ID of the document that contains the page to get the content of | |
| pageIdOrName | Yes | The ID or name of the page to get the content of |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"docId": {
"description": "The ID of the document that contains the page to get the content of",
"type": "string"
},
"pageIdOrName": {
"description": "The ID or name of the page to get the content of",
"type": "string"
}
},
"required": [
"docId",
"pageIdOrName"
],
"type": "object"
}
Implementation Reference
- src/server.ts:109-121 (handler)Inline handler function for the coda_get_page_content tool. Calls getPageContent helper, returns markdown content or error.async ({ docId, pageIdOrName }): Promise<CallToolResult> => { try { const content = await getPageContent(docId, pageIdOrName); if (content === undefined) { throw new Error("Unknown error has occurred"); } return { content: [{ type: "text", text: content }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to get page content: ${error}` }], isError: true }; } },
- src/server.ts:105-108 (schema)Zod input schema defining docId and pageIdOrName parameters for the tool.{ docId: z.string().describe("The ID of the document that contains the page to get the content of"), pageIdOrName: z.string().describe("The ID or name of the page to get the content of"), },
- src/server.ts:102-122 (registration)Registers the coda_get_page_content tool with the MCP server, including schema and handler.server.tool( "coda_get_page_content", "Get the content of a page as markdown", { docId: z.string().describe("The ID of the document that contains the page to get the content of"), pageIdOrName: z.string().describe("The ID or name of the page to get the content of"), }, async ({ docId, pageIdOrName }): Promise<CallToolResult> => { try { const content = await getPageContent(docId, pageIdOrName); if (content === undefined) { throw new Error("Unknown error has occurred"); } return { content: [{ type: "text", text: content }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to get page content: ${error}` }], isError: true }; } }, );
- src/client/helpers.ts:4-76 (helper)Helper function getPageContent that implements the page content retrieval: starts markdown export via API, polls status every 5s up to 5 retries, downloads the content using axios.export async function getPageContent(docId: string, pageIdOrName: string) { let requestId: string | undefined; try { // Begin page export const beginExportResp = await beginPageContentExport({ path: { docId, pageIdOrName, }, body: { outputFormat: "markdown", }, throwOnError: true, }); if (!beginExportResp.data) { throw new Error("Failed to begin page content export"); } requestId = beginExportResp.data.id; } catch (error) { throw new Error(`Failed to get page content: ${error}`); } // Poll for export status let retries = 0; const maxRetries = 5; let downloadLink: string | undefined; while (retries < maxRetries) { // Wait for 5 seconds await new Promise((resolve) => setTimeout(resolve, 5000)); try { const exportStatusResp = await getPageContentExportStatus({ path: { docId, pageIdOrName, requestId, }, throwOnError: true, }); if (exportStatusResp.data?.status === "complete") { downloadLink = exportStatusResp.data.downloadLink; break; } } catch (error) { throw new Error(`Failed to get page content export status: ${error}`); } retries++; if (retries >= maxRetries) { throw new Error(`Page content export did not complete after ${maxRetries} retries.`); } } if (!downloadLink) { throw new Error("Failed to get page content export status"); } try { const downloadResponse = await axios.get<string>(downloadLink, { responseType: "text", }); const markdownContent = downloadResponse.data; return markdownContent; } catch { throw new Error(`Failed to download exported page content from ${downloadLink}. `); } }