Skip to content

Add MCP server for AI-driven question generation - #3

Closed
chcg305 wants to merge 2 commits into
mainfrom
feature/mcp-question-generation
Closed

chcg305 wants to merge 2 commits into
mainfrom
feature/mcp-question-generation

Conversation

@chcg305

@chcg305 chcg305 commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replaces the earlier server-side shared-API-key generation path with an MCP (Streamable HTTP) server at /mcp, exposing list_materials / get_material_text / submit_questions tools.
  • Each user's own AI client (Claude Desktop, Cursor, etc.) connects via MCP, reads the uploaded PDF's extracted text, generates questions itself, and submits them back — so generation cost is borne by the user's own AI subscription, not the service.
  • PDF text is extracted and cached at upload time via pdf-parse for the get_material_text tool.
  • Home page now shows MCP connection instructions and each material's ID.

Test plan

  • npm install succeeds, server starts
  • Upload a PDF → text extraction cache (<file>.pdf.txt) created
  • Raw MCP JSON-RPC: initialize, tools/list return expected schemas for all 3 tools
  • tools/call list_materials returns uploaded material
  • tools/call get_material_text returns extracted text
  • tools/call submit_questions persists questions; /questions/:id page renders them
  • get_material_text with an invalid id returns isError: true

🤖 Generated with Claude Code

chcg305 and others added 2 commits October 3, 2026 13:02
Replaces the server-side shared-API-key generation path with an MCP
(Streamable HTTP) endpoint exposing list_materials/get_material_text/
submit_questions tools, so each user's own Claude Desktop/Cursor
generates questions using their own AI subscription instead of the
service bearing per-generation API cost. PDF text is extracted and
cached at upload time via pdf-parse for the get_material_text tool.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@Snow0821 Snow0821 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

검토 결과: 수정 요청

검토한 커밋: 8f2f1d1. 게시 직전에도 같은 head인 것을 확인했습니다.

  1. P1: /mcp의 Origin 검증 및 접근 제어가 없습니다. 신뢰하지 않는 Origin과 인증 정보 없는 요청으로 기존 문제를 덮어쓰는 동작을 재현했습니다.
  2. P2: Node 18 이상이라는 실행 조건과 새 PDF 파서의 실제 지원 버전이 맞지 않습니다.
  3. P2: PDF 추출 실패와 기존 업로드 자료가 영구적으로 ‘추출 대기’ 상태에 머뭅니다.
  4. P2: HTTPS 프록시 뒤에서는 안내되는 MCP 주소가 HTTP로 만들어집니다.

각 위치에 재현 방법과 재검토 기준을 남겼습니다.

검증 결과

  • 별도 테스트 사본에서 Node 24.19.0으로 npm ci --ignore-scripts --no-audit --no-fund, node --check server.js, 서버 시작 확인
  • 실제 텍스트 PDF 업로드·추출, initialize, tools/list, 도구 3개 호출, 문제 저장·HTML 렌더링 확인
  • HTML 특수문자 이스케이프, 존재하지 않는 ID 및 경로 이탈 형태 ID 거절 확인
  • npm audit --omit=dev: 알려진 취약점 0건
  • 신뢰하지 않는 Origin 요청의 문제 덮어쓰기, 잘못된 PDF의 성공 처리, 프록시 환경의 HTTP 주소 생성은 실패 사례로 재현

미검증

  • Node 18 실제 실행, Claude Desktop/Cursor 실제 연결, 브라우저 화면·상호작용 테스트
  • 이 head에는 자동 테스트·빌드 스크립트와 CI 상태/체크 실행이 없어 전체 검증 통과로 볼 수 없습니다.

범위 및 동시 작업
현재 구현은 독립 Express 프로토타입이며 PRD의 과목별 인증·개념 등록·2단계 검수까지 충족한 상태는 아닙니다. PR #4에서 Next.js 기반 구조와 mvp-express 분리가 제안되어 있어 루트 package.json/package-lock.json 및 실행 구조가 겹칩니다. #3을 mvp-express로 옮겨 보존할지, 새 구조로 대체할지는 아직 합의된 것으로 보지 않았습니다. 구조 방향을 정한 뒤 통합 결과도 다시 검증해야 합니다.

