Skip to content

Commit f2b5d1c

Browse files
add method to apiHandler
1 parent 49fc1b5 commit f2b5d1c

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

packages/web/src/app/api/(server)/mcp/route.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use server';
2-
31
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
42
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
53
import { createMcpServer } from '@/features/mcp/server';
@@ -10,6 +8,7 @@ import { ErrorCode } from '@/lib/errorCodes';
108
import { StatusCodes } from 'http-status-codes';
119
import { NextRequest } from 'next/server';
1210
import { sew } from '@/actions';
11+
import { apiHandler } from '@/lib/apiHandler';
1312

1413
// @see: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
1514
interface McpSession {
@@ -24,7 +23,7 @@ const MCP_SESSION_ID_HEADER = 'MCP-Session-Id';
2423
// Suitable for containerized/single-instance deployments.
2524
const sessions = new Map<string, McpSession>();
2625

27-
export async function POST(request: NextRequest) {
26+
export const POST = apiHandler(async (request: NextRequest) => {
2827
const response = await sew(() =>
2928
withOptionalAuthV2(async ({ user }) => {
3029
const ownerId = user?.id ?? null;
@@ -66,9 +65,9 @@ export async function POST(request: NextRequest) {
6665
}
6766

6867
return response;
69-
}
68+
});
7069

71-
export async function DELETE(request: NextRequest) {
70+
export const DELETE = apiHandler(async (request: NextRequest) => {
7271
const result = await sew(() =>
7372
withOptionalAuthV2(async ({ user }) => {
7473
const ownerId = user?.id ?? null;
@@ -99,9 +98,9 @@ export async function DELETE(request: NextRequest) {
9998
}
10099

101100
return result;
102-
}
101+
});
103102

104-
export async function GET(request: NextRequest) {
103+
export const GET = apiHandler(async (request: NextRequest) => {
105104
const result = await sew(() =>
106105
withOptionalAuthV2(async ({ user }) => {
107106
const ownerId = user?.id ?? null;
@@ -132,4 +131,4 @@ export async function GET(request: NextRequest) {
132131
}
133132

134133
return result;
135-
}
134+
});

packages/web/src/lib/apiHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ export function apiHandler<H extends AnyHandler>(
4343
const wrappedHandler = async (request: NextRequest, ...rest: unknown[]) => {
4444
if (track) {
4545
const path = request.nextUrl.pathname;
46+
const method = request.method;
4647
const source = request.headers.get('X-Sourcebot-Client-Source') ?? 'unknown';
4748

4849
// Fire and forget - don't await to avoid blocking the request
49-
captureEvent('api_request', { path, source }).catch(() => {
50+
captureEvent('api_request', { path, method, source }).catch(() => {
5051
// Silently ignore tracking errors
5152
});
5253
}

packages/web/src/lib/posthogEvents.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export type PosthogEventMap = {
284284
api_request: {
285285
path: string;
286286
source: string;
287+
method: string;
287288
},
288289
}
289290
export type PosthogEvent = keyof PosthogEventMap;

0 commit comments

Comments
 (0)