Skip to main content
Glama
hiltonbrown

Next.js MCP Server Template

by hiltonbrown
route.ts1.67 kB
// Xero auth initiation import { generateOAuthState, storeOAuthState, getXeroAuthUrl, generatePKCEChallenge } from '@/lib/auth'; import { db } from '@/lib/db'; import { setCache, cacheKeys } from '@/lib/cache'; export async function GET(request: Request) { try { const url = new URL(request.url); const accountId = url.searchParams.get('accountId'); if (!accountId) { return new Response(JSON.stringify({ error: 'Account ID is required' }), { status: 400, headers: { 'Content-Type': 'application/json' } }); } // Verify account exists const account = await db.account.findUnique({ where: { id: accountId } }); if (!account) { return new Response(JSON.stringify({ error: 'Account not found' }), { status: 404, headers: { 'Content-Type': 'application/json' } }); } // Generate OAuth state and PKCE challenge const state = generateOAuthState(); const { verifier, challenge } = generatePKCEChallenge(); // Store state and PKCE verifier (you might want to store verifier in session/cache) await storeOAuthState(state, accountId); // Store PKCE verifier in cache await setCache(cacheKeys.pkce(state), verifier, 600); // 10 minute TTL // Generate Xero authorization URL const authUrl = getXeroAuthUrl(state, challenge); // Redirect to Xero return Response.redirect(authUrl, 302); } catch (error) { console.error('OAuth initiation error:', error); return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500, headers: { 'Content-Type': 'application/json' } }); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hiltonbrown/xero-mcp-with-next-js'

If you have feedback or need assistance with the MCP directory API, please join our Discord server