feat: register ask_chatgpt MCP tool

This commit is contained in:
2026-06-12 12:09:08 +01:00
parent 20bef8a1fb
commit d3aefa5bb8
4 changed files with 123 additions and 4 deletions
+52 -1
View File
@@ -440,4 +440,55 @@ Status: ✅ Complete
- MCP initialize handshake succeeds.
- No tools registered yet — that belongs to Task 5.2.
### Task 5.2 - Register ask_chatgpt MCP tool (NEXT)
### Task 5.2 - Register ask_chatgpt MCP tool
Register `ask_chatgpt` as an MCP tool on the server in `src/server.js`.
**Requirements:**
- Import `baseInputSchema` from `./tools/schemas.js`.
- Import `handleAskChatGpt` from `./tools/ask-chatgpt.js`.
- Import `loadConfig`, `createOpenAIClient`, `sendOpenAIResponse` from config/OpenAI modules.
- Register `ask_chatgpt` with `registerTool()` using the shared input schema and description from ARCHITECTURE.md §7.
- Pass all three deps into `handleAskChatGpt`.
- Return structured MCP tool result: `{ content: [{ type: "text", text }], isError, warnings }`.
**Smoke test results (all passing):**
| Test | Result |
|------|--------|
| initialize handshake | ✅ Server returns `chatgpt-mcp` v0.1.0 |
| tools/list | ✅ Exposes `ask_chatgpt` with correct schema (`question` required + 7 optional fields) |
| tools/call (happy path, mocked OpenAI) | ✅ Structured `{ content, isError: false }` with answer |
| tools/call (minimal input) | ✅ Works with `{ question: "hi" }` |
| tools/call (full input, all optional fields) | ✅ 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.
- Production stdio transport verified end-to-end with real `npm start`.
**Production code (`src/server.js`):**
```js
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { baseInputSchema } from "./tools/schemas.js";
import { handleAskChatGpt } from "./tools/ask-chatgpt.js";
import { loadConfig } from "./config/env.js";
import { createOpenAIClient } from "./openai/client.js";
import { sendOpenAIResponse } from "./openai/responses.js";
const server = new McpServer({ name: "chatgpt-mcp", version: "0.1.0" });
server.registerTool(
"ask_chatgpt",
{ description: "General second-opinion question...", inputSchema: baseInputSchema },
async (input) => { ... }
);
await server.connect(new StdioServerTransport());
```
Status: ✅ Complete
### Task 5.3 - Register remaining MCP tools (NEXT)