← back to Goodquestion

src/app/api/mcp/fetch/[documentId]/route.ts

40 lines

import { NextRequest, NextResponse } from 'next/server'
import { mcpClient } from '@/lib/mcp-client'

export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ documentId: string }> }
) {
  try {
    const { documentId } = await params

    if (!documentId) {
      return NextResponse.json(
        {
          success: false,
          error: 'Document ID is required',
        },
        { status: 400 }
      )
    }

    const document = await mcpClient.fetch(documentId)

    return NextResponse.json({
      success: true,
      document,
    })
  } catch (error) {
    console.error('MCP fetch error:', error)

    return NextResponse.json(
      {
        success: false,
        error: 'Failed to fetch document',
        message: error instanceof Error ? error.message : 'Unknown error',
      },
      { status: 500 }
    )
  }
}