openai_websearch
Provides web search and image search tools using OpenAI's native server-side search. Uses Codex CLI authentication to enable free search via ChatGPT infrastructure.
README
openai_websearch
Self-hostable MCP server (official @modelcontextprotocol/sdk) and reusable API client that exposes OpenAI's native server-side web search via the ChatGPT/Codex Responses API.
No API keys required. Authenticate with your ChatGPT account in 3 ways:
- Browser OAuth — gets a URL, you click Connect (works on any device)
- Device-code flow — URL + code for headless/remote machines (no browser needed)
- Existing Codex auth — auto-falls back to
~/.codex/auth.json
Tokens auto-refresh — no manual re-login every few weeks.
Features
| Capability | Description |
|---|---|
web_search |
Full-text web search with real URLs and citations |
image_search |
Image search returning web image URLs and source pages |
| Built-in OAuth login | node index.js login or --device-code — no Codex install needed |
| Auto-refreshing tokens | refresh_token grant, stores in ~/.openai-websearch/auth.json |
| Official MCP SDK | @modelcontextprotocol/sdk — proper protocol handshake, Zod schemas, JSON Schema output |
| Reusable library | Import in any Node/Bun/Deno project |
| Zero API keys | Uses your ChatGPT subscription |
As an MCP server
Install & authenticate
git clone https://github.com/hffmnnj/openai_websearch.git
cd openai_websearch
npm install
# Authenticate (browser flow — prints a URL)
node index.js login
# Or headless (prints URL + code, enter on any device)
node index.js login --device-code
# Check auth status
node index.js auth-status
Configure your MCP client
{
"mcpServers": {
"openai_websearch": {
"command": "node",
"args": ["/path/to/openai_websearch/index.js"]
}
}
}
Tools
| Tool | Args | Description |
|---|---|---|
web_search |
query (required), context_size (low/medium/high), model |
Text web search with real URLs |
image_search |
query (required), context_size, model |
Image search returning URLs + source pages |
As a library (NPM package)
Install
npm install github:hffmnnj/openai_websearch
Quick start
import { search, imageSearch } from 'openai_websearch';
// Web search
const results = await search('smart ring market size 2026');
console.log(results.text);
console.log(results.searchQueries); // queries OpenAI actually ran
console.log(results.usage); // token counts
// Image search
const images = await imageSearch('oura ring product photos');
console.log(images.text); // URLs and descriptions
Explicit auth (no Codex, no login prompt — pass tokens directly)
import { createClient } from 'openai_websearch';
const client = createClient({
accessToken: 'eyJhbG...', // JWT from your own OAuth flow
refreshToken: 'rt.1.AAB...', // auto-refreshes when expired
accountId: 'uuid-here',
});
const result = await client.search('test query');
Full OAuth in your own code
import { authenticateBrowser, authenticateDeviceCode, createClient } from 'openai_websearch';
// Browser flow
const { tokens, authorizeUrl } = await authenticateBrowser();
// → user opens authorizeUrl, clicks Connect
// Device-code flow (headless)
const { tokens, verificationUrl, userCode } = await authenticateDeviceCode();
// → user visits verificationUrl, enters userCode
// Then use the tokens
const client = createClient({
accessToken: tokens.access_token,
refreshToken: tokens.refresh_token,
});
API reference
search(query, opts?) / client.search(query, opts?)
| Param | Type | Default | Description |
|---|---|---|---|
query |
string |
required | What to search for |
opts.contextSize |
'low' | 'medium' | 'high' |
'medium' |
Web context to retrieve |
opts.model |
string |
'gpt-5.6-luna' |
OpenAI model |
Returns { text, searchQueries, usage, model }.
createClient(opts?)
| Param | Type | Default | Description |
|---|---|---|---|
opts.authPath |
string |
~/.openai-websearch/auth.json |
Auth file location |
opts.accessToken |
string |
— | Explicit JWT |
opts.refreshToken |
string |
— | Auto-refresh when expired |
opts.accountId |
string |
— | ChatGPT account ID |
opts.fallbackToCodex |
boolean |
true |
Fall back to ~/.codex/auth.json |
opts.model |
string |
'gpt-5.6-luna' |
Default model |
Auth helpers (from openai_websearch/auth)
| Export | Description |
|---|---|
authenticateBrowser({ timeoutMs }) |
PKCE browser flow, callback on localhost:1455 |
authenticateDeviceCode({ pollInterval, timeoutMs }) |
Headless flow, returns URL + code |
refreshTokens(refreshToken) |
Refresh grant |
AuthManager |
Load/refresh/save token management |
Configuration
| Env var | Default | Description |
|---|---|---|
OPENAI_WEBSEARCH_AUTH_FILE |
~/.openai-websearch/auth.json |
Auth file path |
OPENAI_WEBSEARCH_MODEL |
gpt-5.6-luna |
Default model |
CODEX_AUTH_PATH |
~/.codex/auth.json |
Fallback Codex auth file |
Requirements
- Node.js 18+ (native
fetch), Bun, or Deno - A ChatGPT account (free/plus/pro — whatever you have)
- No Codex CLI required (unless you want the fallback auth)
How it works
- Auth: OAuth2 with PKCE against
auth.openai.com(same client as Codex CLI). Browser flow or device-code flow. Tokens stored locally, refreshed automatically viarefresh_tokengrant. - Search: Sends requests to the ChatGPT backend Responses API (
chatgpt.com/backend-api/codex/responses) with theweb_searchtool. - MCP: The server uses the official
@modelcontextprotocol/sdk— proper JSON-RPC framing, protocol version negotiation, Zod → JSON Schema derivation, argument validation.
All search runs server-side at OpenAI — same infrastructure that powers ChatGPT's web search.
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。