coda_peek_page
Retrieve the initial lines of a Coda page by specifying document ID, page ID or name, and desired number of lines for quick preview and analysis.
Instructions
Peek into the beginning of a page and return a limited number of lines
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| docId | Yes | The ID of the document that contains the page to peek into | |
| numLines | Yes | The number of lines to return from the start of the page - usually 30 lines is enough | |
| pageIdOrName | Yes | The ID or name of the page to peek into |
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 peek into",
"type": "string"
},
"numLines": {
"description": "The number of lines to return from the start of the page - usually 30 lines is enough",
"exclusiveMinimum": 0,
"type": "integer"
},
"pageIdOrName": {
"description": "The ID or name of the page to peek into",
"type": "string"
}
},
"required": [
"docId",
"pageIdOrName",
"numLines"
],
"type": "object"
}
Implementation Reference
- src/server.ts:136-153 (handler)The handler function that implements the core logic of the 'coda_peek_page' tool: fetches the full page content using the getPageContent helper and slices the first 'numLines' lines to provide a preview.async ({ docId, pageIdOrName, numLines }): Promise<CallToolResult> => { try { const content = await getPageContent(docId, pageIdOrName); if (!content) { throw new Error("Unknown error has occurred"); } const preview = content.split(/\r?\n/).slice(0, numLines).join("\n"); return { content: [{ type: "text", text: preview }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to peek page: ${error}` }], isError: true, }; } },
- src/server.ts:127-135 (schema)Zod input schema defining parameters: docId (string), pageIdOrName (string), numLines (positive integer).{ docId: z.string().describe("The ID of the document that contains the page to peek into"), pageIdOrName: z.string().describe("The ID or name of the page to peek into"), numLines: z .number() .int() .positive() .describe("The number of lines to return from the start of the page - usually 30 lines is enough"), },
- src/server.ts:124-126 (registration)Registers the 'coda_peek_page' tool with the MCP server, specifying name and description.server.tool( "coda_peek_page", "Peek into the beginning of a page and return a limited number of lines",
- src/client/helpers.ts:4-76 (helper)Supporting helper function to fetch the full markdown content of a page by initiating an export, polling for completion, and downloading the result. Used by 'coda_peek_page' and other tools.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}. `); } }