Files
chatgpt-mcp/PROJECT_STATE.md
T

6.6 KiB

PROJECT_STATE.md

Project

ChatGPT MCP Server

Status

Planning complete. Phase 0 complete. Phase 1 complete. Phase 2 complete. Phase 3 complete. Task 4.1 complete. Task 4.2 complete. Task 4.3 complete. Task 4.4 complete. Task 4.5 complete. Phase 4 complete. Task 5.1 complete. Task 5.2 complete. Task 5.3 complete.

Current Phase

Phase 5 - MCP Server and Tool Registration

Completed Tasks

  • Task 0.1 — Create repository skeleton

  • Task 0.2 — package.json with dependencies

  • Task 1.1 — Configuration loader

  • Task 1.2 — Secret redaction utility (src/utils/redact.js)

  • Task 1.3 — Context budget utility (src/utils/context-budget.js)

  • Task 1.4 — Safe logging helper (src/utils/logging.js)

  • Task 2.1 — OpenAI client wrapper (src/openai/client.js)

  • Task 2.2 — Response builder (src/openai/responses.js)

  • Task 2.3 — Error handling and edge cases for OpenAI integration (tests)

  • Task 3.1 — Zod input validation schemas (src/tools/schemas.js, test/tools/schemas.test.js)

  • Task 3.2 — Base prompt template (src/prompts/base.js, test/prompts/base.test.js)

  • Task 3.3 — ask_chatgpt prompt builder (src/prompts/ask-chatgpt.js, test/prompts/ask-chatgpt.test.js)

  • Task 3.4 — review_plan prompt builder (src/prompts/review-plan.js, test/prompts/review-plan.test.js)

  • Task 3.5 — review_code prompt builder (src/prompts/review-code.js, test/prompts/review-code.test.js)

  • Task 3.6 — debug_issue prompt builder (src/prompts/debug-issue.js, test/prompts/debug-issue.test.js)

  • Task 3.7 — architecture_review prompt builder (src/prompts/architecture-review.js, test/prompts/architecture-review.test.js)

  • Task 4.1 — ask_chatgpt MCP tool handler (src/tools/ask-chatgpt.js, test/tools/ask-chatgpt.test.js)

  • Task 4.2 — review_plan MCP tool handler (src/tools/review-plan.js, test/tools/review-plan.test.js)

  • Task 4.3 — review_code MCP tool handler (src/tools/review-code.js, test/tools/review-code.test.js)

  • Task 4.4 — debug_issue tool handler (src/tools/debug-issue.js, test/tools/debug-issue.test.js)

  • Task 4.5 — architecture_review tool handler (src/tools/architecture-review.js, test/tools/architecture-review.test.js)

  • Task 5.1 — MCP server skeleton (src/server.js)

  • Task 5.2 — ask_chatgpt MCP tool registered on the server

    ask_chatgpt registration details:

    • src/server.js registers ask_chatgpt with registerTool() using the shared baseInputSchema.
    • All three external deps injected: loadConfig, createOpenAIClient, sendOpenAIResponse.
    • Returns structured MCP tool result: { content: [{ type: "text", text }], isError, warnings }.

    Smoke test results (all passing):

    • initialize → server returns chatgpt-mcp v0.1.0
    • tools/list → exposes ask_chatgpt with correct schema (question required + 7 optional)
    • tools/call (happy path, mocked OpenAI) → { content: [...], isError: false } with answer
    • tools/call (minimal input { question: "hi" }) → works
    • tools/call (full input, all 10 schema fields) → handled correctly
    • tools/call (missing OPENAI_API_KEY) → structured MCP error "Error: Configuration error: OPENAI_API_KEY is missing."
    • tools/call (invalid API key) → structured MCP error "OpenAI API error (OpenAIAuthError): 401"
    • All 523 unit tests pass across 18 test files
  • Task 5.3 — Register remaining MCP tools

    Registered tools:

    • review_plan → handleReviewPlan
    • review_code → handleReviewCode
    • debug_issue → handleDebugIssue
    • architecture_review → handleArchitectureReview

    All five MCP tools now registered: ask_chatgpt, review_plan, review_code, debug_issue, architecture_review.

    Smoke test results (all passing):

    • initialize → server returns chatgpt-mcp v0.1.0
    • tools/list → 5 tools total
    • tools/call reaches handlers for all 5 tools
    • missing OPENAI_API_KEY → structured tool errors ("Error: Configuration error: OPENAI_API_KEY is missing.")
    • npm test → 523 tests pass across 18 test files, no regressions
  • Task 5.4 — Normalize MCP tool error formatting (NEXT)

Phase 3 Completion Summary

Phase 3 — Tool Inputs and Prompts — is now complete.

Completed prompt builders:

  • buildBasePrompt — base system prompt (ARCHITECTURE.md §11)
  • buildAskChatGptPrompt — general second-opinion advisor
  • buildReviewPlanPrompt — plan review before implementation
  • buildReviewCodePrompt — focused code/diff review
  • buildDebugIssuePrompt — error/log/stack trace analysis
  • buildArchitectureReviewPrompt — architecture decision trade-off review

What Phase 3 established:

  • Prompt layer complete with composition pattern established.
  • All prompt builders tested (56 tests for architecture-review alone; 384 total).
  • Each builder follows the same pattern: buildBasePrompt()\n\n---\n\n → tool-specific section.
  • Guard rails reinforced in every builder (Claude Code is executor; ChatGPT is advisory only).

Not done yet (belongs to Phase 4):

  • No MCP tool registration.
  • No tool handlers.

Phase 4 Completion Summary — Tool Handlers

All five tool handlers are implemented and tested:

# Handler File Tests
1 handleAskChatGpt src/tools/ask-chatgpt.js 27
2 handleReviewPlan src/tools/review-plan.js 28
3 handleReviewCode src/tools/review-code.js 28
4 handleDebugIssue src/tools/debug-issue.js 28
5 handleArchitectureReview src/tools/architecture-review.js 28

What Phase 4 established:

  • Five standalone, dependency-injected handlers following the same orchestration pattern: validate → config → budget → prompt → client → response.
  • All external deps injected (loadConfig, createOpenAIClient, sendOpenAIResponse); internal utilities imported directly.
  • Every handler returns structured { ok, answer|error, warnings } — never throws to caller.
  • Budget check short-circuits before prompt building or client creation.
  • OpenAI errors pass through String(err) unchanged — no wrapping or reformatting.
  • 139 orchestration-only tests covering success, validation failure, config failure, budget failure, client failure, OpenAI failure, call order, prompt integration, throws escaping, warnings, result shape, and short-circuit behavior.

What Phase 4 did NOT do:

  • No MCP tool registration yet.
  • No server or router code yet.
  • That belongs to Phase 5.

Next Pending

Task 5.4 - Normalize MCP tool error formatting