Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const defaultConfig = {
'./public/images/og-image/docs-background.jpg',
'./public/images/technology-logos/neon-dark.svg',
],
'/mcp-server/stats/og': [
'./src/fonts/geist-mono/GeistMono-Regular.ttf',
'./src/fonts/inter/Inter-Regular.ttf',
'./public/images/og-image/logo.png',
],
// The blog `.md` route handler reads the blog snapshot from disk at request
// time (unlike the blog pages, which are statically generated at build).
// Its read path is dynamic (process.cwd() + join), so nft can't detect the
Expand Down
119 changes: 119 additions & 0 deletions src/app/mcp-server/stats/og/route.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';

import { ImageResponse } from 'next/og';

import { buildClientShares } from 'components/pages/mcp-server-stats/share-series';
import { formatWeekRange } from 'components/pages/mcp-server-stats/weeks';
import { getMcpStats } from 'utils/api-mcp-stats';

export const revalidate = 3600;

const TOP_AGENTS = 5;

const assets = Promise.all([
readFile(join(process.cwd(), 'src', 'fonts', 'geist-mono', 'GeistMono-Regular.ttf')),
readFile(join(process.cwd(), 'src', 'fonts', 'inter', 'Inter-Regular.ttf')),
readFile(join(process.cwd(), 'public', 'images', 'og-image', 'logo.png')),
]);

const toDataUri = (buffer, contentType) =>
`data:${contentType};base64,${Buffer.from(buffer).toString('base64')}`;

export async function GET() {
const stats = await getMcpStats();
if (!stats) return new Response('Not found', { status: 404 });

const { latestWeek, ranked } = buildClientShares(stats.clients);
const agents = ranked.filter(({ isGrouped }) => !isGrouped).slice(0, TOP_AGENTS);
const leaderShare = agents[0].share;
const [fontDataMono, fontDataInter, logoBuffer] = await assets;

return new ImageResponse(
<div
style={{
backgroundColor: '#0A0B0D',
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'column',
padding: '56px 64px 56px',
}}
>
<img width={171} height={48} src={toDataUri(logoBuffer, 'image/png')} alt="" />

<div
style={{
marginTop: 44,
fontFamily: 'Inter',
fontSize: 64,
lineHeight: 1.05,
letterSpacing: '-0.04em',
color: 'white',
}}
>
Neon MCP Stats
</div>
<div style={{ marginTop: 14, fontFamily: 'Inter', fontSize: 28, color: '#94979E' }}>
{`Top agents by share of weekly active users, ${formatWeekRange(latestWeek)}`}
</div>

<div style={{ display: 'flex', flexDirection: 'column', gap: 14, marginTop: 'auto' }}>
{agents.map(({ key, label, color, share }) => (
<div key={key} style={{ display: 'flex', alignItems: 'center', gap: 24 }}>
<div
style={{
display: 'flex',
width: 240,
flexShrink: 0,
fontFamily: 'Inter',
fontSize: 28,
color: 'white',
}}
>
{label}
</div>
<div
style={{
display: 'flex',
flexGrow: 1,
flexShrink: 1,
height: 16,
backgroundColor: '#1C1D1F',
}}
>
<div
style={{
width: `${(share / leaderShare) * 100}%`,
height: '100%',
backgroundColor: color,
}}
/>
</div>
<div
style={{
width: 120,
flexShrink: 0,
display: 'flex',
justifyContent: 'flex-end',
fontFamily: 'Geist Mono',
fontSize: 28,
color: 'white',
}}
>
{`${share.toFixed(1)}%`}
</div>
</div>
))}
</div>
</div>,
{
width: 1200,
height: 630,
fonts: [
{ name: 'Geist Mono', data: fontDataMono, style: 'normal', weight: 400 },
{ name: 'Inter', data: fontDataInter, style: 'normal', weight: 400 },
],
}
);
}
7 changes: 6 additions & 1 deletion src/app/mcp-server/stats/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { notFound } from 'next/navigation';

import McpServerStats from 'components/pages/mcp-server-stats/mcp-server-stats';
import Layout from 'components/shared/layout';
import VERCEL_URL from 'constants/base';
import LINKS from 'constants/links';
import SEO_DATA from 'constants/seo-data';
import { getMcpStats } from 'utils/api-mcp-stats';
import getMetadata from 'utils/get-metadata';

export const metadata = getMetadata(SEO_DATA.mcpServerStats);
export const metadata = getMetadata({
...SEO_DATA.mcpServerStats,
imagePath: `${VERCEL_URL}${LINKS.mcpServerStats}/og`,
});

export const revalidate = 3600;

Expand Down
Loading