Merge pull request #81 from jonathanhefner/examples-use-content-for-now

Use `content` instead of `structuredContent` in examples
This commit is contained in:
Jonathan Hefner 2025-12-05 16:36:32 -06:00 • committed by GitHub
commit 437b9185cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 150 deletions

View file

@ -149,17 +149,6 @@ function generateCohortData(
};
}
function formatCohortSummary(data: CohortData): string {
const avgRetention = data.cohorts
.flatMap((c) => c.cells)
.filter((cell) => cell.periodIndex > 0)
.reduce((sum, cell, _, arr) => sum + cell.retention / arr.length, 0);
return `Cohort Analysis: ${data.cohorts.length} cohorts, ${data.periods.length} periods
Average retention: ${(avgRetention * 100).toFixed(1)}%
Metric: ${data.metric}, Period: ${data.periodType}`;
}
const server = new McpServer({
name: "Cohort Heatmap Server",
version: "1.0.0",
@ -176,7 +165,6 @@ const server = new McpServer({
description:
"Returns cohort retention heatmap data showing customer retention over time by signup month",
inputSchema: GetCohortDataInputSchema.shape,
outputSchema: CohortDataSchema.shape,
_meta: { [RESOURCE_URI_META_KEY]: resourceUri },
},
async ({ metric, periodType, cohortCount, maxPeriods }) => {
@ -188,8 +176,7 @@ const server = new McpServer({
);
return {
content: [{ type: "text", text: formatCohortSummary(data) }],
structuredContent: data,
content: [{ type: "text", text: JSON.stringify(data) }],
};
},
);

View file

@ -103,7 +103,13 @@ function CohortHeatmapInner({ app }: { app: App }) {
maxPeriods: 12,
},
});
setData(result.structuredContent as unknown as CohortData);
const text = result
.content!.filter(
(c): c is { type: "text"; text: string } => c.type === "text",
)
.map((c) => c.text)
.join("");
setData(JSON.parse(text) as CohortData);
} catch (e) {
console.error("Failed to fetch cohort data:", e);
} finally {