chatgpt-webui-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1,50 @@
1
+ # Required: value of the `__Secure-next-auth.session-token` cookie from chatgpt.com
2
+ CHATGPT_SESSION_TOKEN=
3
+
4
+ # Alternative (recommended): store the token in a file and point at it.
5
+ CHATGPT_SESSION_TOKEN_FILE=
6
+
7
+ # Transport mode defaults to camofox.
8
+ # Set only if you explicitly want the fallback transport:
9
+ # CHATGPT_TRANSPORT=httpcloak
10
+
11
+ # Optional: alternate base URL
12
+ CHATGPT_WEBUI_BASE_URL=https://chatgpt.com
13
+
14
+ # Optional transport settings
15
+ MCP_TRANSPORT=stdio
16
+ MCP_SSE_HOST=127.0.0.1
17
+ MCP_SSE_PORT=8791
18
+
19
+ # Optional async job retention settings (for *_ask_async_* tools)
20
+ CHATGPT_ASYNC_JOB_TTL_MS=86400000
21
+ CHATGPT_ASYNC_JOB_MAX=150
22
+
23
+ # Optional camofox settings (default transport)
24
+ CHATGPT_BROWSER_BASE_URL=http://127.0.0.1:9377
25
+ CHATGPT_USER_ID=chatgpt-webui-mcp
26
+ CHATGPT_SESSION_KEY=chatgpt-webui
27
+ CHATGPT_WAIT_TIMEOUT_MS=5400000
28
+ CHATGPT_WORKSPACE=PRO
29
+ # Backward-compatible aliases are still supported:
30
+ # CHATGPT_CAMOFOX_BASE_URL, CHATGPT_CAMOFOX_USER_ID, CHATGPT_CAMOFOX_SESSION_KEY,
31
+ # CHATGPT_CAMOFOX_WAIT_TIMEOUT_MS, CHATGPT_CAMOFOX_WORKSPACE
32
+ # If your camofox server enables cookie import protection, set one of these:
33
+ CHATGPT_CAMOFOX_API_KEY=
34
+ CAMOFOX_API_KEY=
35
+
36
+ # Optional httpcloak transport settings
37
+ CHATGPT_HTTPCLOAK_PRESET=chrome-145
38
+ CHATGPT_HTTPCLOAK_HTTP_VERSION=auto
39
+ CHATGPT_HTTPCLOAK_TIMEOUT_SECONDS=30
40
+ CHATGPT_HTTPCLOAK_PROXY=
41
+ CHATGPT_HTTPCLOAK_TCP_PROXY=
42
+ CHATGPT_HTTPCLOAK_UDP_PROXY=
43
+ CHATGPT_HTTPCLOAK_TLS_ONLY=false
44
+ CHATGPT_HTTPCLOAK_VERIFY_TLS=true
45
+ CHATGPT_HTTPCLOAK_ALLOW_REDIRECTS=true
46
+ CHATGPT_HTTPCLOAK_MAX_REDIRECTS=10
47
+ CHATGPT_HTTPCLOAK_RETRY=3
48
+ CHATGPT_HTTPCLOAK_PREFER_IPV4=false
49
+ CHATGPT_HTTPCLOAK_ECH_CONFIG_DOMAIN=
50
+ CHATGPT_HTTPCLOAK_QUIC_IDLE_TIMEOUT_SECONDS=30
package/INSTALL.md ADDED
@@ -0,0 +1,65 @@
1
+ # chatgpt-webui-mcp - install
2
+
3
+ this is a minimal standalone MCP server for ChatGPT WebUI.
4
+
5
+ it uses `camofox` (UI-driven) by default for robust long-running tasks (pro, deep research).
6
+
7
+ > important: this uses undocumented webui endpoints and a session cookie token. for personal/local tinkering only - not affiliated with openai.
8
+
9
+ ---
10
+
11
+ ## quick start (from source)
12
+
13
+ ```bash
14
+ git clone https://github.com/Microck/chatgpt-webui-mcp.git
15
+ cd chatgpt-webui-mcp
16
+ npm install
17
+ npm run build
18
+ ```
19
+
20
+ set your session token:
21
+
22
+ ```bash
23
+ export CHATGPT_SESSION_TOKEN="your_session_token_here"
24
+ ```
25
+
26
+ run (stdio):
27
+
28
+ ```bash
29
+ node dist/index.js
30
+ ```
31
+
32
+ ---
33
+
34
+ ## opencode config (recommended)
35
+
36
+ add this to your OpenCode config (`~/.config/opencode/opencode.json`) under `mcp`:
37
+
38
+ ```json
39
+ {
40
+ "mcp": {
41
+ "chatgpt-webui": {
42
+ "type": "local",
43
+ "enabled": true,
44
+ "timeout": 5400000,
45
+ "command": [
46
+ "node",
47
+ "/absolute/path/to/chatgpt-webui-mcp/dist/index.js"
48
+ ],
49
+ "environment": {
50
+ "CHATGPT_SESSION_TOKEN": "your_session_token_here",
51
+ "CHATGPT_BROWSER_BASE_URL": "http://127.0.0.1:9377",
52
+ "CHATGPT_WAIT_TIMEOUT_MS": "5400000"
53
+ }
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ `camofox` is the default path. set `CHATGPT_TRANSPORT=httpcloak` only for optional advanced fallback mode.
60
+
61
+ ---
62
+
63
+ ## remote SSE (optional)
64
+
65
+ if you want the server always-on (recommended for background runs), use the `deploy/systemd` templates in this repo.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Microck
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+
2
+
3
+ <h1 align="">chatgpt-webui-mcp</h1>
4
+
5
+ <p align="">
6
+ mcp server for querying chatgpt (chatgpt.com) via webui session token.
7
+ </p>
8
+
9
+ <p align="">
10
+ <img src="https://img.shields.io/badge/license-MIT-green" alt="license">
11
+ <img src="https://img.shields.io/badge/language-typescript-blue" alt="language">
12
+ <img src="https://img.shields.io/badge/mcp-sdk-orange" alt="mcp">
13
+ <a href="https://github.com/Microck/opencode-studio"><img src="https://img.shields.io/badge/opencode-studio-brown" alt="Add with OpenCode Studio" /></a>
14
+ </p>
15
+
16
+ ---
17
+
18
+ ## quick start
19
+
20
+ manual run:
21
+
22
+ ```bash
23
+ CHATGPT_SESSION_TOKEN="your_token_here" npm install
24
+ CHATGPT_SESSION_TOKEN="your_token_here" npm run build
25
+ CHATGPT_SESSION_TOKEN="your_token_here" node dist/index.js
26
+ ```
27
+
28
+ > important: this uses chatgpt's internal webui api with a session cookie. for personal/local tinkering only - not affiliated with openai.
29
+
30
+ ---
31
+
32
+ ### overview
33
+
34
+ chatgpt-webui-mcp is a standalone MCP server that drives chatgpt.com via `camofox` (UI automation).
35
+
36
+ it is built for long-running tasks (gpt-5.2 pro runs that take 1h+), deep research, and image generation mode.
37
+
38
+ ---
39
+
40
+ ### getting your session token
41
+
42
+ 1. open https://chatgpt.com and log in
43
+ 2. open devtools
44
+ 3. application -> cookies -> `https://chatgpt.com`
45
+ 4. copy the value of `__Secure-next-auth.session-token`
46
+
47
+ ---
48
+
49
+ ### configuration
50
+
51
+ because this server uses `stdio` or `sse`, you configure it as a local command (or remote url) and pass the token via env.
52
+
53
+ **mcp client config (claude desktop, opencode, etc)**
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "chatgpt-webui": {
59
+ "command": "node",
60
+ "args": ["/absolute/path/to/chatgpt-webui-mcp/dist/index.js"],
61
+ "timeout": 5400000,
62
+ "env": {
63
+ "CHATGPT_SESSION_TOKEN_FILE": "/path/to/session-token.txt",
64
+ "CHATGPT_BROWSER_BASE_URL": "http://127.0.0.1:9377",
65
+ "CHATGPT_WAIT_TIMEOUT_MS": "5400000"
66
+ }
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ legacy `CHATGPT_CAMOFOX_*` env vars are still supported for compatibility.
73
+ `CHATGPT_TRANSPORT=httpcloak` is optional fallback mode for advanced/debug scenarios.
74
+
75
+ ---
76
+
77
+ ### opencode workflow (the natural language style)
78
+
79
+ if you want to type commands like:
80
+
81
+ - `with chatgpt webui on gpt 5.2 pro extended thinking: <prompt>`
82
+ - `do deepresearch with chatgpt webui on <topic>`
83
+
84
+ use this tool:
85
+
86
+ | tool | what it does |
87
+ |------|--------------|
88
+ | `chatgpt_webui_command` | parses your sentence into the right call and runs it |
89
+
90
+ example:
91
+
92
+ ```json
93
+ {
94
+ "name": "chatgpt_webui_command",
95
+ "arguments": {
96
+ "command": "with chatgpt webui on gpt 5.2 pro extended thinking: write a 1-page memo about X",
97
+ "mode": "auto"
98
+ }
99
+ }
100
+ ```
101
+
102
+ ---
103
+
104
+ ### long runs (recommended)
105
+
106
+ use the unified tools:
107
+
108
+ | tool | description |
109
+ |------|-------------|
110
+ | `chatgpt_webui_prompt` | main tool. `mode=auto` chooses wait vs background |
111
+ | `chatgpt_webui_run` | check/wait for background runs (`run_id`) |
112
+
113
+ why: deep research and gpt-5.2 pro can take a long time and may exceed a single client timeout. `mode=auto` returns a `run_id` for long jobs.
114
+
115
+ ---
116
+
117
+ ### image generation
118
+
119
+ set `create_image=true` to switch chatgpt into image generation mode before sending the prompt.
120
+
121
+ notes:
122
+ - `image_urls` is best-effort (derived from page links + visited urls) and may be empty depending on how chatgpt renders images in the webui.
123
+ - if you want a fallback screenshot (as a `data:image/...` url), set `CHATGPT_IMAGE_SCREENSHOT_FALLBACK=1` (can be large).
124
+ - for reliable retrieval, you can also use the conversation_id and open the chatgpt UI.
125
+
126
+ ---
127
+
128
+ ### self-test
129
+
130
+ ```bash
131
+ # env
132
+ CHATGPT_SESSION_TOKEN="your_token_here" npm run self-test
133
+
134
+ # cli flag
135
+ npm run self-test -- --token "your_token_here"
136
+
137
+ # file
138
+ echo "your_token_here" > /tmp/chatgpt-session-token.txt
139
+ npm run self-test -- --token-file /tmp/chatgpt-session-token.txt
140
+ ```
141
+
142
+ ---
143
+
144
+ ### remote deployment over tailscale (optional)
145
+
146
+ if you want background runs to survive for a long time, run this server as an always-on SSE service.
147
+
148
+ 1) copy templates from this repo:
149
+ - `deploy/systemd/chatgpt-webui-mcp.env.example`
150
+ - `deploy/systemd/chatgpt-webui-mcp-sse.sh`
151
+ - `deploy/systemd/chatgpt-webui-mcp.service`
152
+
153
+ 2) install and enable service (user service):
154
+
155
+ ```bash
156
+ mkdir -p ~/.config ~/.config/systemd/user ~/.local/bin ~/.local/share/chatgpt-webui-mcp
157
+ cp deploy/systemd/chatgpt-webui-mcp.env.example ~/.config/chatgpt-webui-mcp.env
158
+ cp deploy/systemd/chatgpt-webui-mcp-sse.sh ~/.local/bin/chatgpt-webui-mcp-sse.sh
159
+ cp deploy/systemd/chatgpt-webui-mcp.service ~/.config/systemd/user/chatgpt-webui-mcp.service
160
+ chmod 600 ~/.config/chatgpt-webui-mcp.env
161
+ chmod 755 ~/.local/bin/chatgpt-webui-mcp-sse.sh
162
+ systemctl --user daemon-reload
163
+ systemctl --user enable --now chatgpt-webui-mcp.service
164
+ ```
165
+
166
+ 3) point opencode (cloud host) to the endpoint:
167
+
168
+ ```json
169
+ {
170
+ "mcp": {
171
+ "chatgpt-webui": {
172
+ "type": "remote",
173
+ "url": "http://<tailscale-ip>:8791/sse",
174
+ "enabled": true,
175
+ "timeout": 5400000,
176
+ "oauth": false
177
+ }
178
+ }
179
+ }
180
+ ```
181
+
182
+ ---
183
+
184
+ ### tools
185
+
186
+ | tool | description |
187
+ |------|-------------|
188
+ | `chatgpt_webui_session` | validate token and return session payload |
189
+ | `chatgpt_webui_models` | list available models |
190
+ | `chatgpt_webui_command` | natural-language command wrapper |
191
+ | `chatgpt_webui_prompt` | unified prompt tool (wait/background) |
192
+ | `chatgpt_webui_run` | check/wait for background runs |
193
+ | `chatgpt_webui_ask` | direct wait-style prompt tool (legacy/simple) |
194
+
195
+ ---
196
+
197
+ ### project structure
198
+
199
+ ```
200
+ chatgpt-webui-mcp/
201
+ ├── deploy/
202
+ │ └── systemd/
203
+ │ ├── chatgpt-webui-mcp.env.example
204
+ │ ├── chatgpt-webui-mcp-sse.sh
205
+ │ └── chatgpt-webui-mcp.service
206
+ ├── src/
207
+ │ ├── index.ts # MCP server
208
+ │ └── chatgpt-webui-client.ts # WebUI automation client
209
+ ├── package.json
210
+ ├── tsconfig.json
211
+ ├── .env.example
212
+ ├── .gitignore
213
+ ├── LICENSE
214
+ ├── INSTALL.md
215
+ └── README.md
216
+ ```
217
+
218
+ ---
219
+
220
+ ### license
221
+
222
+ mit
223
+
224
+ ---
225
+
226
+ ### author
227
+
228
+ [Microck](https://github.com/Microck)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ENV_FILE="${ENV_FILE:-$HOME/.config/chatgpt-webui-mcp.env}"
5
+
6
+ if [ ! -f "$ENV_FILE" ]; then
7
+ echo "missing env file: $ENV_FILE" >&2
8
+ exit 1
9
+ fi
10
+
11
+ set -a
12
+ # shellcheck disable=SC1090
13
+ source "$ENV_FILE"
14
+ set +a
15
+
16
+ exec node "${CHATGPT_WEBUI_MCP_DIST:-$HOME/.local/share/chatgpt-webui-mcp/dist/index.js}"
@@ -0,0 +1,28 @@
1
+ # ChatGPT session cookie token
2
+ CHATGPT_SESSION_TOKEN=
3
+
4
+ # transport defaults to camofox.
5
+ # set only if you explicitly want fallback mode:
6
+ # CHATGPT_TRANSPORT=httpcloak
7
+
8
+ # ChatGPT base URL
9
+ CHATGPT_WEBUI_BASE_URL=https://chatgpt.com
10
+
11
+ # camofox browser server
12
+ CHATGPT_BROWSER_BASE_URL=http://127.0.0.1:9377
13
+ CHATGPT_USER_ID=chatgpt-webui-mcp
14
+ CHATGPT_SESSION_KEY=chatgpt-webui
15
+ CHATGPT_WAIT_TIMEOUT_MS=5400000
16
+ CHATGPT_WORKSPACE=PRO
17
+
18
+ # if camofox cookie import is protected
19
+ CHATGPT_CAMOFOX_API_KEY=
20
+
21
+ # MCP server transport
22
+ MCP_TRANSPORT=sse
23
+ MCP_SSE_HOST=0.0.0.0
24
+ MCP_SSE_PORT=8791
25
+
26
+ # background run retention
27
+ CHATGPT_ASYNC_JOB_TTL_MS=86400000
28
+ CHATGPT_ASYNC_JOB_MAX=150
@@ -0,0 +1,15 @@
1
+ [Unit]
2
+ Description=chatgpt-webui-mcp (SSE)
3
+ After=network-online.target
4
+ Wants=network-online.target
5
+
6
+ [Service]
7
+ Type=simple
8
+ Environment=ENV_FILE=%h/.config/chatgpt-webui-mcp.env
9
+ Environment=CHATGPT_WEBUI_MCP_DIST=%h/.local/share/chatgpt-webui-mcp/dist/index.js
10
+ ExecStart=%h/.local/bin/chatgpt-webui-mcp-sse.sh
11
+ Restart=on-failure
12
+ RestartSec=2
13
+
14
+ [Install]
15
+ WantedBy=default.target
@@ -0,0 +1,43 @@
1
+ export type ChatgptWebuiClientOptions = {
2
+ baseUrl?: string;
3
+ sessionToken?: string;
4
+ transport?: "camofox" | "httpcloak";
5
+ };
6
+ export type AskInput = {
7
+ prompt: string;
8
+ model?: string;
9
+ modelMode?: "auto" | "instant" | "thinking" | "pro";
10
+ reasoningEffort?: "none" | "standard" | "extended";
11
+ deepResearch?: boolean;
12
+ deepResearchSiteMode?: "search_web" | "specific_sites";
13
+ createImage?: boolean;
14
+ waitTimeoutMs?: number;
15
+ workspace?: string;
16
+ conversationId?: string;
17
+ parentMessageId?: string;
18
+ };
19
+ export type AskOutput = {
20
+ text: string;
21
+ conversationId: string | null;
22
+ parentMessageId: string | null;
23
+ model: string | null;
24
+ imageUrls?: string[];
25
+ };
26
+ type SessionPayload = {
27
+ accessToken?: string;
28
+ user?: {
29
+ id?: string;
30
+ name?: string;
31
+ email?: string;
32
+ };
33
+ expires?: string;
34
+ };
35
+ export declare class ChatgptWebuiClient {
36
+ #private;
37
+ constructor(options?: ChatgptWebuiClientOptions);
38
+ close(): void;
39
+ getSession(): Promise<SessionPayload>;
40
+ getModels(): Promise<unknown>;
41
+ ask(input: AskInput): Promise<AskOutput>;
42
+ }
43
+ export {};