Comment thread server.js
app.post('/mcp', express.json(), async (req, res) => {
const server = buildMcpServer();
try {
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 · MCP Origin/접근 제어를 추가해 주세요

이 transport는 sessionIdGenerator만 설정하고 있습니다. 설치된 SDK의 enableDnsRebindingProtection 기본값은 false이고, 앞단에도 Origin/Host 검증 또는 인증이 없습니다. 별도 로컬 테스트 서버에서 Origin: https://untrusted.example를 보낸 인증 없는 submit_questions 요청이 200으로 성공하고 기존 문제를 덮어쓰는 것을 재현했습니다. 로컬 서버도 모든 인터페이스에 바인딩됩니다.

재검토 기준: 허용하지 않은 Origin/Host를 거절하고 정상 MCP 클라이언트 호출은 유지해 주세요. 공개 또는 다중 사용자 실행을 지원한다면 자료 읽기·문제 변경에 맞는 인증/권한 검증도 필요합니다. 로컬 전용으로 한정한다면 기본 바인딩과 사용 안내도 그 범위를 일치시켜 주세요.

근거: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#security-warning

Comment thread package.json
"express": "^4.19.2",
"multer": "^2.0.0"
"multer": "^2.0.0",
"pdf-parse": "^2.4.5",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · 선언한 Node 지원 범위가 새 의존성과 맞지 않습니다

package.json은 Node >=18이고 사용 매뉴얼도 Node 18 이상이라고 안내하지만, lockfile의 pdf-parse 2.4.5는 >=20.16.0 <21 || >=22.3.0을 요구합니다(package-lock.json 1453–1454행). pdfjs-dist도 Node 18을 지원 범위에 포함하지 않습니다. 현재 Node 24에서만 실행을 확인했으며 Node 18 실행은 미검증입니다.

재검토 기준: 지원하는 Node 버전을 engines와 문서에 동일하게 명시하고 그 최소 버전에서 설치·시작·PDF 추출을 확인하거나, 기존 Node 18 지원을 유지할 수 있는 의존성으로 조정해 주세요.

Comment thread server.js
}
const txtPath = textFilePath(id);
if (!fs.existsSync(txtPath)) {
return { content: [{ type: 'text', text: '이 자료는 아직 텍스트 추출이 끝나지 않았습니다. 잠시 후 다시 시도해주세요.' }], isError: true };

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · 실패/기존 자료를 영구 대기로 표시하지 않도록 해 주세요

업로드의 extractAndCacheText 실패를 211–215행에서 로그만 남긴 뒤 정상 metadata와 302 응답을 생성합니다. application/pdf로 보낸 잘못된 PDF 바이트로 이를 재현했습니다. 이후 이 분기는 ‘잠시 후 다시 시도’만 반환하지만 다시 추출하는 작업이 없어 영구적으로 실패합니다. 이 PR 이전에 올라온 정상 PDF도 .txt 캐시가 없어서 같은 상태가 됩니다.

재검토 기준: 추출 실패를 명확한 상태/사용자 메시지로 반환하고, 기존 정상 PDF에는 지연 추출 또는 마이그레이션을 제공해 주세요. 잘못된 PDF·텍스트 없는 PDF·기존 업로드 PDF를 각각 테스트하고 실제 대기 상태와 영구 실패를 구별해 주세요.

Comment thread server.js
}

function mcpInstructionsHtml(req) {
const mcpUrl = `${req.protocol}://${req.get('host')}/mcp`;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · HTTPS 프록시 환경에서 잘못된 MCP 주소가 표시됩니다

서버로 Host: public.example 및 X-Forwarded-Proto: https를 전달했을 때 안내 입력값이 http://public.example/mcp로 생성되는 것을 재현했습니다. TLS를 프록시에서 종료하는 배포에서 사용자가 HTTP 주소를 그대로 등록하게 됩니다.

재검토 기준: 검증된 공개 기본 URL을 사용하거나 배포 환경에 맞게 제한적으로 신뢰 프록시를 설정하고, HTTPS 접속 시 https://…/mcp가 표시되는지 확인해 주세요. 임의의 forwarded header를 무조건 신뢰하는 변경은 피해주세요.

@wpalswpa

wpalswpa commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Mint 재검토를 요청드립니다. 기존 수정 요청과 현재 head 8f2f1d1을 대조했습니다. 기존 지적을 해소한 코드 변경이 올라온 상태는 아니므로 승인이나 해결 처리를 요청하는 것은 아닙니다.

확인 결과:

  • /mcp 앞단에 인증·자료 소유권 검사와 Origin/Host 검사가 없는 구조, 추출 실패를 로그만 남긴 뒤 정상 목록에 넣는 흐름, req.protocol로 안내 주소를 만드는 부분을 소스로 확인했습니다.
  • package.json의 Node >=18과 lockfile의 pdf-parse >=20.16.0 <21 || >=22.3.0 불일치를 별도로 확인했습니다.
  • 이번 검토에서는 서버 공격 요청이나 PDF 업로드를 다시 실행하지 않았습니다. 기존 리뷰의 실행 결과와 제 소스 확인을 구분합니다.

관련 수정안 #6을 올렸습니다. 학생의 별도 AI 계정·MCP 연결을 없애고 서버가 학교 API로 문제를 생성하는 방향이며, 현재 팀 검토안입니다. 이 방향을 채택하면 PDF 추출·문항 저장은 재사용하고 사용자 MCP 노출 부분은 제외하는 것이 맞겠습니다. 인증·소유권·실패 상태 검사는 방식이 바뀌어도 필요합니다.

재검토 요청은 #6 방향을 기준으로 #3에서 재사용할 범위와 #4와의 통합 경로를 확정하는 것입니다. 그 결과를 PR 본문·실행 문서에 반영하고, 수정 커밋에서 잘못된 PDF·기존 자료 재처리·비인가 접근·프록시 주소를 검증한 뒤 코드 재검토를 요청하는 순서를 제안합니다.

검토·댓글 작성: Codex. 코드 수정·승인·병합은 수행하지 않았습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants