Provides intelligent web search capabilities using OpenAI's Web Search API and reasoning models, enabling AI assistants to perform searches with source citations and localized results.
OpenAI WebSearch MCP Server (TypeScript) π
A TypeScript MCP server that provides intelligent web search capabilities using OpenAI's reasoning models and Web Search API. Built with Bun for blazing-fast performance.
What is MCP? The Model Context Protocol allows AI assistants like Claude to connect to external tools and data sources. This server adds web search capabilities to your AI assistant.
Table of Contents
β¨ Features
π OpenAI Web Search API: Direct integration with OpenAI's Web Search API
π Localized Results: Support for location-based search customization
π Rich Type Safety: Full TypeScript types for all parameters and responses
π Bun-Powered: Lightning-fast runtime and package management
π§ Flexible Configuration: Environment variable support for easy deployment
π Source Citations: Automatic extraction and formatting of web sources
π Quick Start
Prerequisites
Bun runtime (v1.2 or higher)
curl -fsSL https://bun.sh/install | bashOpenAI API Key with Web Search API access
Get your API key from OpenAI Platform
Ensure your account has access to the Web Search API
Installation
Testing the Server
Before integrating with an MCP client, test that the server works:
If the server starts successfully, you'll see:
βοΈ Configuration
Environment Variables
The server requires the following environment variables:
Variable | Description | Required | Default |
| Your OpenAI API key | Yes | - |
| Default model to use | No |
|
Create a .env file in the project root:
MCP Client Configuration
Configure your MCP client to connect to this server. Choose either the published package (recommended) or local development setup.
Claude Desktop
Find your config file location:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Add this server configuration:
Option 1: Using npx (recommended for published package)
Option 2: Using bunx (alternative for Bun users)
Option 3: Local development setup
Restart Claude Desktop
Look for the π icon in Claude to verify the server is connected
Cursor
Open Cursor Settings (
Cmd/Ctrl + ,)Search for "MCP" in settings
Add server configuration (same format as Claude Desktop above)
Restart Cursor
Other MCP Clients
Any MCP-compatible client can use this server with the stdio transport:
Using npx:
Using bunx:
Local development:
π οΈ Available Tools
openai_web_search
Performs intelligent web search with AI reasoning capabilities.
Parameters
Parameter | Type | Required | Description | Default |
|
| Yes | The search query or question | - |
|
| No | AI model to use |
|
|
| No | Location for localized results (must include |
|
Supported Models
All models support OpenAI's Web Search API:
gpt-4o-search-preview- High-quality web search with comprehensive results (default)gpt-4o-mini-search-preview- Faster web search with efficient performancegpt-5-search-api- Advanced search capabilities
π¬ Usage Examples
Once configured in your MCP client (Claude Desktop, Cursor, etc.), simply ask questions that require web search:
Quick Search
The AI assistant will automatically use openai_web_search with the default model.
Localized Search
You can provide location context for more relevant local results.
Specific Model Selection
Choose a specific model for your search needs (speed vs quality trade-off).
Common Use Cases
π° News & Current Events: "What happened in tech news today?"
π Research: "Latest papers on transformer architectures"
πΊοΈ Local Information: "Best coffee shops near me"
π» Technical Documentation: "FastAPI async database patterns"
π― Product Research: "Compare M3 MacBook Pro vs Air"
π Market Data: "Current AI startup funding trends"
π€ Model Selection Guide
Standard Web Search (Default)
Recommended:
gpt-4o-search-preview(default)Use Case: General web search, current information, comprehensive results
Benefits: High-quality responses with source citations
Fast Web Search
Recommended:
gpt-4o-mini-search-previewUse Case: Quick queries, real-time information, faster responses
Benefits: Lower latency, cost-effective for frequent searches
Advanced Search
Recommended:
gpt-5-search-apiUse Case: Complex search queries, advanced capabilities
Benefits: Latest search features and capabilities
π¦ Development
π€ Publishing to NPM
Prerequisites
NPM Account: Create one at npmjs.com/signup if you don't have one
Email Verified: Ensure your NPM account email is verified
Before Publishing
Update package.json metadata:
Replace
YOUR_USERNAMEinrepository.urlwith your GitHub usernameReplace
YOUR_USERNAMEinhomepagewith your GitHub usernameReplace
YOUR_USERNAMEinbugs.urlwith your GitHub usernameOptionally add
authorfield:"author": "Your Name <your.email@example.com>"
Remove any test dependencies:
Check for any
file:references in dependenciesRemove test tarballs from the project directory
Publishing Steps
What Happens During Publish
The prepublishOnly script automatically runs:
bun run typecheck- Verifies TypeScript typesbun run build- Builds the dist/ folderNPM packages and uploads only files in the
filesarray (dist/, README.md, LICENSE)
After Publishing
Your package will be available at:
https://www.npmjs.com/package/openai-websearch-mcpUsers can install it with:
npx openai-websearch-mcporbunx openai-websearch-mcpIt will appear in NPM search results
Publishing Updates
When you need to publish a new version:
Optional: Scoped Package
To publish under your username (e.g., @yourusername/openai-websearch-mcp):
Change
"name"in package.json to"@yourusername/openai-websearch-mcp"Publish with:
npm publish --access public
Verify Publication
After publishing, verify your package:
ποΈ Project Structure
π Debugging & Troubleshooting
Using MCP Inspector
The MCP Inspector provides a web UI for testing your server:
This will open a browser interface where you can:
See available tools
Test tool calls with different parameters
View request/response logs
Debug errors
Common Issues
"OPENAI_API_KEY environment variable is required"
Solution: Create a .env file with your API key:
"Invalid OpenAI API key format"
Solution: Ensure your API key starts with sk-
"Server not appearing in Claude Desktop"
Solutions:
Verify the absolute path in your config is correct
Restart Claude Desktop completely
Check Claude's logs:
macOS:
~/Library/Logs/Claude/Windows:
%APPDATA%\Claude\logs\Linux:
~/.config/Claude/logs/
"Command 'bun' not found"
Solution: Install Bun:
Logging
The server logs to stderr. To see detailed logs:
Testing Individual Components
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
π₯ Powered by OpenAI's Web Search API
π οΈ Built on the Model Context Protocol
β‘ Runtime by Bun
π Inspired by ConechoAI's Python implementation