#!/usr/bin/env node
// Test script for Get Records endpoint
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
const SERVER_URL = process.env.MCP_SERVER_URL || "http://localhost:3000/mcp";
const DATASHEET_ID = process.env.TEST_DATASHEET_ID || "";
if (!DATASHEET_ID) {
console.error("Error: Please set TEST_DATASHEET_ID environment variable");
console.error("Example: TEST_DATASHEET_ID=dst0Yj5aNeoHldqvf6 pnpm tsx src/test-get-records.ts");
process.exit(1);
}
async function testGetRecords() {
console.log(`Testing Get Records endpoint...`);
console.log(`Server: ${SERVER_URL}`);
console.log(`Datasheet ID: ${DATASHEET_ID}\n`);
const client = new Client(
{ name: "test-client", version: "1.0.0" },
{ capabilities: {} }
);
const transport = new StreamableHTTPClientTransport(new URL(SERVER_URL));
try {
// Connect
console.log("Connecting to server...");
await client.connect(transport);
console.log("✓ Connected\n");
// Test 1: Basic get records
console.log("Test 1: Get first 10 records");
const result1 = await client.request(
{
method: "tools/call",
params: {
name: "get_records",
arguments: {
datasheetId: DATASHEET_ID,
pageSize: 10,
},
},
} as any,
{} as any
);
console.log("Response:", JSON.stringify(result1, null, 2));
console.log("\n---\n");
// Test 2: Get records with specific fields
console.log("Test 2: Get records with field filtering (if you have field names, edit this test)");
// Uncomment and modify when you know your field names:
/*
const result2 = await client.request(
{
method: "tools/call",
params: {
name: "get_records",
arguments: {
datasheetId: DATASHEET_ID,
pageSize: 5,
fields: ["Name", "Email"], // Replace with your actual field names
},
},
} as any,
{} as any
);
console.log("Response:", JSON.stringify(result2, null, 2));
console.log("\n---\n");
*/
// Test 3: Get with pagination
console.log("Test 3: Get page 2 with 5 records per page");
const result3 = await client.request(
{
method: "tools/call",
params: {
name: "get_records",
arguments: {
datasheetId: DATASHEET_ID,
pageSize: 5,
pageNum: 2,
},
},
} as any,
{} as any
);
console.log("Response:", JSON.stringify(result3, null, 2));
console.log("\n---\n");
// Close
await transport.close();
console.log("\n✓ All tests completed successfully");
} catch (error) {
console.error("❌ Error:", error);
process.exit(1);
}
}
testGetRecords();