Skip to content

Commit b911a00

Browse files
feat: analytics (#88)
1 parent f6ce89f commit b911a00

File tree

12 files changed

+86
-9
lines changed

12 files changed

+86
-9
lines changed

apps/mcp-remote/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@sveltejs/mcp-schema": "workspace:^",
6666
"@sveltejs/mcp-server": "workspace:^",
6767
"@tmcp/transport-http": "^0.7.1",
68+
"@vercel/analytics": "^1.5.0",
6869
"tmcp": "^1.15.3"
6970
}
7071
}

apps/mcp-remote/src/hooks.server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { dev } from '$app/environment';
12
import { http_transport } from '$lib/mcp/index.js';
23
import { db } from '$lib/server/db/index.js';
34
import { redirect } from '@sveltejs/kit';
5+
import { track } from '@vercel/analytics/server';
46

57
export async function handle({ event, resolve }) {
68
if (event.request.method === 'POST') {
@@ -19,6 +21,12 @@ export async function handle({ event, resolve }) {
1921
}
2022
const mcp_response = await http_transport.respond(event.request, {
2123
db,
24+
// only add analytics in production
25+
track: dev
26+
? undefined
27+
: async (session_id, event, slug) => {
28+
await track(event, { session_id, ...(slug ? { slug } : {}) });
29+
},
2230
});
2331
// we are deploying on vercel the SSE connection will timeout after 5 minutes...for
2432
// the moment we are not sending back any notifications (logs, or list changed notifications)

apps/mcp-remote/src/lib/server/db/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { createClient } from '@libsql/client';
22
import { drizzle } from 'drizzle-orm/libsql';
33
import * as schema from './schema.js';
4-
// let's disable it for the moment...i can't figure out a way to make it wotk with eslint
5-
// eslint-disable-next-line import/extensions
64
import { DATABASE_TOKEN, DATABASE_URL } from '$env/static/private';
75
if (!DATABASE_URL) throw new Error('DATABASE_URL is not set');
86
if (!DATABASE_TOKEN) throw new Error('DATABASE_TOKEN is not set');

eslint.config.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ export default /** @type {import("eslint").Linter.Config} */ ([
4848
'import/no-unresolved': 'off', // this doesn't work well with typescript path mapping
4949
'import/extensions': [
5050
'error',
51-
'ignorePackages',
5251
{
53-
js: 'always',
54-
mjs: 'always',
55-
cjs: 'always',
56-
ts: 'always',
57-
svelte: 'always',
52+
ignorePackages: true,
53+
pattern: {
54+
js: 'always',
55+
mjs: 'always',
56+
cjs: 'always',
57+
ts: 'always',
58+
svelte: 'always',
59+
svg: 'always',
60+
json: 'always',
61+
},
5862
},
5963
],
6064
},

packages/mcp-server/src/mcp/handlers/prompts/svelte-task.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export function setup_svelte_task(server: SvelteMcp) {
6868
icons,
6969
},
7070
async ({ task }) => {
71+
if (server.ctx.sessionId && server.ctx.custom?.track) {
72+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'svelte-task');
73+
}
7174
const available_docs = await format_sections_list();
7275

7376
return {

packages/mcp-server/src/mcp/handlers/resources/doc-section.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export async function list_sections(server: SvelteMcp) {
4646
icons,
4747
},
4848
async (uri, { slug }) => {
49+
if (server.ctx.sessionId && server.ctx.custom?.track) {
50+
await server.ctx.custom?.track?.(
51+
server.ctx.sessionId,
52+
'svelte-doc-section',
53+
Array.isArray(slug) ? slug.join(',') : slug,
54+
);
55+
}
4956
const section = sections.find((section) => {
5057
return slug === section.slug;
5158
});

packages/mcp-server/src/mcp/handlers/tools/get-documentation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export function get_documentation(server: SvelteMcp) {
2121
icons,
2222
},
2323
async ({ section }) => {
24+
if (server.ctx.sessionId && server.ctx.custom?.track) {
25+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'get-documentation');
26+
}
2427
let sections: string[];
2528

2629
if (Array.isArray(section)) {

packages/mcp-server/src/mcp/handlers/tools/list-sections.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export function list_sections(server: SvelteMcp) {
1212
icons,
1313
},
1414
async () => {
15+
if (server.ctx.sessionId && server.ctx.custom?.track) {
16+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'list-sections');
17+
}
1518
const formatted_sections = await format_sections_list();
1619

1720
return {

packages/mcp-server/src/mcp/handlers/tools/playground-link.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export function playground_link(server: SvelteMcp) {
5959
icons,
6060
},
6161
async ({ files, name, tailwind }) => {
62+
if (server.ctx.sessionId && server.ctx.custom?.track) {
63+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'playground-link');
64+
}
6265
const playground_base = new URL('https://svelte.dev/playground');
6366
const playground_files: File[] = [];
6467

@@ -76,6 +79,9 @@ export function playground_link(server: SvelteMcp) {
7679
}
7780

7881
if (!has_app_svelte) {
82+
if (server.ctx.sessionId && server.ctx.custom?.track) {
83+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'playground-link-no-app-svelte');
84+
}
7985
return {
8086
isError: true,
8187
content: [

packages/mcp-server/src/mcp/handlers/tools/svelte-autofixer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ export function svelte_autofixer(server: SvelteMcp) {
4646
filename: filename_or_path,
4747
desired_svelte_version: desired_svelte_version_unchecked,
4848
}) => {
49+
if (server.ctx.sessionId && server.ctx.custom?.track) {
50+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'svelte-autofixer');
51+
}
4952
// we validate manually because some clients don't support union in the input schema (looking at you cursor)
5053
const parsed_version = v.safeParse(
5154
v.union([v.literal(4), v.literal(5), v.literal('4'), v.literal('5')]),
5255
desired_svelte_version_unchecked,
5356
);
5457
if (parsed_version.success === false) {
58+
if (server.ctx.sessionId && server.ctx.custom?.track) {
59+
await server.ctx.custom?.track?.(server.ctx.sessionId, 'svelte-autofixer-wrong-version');
60+
}
5561
return {
5662
isError: true,
5763
content: [

0 commit comments

Comments
 (0)