# OpenAI MCP

> OpenAI provides a single access point for GPT-4o chat completions, DALL-E 3 image generation, text embeddings, and content moderation. Build agents that can talk, visualize, understand data semantics, and enforce safety policies all from one connection.

## Overview
- **Category:** superpower
- **Price:** Free
- **Tags:** llm, generative-ai, embeddings, content-moderation, fine-tuning, image-generation, structured-output

## Description

## OpenAI MCP Server: The One Stop Shop for AI Agents

This server connects your agent directly to all of OpenAI's major services—GPT chat models, DALL-E image creation, vector embeddings, and content moderation. You don't just hit a basic API endpoint; you run complex, multi-step workflows from one place.

***

### **Generating Content and Conversations**

The `chat_completion` tool lets your agent talk like GPT-4o or GPT-4o-mini. You feed it a message history, and it spits out the next part of the conversation. For creating visual assets, you run `generate_image`, sending it just a text prompt, and it returns a direct URL for the finished picture.

For agents that need to make sure their output is predictable—say, when they're spitting out data that another system has to read—you use `structured_output`. This forces the agent to format its response strictly according to a JSON schema you define. It’s how you ensure machine-readable garbage doesn't slip through.

### **Handling and Indexing Data**

Need your agent to understand what text *means*, not just what keywords are in it? You call `create_embedding`. This tool converts any chunk of raw text into a vector representation. These vectors let you run semantic searches, letting your agent find information based on meaning, regardless of how the original text was phrased.

If you're building an agent that needs to reference external documents for training or context, you can use `list_files` to see every file uploaded to the platform. You also need to keep track of models; `list_models` gives you a full rundown of all the available GPT models you can actually utilize.

### **Training and Model Management**

You've got data, and it needs to improve your model's performance? You use `create_fine_tune`. This initiates a custom model training job using data from an uploaded JSONL file ID. To track whether that job is actually done or if it’s still chewing up compute cycles, you check the status with `list_fine_tunes`. The platform also lets you manage agents themselves; run `list_assistants` to get a full list of every configured OpenAI Assistant associated with your account.

### **Safety and Control**

When building anything public-facing, you gotta worry about bad input. You run `moderate_content` on any text string to check it against policy guidelines for things like hate speech or violence. For deeper model customization, the server also exposes `list_embeddings`, which shows you all your uploaded file data, and gives access to a mechanism to list available assistants.

### **The Full Stack**

This single connection lets your agent do it all: talk through conversations (`chat_completion`), create pictures (`generate_image`), index massive amounts of text into usable vectors (`create_embedding`), enforce strict data formats (`structured_output`), and check the content for garbage before sending it out. It's everything you need, without having to juggle five different API keys or wrappers.

## Tools

### chat_completion
Generates text responses from specified OpenAI models like gpt-4o or gpt-4o-mini.

### create_embedding
Converts provided raw text into a vector representation suitable for semantic searching.

### create_fine_tune
Initiates a custom model training job using data from a previously uploaded JSONL file ID.

### generate_image
Creates an image based on a text prompt and returns the resulting URL.

### list_assistants
Retrieves a list of configured OpenAI Assistants associated with your account.

### list_files
Shows all files you've uploaded to the OpenAI platform, useful for training or referencing data.

### list_fine_tunes
Lists the status and details of your active and completed fine-tuning jobs.

### list_models
Returns a list of all available OpenAI models you can use for chat completions or other tasks.

### moderate_content
Checks submitted text against policy guidelines to detect potential violations.

### structured_output
Forces the agent to generate a response that strictly adheres to a defined JSON schema from a prompt and message.

## Prompt Examples

**Prompt:** 
```
Ask GPT-4o to summarize this document in 3 bullet points.
```

**Response:** 
```
Here's the GPT-4o summary:

• **Revenue grew 23%** YoY driven by enterprise contracts
• **Operating costs decreased** 8% through automation initiatives
• **Customer retention** reached 94%, highest in company history
```

**Prompt:** 
```
Generate an image of a futuristic cityscape at sunset.
```

**Response:** 
```
🎨 Image generated!

- **URL**: https://oaidalleapiprodscus.blob.core.windows.net/...
- **Size**: 1024x1024
- **Revised prompt**: A breathtaking futuristic cityscape...
```

**Prompt:** 
```
Check if this text violates content policies.
```

**Response:** 
```
✅ Content analysis complete:

| Category | Flagged | Score |
|----------|---------|-------|
| Hate | No | 0.001 |
| Violence | No | 0.002 |
| Sexual | No | 0.000 |
| Self-harm | No | 0.000 |

No policy violations detected.
```

## Capabilities

### Generate Conversational Content
Use `chat_completion` to get responses from various GPT models based on a message history.

