@ririaru/mcp-gpt5-server
Version:
Enhanced MCP server for GPT-5 with advanced features
116 lines (100 loc) • 3.52 kB
JavaScript
// MCP GPT-5 Bridge Server
// This server acts as a bridge between Claude Code MCP and the GPT-5 proxy on Vercel
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
const API_URL = 'https://mcpgpt5.vercel.app/api/messages';
// Call GPT-5 API via your enhanced proxy
async function callGPT5(message, level = 'low', verbosity = 'concise') {
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 10_000); // 10s タイムアウト
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'gpt5-mcp-bridge/2.1',
},
body: JSON.stringify({
prompt: message,
level: level,
verbosity: verbosity
}),
signal: ctrl.signal,
});
const reqId = response.headers.get('x-req-id') || 'n/a';
const text = await response.text();
if (!response.ok) {
// Vercel の 500 汎用文面("A server error has occurred" 等)もここに入る
throw new Error(`API error: ${response.status} - ${text} (x-req-id=${reqId})`);
}
let data;
try {
data = JSON.parse(text);
} catch {
throw new Error(`Non-JSON response: ${text} (x-req-id=${reqId})`);
}
console.error('[sk_gpt5] OK', { reqId, status: response.status, hasContent: !!data.content });
return data.content?.[0]?.text || data.content || 'No response from GPT-5';
} catch (error) {
console.error('[sk_gpt5] ERROR', error.message);
throw error;
} finally {
clearTimeout(timer);
}
}
// Start the server
async function main() {
const server = new McpServer({
name: 'gpt5-proxy',
version: '2.1.0',
description: 'Enhanced GPT-5 MCP with reasoning levels, caching, and verbosity control',
});
// Register enhanced tool with level and verbosity controls
server.registerTool(
'sk_gpt5',
{
title: 'Chat with Enhanced GPT-5 via Vercel proxy',
description: 'Calls GPT-5 through your enhanced Vercel proxy with reasoning levels and verbosity control',
inputSchema: {
message: z.string().describe('Message to send to GPT-5'),
level: z.enum(['low', 'medium', 'high']).optional().describe('Reasoning effort level (default: low)'),
verbosity: z.enum(['concise', 'normal', 'verbose']).optional().describe('Response verbosity (default: concise)')
},
},
async ({ message, level, verbosity }) => {
console.error('Calling enhanced sk_gpt5 with:', { message, level, verbosity });
try {
const responseText = await callGPT5(message, level, verbosity);
return {
content: [
{
type: 'text',
text: responseText,
},
],
};
} catch (error) {
console.error('Error calling GPT-5:', error);
return {
content: [
{
type: 'text',
text: `Error: ${error.message}`,
},
],
};
}
}
);
// Connect transport
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('GPT-5 MCP Bridge Server started');
}
main().catch((error) => {
console.error('Failed to start server:', error);
process.exit(1);
});