hasdata-chatgpt-mcp 1.0.0__tar.gz

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.
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
+ "name": "hasdata-chatgpt-mcp",
4
+ "version": "1.0.0",
5
+ "description": "ChatGPT MCP server for Cursor. Send a prompt to ChatGPT anonymously and get the answer as markdown together with the web sources it consulted, as structured JSON. No OpenAI account or API key. Remote MCP server hosted by HasData, connects over streamable HTTP with your HasData API key.",
6
+ "author": {
7
+ "name": "HasData",
8
+ "url": "https://hasdata.com"
9
+ },
10
+ "homepage": "https://hasdata.com/apis/chatgpt-api",
11
+ "repository": "https://github.com/HasData/chatgpt-mcp",
12
+ "license": "MIT",
13
+ "keywords": [
14
+ "mcp",
15
+ "chatgpt",
16
+ "chatgpt-mcp",
17
+ "chatgpt-api",
18
+ "llm",
19
+ "ai-search",
20
+ "model-context-protocol",
21
+ "hasdata",
22
+ "scraper"
23
+ ],
24
+ "logo": "https://hasdata.com/favicon.svg"
25
+ }
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: Something in the README is wrong
3
+ about: A tool table, a response sample or a documented behaviour does not match reality
4
+ labels: documentation
5
+ ---
6
+
7
+ **Where in the README**
8
+
9
+ Section or heading.
10
+
11
+ **What it says**
12
+
13
+ Quote the line.
14
+
15
+ **The call you made**
16
+
17
+ Tool name and arguments, or the equivalent REST URL with your key removed.
18
+
19
+ **What came back**
20
+
21
+ Trimmed response, with anything private removed.
@@ -0,0 +1,31 @@
1
+ # The tool contract is checked on a schedule as well as on push, because the upstream tool list
2
+ # can change without a single commit in this repository.
3
+ name: tool contract
4
+
5
+ on:
6
+ push:
7
+ branches: [main]
8
+ pull_request:
9
+ schedule:
10
+ - cron: '0 6 * * 1'
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ contract:
18
+ runs-on: ubuntu-latest
19
+ timeout-minutes: 5
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - uses: actions/setup-node@v4
23
+ with:
24
+ node-version: '22'
25
+ # Forks cannot read repository secrets. The suite skips its live checks when the key is
26
+ # absent, so a pull request from a fork stays green instead of failing for a reason the
27
+ # contributor cannot fix.
28
+ - name: Assert the tool list still matches the README
29
+ env:
30
+ HASDATA_API_KEY: ${{ secrets.HASDATA_API_KEY }}
31
+ run: npm test
@@ -0,0 +1,87 @@
1
+ # Publishes the npm and PyPI wrapper packages on a version tag, using OIDC
2
+ # trusted publishing. No NPM_TOKEN or PYPI_TOKEN is stored anywhere: GitHub
3
+ # mints a short-lived OIDC token per run, and npmjs.org / pypi.org accept it
4
+ # because this repo + workflow are configured as trusted publishers.
5
+ #
6
+ # One-time setup, done once per package on the registries (not in this repo):
7
+ # npmjs.org -> package settings -> Trusted Publisher -> GitHub Actions,
8
+ # repo HasData/chatgpt-mcp, workflow publish.yml
9
+ # pypi.org -> the hasdata org -> Publishing -> add a trusted publisher
10
+ # (pending publisher works before the first release),
11
+ # repo HasData/chatgpt-mcp, workflow publish.yml
12
+ #
13
+ # The MCP registry entry (com.hasdata/chatgpt) is NOT published here. It uses
14
+ # domain auth, which would need the namespace-wide Ed25519 key as a secret in
15
+ # every repo. That key stays off CI; the registry entry is published by hand
16
+ # when server.json changes, after the package versions below are live.
17
+ #
18
+ # Release: bump nothing by hand. Tag the commit `vX.Y.Z` and push the tag; the
19
+ # tag is the single source of the version and is written into both manifests.
20
+
21
+ name: publish
22
+
23
+ on:
24
+ push:
25
+ tags: ['v*.*.*']
26
+
27
+ permissions:
28
+ contents: read
29
+ id-token: write
30
+
31
+ jobs:
32
+ npm:
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v4
36
+ # No registry-url here on purpose. With it, setup-node writes an .npmrc
37
+ # carrying _authToken=${NODE_AUTH_TOKEN}, which resolves to a placeholder
38
+ # when no token is passed. npm then authenticates with that garbage instead
39
+ # of falling back to OIDC, and a scoped package answers 404.
40
+ - uses: actions/setup-node@v4
41
+ with:
42
+ node-version: '24'
43
+ # OIDC trusted publishing landed in npm 11.5.1. Node 24 already ships a
44
+ # newer npm than that, but pinning the upgrade here keeps the job working
45
+ # if the runner image drifts back.
46
+ - name: Upgrade npm for OIDC trusted publishing
47
+ run: |
48
+ npm install -g npm@latest
49
+ npm -v
50
+ - name: Set version from the tag
51
+ run: npm version "${GITHUB_REF_NAME#v}" --no-git-tag-version --allow-same-version
52
+ # The first version of a brand new package has to go up by hand, because npm only
53
+ # offers the trusted-publisher setting on a package that already exists. After that
54
+ # manual publish the tag workflow would fail forever on "cannot publish over
55
+ # previously published version", so skip a version that is already on the registry
56
+ # instead of failing the run.
57
+ - name: Publish to npm (OIDC, no token)
58
+ run: |
59
+ name=$(node -p "require('./package.json').name")
60
+ version=$(node -p "require('./package.json').version")
61
+ if npm view "$name@$version" version >/dev/null 2>&1; then
62
+ echo "$name@$version is already on npm, nothing to publish"
63
+ exit 0
64
+ fi
65
+ npm publish --access public
66
+
67
+ pypi:
68
+ runs-on: ubuntu-latest
69
+ steps:
70
+ - uses: actions/checkout@v4
71
+ - uses: actions/setup-python@v5
72
+ with:
73
+ python-version: '3.12'
74
+ - name: Set version from the tag
75
+ run: |
76
+ python - "${GITHUB_REF_NAME#v}" <<'PY'
77
+ import re, sys
78
+ v = sys.argv[1]
79
+ p = "pyproject.toml"
80
+ t = open(p, encoding="utf-8").read()
81
+ t = re.sub(r'(?m)^version = ".*"$', f'version = "{v}"', t, count=1)
82
+ open(p, "w", encoding="utf-8", newline="\n").write(t)
83
+ PY
84
+ - name: Build the wheel and sdist
85
+ run: pipx run build
86
+ - name: Publish to PyPI (OIDC, no token)
87
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ node_modules/
2
+ package-lock.json
3
+ dist/
4
+ build/
5
+ *.egg-info/
6
+ __pycache__/
7
+ *.pyc
8
+ .env
9
+ .env.*
10
+ .DS_Store
11
+ *.log
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HasData
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.
@@ -0,0 +1,267 @@
1
+ Metadata-Version: 2.5
2
+ Name: hasdata-chatgpt-mcp
3
+ Version: 1.0.0
4
+ Summary: MCP server for the ChatGPT Scraper API through HasData's hosted API. No OpenAI account.
5
+ Project-URL: Homepage, https://hasdata.com/apis/chatgpt-api
6
+ Project-URL: Repository, https://github.com/HasData/chatgpt-mcp
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Keywords: ai-search,chatgpt,chatgpt-api,hasdata,llm,mcp,model-context-protocol
10
+ Requires-Python: >=3.10
11
+ Requires-Dist: mcp-proxy>=0.12.0
12
+ Requires-Dist: mcp<2,>=1.28.1
13
+ Description-Content-Type: text/markdown
14
+
15
+ # ChatGPT MCP Server
16
+
17
+ <!-- mcp-name: com.hasdata/chatgpt -->
18
+
19
+ A hosted Model Context Protocol (MCP) server that gives Claude, Cursor, Windsurf and any other MCP client one ChatGPT tool. Send a prompt anonymously and get the answer back as markdown together with the web pages ChatGPT consulted, as structured JSON, with no OpenAI account and no API key of your own.
20
+
21
+ **1,000 free credits every month, no card required**, which is 100 prompts.
22
+
23
+ ```
24
+ https://mcp.hasdata.com/mcp?apis=chatgpt
25
+ ```
26
+
27
+ [![Glama score](https://glama.ai/mcp/servers/HasData/chatgpt-mcp/badges/score.svg)](https://glama.ai/mcp/servers/HasData/chatgpt-mcp)
28
+ [![tool contract](https://github.com/HasData/chatgpt-mcp/actions/workflows/contract.yml/badge.svg)](https://github.com/HasData/chatgpt-mcp/actions/workflows/contract.yml)
29
+ [![MCP](https://img.shields.io/badge/MCP-remote%20%7C%20streamable%20HTTP-6366f1?style=flat-square)](https://modelcontextprotocol.io)
30
+ [![Tools](https://img.shields.io/badge/tools-1-10b981?style=flat-square)](#tools)
31
+ [![npm](https://img.shields.io/npm/v/@hasdata/chatgpt-mcp?style=flat-square&logo=npm&label=npm&color=cb3837)](https://www.npmjs.com/package/@hasdata/chatgpt-mcp)
32
+ [![PyPI](https://img.shields.io/pypi/v/hasdata-chatgpt-mcp?style=flat-square&logo=pypi&logoColor=white&label=PyPI&color=3775a9)](https://pypi.org/project/hasdata-chatgpt-mcp/)
33
+ [![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](LICENSE)
34
+
35
+ ## Contents
36
+
37
+ - [What you need](#what-you-need)
38
+ - [Quick start](#quick-start)
39
+ - [Example prompts](#example-prompts)
40
+ - [Tools](#tools)
41
+ - [Errors and failure paths](#errors-and-failure-paths)
42
+ - [Pricing, free tier and limits](#pricing-free-tier-and-limits)
43
+ - [How it compares](#how-it-compares)
44
+ - [FAQ](#faq)
45
+ - [HasData links](#hasdata-links)
46
+ - [Development](#development)
47
+ - [Contributing](#contributing)
48
+ - [License](#license)
49
+
50
+ ## What you need
51
+
52
+ An MCP client and a HasData API key from the [dashboard](https://app.hasdata.com/sign-up?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp), free to create with no card, and the free tier covers 100 calls a month at the 10-credit rate. This is a remote server, so the simplest path is a URL and an `x-api-key` header, with no container to run and no OpenAI billing anywhere in the flow. A client that only speaks stdio reaches it through a thin launcher, published as `@hasdata/chatgpt-mcp` on npm and `hasdata-chatgpt-mcp` on PyPI, shown below.
53
+
54
+ ## Quick start
55
+
56
+ The server URL is the same for every client. We run it hands-on in Claude Code and Claude Desktop. The other blocks follow each client's own documented format for a remote server.
57
+
58
+ | Field | Value |
59
+ | :--- | :--- |
60
+ | URL | `https://mcp.hasdata.com/mcp?apis=chatgpt` |
61
+ | Transport | HTTP, streamable |
62
+ | Auth header | `x-api-key: HASDATA_API_KEY` |
63
+
64
+ Clients with OAuth support can add the same URL as a connector and sign in without putting a key in a config file.
65
+
66
+ <details>
67
+ <summary><b>Claude Code</b></summary>
68
+
69
+ ```bash
70
+ claude mcp add --transport http chatgpt "https://mcp.hasdata.com/mcp?apis=chatgpt" \
71
+ --header "x-api-key: HASDATA_API_KEY"
72
+ ```
73
+
74
+ </details>
75
+
76
+ <details>
77
+ <summary><b>Claude Desktop</b></summary>
78
+
79
+ ```json
80
+ {
81
+ "mcpServers": {
82
+ "chatgpt": {
83
+ "type": "http",
84
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
85
+ "headers": { "x-api-key": "HASDATA_API_KEY" }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ </details>
92
+
93
+ <details>
94
+ <summary><b>Cursor</b></summary>
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "chatgpt": {
100
+ "type": "streamable-http",
101
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
102
+ "headers": { "x-api-key": "HASDATA_API_KEY" }
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ </details>
109
+
110
+ <details>
111
+ <summary><b>VS Code</b></summary>
112
+
113
+ ```json
114
+ {
115
+ "servers": {
116
+ "chatgpt": {
117
+ "type": "http",
118
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
119
+ "headers": { "x-api-key": "HASDATA_API_KEY" }
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ </details>
126
+
127
+ ## Example prompts
128
+
129
+ Prompts, not code. Paste one in and the agent picks the tool itself. Each is annotated with the calls it takes, because every successful call costs 10 credits.
130
+
131
+ > Ask ChatGPT what the current state of the Artemis program is, and list the sources it used.
132
+
133
+ *One call, 10 credits. The answer and the sources come back together.*
134
+
135
+ > Ask ChatGPT the same question in German.
136
+
137
+ *One call, 10 credits. The answer follows the language of the prompt, so write the prompt in the language you want back.*
138
+
139
+ > Ask ChatGPT what happened in AI this week, with Berlin as the current date.
140
+
141
+ *One call, 10 credits. `timezone` is what fixes the meaning of "this week".*
142
+
143
+ > Put the same question to ChatGPT three times and show where the answers differ.
144
+
145
+ *Three calls, 30 credits. Each request is a fresh conversation, so there is no carry-over between them.*
146
+
147
+ ## Tools
148
+
149
+ | Tool | What it returns |
150
+ | --- | --- |
151
+ | `hasdata_chatgpt_chat_getChatgptAnswer` | The answer as markdown, the web sources ChatGPT consulted with their domain and title, the conversation title it generated, the model that answered, and whether a web search was used. 10 credits a call |
152
+
153
+ One tool, 10 credits per successful call.
154
+
155
+ ### Ask ChatGPT
156
+
157
+ [`hasdata_chatgpt_chat_getChatgptAnswer`](https://docs.hasdata.com/apis/chatgpt/chat?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp)
158
+
159
+ | Parameter | Type | Required | Notes |
160
+ | :--- | :--- | :--- | :--- |
161
+ | `prompt` | string | yes | The question or instruction, up to 8000 characters |
162
+ | `timezone` | string | | IANA zone name such as `Europe/Berlin`. It sets what ChatGPT treats as today |
163
+
164
+ Everything lands under `conversation`. The answer is in `answer` as markdown, with `title` holding the name ChatGPT generated for the thread, `model` the model that answered, and `usedWebSearch` saying whether it went to the web at all. `finishReason` and `complete` tell a truncated answer from a finished one.
165
+
166
+ ```json
167
+ {
168
+ "conversation": {
169
+ "answer": "As of **October 5, 2026**, NASA's Artemis program has made substantial progress…",
170
+ "title": "Artemis developments cited",
171
+ "model": "gpt-5-6",
172
+ "usedWebSearch": true,
173
+ "finishReason": "stop",
174
+ "complete": true,
175
+ "sources": [
176
+ { "title": "Artemis News - NASA", "url": "https://www.nasa.gov/artemis-news/", "domain": "www.nasa.gov" }
177
+ ]
178
+ }
179
+ }
180
+ ```
181
+
182
+ ## Errors and failure paths
183
+
184
+ Your client almost never sees an HTTP error code from a tool call. The MCP layer answers 200 and puts the failure inside the result, with `isError` set to `true` and the reason as text.
185
+
186
+ **`sources` is uneven, and partly absent.** In a measured answer carrying twenty sources, every one had `title`, `url` and `domain`, eleven had `publishedDate` and only five had `snippet`. Read each field defensively rather than assuming the shape of the first element holds for the rest.
187
+
188
+ **No web search means no sources.** `usedWebSearch` is false when ChatGPT answers from the model alone, and `sources` is then empty or missing. A prompt about a stable fact often takes that path, so ask for current information when citations are the point.
189
+
190
+ **Every call is a fresh conversation.** There is no memory between requests, so a follow-up has to carry its own context in the prompt. `conversationId` identifies the thread that answered, not a thread you can continue.
191
+
192
+ **A truncated answer still succeeds.** Check `complete` and `finishReason` before treating `answer` as the whole response.
193
+
194
+ Each successful call spends credits from the connected account. A call that fails validation is not billed.
195
+
196
+ ## Pricing, free tier and limits
197
+
198
+ The ChatGPT tool costs **10 credits per successful call**. Answer length does not change the price.
199
+
200
+ The free tier is **1,000 credits every month with no card**, which is 100 prompts.
201
+
202
+ Paid plans start at **$59 a month** for 200,000 credits, which is 20,000 calls. The unit price falls on larger plans. Current numbers are on the [plans page](https://hasdata.com/prices?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp).
203
+
204
+ ## How it compares
205
+
206
+ | | OpenAI API | This server |
207
+ | :--- | :--- | :--- |
208
+ | Account | Your own OpenAI account and billing | One HasData key |
209
+ | What you get | The model's answer | The answer plus the web sources behind it |
210
+ | Web search | A separate tool you wire up | Included, with `usedWebSearch` reporting whether it ran |
211
+ | Output | Your own schema | Parsed JSON with the sources already split out |
212
+
213
+ The two are not substitutes. The OpenAI API is the right call when you need system prompts, tools, streaming and conversation state. This server is the right call when you want what ChatGPT publicly answers, with its citations, and no account of your own.
214
+
215
+ ## FAQ
216
+
217
+ ### Do I need an OpenAI account or an API key?
218
+
219
+ No. The server answers anonymously through HasData, and the only credential involved is your HasData key.
220
+
221
+ ### Which model answers?
222
+
223
+ Whichever ChatGPT serves anonymously at the time. The response reports it in `model`, so read it rather than assuming. A measured call returned `gpt-5-6`.
224
+
225
+ ### Can I continue a conversation?
226
+
227
+ No. Each request is a fresh thread with no memory of earlier ones. Carry the context in the prompt instead.
228
+
229
+ ### What language will the answer be in?
230
+
231
+ The language of the prompt. Ask in German and the answer comes back in German, or ask explicitly for a language in the prompt.
232
+
233
+ ### Is HasData affiliated with OpenAI?
234
+
235
+ No. HasData is an independent web data provider and is not affiliated with, endorsed by or sponsored by OpenAI. All trademarks belong to their owners.
236
+
237
+ ### Compliance and personal data
238
+
239
+ The server reads what ChatGPT answers publicly to an anonymous visitor. It does not log in, and it does not reach private conversations or account data.
240
+
241
+ ## HasData links
242
+
243
+ | | |
244
+ | :--- | :--- |
245
+ | Product page and request builder | [ChatGPT Scraper API](https://hasdata.com/apis/chatgpt-api?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
246
+ | Endpoint documentation | [ChatGPT Scraper API docs](https://docs.hasdata.com/apis/chatgpt/chat?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
247
+ | Server documentation | [MCP server docs](https://docs.hasdata.com/mcp-server?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
248
+ | Every tool in one server | [HasData/hasdata-mcp](https://github.com/HasData/hasdata-mcp) |
249
+ | Client walkthroughs | [MCP clients and integrations](https://hasdata.com/integrations/mcp?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
250
+ | Plans and credit costs | [Plans and credit costs](https://hasdata.com/prices?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
251
+
252
+ ## Development
253
+
254
+ ```bash
255
+ npm install
256
+ npm test
257
+ ```
258
+
259
+ The tests in `test/` assert the tool contract, the part that can break without a commit here. They check that `?apis=chatgpt` returns the one expected tool, that its name and required parameter have not changed, that it carries a description, and that a real call still puts the answer under `conversation`.
260
+
261
+ ## Contributing
262
+
263
+ The parameter table and the sample above were read from the live schema and from real calls rather than from documentation. A correction is welcome when a field or a failure mode has changed. Open an issue with the response you saw.
264
+
265
+ ## License
266
+
267
+ MIT
@@ -0,0 +1,253 @@
1
+ # ChatGPT MCP Server
2
+
3
+ <!-- mcp-name: com.hasdata/chatgpt -->
4
+
5
+ A hosted Model Context Protocol (MCP) server that gives Claude, Cursor, Windsurf and any other MCP client one ChatGPT tool. Send a prompt anonymously and get the answer back as markdown together with the web pages ChatGPT consulted, as structured JSON, with no OpenAI account and no API key of your own.
6
+
7
+ **1,000 free credits every month, no card required**, which is 100 prompts.
8
+
9
+ ```
10
+ https://mcp.hasdata.com/mcp?apis=chatgpt
11
+ ```
12
+
13
+ [![Glama score](https://glama.ai/mcp/servers/HasData/chatgpt-mcp/badges/score.svg)](https://glama.ai/mcp/servers/HasData/chatgpt-mcp)
14
+ [![tool contract](https://github.com/HasData/chatgpt-mcp/actions/workflows/contract.yml/badge.svg)](https://github.com/HasData/chatgpt-mcp/actions/workflows/contract.yml)
15
+ [![MCP](https://img.shields.io/badge/MCP-remote%20%7C%20streamable%20HTTP-6366f1?style=flat-square)](https://modelcontextprotocol.io)
16
+ [![Tools](https://img.shields.io/badge/tools-1-10b981?style=flat-square)](#tools)
17
+ [![npm](https://img.shields.io/npm/v/@hasdata/chatgpt-mcp?style=flat-square&logo=npm&label=npm&color=cb3837)](https://www.npmjs.com/package/@hasdata/chatgpt-mcp)
18
+ [![PyPI](https://img.shields.io/pypi/v/hasdata-chatgpt-mcp?style=flat-square&logo=pypi&logoColor=white&label=PyPI&color=3775a9)](https://pypi.org/project/hasdata-chatgpt-mcp/)
19
+ [![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](LICENSE)
20
+
21
+ ## Contents
22
+
23
+ - [What you need](#what-you-need)
24
+ - [Quick start](#quick-start)
25
+ - [Example prompts](#example-prompts)
26
+ - [Tools](#tools)
27
+ - [Errors and failure paths](#errors-and-failure-paths)
28
+ - [Pricing, free tier and limits](#pricing-free-tier-and-limits)
29
+ - [How it compares](#how-it-compares)
30
+ - [FAQ](#faq)
31
+ - [HasData links](#hasdata-links)
32
+ - [Development](#development)
33
+ - [Contributing](#contributing)
34
+ - [License](#license)
35
+
36
+ ## What you need
37
+
38
+ An MCP client and a HasData API key from the [dashboard](https://app.hasdata.com/sign-up?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp), free to create with no card, and the free tier covers 100 calls a month at the 10-credit rate. This is a remote server, so the simplest path is a URL and an `x-api-key` header, with no container to run and no OpenAI billing anywhere in the flow. A client that only speaks stdio reaches it through a thin launcher, published as `@hasdata/chatgpt-mcp` on npm and `hasdata-chatgpt-mcp` on PyPI, shown below.
39
+
40
+ ## Quick start
41
+
42
+ The server URL is the same for every client. We run it hands-on in Claude Code and Claude Desktop. The other blocks follow each client's own documented format for a remote server.
43
+
44
+ | Field | Value |
45
+ | :--- | :--- |
46
+ | URL | `https://mcp.hasdata.com/mcp?apis=chatgpt` |
47
+ | Transport | HTTP, streamable |
48
+ | Auth header | `x-api-key: HASDATA_API_KEY` |
49
+
50
+ Clients with OAuth support can add the same URL as a connector and sign in without putting a key in a config file.
51
+
52
+ <details>
53
+ <summary><b>Claude Code</b></summary>
54
+
55
+ ```bash
56
+ claude mcp add --transport http chatgpt "https://mcp.hasdata.com/mcp?apis=chatgpt" \
57
+ --header "x-api-key: HASDATA_API_KEY"
58
+ ```
59
+
60
+ </details>
61
+
62
+ <details>
63
+ <summary><b>Claude Desktop</b></summary>
64
+
65
+ ```json
66
+ {
67
+ "mcpServers": {
68
+ "chatgpt": {
69
+ "type": "http",
70
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
71
+ "headers": { "x-api-key": "HASDATA_API_KEY" }
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ </details>
78
+
79
+ <details>
80
+ <summary><b>Cursor</b></summary>
81
+
82
+ ```json
83
+ {
84
+ "mcpServers": {
85
+ "chatgpt": {
86
+ "type": "streamable-http",
87
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
88
+ "headers": { "x-api-key": "HASDATA_API_KEY" }
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ </details>
95
+
96
+ <details>
97
+ <summary><b>VS Code</b></summary>
98
+
99
+ ```json
100
+ {
101
+ "servers": {
102
+ "chatgpt": {
103
+ "type": "http",
104
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
105
+ "headers": { "x-api-key": "HASDATA_API_KEY" }
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ </details>
112
+
113
+ ## Example prompts
114
+
115
+ Prompts, not code. Paste one in and the agent picks the tool itself. Each is annotated with the calls it takes, because every successful call costs 10 credits.
116
+
117
+ > Ask ChatGPT what the current state of the Artemis program is, and list the sources it used.
118
+
119
+ *One call, 10 credits. The answer and the sources come back together.*
120
+
121
+ > Ask ChatGPT the same question in German.
122
+
123
+ *One call, 10 credits. The answer follows the language of the prompt, so write the prompt in the language you want back.*
124
+
125
+ > Ask ChatGPT what happened in AI this week, with Berlin as the current date.
126
+
127
+ *One call, 10 credits. `timezone` is what fixes the meaning of "this week".*
128
+
129
+ > Put the same question to ChatGPT three times and show where the answers differ.
130
+
131
+ *Three calls, 30 credits. Each request is a fresh conversation, so there is no carry-over between them.*
132
+
133
+ ## Tools
134
+
135
+ | Tool | What it returns |
136
+ | --- | --- |
137
+ | `hasdata_chatgpt_chat_getChatgptAnswer` | The answer as markdown, the web sources ChatGPT consulted with their domain and title, the conversation title it generated, the model that answered, and whether a web search was used. 10 credits a call |
138
+
139
+ One tool, 10 credits per successful call.
140
+
141
+ ### Ask ChatGPT
142
+
143
+ [`hasdata_chatgpt_chat_getChatgptAnswer`](https://docs.hasdata.com/apis/chatgpt/chat?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp)
144
+
145
+ | Parameter | Type | Required | Notes |
146
+ | :--- | :--- | :--- | :--- |
147
+ | `prompt` | string | yes | The question or instruction, up to 8000 characters |
148
+ | `timezone` | string | | IANA zone name such as `Europe/Berlin`. It sets what ChatGPT treats as today |
149
+
150
+ Everything lands under `conversation`. The answer is in `answer` as markdown, with `title` holding the name ChatGPT generated for the thread, `model` the model that answered, and `usedWebSearch` saying whether it went to the web at all. `finishReason` and `complete` tell a truncated answer from a finished one.
151
+
152
+ ```json
153
+ {
154
+ "conversation": {
155
+ "answer": "As of **October 5, 2026**, NASA's Artemis program has made substantial progress…",
156
+ "title": "Artemis developments cited",
157
+ "model": "gpt-5-6",
158
+ "usedWebSearch": true,
159
+ "finishReason": "stop",
160
+ "complete": true,
161
+ "sources": [
162
+ { "title": "Artemis News - NASA", "url": "https://www.nasa.gov/artemis-news/", "domain": "www.nasa.gov" }
163
+ ]
164
+ }
165
+ }
166
+ ```
167
+
168
+ ## Errors and failure paths
169
+
170
+ Your client almost never sees an HTTP error code from a tool call. The MCP layer answers 200 and puts the failure inside the result, with `isError` set to `true` and the reason as text.
171
+
172
+ **`sources` is uneven, and partly absent.** In a measured answer carrying twenty sources, every one had `title`, `url` and `domain`, eleven had `publishedDate` and only five had `snippet`. Read each field defensively rather than assuming the shape of the first element holds for the rest.
173
+
174
+ **No web search means no sources.** `usedWebSearch` is false when ChatGPT answers from the model alone, and `sources` is then empty or missing. A prompt about a stable fact often takes that path, so ask for current information when citations are the point.
175
+
176
+ **Every call is a fresh conversation.** There is no memory between requests, so a follow-up has to carry its own context in the prompt. `conversationId` identifies the thread that answered, not a thread you can continue.
177
+
178
+ **A truncated answer still succeeds.** Check `complete` and `finishReason` before treating `answer` as the whole response.
179
+
180
+ Each successful call spends credits from the connected account. A call that fails validation is not billed.
181
+
182
+ ## Pricing, free tier and limits
183
+
184
+ The ChatGPT tool costs **10 credits per successful call**. Answer length does not change the price.
185
+
186
+ The free tier is **1,000 credits every month with no card**, which is 100 prompts.
187
+
188
+ Paid plans start at **$59 a month** for 200,000 credits, which is 20,000 calls. The unit price falls on larger plans. Current numbers are on the [plans page](https://hasdata.com/prices?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp).
189
+
190
+ ## How it compares
191
+
192
+ | | OpenAI API | This server |
193
+ | :--- | :--- | :--- |
194
+ | Account | Your own OpenAI account and billing | One HasData key |
195
+ | What you get | The model's answer | The answer plus the web sources behind it |
196
+ | Web search | A separate tool you wire up | Included, with `usedWebSearch` reporting whether it ran |
197
+ | Output | Your own schema | Parsed JSON with the sources already split out |
198
+
199
+ The two are not substitutes. The OpenAI API is the right call when you need system prompts, tools, streaming and conversation state. This server is the right call when you want what ChatGPT publicly answers, with its citations, and no account of your own.
200
+
201
+ ## FAQ
202
+
203
+ ### Do I need an OpenAI account or an API key?
204
+
205
+ No. The server answers anonymously through HasData, and the only credential involved is your HasData key.
206
+
207
+ ### Which model answers?
208
+
209
+ Whichever ChatGPT serves anonymously at the time. The response reports it in `model`, so read it rather than assuming. A measured call returned `gpt-5-6`.
210
+
211
+ ### Can I continue a conversation?
212
+
213
+ No. Each request is a fresh thread with no memory of earlier ones. Carry the context in the prompt instead.
214
+
215
+ ### What language will the answer be in?
216
+
217
+ The language of the prompt. Ask in German and the answer comes back in German, or ask explicitly for a language in the prompt.
218
+
219
+ ### Is HasData affiliated with OpenAI?
220
+
221
+ No. HasData is an independent web data provider and is not affiliated with, endorsed by or sponsored by OpenAI. All trademarks belong to their owners.
222
+
223
+ ### Compliance and personal data
224
+
225
+ The server reads what ChatGPT answers publicly to an anonymous visitor. It does not log in, and it does not reach private conversations or account data.
226
+
227
+ ## HasData links
228
+
229
+ | | |
230
+ | :--- | :--- |
231
+ | Product page and request builder | [ChatGPT Scraper API](https://hasdata.com/apis/chatgpt-api?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
232
+ | Endpoint documentation | [ChatGPT Scraper API docs](https://docs.hasdata.com/apis/chatgpt/chat?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
233
+ | Server documentation | [MCP server docs](https://docs.hasdata.com/mcp-server?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
234
+ | Every tool in one server | [HasData/hasdata-mcp](https://github.com/HasData/hasdata-mcp) |
235
+ | Client walkthroughs | [MCP clients and integrations](https://hasdata.com/integrations/mcp?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
236
+ | Plans and credit costs | [Plans and credit costs](https://hasdata.com/prices?utm_source=github&utm_medium=syndication&utm_campaign=chatgpt-mcp) |
237
+
238
+ ## Development
239
+
240
+ ```bash
241
+ npm install
242
+ npm test
243
+ ```
244
+
245
+ The tests in `test/` assert the tool contract, the part that can break without a commit here. They check that `?apis=chatgpt` returns the one expected tool, that its name and required parameter have not changed, that it carries a description, and that a real call still puts the answer under `conversation`.
246
+
247
+ ## Contributing
248
+
249
+ The parameter table and the sample above were read from the live schema and from real calls rather than from documentation. A correction is welcome when a field or a failure mode has changed. Open an issue with the response you saw.
250
+
251
+ ## License
252
+
253
+ MIT
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: sourced-answer
3
+ description: Ask ChatGPT a question and report the answer with the sources it actually cited
4
+ ---
5
+
6
+ Put a question to ChatGPT and come back with the answer and the evidence behind it.
7
+
8
+ Ask me for the question if I have not given one. Ask which timezone to assume when the question involves "today", "this week" or anything else that depends on the date.
9
+
10
+ Then:
11
+
12
+ 1. Call `hasdata_chatgpt_chat_getChatgptAnswer` with the question as `prompt`, and `timezone` set when the date matters. Write the prompt in the language the answer should come back in.
13
+ 2. Read `conversation.complete` and `conversation.finishReason` first. If the answer was cut off, say so before quoting it.
14
+ 3. Report the answer, then the sources as a list of domain and title, with the publication date where the source carries one. Do not invent dates for the ones that do not.
15
+ 4. Say whether `usedWebSearch` was true. If it was false there are no sources, and the answer came from the model alone, which the reader needs to know.
16
+
17
+ Count the sources and say how many carried a snippet and how many a date. Those fields are present on some and missing on others, and a reader who sees five snippets under twenty sources should know that is the API rather than your summarising.
18
+
19
+ Each successful call spends credits, so ask once with a well-formed question rather than iterating on phrasing.
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://glama.ai/mcp/schemas/server.json",
3
+ "maintainers": [
4
+ "HasData",
5
+ "sergey-ermakovich"
6
+ ]
7
+ }
@@ -0,0 +1,28 @@
1
+ """Thin launcher for HasData's hosted ChatGPT MCP server.
2
+
3
+ Connects an MCP client to the remote streamable-HTTP endpoint through mcp-proxy.
4
+ The server runs on HasData's infrastructure. This package only proxies stdio to it.
5
+ """
6
+ import os
7
+ import sys
8
+ import subprocess
9
+
10
+ URL = "https://mcp.hasdata.com/mcp?apis=chatgpt"
11
+
12
+
13
+ def main() -> None:
14
+ key = os.environ.get("HASDATA_API_KEY")
15
+ if not key:
16
+ sys.stderr.write(
17
+ "HASDATA_API_KEY is not set. Create a free key at https://app.hasdata.com "
18
+ "and set HASDATA_API_KEY.\n"
19
+ )
20
+ raise SystemExit(1)
21
+ args = [
22
+ sys.executable, "-m", "mcp_proxy", URL,
23
+ "--transport=streamablehttp",
24
+ "--headers", "x-api-key", key,
25
+ ]
26
+ rc = subprocess.call(args)
27
+ # subprocess returns -N when mcp_proxy is killed by signal N; map to 128+N.
28
+ raise SystemExit(rc if rc >= 0 else 128 - rc)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher: connects an MCP client to HasData's hosted ChatGPT MCP server
3
+ // (streamable HTTP) through the mcp-remote stdio bridge. The server runs remotely.
4
+ // This package only proxies, so nothing here scrapes anything.
5
+ import { spawn } from 'node:child_process';
6
+ import { createRequire } from 'node:module';
7
+ import { dirname, join } from 'node:path';
8
+
9
+ const URL = 'https://mcp.hasdata.com/mcp?apis=chatgpt';
10
+ const key = process.env.HASDATA_API_KEY;
11
+ if (!key) {
12
+ process.stderr.write('HASDATA_API_KEY is not set. Create a free key at https://app.hasdata.com and set HASDATA_API_KEY.\n');
13
+ process.exit(1);
14
+ }
15
+ // Resolve mcp-remote's CLI from its own package.json bin, so a future layout change
16
+ // or an exports map does not break a hardcoded deep path.
17
+ const require = createRequire(import.meta.url);
18
+ const pkg = require('mcp-remote/package.json');
19
+ const proxy = join(dirname(require.resolve('mcp-remote/package.json')), pkg.bin['mcp-remote']);
20
+ const child = spawn(process.execPath, [proxy, URL, '--header', `x-api-key:${key}`], { stdio: 'inherit' });
21
+ child.on('exit', (code, signal) => {
22
+ if (signal) process.kill(process.pid, signal);
23
+ else process.exit(code ?? 0);
24
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
3
+ "mcpServers": {
4
+ "chatgpt": {
5
+ "type": "streamable-http",
6
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
7
+ "headers": {
8
+ "x-api-key": "YOUR_HASDATA_API_KEY"
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@hasdata/chatgpt-mcp",
3
+ "mcpName": "com.hasdata/chatgpt",
4
+ "version": "1.0.0",
5
+ "description": "MCP server for the ChatGPT Scraper API through HasData's hosted API: send a prompt anonymously and get the answer as markdown with the web sources ChatGPT consulted. No OpenAI account or API key. 1,000 free credits every month.",
6
+ "type": "module",
7
+ "bin": {
8
+ "hasdata-chatgpt-mcp": "index.mjs"
9
+ },
10
+ "files": [
11
+ "index.mjs",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "test": "node --test"
17
+ },
18
+ "dependencies": {
19
+ "mcp-remote": "^0.1.43"
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/HasData/chatgpt-mcp.git"
28
+ },
29
+ "homepage": "https://hasdata.com/apis/chatgpt-api",
30
+ "keywords": [
31
+ "mcp",
32
+ "chatgpt",
33
+ "chatgpt-mcp",
34
+ "chatgpt-api",
35
+ "llm",
36
+ "ai-search",
37
+ "model-context-protocol",
38
+ "hasdata",
39
+ "scraper"
40
+ ]
41
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
+ "name": "hasdata-chatgpt-mcp",
4
+ "version": "1.0.0",
5
+ "description": "ChatGPT MCP server for Cursor. Send a prompt to ChatGPT anonymously and get the answer as markdown together with the web sources it consulted, as structured JSON. No OpenAI account or API key. Remote MCP server hosted by HasData, connects over streamable HTTP with your HasData API key.",
6
+ "author": {
7
+ "name": "HasData",
8
+ "url": "https://hasdata.com"
9
+ },
10
+ "homepage": "https://hasdata.com/apis/chatgpt-api",
11
+ "repository": "https://github.com/HasData/chatgpt-mcp",
12
+ "license": "MIT",
13
+ "keywords": [
14
+ "mcp",
15
+ "chatgpt",
16
+ "chatgpt-mcp",
17
+ "chatgpt-api",
18
+ "llm",
19
+ "ai-search",
20
+ "model-context-protocol",
21
+ "hasdata",
22
+ "scraper"
23
+ ]
24
+ }
@@ -0,0 +1,24 @@
1
+ [project]
2
+ name = "hasdata-chatgpt-mcp"
3
+ version = "1.0.0"
4
+ description = "MCP server for the ChatGPT Scraper API through HasData's hosted API. No OpenAI account."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = { text = "MIT" }
8
+ keywords = ["mcp", "chatgpt", "chatgpt-api", "llm", "ai-search", "model-context-protocol", "hasdata"]
9
+ # mcp is pinned below 2 because mcp-proxy 0.12.0 imports request_ctx, removed in the mcp 2.x SDK.
10
+ dependencies = ["mcp-proxy>=0.12.0", "mcp>=1.28.1,<2"]
11
+
12
+ [project.urls]
13
+ Homepage = "https://hasdata.com/apis/chatgpt-api"
14
+ Repository = "https://github.com/HasData/chatgpt-mcp"
15
+
16
+ [project.scripts]
17
+ hasdata-chatgpt-mcp = "hasdata_chatgpt_mcp:main"
18
+
19
+ [build-system]
20
+ requires = ["hatchling"]
21
+ build-backend = "hatchling.build"
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["hasdata_chatgpt_mcp"]
@@ -0,0 +1,34 @@
1
+ ---
2
+ description: How to ask ChatGPT a question and read its answer and sources through the HasData MCP server
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # ChatGPT through HasData
7
+
8
+ One tool, `hasdata_chatgpt_chat_getChatgptAnswer`, and it takes `prompt`. Nothing else is required. The call is anonymous, so no OpenAI account is involved and there is no conversation to resume.
9
+
10
+ ## Everything is under `conversation`
11
+
12
+ The answer is `conversation.answer`, as markdown rather than plain text. Alongside it sit `title`, the name ChatGPT generated for the thread, `model`, `usedWebSearch`, `finishReason` and `complete`.
13
+
14
+ Check `complete` before treating the answer as whole. A truncated answer still comes back as a successful call, and `finishReason` says why it stopped.
15
+
16
+ ## Sources are uneven
17
+
18
+ `conversation.sources` is where the citations live, and the fields are not uniform. In a measured answer with twenty sources, all twenty carried `title`, `url` and `domain`, eleven carried `publishedDate` and five carried `snippet`. Read each field defensively instead of taking the shape of the first element as the shape of the rest.
19
+
20
+ `usedWebSearch` decides whether there are sources at all. When ChatGPT answers from the model alone the flag is false and the array is empty or missing, which is ordinary rather than a failure. A question about a settled fact usually takes that path, so ask about something current when citations are the point of the call.
21
+
22
+ ## The prompt sets the language
23
+
24
+ The answer comes back in the language of the prompt. Ask in German and the reply is German. Asking in English for an answer in another language also works, but writing the prompt in the target language is the reliable route.
25
+
26
+ ## No memory between calls
27
+
28
+ Each request is a fresh conversation. `conversationId` names the thread that answered, not one that can be continued, so a follow-up has to restate its own context. A prompt that says "as I mentioned earlier" is talking to nobody.
29
+
30
+ ## Dates need a timezone
31
+
32
+ `timezone` takes an IANA name such as `Europe/Berlin` and sets what ChatGPT treats as today. Without it, words like "today" and "this week" resolve to wherever the request happens to leave from, which is rarely what the user meant.
33
+
34
+ Each successful call spends credits from the connected account, and the length of the answer does not change the price.
@@ -0,0 +1,61 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "com.hasdata/chatgpt",
4
+ "title": "HasData ChatGPT",
5
+ "description": "Send a prompt to ChatGPT anonymously and get the answer with its web sources, as JSON.",
6
+ "version": "1.0.0",
7
+ "websiteUrl": "https://hasdata.com/apis/chatgpt-api",
8
+ "repository": {
9
+ "url": "https://github.com/HasData/chatgpt-mcp",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://mcp.hasdata.com/mcp?apis=chatgpt",
16
+ "headers": [
17
+ {
18
+ "name": "x-api-key",
19
+ "description": "HasData API key, created at app.hasdata.com. 1,000 free credits every month, no card.",
20
+ "isRequired": true,
21
+ "isSecret": true
22
+ }
23
+ ]
24
+ }
25
+ ],
26
+ "packages": [
27
+ {
28
+ "registryType": "npm",
29
+ "identifier": "@hasdata/chatgpt-mcp",
30
+ "version": "1.0.0",
31
+ "transport": {
32
+ "type": "stdio"
33
+ },
34
+ "environmentVariables": [
35
+ {
36
+ "name": "HASDATA_API_KEY",
37
+ "description": "HasData API key, created at app.hasdata.com. 1,000 free credits every month, no card.",
38
+ "isRequired": true,
39
+ "isSecret": true
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "registryType": "pypi",
45
+ "identifier": "hasdata-chatgpt-mcp",
46
+ "version": "1.0.0",
47
+ "runtimeHint": "uvx",
48
+ "transport": {
49
+ "type": "stdio"
50
+ },
51
+ "environmentVariables": [
52
+ {
53
+ "name": "HASDATA_API_KEY",
54
+ "description": "HasData API key, created at app.hasdata.com. 1,000 free credits every month, no card.",
55
+ "isRequired": true,
56
+ "isSecret": true
57
+ }
58
+ ]
59
+ }
60
+ ]
61
+ }
@@ -0,0 +1,158 @@
1
+ // Tool contract test.
2
+ //
3
+ // The README promises one tool with a specific name and one required parameter. The upstream list
4
+ // can change without a single commit here, and the README would start lying silently. These
5
+ // checks catch that before a user does.
6
+ //
7
+ // The last test calls the tool for real. Listing tools accepts any non-empty key, so a contract
8
+ // check that only lists tools stays green with a revoked or mistyped key. That call costs
9
+ // 10 credits, which is the price of a canary that can fail for the right reason.
10
+ //
11
+ // Run: HASDATA_API_KEY=your_key_here npm test
12
+
13
+ import { test } from 'node:test';
14
+ import assert from 'node:assert/strict';
15
+
16
+ const ENDPOINT = 'https://mcp.hasdata.com/mcp?apis=chatgpt';
17
+ const KEY = process.env.HASDATA_API_KEY;
18
+ const TIMEOUT_MS = 30_000;
19
+
20
+ const EXPECTED = {
21
+ hasdata_chatgpt_chat_getChatgptAnswer: ['prompt'],
22
+ };
23
+
24
+ // A streamable HTTP body arrives either as plain JSON or as server-sent events. One SSE event
25
+ // can span several data: lines, several events can share one response, and a server is free to
26
+ // send progress notifications before the answer. So collect every event and pick the message
27
+ // carrying our request id instead of trusting the first data: line.
28
+ function parseRpc(raw, id) {
29
+ const trimmed = raw.trim();
30
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) return JSON.parse(trimmed);
31
+
32
+ const messages = [];
33
+ for (const event of trimmed.split(/\r?\n\r?\n+/)) {
34
+ const data = event
35
+ .split(/\r?\n/)
36
+ .filter((l) => l.startsWith('data:'))
37
+ .map((l) => l.slice(5).replace(/^ /, ''))
38
+ .join('\n');
39
+ if (!data || data === '[DONE]') continue;
40
+ try {
41
+ messages.push(JSON.parse(data));
42
+ } catch {
43
+ // A keep-alive or a partial event is not our response.
44
+ }
45
+ }
46
+ assert.ok(messages.length, `no JSON-RPC message in the response: ${raw.slice(0, 300)}`);
47
+ const match = messages.find((m) => m.id === id);
48
+ assert.ok(match, `no message with id ${id} in the response: ${raw.slice(0, 300)}`);
49
+ return match;
50
+ }
51
+
52
+ let nextId = 1;
53
+
54
+ async function rpc(method, params = {}) {
55
+ // The CI key sits on the free plan, where concurrency is 1. When several of
56
+ // these repos are pushed at once their contract runs collide, and HasData
57
+ // answers 429 with code concurrency_limit straight away rather than queueing.
58
+ // That is a plan limit, not a broken contract, so the call is retried before
59
+ // the test gives up. A 401 still fails on the first attempt.
60
+ for (let attempt = 1; ; attempt++) {
61
+ const id = nextId++;
62
+ const res = await fetch(ENDPOINT, {
63
+ method: 'POST',
64
+ headers: {
65
+ 'x-api-key': KEY,
66
+ 'Content-Type': 'application/json',
67
+ // The server answers over streamable HTTP, so accept both a plain body and a stream.
68
+ Accept: 'application/json, text/event-stream',
69
+ },
70
+ body: JSON.stringify({ jsonrpc: '2.0', id, method, params }),
71
+ signal: AbortSignal.timeout(TIMEOUT_MS),
72
+ });
73
+ assert.equal(res.status, 200, `${method} returned ${res.status}`);
74
+ const raw = await res.text();
75
+ if (raw.includes('concurrency_limit') && attempt < 5) {
76
+ await new Promise((r) => setTimeout(r, attempt * 4000));
77
+ continue;
78
+ }
79
+ return { raw, body: parseRpc(raw, id) };
80
+ }
81
+ }
82
+
83
+ // One network round trip for every test that needs the list.
84
+ let toolsPromise;
85
+ function listTools() {
86
+ toolsPromise ??= rpc('tools/list').then(({ body }) => {
87
+ assert.ok(body.result?.tools, 'the response carried no result.tools');
88
+ return body.result.tools;
89
+ });
90
+ return toolsPromise;
91
+ }
92
+
93
+ const live = { skip: KEY ? false : 'HASDATA_API_KEY is not set, skipping the live checks' };
94
+
95
+ test('apis=chatgpt exposes exactly one tool', live, async () => {
96
+ const tools = await listTools();
97
+ const names = tools.map((t) => t.name).sort().join(', ');
98
+ assert.equal(
99
+ tools.length,
100
+ Object.keys(EXPECTED).length,
101
+ `expected ${Object.keys(EXPECTED).length} tool, got ${tools.length}: ${names}`
102
+ );
103
+ });
104
+
105
+ test('the tool name has not changed', live, async () => {
106
+ const tools = await listTools();
107
+ const names = new Set(tools.map((t) => t.name));
108
+ for (const expected of Object.keys(EXPECTED)) {
109
+ assert.ok(names.has(expected), `tool ${expected} is missing from the list`);
110
+ }
111
+ });
112
+
113
+ test('the tool still declares its required parameter', live, async () => {
114
+ const tools = await listTools();
115
+ for (const tool of tools) {
116
+ const required = tool.inputSchema?.required ?? [];
117
+ const want = EXPECTED[tool.name];
118
+ assert.ok(want, `tool ${tool.name} is not covered by this test`);
119
+ for (const param of want) {
120
+ assert.ok(
121
+ required.includes(param),
122
+ `${tool.name} should require ${param}, declares: ${required.join(', ') || 'nothing'}`
123
+ );
124
+ }
125
+ }
126
+ });
127
+
128
+ test('the tool carries a description', live, async () => {
129
+ const tools = await listTools();
130
+ for (const tool of tools) {
131
+ assert.ok(
132
+ (tool.description || '').trim().length > 20,
133
+ `${tool.name} has an empty or near-empty description`
134
+ );
135
+ }
136
+ });
137
+
138
+ test('the key is accepted and the answer lands under conversation', live, async () => {
139
+ const { raw, body } = await rpc('tools/call', {
140
+ name: 'hasdata_chatgpt_chat_getChatgptAnswer',
141
+ // A short, stable question. The point is the shape of the response, not the content,
142
+ // and a prompt about current events would make the call slower for no gain here.
143
+ arguments: { prompt: 'Name the capital of Japan in one word.' },
144
+ });
145
+ assert.ok(!raw.includes('401 Unauthorized'), 'HasData rejected the key');
146
+ assert.ok(!raw.includes('"isError":true'), `the tool call failed: ${raw.slice(0, 300)}`);
147
+
148
+ // The README puts everything under conversation. That is the shape every prompt depends on,
149
+ // and no schema check can see it.
150
+ const text = body.result?.content?.[0]?.text ?? '';
151
+ const payload = JSON.parse(text);
152
+ const json = payload.json ?? payload;
153
+ assert.ok(json.conversation, `expected a conversation object: ${text.slice(0, 300)}`);
154
+ assert.ok(
155
+ typeof json.conversation.answer === 'string' && json.conversation.answer.length > 0,
156
+ 'conversation.answer came back empty'
157
+ );
158
+ });