### Create Visual Assets
Run the `generate_image` tool, sending a text prompt and receiving a direct URL for the resulting image.

### Index Text Data
Call `create_embedding` to convert arbitrary chunks of text into usable vector data for semantic search engines.

### Enforce Content Policy
Run `moderate_content` on any given string to check it against policy violations like hate speech or violence.

### Structure Agent Output
Force predictable data formats—like JSON schema—using `structured_output`, ensuring the agent's output is machine-readable.

## Use Cases

### Building an E-commerce Product Catalog
A user submits a rough product description. The agent first calls `moderate_content` to check the text for policy violations. If clean, it uses `chat_completion` to write 5 bullet points and then runs `generate_image` with those bullet points as inspiration, creating marketing assets simultaneously.

### Creating a Semantic Internal Wiki Search
Instead of keyword search, an employee asks the agent a question. The agent uses `create_embedding` on the query and compares it against pre-indexed document vectors (using `list_files` to manage source data). It returns the most semantically relevant document chunks via `chat_completion`.

### Automating API Documentation Generation
An architect needs to define a new endpoint's expected inputs. The agent uses `structured_output` with a Pydantic schema definition, forcing the model to return an OpenAPI YAML object, which is then used by the client code.

### Fine-Tuning for Niche Industry Jargon
A finance team needs their agent to speak like industry experts. They use `create_fine_tune` with proprietary JSONL data and monitor job status via `list_fine_tunes`, ensuring the model understands highly specific jargon.

## Benefits

- **Consistent Output with `structured_output`:** Stop getting freeform text when you need structured data. Force the agent to output predictable JSON objects that your code can parse immediately.
- **Visuals on Demand via `generate_image`:** Build workflows where content generation and asset creation are linked. Pass a concept to the agent, and have it return an actionable image URL in the same response cycle.
- **Smart Searching with `create_embedding`:** Don't rely on keyword matching. Use embeddings to convert your knowledge base into vectors, allowing agents to find information based on *meaning* alone.
- **Built-in Safety Layer (`moderate_content`):** Never risk sending bad data downstream. Check user input or generated content for policy violations before it leaves the agent's scope.
- **Model Control and Scaling:** Use `list_models` to pick the right tool for the job—GPT-4o for complex reasoning, GPT-4o-mini for speed, etc.—all through one API call.

## How It Works

The bottom line is: you treat complex external APIs like simple functions that just return data to your local code.

1. Your AI client calls a tool, for example, `chat_completion`, providing a model name and message array.
2. The MCP Server validates the request, executes the call against the OpenAI API, and handles rate limiting or authentication failures.
3. You receive structured data—be it generated text, an image URL, or a moderation score—back into your agent's workflow.

## Frequently Asked Questions

**How do I make sure my AI agent output is always valid JSON using structured_output?**
You specify the desired JSON schema in your request parameters, and the `structured_output` tool forces the model to return data that exactly matches that schema. It's reliable for machine parsing.

**Is there a difference between list_assistants and chat_completion?**
Yes. `list_assistants` just shows you which Assistants are configured; it doesn't run them. You use `chat_completion` to actually send messages and get responses from the GPT models.

**How do I handle custom model training with create_fine_tune?**
You must first upload your proprietary data using the file management tools (`list_files`) to get an ID. Then, you use `create_fine_tune` with that specific JSONL file ID.

**Can I check if user input is safe before processing it?**
Yes, run the `moderate_content` tool immediately upon receiving user input. This checks for policy violations across multiple categories (Hate, Violence, etc.) and gives you a score.

**What models can I use with chat_completion?**
You can list available models first using `list_models`. Common choices include gpt-4o for advanced reasoning or gpt-4o-mini when speed is the priority.

**How do I use the `list_files` tool to manage data for training or embeddings?**
It gives you a full manifest of all uploaded files. You check this list before running any job—whether it's creating embeddings or starting fine-tuning—to ensure your agent has access to the correct file IDs.

**After calling `create_fine_tune`, how do I check if my model training job is complete?**
You use the `list_fine_tunes` tool. This lets you poll for the current status of your job, telling you exactly whether it's queued, running, or ready to be deployed.

**Before calling `chat_completion`, how do I confirm which models are currently supported by the API?**
You run `list_models`. This returns a list of all available model IDs. It ensures you always use the correct and current name for your chat completions.

**Which models can I use?**
Any model available on your API key: GPT-4o, GPT-4o-mini, GPT-4-turbo, o1, o3 — use `list_models` to see all.

**Can I generate images?**
Yes! Use `generate_image` with a text prompt. Supports 1024x1024, 1792x1024, and 1024x1792 sizes.

**How does content moderation work?**
The `moderate_content` tool analyzes text against OpenAI's content policy, flagging categories like hate, violence, and self-harm with confidence scores.