feat: register ask_chatgpt MCP tool
This commit is contained in:
@@ -1,9 +1,38 @@
|
||||
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 for advice, alternatives, risks, and clarification.",
|
||||
inputSchema: baseInputSchema,
|
||||
},
|
||||
async (input) => {
|
||||
const result = await handleAskChatGpt(input, {
|
||||
loadConfig,
|
||||
createOpenAIClient,
|
||||
sendOpenAIResponse,
|
||||
});
|
||||
|
||||
return {
|
||||
content: [
|
||||
{ type: "text", text: result.ok ? result.answer : `Error: ${result.error}` },
|
||||
],
|
||||
isError: !result.ok,
|
||||
warnings: result.warnings?.length ? result.warnings : undefined,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
await server.connect(new StdioServerTransport());
|
||||
|
||||
Reference in New Issue
Block a user