openai-mcp-server
Integrates OpenAI APIs into MCP-compatible clients, providing tools for text generation, chat completions, model discovery, image creation/editing, audio transcription, speech synthesis, embeddings, and content moderation.
README
openai-mcp-server
An MCP server that puts the OpenAI API into any MCP client — Claude Desktop, Claude Code, Cowork, Cursor, or anything else that speaks the protocol.
Nine tools: text generation, chat completions, model discovery, image generation and editing, transcription, speech synthesis, embeddings, and moderation.
Why this exists
There is no official OpenAI plugin in the Claude plugin catalogue. This server is the equivalent, built as a normal open-source project you own and can extend.
Tools
| Tool | What it does | Read-only |
|---|---|---|
openai_generate_text |
Generate text via the Responses API — instructions, reasoning effort, forced JSON, response chaining | no |
openai_chat_completion |
Send an explicit message history via Chat Completions | no |
openai_list_models |
List the model IDs your key can use, filtered and paginated | yes |
openai_generate_image |
Create images from a prompt, written to disk | no |
openai_edit_image |
Edit or combine existing images, optionally with a mask | no |
openai_transcribe_audio |
Transcribe a local audio file | no |
openai_text_to_speech |
Synthesize speech to an audio file | no |
openai_create_embeddings |
Embed texts for semantic search, written to JSON | no |
openai_moderate_content |
Check text against OpenAI's moderation policy | yes |
Every tool takes response_format: "markdown" | "json" — markdown for reading, JSON for processing. All tools also return structuredContent, so clients that understand output schemas get typed data without parsing.
Requirements
- Node.js 20 or newer
- An OpenAI API key with available quota
Install
git clone <your-repo-url> openai-mcp-server
cd openai-mcp-server
npm install
npm run build
Verify the build:
node dist/index.js --version # prints 1.0.0
node dist/index.js --help # lists all environment variables
Configure your MCP client
The server speaks MCP over stdio, so the client launches it as a subprocess.
Claude Desktop
Edit claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"openai": {
"command": "node",
"args": ["/absolute/path/to/openai-mcp-server/dist/index.js"],
"env": {
"OPENAI_API_KEY": "sk-proj-...",
"OPENAI_MCP_OUTPUT_DIR": "/Users/you/openai-mcp-output"
}
}
}
}
Restart Claude Desktop afterwards.
Claude Code
claude mcp add openai \
--env OPENAI_API_KEY=sk-proj-... \
-- node /absolute/path/to/openai-mcp-server/dist/index.js
Any other MCP client
Point it at node /absolute/path/to/dist/index.js with OPENAI_API_KEY in the environment.
Configuration
Only OPENAI_API_KEY is required. See .env.example for a copyable template.
| Variable | Default | Purpose |
|---|---|---|
OPENAI_API_KEY |
— | Required. Your OpenAI API key |
OPENAI_BASE_URL |
OpenAI's default | Alternative endpoint (Azure, gateway, proxy) |
OPENAI_ORG_ID |
— | Organization ID |
OPENAI_PROJECT_ID |
— | Project ID |
OPENAI_MCP_OUTPUT_DIR |
<tmp>/openai-mcp |
Where generated files are written |
OPENAI_MCP_ALLOWED_DIRS |
output dir only | Colon-separated absolute dirs the server may read from |
OPENAI_MCP_TIMEOUT_MS |
120000 |
Per-request timeout |
OPENAI_MCP_MAX_RETRIES |
2 |
Retries for transient failures |
OPENAI_DEFAULT_TEXT_MODEL |
gpt-5.6-terra |
Default text model |
OPENAI_DEFAULT_IMAGE_MODEL |
gpt-image-2 |
Default image model |
OPENAI_DEFAULT_EMBEDDING_MODEL |
text-embedding-3-small |
Default embedding model |
OPENAI_DEFAULT_TRANSCRIPTION_MODEL |
gpt-transcribe |
Default transcription model |
OPENAI_DEFAULT_SPEECH_MODEL |
gpt-4o-mini-tts |
Default speech model |
OPENAI_DEFAULT_MODERATION_MODEL |
omni-moderation-latest |
Default moderation model |
Model IDs change. OpenAI adds, renames and retires models, and access differs per project. Every default is overridable, and openai_list_models reports what your key can actually reach — if a call fails with "model not found", start there.
Security model
Two deliberate constraints:
The filesystem is sandboxed. Tools that read local files (openai_edit_image, openai_transcribe_audio) accept only absolute paths inside OPENAI_MCP_ALLOWED_DIRS. Paths are canonicalised with realpath before the check, so symlinks and ../ traversal cannot escape. The output directory is always allowed; nothing else is, until you add it. Keep that list narrow.
Binary output never enters the conversation. Images, audio and embedding vectors are written to disk and only their paths are returned. A single base64 PNG or a 3072-float vector would otherwise flood the model's context window.
The API key is read from the environment only — it never appears in a tool argument, a log line, or an error message.
Examples
Ask your MCP client in plain language; it picks the tool.
"Use the OpenAI server to summarise this text in three sentences."
→ openai_generate_text
"Which OpenAI embedding models can I use?"
→ openai_list_models with filter="embedding"
"Generate a transparent PNG logo of a blue fox."
→ openai_generate_image with background="transparent"
"Transcribe ~/Documents/audio/interview.m4a in German."
→ openai_transcribe_audio with language="de" — requires that directory in OPENAI_MCP_ALLOWED_DIRS
"Embed these 40 product descriptions so I can cluster them."
→ openai_create_embeddings, then read the JSON file it reports
Development
npm run dev # watch mode via tsx
npm run typecheck # tsc --noEmit, strict
npm test # unit tests, no network calls
npm run build # compile to dist/
The test suite covers configuration parsing, the filesystem sandbox (including symlink escape and traversal), error formatting and response shaping. It never contacts the OpenAI API.
Project layout
src/
├── index.ts entry point, server assembly, CLI flags
├── config.ts environment parsing and validation
├── client.ts OpenAI client construction
├── constants.ts defaults, limits, response formats
├── errors.ts API errors → actionable agent messages
├── files.ts sandboxed read/write
├── format.ts tool result shaping, character limit
└── tools/
├── text.ts generate_text, chat_completion
├── models.ts list_models
├── images.ts generate_image, edit_image
├── audio.ts transcribe_audio, text_to_speech
└── analysis.ts create_embeddings, moderate_content
Adding a tool
- Write a Zod schema with
.strict()and a.describe()on every field. - Register it with
server.registerTool(name, config, handler)— includetitle,description,inputSchema,outputSchemaandannotations. - Return via
toolResult(...)so markdown/JSON handling and the character limit stay consistent; catch errors witherrorResult(...). - Add the registration call in
src/index.tsand a test intest/.
Troubleshooting
| Symptom | Cause |
|---|---|
| Client shows no tools | Wrong path in the config, or the project was not built (npm run build) |
Configuration error: OPENAI_API_KEY is not set (exit 78) |
The key is missing from the client's env block |
Error: Access to ... is not permitted |
The path is outside OPENAI_MCP_ALLOWED_DIRS |
Error: Not found on a generation |
The model ID does not exist for your key — run openai_list_models |
Error: Rate limit or quota exceeded |
Retry later, or check billing on the project |
The server logs to stderr; stdout carries the JSON-RPC stream and must stay clean.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。