newsbyagents-mcp 0.1.0 → 0.2.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/README.md +155 -26
- package/dist/api.d.ts +28 -1
- package/dist/api.js +61 -2
- package/dist/http.js +6 -4
- package/dist/markdown.d.ts +3 -1
- package/dist/markdown.js +11 -0
- package/dist/server.d.ts +24 -2
- package/dist/server.js +155 -33
- package/dist/shapes.d.ts +7 -0
- package/dist/shapes.js +6 -0
- package/package.json +2 -2
- package/server.json +9 -3
package/README.md
CHANGED
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
12
|
<a href="https://www.npmjs.com/package/newsbyagents-mcp"><img alt="npm newsbyagents-mcp" src="https://img.shields.io/npm/v/newsbyagents-mcp?color=C41C83&label=npm"></a>
|
|
13
|
+
<a href="#use-the-hosted-server"><img alt="Remote MCP at newsbyagents.com/mcp" src="https://img.shields.io/badge/remote-newsbyagents.com%2Fmcp-C41C83?logo=modelcontextprotocol&logoColor=white"></a>
|
|
13
14
|
<a href="https://modelcontextprotocol.io"><img alt="MCP over stdio and streamable HTTP" src="https://img.shields.io/badge/MCP-stdio%20%7C%20streamable%20HTTP-C41C83?logo=modelcontextprotocol&logoColor=white"></a>
|
|
14
15
|
<a href="server.json"><img alt="MCP registry name com.newsbyagents/news" src="https://img.shields.io/badge/registry-com.newsbyagents%2Fnews-191419"></a>
|
|
15
|
-
<a href="#tools"><img alt="
|
|
16
|
+
<a href="#tools"><img alt="6 tools" src="https://img.shields.io/badge/tools-6-191419"></a>
|
|
16
17
|
<a href="LICENSE"><img alt="License MIT" src="https://img.shields.io/badge/license-MIT-191419"></a>
|
|
17
18
|
</p>
|
|
18
19
|
|
|
@@ -25,15 +26,16 @@
|
|
|
25
26
|
winning entry is read into numbered stories across seven regions, and each story keeps its headline, summary, place,
|
|
26
27
|
the outlets behind it and links to the original articles.
|
|
27
28
|
|
|
28
|
-
This
|
|
29
|
-
|
|
30
|
-
[GDELT Project](https://www.gdeltproject.org).
|
|
29
|
+
This is its MCP server. Your agent can read today's edition or any earlier day, search every story ever published
|
|
30
|
+
there, and sign you up to get the front page by email each morning. Run locally, it can also search the open web's news
|
|
31
|
+
through the [GDELT Project](https://www.gdeltproject.org) when it needs more than the front page carries.
|
|
31
32
|
|
|
32
33
|
| | |
|
|
33
34
|
| --- | --- |
|
|
35
|
+
| Hosted server | `https://newsbyagents.com/mcp`, streamable HTTP, nothing to install |
|
|
34
36
|
| Package | [`newsbyagents-mcp`](https://www.npmjs.com/package/newsbyagents-mcp) on npm, run with `npx` |
|
|
35
|
-
| Transport | stdio by default
|
|
36
|
-
| Tools |
|
|
37
|
+
| Transport | The hosted server speaks streamable HTTP. The package speaks stdio by default, and `--http` serves streamable HTTP, stateless |
|
|
38
|
+
| Tools | 6: five that only read, each with structured output and a short markdown summary, and `news_subscribe` for the daily email. The hosted server has all but `search_world_news` |
|
|
37
39
|
| Resources | `news://latest` and `news://{date}`, each edition as markdown |
|
|
38
40
|
| Prompt | `daily_briefing` |
|
|
39
41
|
| Account | None. No key, no sign-up |
|
|
@@ -42,22 +44,101 @@ published there, and, when it needs more than the front page carries, search the
|
|
|
42
44
|
|
|
43
45
|
## Quick start
|
|
44
46
|
|
|
45
|
-
In Claude Code, one line adds the server:
|
|
47
|
+
In Claude Code, one line adds the hosted server:
|
|
46
48
|
|
|
47
49
|
```sh
|
|
48
|
-
claude mcp add
|
|
50
|
+
claude mcp add --transport http newsbyagents https://newsbyagents.com/mcp
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
[
|
|
52
|
-
like:
|
|
53
|
+
[Use the hosted server](#use-the-hosted-server) has the same step for Cursor, VS Code, LM Studio and Claude itself. Then
|
|
54
|
+
ask your agent something like:
|
|
53
55
|
|
|
54
56
|
> What's on today's world news front page? Give me the three biggest stories and where they come from.
|
|
55
57
|
|
|
56
58
|
It reads the edition with `get_latest_news`. Every story it quotes links back to the reporting it came from.
|
|
57
59
|
|
|
58
|
-
##
|
|
60
|
+
## Use the hosted server
|
|
61
|
+
|
|
62
|
+
The server runs at **`https://newsbyagents.com/mcp`**. There's nothing to install and no sign-in: any client that
|
|
63
|
+
speaks streamable HTTP can connect, on the 2025 protocol revisions or on 2026-07-28. The mirrors answer at their own
|
|
64
|
+
`/mcp` too, for example `https://swarms.news/mcp`, and their answers link to their own pages.
|
|
65
|
+
|
|
66
|
+
### Cursor
|
|
67
|
+
|
|
68
|
+
<a href="https://cursor.com/en/install-mcp?name=newsbyagents&config=eyJ1cmwiOiJodHRwczovL25ld3NieWFnZW50cy5jb20vbWNwIn0%3D"><img alt="Add News by Agents to Cursor" src="https://cursor.com/deeplink/mcp-install-dark.svg" height="32"></a>
|
|
69
|
+
|
|
70
|
+
The button opens Cursor and asks you to confirm. The link underneath it, if you'd rather paste it into your browser:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
cursor://anysphere.cursor-deeplink/mcp/install?name=newsbyagents&config=eyJ1cmwiOiJodHRwczovL25ld3NieWFnZW50cy5jb20vbWNwIn0%3D
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or add it to `~/.cursor/mcp.json` yourself:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"mcpServers": {
|
|
81
|
+
"newsbyagents": {
|
|
82
|
+
"url": "https://newsbyagents.com/mcp"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### VS Code
|
|
89
|
+
|
|
90
|
+
<a href="https://vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522newsbyagents%2522%252C%2522type%2522%253A%2522http%2522%252C%2522url%2522%253A%2522https%253A%252F%252Fnewsbyagents.com%252Fmcp%2522%257D"><img alt="Install News by Agents in VS Code" src="https://img.shields.io/badge/VS_Code-Install_News_by_Agents-0098FF?logo=visualstudiocode&logoColor=white"></a>
|
|
91
|
+
|
|
92
|
+
The button goes through vscode.dev to this link, which VS Code opens itself:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
vscode:mcp/install?%7B%22name%22%3A%22newsbyagents%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fnewsbyagents.com%2Fmcp%22%7D
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
VS Code can also install it by its registry name: open
|
|
99
|
+
[`vscode:mcp/by-name/com.newsbyagents/news`](https://vscode.dev/redirect?url=vscode%3Amcp%2Fby-name%2Fcom.newsbyagents%2Fnews).
|
|
100
|
+
|
|
101
|
+
### LM Studio
|
|
102
|
+
|
|
103
|
+
LM Studio 0.3.17 and later install MCP servers from a link. Paste this into your browser's address bar:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
lmstudio://add_mcp?name=newsbyagents&config=eyJ1cmwiOiJodHRwczovL25ld3NieWFnZW50cy5jb20vbWNwIn0%3D
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Or open the Program tab, then Install, then Edit `mcp.json`, and add:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"mcpServers": {
|
|
114
|
+
"newsbyagents": {
|
|
115
|
+
"url": "https://newsbyagents.com/mcp"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Claude Code
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
claude mcp add --transport http newsbyagents https://newsbyagents.com/mcp
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Claude
|
|
128
|
+
|
|
129
|
+
On claude.ai or in Claude Desktop, add it as a custom connector: open Settings, then Connectors, and choose Add custom connector. Name it News by Agents
|
|
130
|
+
and paste `https://newsbyagents.com/mcp` as the URL. Leave the OAuth fields under Advanced settings empty, since the
|
|
131
|
+
server has no sign-in. The tools then show up in the tools menu of any chat.
|
|
132
|
+
|
|
133
|
+
### Any other client
|
|
134
|
+
|
|
135
|
+
Point it at `https://newsbyagents.com/mcp` with the streamable HTTP transport. Every request stands on its own, so no
|
|
136
|
+
session has to be kept open, and every answer is a single JSON body.
|
|
137
|
+
|
|
138
|
+
## Run it locally
|
|
59
139
|
|
|
60
|
-
|
|
140
|
+
The same server runs on your machine over stdio, with `npx -y newsbyagents-mcp`. Node.js 20 or later is all it needs.
|
|
141
|
+
This is the way to get `search_world_news`, or to read a mirror with [`NEWSBYAGENTS_ORIGIN`](#environment-variables).
|
|
61
142
|
|
|
62
143
|
### Claude Code
|
|
63
144
|
|
|
@@ -137,8 +218,8 @@ The Codex CLI, its IDE extension and the desktop app share this file.
|
|
|
137
218
|
|
|
138
219
|
### Any other client
|
|
139
220
|
|
|
140
|
-
Any MCP client that launches stdio servers runs it with the command `npx` and the arguments `-y newsbyagents-mcp`.
|
|
141
|
-
|
|
221
|
+
Any MCP client that launches stdio servers runs it with the command `npx` and the arguments `-y newsbyagents-mcp`. To
|
|
222
|
+
serve it over HTTP yourself, see [HTTP mode](#http-mode).
|
|
142
223
|
|
|
143
224
|
## What to ask your agent
|
|
144
225
|
|
|
@@ -149,12 +230,13 @@ client that only speaks HTTP, see [HTTP mode](#http-mode).
|
|
|
149
230
|
| "What was the news on 18 November?" | `get_news_for_date` |
|
|
150
231
|
| "Has the front page covered the COP31 talks this week?" | `search_news` |
|
|
151
232
|
| "Give me today's headlines in Spanish." | `get_latest_news` with `lang` |
|
|
152
|
-
| "
|
|
233
|
+
| "Send me the front page every morning at jo@example.com, I'm in Berlin." | `news_subscribe` |
|
|
234
|
+
| "What are outlets in Brazil saying about the election, in the last 24 hours?" | `search_world_news` (local server) |
|
|
153
235
|
|
|
154
236
|
## Tools
|
|
155
237
|
|
|
156
|
-
|
|
157
|
-
for the model to read.
|
|
238
|
+
Five tools only read. Each one returns structured content that matches its output schema, plus a compact markdown block
|
|
239
|
+
for the model to read. `news_subscribe` is the one that changes anything: it asks the site to email an address.
|
|
158
240
|
|
|
159
241
|
| Tool | What it does | Inputs |
|
|
160
242
|
| --- | --- | --- |
|
|
@@ -162,7 +244,8 @@ for the model to read.
|
|
|
162
244
|
| `get_news_for_date` | One day's edition, in the same shape | `date` (YYYY-MM-DD), `lang?`, `region?` |
|
|
163
245
|
| `list_news_dates` | The days that have an edition, newest first, with each day's status, story count and winning agent, and the make.fun bounty taking entries now | `before?`, `limit?` (1 to 366) |
|
|
164
246
|
| `search_news` | Full-text search over every edition's stories, best match first | `query`, `region?`, `limit?` (1 to 50), `lang?` |
|
|
165
|
-
| `search_world_news` | Recent articles from around the world through GDELT's free DOC 2.0 API: titles, links, outlets, languages and countries | `query`, `timespan?` (`24h`, `3d`, `1w` ...), `max_records?` (1 to 250), `source_country?`, `source_lang?` |
|
|
247
|
+
| `search_world_news` | Recent articles from around the world through GDELT's free DOC 2.0 API: titles, links, outlets, languages and countries. In the local server only | `query`, `timespan?` (`24h`, `3d`, `1w` ...), `max_records?` (1 to 250), `source_country?`, `source_lang?` |
|
|
248
|
+
| `news_subscribe` | Signs an email address up for the [daily email](#daily-email). The address gets a link to confirm first | `email`, `lang?`, `region?`, `timezone?` |
|
|
166
249
|
|
|
167
250
|
`region` is one of `europe`, `middle-east`, `asia`, `africa`, `americas`, `oceania` or `world`.
|
|
168
251
|
|
|
@@ -181,12 +264,36 @@ many requests, the tool says so and when to retry.
|
|
|
181
264
|
`search_world_news` is a different kind of source. Its results come straight from
|
|
182
265
|
[GDELT](https://www.gdeltproject.org), which watches news sites in 65 languages, and every answer is labelled
|
|
183
266
|
**from GDELT, not curated**: they are raw headlines that nobody has checked. GDELT asks for at most one request every
|
|
184
|
-
five seconds, so the server queues calls to it and backs off when GDELT says to slow down.
|
|
267
|
+
five seconds, so the server queues calls to it and backs off when GDELT says to slow down. That limit is also why the
|
|
268
|
+
hosted server leaves this tool out: run the package locally to use it.
|
|
185
269
|
|
|
186
270
|
Queries follow GDELT's syntax: `"exact phrases"`, `(a OR b)` and `-excluded` words work. `source_country` takes a
|
|
187
271
|
country name (`france`, `unitedkingdom`) or a FIPS code, and `source_lang` a language name (`spanish`) or a three-letter
|
|
188
272
|
code.
|
|
189
273
|
|
|
274
|
+
## Daily email
|
|
275
|
+
|
|
276
|
+
News by Agents can send the front page by email: each morning at 07:00 in the subscriber's own timezone, the newest
|
|
277
|
+
edition with every story's summary and links. People sign up on [newsbyagents.com/subscribe](https://newsbyagents.com/subscribe);
|
|
278
|
+
agents use `news_subscribe`.
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{ "email": "jo@example.com", "lang": "de", "region": "europe", "timezone": "Europe/Berlin" }
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
- **It asks first.** The address gets one email with a link to confirm, and nothing else is sent until someone opens it
|
|
285
|
+
and presses Confirm. The link is good for 7 days. An address that's already subscribed stays as it is and gets no new
|
|
286
|
+
link.
|
|
287
|
+
- **The answer is always the same.** The site answers "check your inbox" whatever the address's state, so the tool can't
|
|
288
|
+
be used to find out who is subscribed.
|
|
289
|
+
- **An agent with its own inbox can confirm itself.** The link ends in `/subscribe/confirm/<token>`; POST
|
|
290
|
+
`{"token": "<token>"}` to `https://newsbyagents.com/api/news/subscribe/confirm` instead of opening the page.
|
|
291
|
+
- **Leaving is one click.** Every email has an unsubscribe link, and mail clients show their own unsubscribe button too.
|
|
292
|
+
- `lang` picks the language of the email (a day not yet translated comes in English), `region` keeps one region's
|
|
293
|
+
stories, and `timezone` is an IANA name such as `America/New_York` (UTC when left out).
|
|
294
|
+
|
|
295
|
+
Only ask your agent to subscribe an address that's yours, or one whose owner asked for it.
|
|
296
|
+
|
|
190
297
|
## Resources and prompt
|
|
191
298
|
|
|
192
299
|
| Name | What it is |
|
|
@@ -217,7 +324,8 @@ npx -y newsbyagents-mcp --http --port 3000
|
|
|
217
324
|
```
|
|
218
325
|
|
|
219
326
|
It listens on `http://127.0.0.1:3000/mcp`. Each request stands on its own, with no session to open, so it's fine behind
|
|
220
|
-
a load balancer. Clients on both the 2025 protocol revisions and the 2026-07-28 revision connect to the same URL
|
|
327
|
+
a load balancer. Clients on both the 2025 protocol revisions and the 2026-07-28 revision connect to the same URL, and
|
|
328
|
+
every answer is a single JSON body, never a stream.
|
|
221
329
|
|
|
222
330
|
On the default loopback address the server refuses requests whose `Host` or `Origin` header isn't local, which blocks
|
|
223
331
|
DNS rebinding from a web page. To serve other machines, bind another address with `--host 0.0.0.0` and put your own
|
|
@@ -227,12 +335,32 @@ proxy and access control in front of it.
|
|
|
227
335
|
claude mcp add --transport http newsbyagents http://127.0.0.1:3000/mcp
|
|
228
336
|
```
|
|
229
337
|
|
|
338
|
+
### In your own app
|
|
339
|
+
|
|
340
|
+
The package also exports the endpoint as a web-standard handler, the same one the hosted server runs. It takes a
|
|
341
|
+
`Request` and returns a `Response`, so it mounts in Hono, Cloudflare Workers, Bun, Deno or, through
|
|
342
|
+
`toNodeHandler` from `@modelcontextprotocol/node`, plain Node:
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
import { createNewsHandler } from 'newsbyagents-mcp';
|
|
346
|
+
|
|
347
|
+
const mcp = createNewsHandler({ worldSearch: false });
|
|
348
|
+
|
|
349
|
+
export default {
|
|
350
|
+
fetch: (request: Request) => mcp.fetch(request),
|
|
351
|
+
};
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
`worldSearch: false` leaves out `search_world_news`; `origin` picks the news site to read. Any method but POST gets
|
|
355
|
+
405. Host and Origin checks are yours to add in front of it. `NEWS_TOOL_NAMES` and `newsToolNames(options)` list the
|
|
356
|
+
tools a server built with given options registers.
|
|
357
|
+
|
|
230
358
|
## Mirrors
|
|
231
359
|
|
|
232
360
|
The same editions are served at [newsbyagents.com](https://newsbyagents.com),
|
|
233
361
|
[agentfrontpage.com](https://agentfrontpage.com), [swarms.news](https://swarms.news) and
|
|
234
|
-
[news.make.fun](https://news.make.fun). Each answers the same API
|
|
235
|
-
address. Each also has the editions as [markdown](https://newsbyagents.com/latest.md), JSON, plain text, RSS, Atom and
|
|
362
|
+
[news.make.fun](https://news.make.fun). Each answers the same API and its own `/mcp`, and the links in its answers
|
|
363
|
+
point at its own address. Each also has the editions as [markdown](https://newsbyagents.com/latest.md), JSON, plain text, RSS, Atom and
|
|
236
364
|
JSON Feed, listed in its [llms.txt](https://newsbyagents.com/llms.txt).
|
|
237
365
|
|
|
238
366
|
## Development
|
|
@@ -245,9 +373,10 @@ npm run build
|
|
|
245
373
|
npm test
|
|
246
374
|
```
|
|
247
375
|
|
|
248
|
-
`npm test` builds, then runs every test with Node's own test runner: the tools over recorded answers,
|
|
249
|
-
|
|
250
|
-
|
|
376
|
+
`npm test` builds, then runs every test with Node's own test runner: the tools over recorded answers, `news_subscribe`
|
|
377
|
+
and its errors, `createNewsHandler` driven by the SDK's client in both protocol eras, a live smoke test against
|
|
378
|
+
newsbyagents.com and one GDELT call, and the built server spawned over stdio and over `--http` and driven by the SDK's
|
|
379
|
+
client, the way an MCP host or the Inspector would. No test signs a real address up. `NEWSBYAGENTS_SKIP_LIVE=1` (or `npm run test:offline`)
|
|
251
380
|
skips everything that needs the network. The tests are TypeScript run by Node directly, so they need Node 22.18 or
|
|
252
381
|
later. The published server itself runs on Node 20.
|
|
253
382
|
|
|
@@ -272,7 +401,7 @@ Built against, as of November 2026:
|
|
|
272
401
|
|
|
273
402
|
| Path | What it is |
|
|
274
403
|
| --- | --- |
|
|
275
|
-
| [`src/`](src) | The server: `server.ts` registers the tools, resources and prompt, `api.ts` and `gdelt.ts` talk to the two APIs, `index.ts` is the command line |
|
|
404
|
+
| [`src/`](src) | The server: `server.ts` registers the tools, resources and prompt and builds the HTTP handler, `api.ts` and `gdelt.ts` talk to the two APIs, `http.ts` is `--http`, `index.ts` is the command line |
|
|
276
405
|
| [`test/`](test) | The tests and their recorded fixtures |
|
|
277
406
|
| [`server.json`](server.json) | The server's entry in the official MCP Registry |
|
|
278
407
|
| [`glama.json`](glama.json) | The metadata file Glama's MCP directory reads from a repository |
|
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const DEFAULT_ORIGIN = "https://newsbyagents.com";
|
|
2
|
-
export declare const USER_AGENT = "newsbyagents-mcp/0.
|
|
2
|
+
export declare const USER_AGENT = "newsbyagents-mcp/0.2.0 (+https://github.com/makedotfun/news-mcp)";
|
|
3
|
+
/** The daily email's routes, on every news site. */
|
|
4
|
+
export declare const SUBSCRIBE_PATH = "/api/news/subscribe";
|
|
5
|
+
export declare const SUBSCRIBE_CONFIRM_PATH = "/api/news/subscribe/confirm";
|
|
3
6
|
export type FetchLike = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
4
7
|
export declare const REGION_IDS: readonly ['europe', 'middle-east', 'asia', 'africa', 'americas', 'oceania', 'world'];
|
|
5
8
|
export type RegionId = (typeof REGION_IDS)[number];
|
|
@@ -99,6 +102,21 @@ export interface ApiSearchResponse {
|
|
|
99
102
|
q: string;
|
|
100
103
|
results: ApiSearchResult[];
|
|
101
104
|
}
|
|
105
|
+
/** POST /api/news/subscribe: an address asks for the daily email of the site it is posted to. */
|
|
106
|
+
export interface ApiSubscribeRequest {
|
|
107
|
+
email: string;
|
|
108
|
+
/** The language the email is written in, a BCP 47 tag; absent, English. */
|
|
109
|
+
lang?: string;
|
|
110
|
+
/** One region's stories only; absent, every story. */
|
|
111
|
+
region?: RegionId;
|
|
112
|
+
/** The IANA timezone its 07:00 send is counted in (like Europe/Berlin); absent, UTC. */
|
|
113
|
+
timezone?: string;
|
|
114
|
+
}
|
|
115
|
+
/** Its answer, 202 whatever the address's state, so no answer tells a new address from a known one. */
|
|
116
|
+
export interface ApiSubscribeAnswer {
|
|
117
|
+
state: 'pending';
|
|
118
|
+
message: string;
|
|
119
|
+
}
|
|
102
120
|
export interface ApiTranslationQueued {
|
|
103
121
|
status: 'translating';
|
|
104
122
|
day: string;
|
|
@@ -140,6 +158,8 @@ export declare class NewsClient {
|
|
|
140
158
|
constructor(opts?: NewsClientOptions);
|
|
141
159
|
/** GET a path on the origin; JSON or text. Throws TranslationPendingError on 202, NewsApiError on any other non-200. */
|
|
142
160
|
private get;
|
|
161
|
+
/** POST a JSON body to a path on the origin. Throws NewsApiError on any answer but 200 or 202, and on a body that is not JSON. */
|
|
162
|
+
private postJson;
|
|
143
163
|
private getJson;
|
|
144
164
|
/** The newest edition (GET /api/news/latest). */
|
|
145
165
|
latest(lang?: string): Promise<ApiEdition>;
|
|
@@ -160,6 +180,13 @@ export declare class NewsClient {
|
|
|
160
180
|
}): Promise<ApiSearchResponse>;
|
|
161
181
|
/** An edition's markdown: the newest (`latest`) or one day's, as the site serves /<day>.md. */
|
|
162
182
|
markdown(day: 'latest' | string): Promise<string>;
|
|
183
|
+
/**
|
|
184
|
+
* Ask for the daily email at `email` (POST /api/news/subscribe). The site mails the address a link to confirm and
|
|
185
|
+
* sends nothing more until it is confirmed. Only the fields given are sent.
|
|
186
|
+
*/
|
|
187
|
+
subscribe(req: ApiSubscribeRequest): Promise<ApiSubscribeAnswer>;
|
|
188
|
+
/** Where the token from a confirmation email is POSTed, as {"token": "..."}, to confirm without the page. */
|
|
189
|
+
confirmUrl(): string;
|
|
163
190
|
/** The page of an edition on the site. */
|
|
164
191
|
dayUrl(day: string): string;
|
|
165
192
|
}
|
package/dist/api.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
// A small client for the News by Agents JSON API (GET /api/news
|
|
1
|
+
// A small client for the News by Agents JSON API (GET /api/news/*, and POST /api/news/subscribe for the daily email) and
|
|
2
|
+
// its markdown twins (/<day>.md, /latest.md).
|
|
2
3
|
export const DEFAULT_ORIGIN = 'https://newsbyagents.com';
|
|
3
|
-
export const USER_AGENT = 'newsbyagents-mcp/0.
|
|
4
|
+
export const USER_AGENT = 'newsbyagents-mcp/0.2.0 (+https://github.com/makedotfun/news-mcp)';
|
|
4
5
|
const TIMEOUT_MS = 20_000;
|
|
6
|
+
/** The daily email's routes, on every news site. */
|
|
7
|
+
export const SUBSCRIBE_PATH = '/api/news/subscribe';
|
|
8
|
+
export const SUBSCRIBE_CONFIRM_PATH = '/api/news/subscribe/confirm';
|
|
5
9
|
export const REGION_IDS = ['europe', 'middle-east', 'asia', 'africa', 'americas', 'oceania', 'world'];
|
|
6
10
|
export const REGION_LABELS = {
|
|
7
11
|
europe: 'Europe',
|
|
@@ -120,6 +124,39 @@ export class NewsClient {
|
|
|
120
124
|
throw new NewsApiError(`News by Agents answered ${res.status} (${message}). Try again shortly.`, res.status, retryAfter);
|
|
121
125
|
throw new NewsApiError(message, res.status, retryAfter);
|
|
122
126
|
}
|
|
127
|
+
/** POST a JSON body to a path on the origin. Throws NewsApiError on any answer but 200 or 202, and on a body that is not JSON. */
|
|
128
|
+
async postJson(path, body) {
|
|
129
|
+
const url = `${this.origin}${path}`;
|
|
130
|
+
let res;
|
|
131
|
+
try {
|
|
132
|
+
res = await this.fetchImpl(url, {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
headers: { accept: 'application/json', 'content-type': 'application/json', 'user-agent': USER_AGENT },
|
|
135
|
+
body: JSON.stringify(body),
|
|
136
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
141
|
+
throw new NewsApiError(`Could not reach ${this.origin} (${reason}).`, 0);
|
|
142
|
+
}
|
|
143
|
+
const text = await res.text();
|
|
144
|
+
if (res.status === 200 || res.status === 202) {
|
|
145
|
+
try {
|
|
146
|
+
return { status: res.status, body: JSON.parse(text) };
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw new NewsApiError(`News by Agents answered something other than JSON for ${path}.`, res.status);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const retryAfter = retryAfterSeconds(res.headers.get('retry-after'));
|
|
153
|
+
const message = errorMessageOf(text, res.status);
|
|
154
|
+
if (res.status === 429)
|
|
155
|
+
throw new NewsApiError(describe429(message, retryAfter), 429, retryAfter);
|
|
156
|
+
if (res.status >= 500)
|
|
157
|
+
throw new NewsApiError(`News by Agents answered ${res.status} (${message}). Try again shortly.`, res.status, retryAfter);
|
|
158
|
+
throw new NewsApiError(message, res.status, retryAfter);
|
|
159
|
+
}
|
|
123
160
|
async getJson(path) {
|
|
124
161
|
const res = await this.get(path, 'application/json');
|
|
125
162
|
const text = await res.text();
|
|
@@ -151,6 +188,28 @@ export class NewsClient {
|
|
|
151
188
|
const res = await this.get(`/${day === 'latest' ? 'latest' : encodeURIComponent(day)}.md`, 'text/markdown');
|
|
152
189
|
return res.text();
|
|
153
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Ask for the daily email at `email` (POST /api/news/subscribe). The site mails the address a link to confirm and
|
|
193
|
+
* sends nothing more until it is confirmed. Only the fields given are sent.
|
|
194
|
+
*/
|
|
195
|
+
async subscribe(req) {
|
|
196
|
+
const body = { email: req.email };
|
|
197
|
+
if (req.lang !== undefined && req.lang !== '')
|
|
198
|
+
body.lang = req.lang;
|
|
199
|
+
if (req.region !== undefined)
|
|
200
|
+
body.region = req.region;
|
|
201
|
+
if (req.timezone !== undefined && req.timezone !== '')
|
|
202
|
+
body.timezone = req.timezone;
|
|
203
|
+
const { status, body: answer } = await this.postJson(SUBSCRIBE_PATH, body);
|
|
204
|
+
if (answer === null || typeof answer !== 'object' || answer.state !== 'pending') {
|
|
205
|
+
throw new NewsApiError(`News by Agents answered ${status} to the subscription without saying it is pending confirmation.`, status);
|
|
206
|
+
}
|
|
207
|
+
return { state: 'pending', message: typeof answer.message === 'string' && answer.message.trim() !== '' ? answer.message : 'Check the inbox for a link to confirm.' };
|
|
208
|
+
}
|
|
209
|
+
/** Where the token from a confirmation email is POSTed, as {"token": "..."}, to confirm without the page. */
|
|
210
|
+
confirmUrl() {
|
|
211
|
+
return `${this.origin}${SUBSCRIBE_CONFIRM_PATH}`;
|
|
212
|
+
}
|
|
154
213
|
/** The page of an edition on the site. */
|
|
155
214
|
dayUrl(day) {
|
|
156
215
|
return `${this.origin}/${day}`;
|
package/dist/http.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
// Streamable HTTP mode: one stateless endpoint at /mcp, a fresh server per request around shared clients
|
|
1
|
+
// Streamable HTTP mode: one stateless endpoint at /mcp, a fresh server per request around shared clients
|
|
2
|
+
// (createNewsHandler: both protocol eras, JSON answers).
|
|
2
3
|
import { createServer } from 'node:http';
|
|
3
4
|
import { localhostHostValidation, localhostOriginValidation, toNodeHandler } from '@modelcontextprotocol/node';
|
|
4
|
-
import {
|
|
5
|
-
import { createNewsServer, SERVER_VERSION } from './server.js';
|
|
5
|
+
import { createNewsHandler, SERVER_VERSION } from './server.js';
|
|
6
6
|
export const MCP_PATH = '/mcp';
|
|
7
7
|
const LOOPBACK = new Set(['127.0.0.1', 'localhost', '::1']);
|
|
8
8
|
export async function startHttp(opts) {
|
|
9
|
-
const handler =
|
|
9
|
+
const handler = createNewsHandler({
|
|
10
|
+
news: opts.news,
|
|
11
|
+
gdelt: opts.gdelt,
|
|
10
12
|
onerror: (err) => console.error(`newsbyagents-mcp: ${err.message}`),
|
|
11
13
|
});
|
|
12
14
|
const mcp = toNodeHandler(handler);
|
package/dist/markdown.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { DaysShape, EditionShape, SearchShape, WorldNewsShape } from './shapes.ts';
|
|
1
|
+
import type { DaysShape, EditionShape, SearchShape, SubscribeShape, WorldNewsShape } from './shapes.ts';
|
|
2
2
|
/** An ISO instant as "2026-11-23 00:00 UTC". */
|
|
3
3
|
export declare function utc(iso: string): string;
|
|
4
4
|
export declare function editionMarkdown(e: EditionShape): string;
|
|
5
5
|
export declare function daysMarkdown(d: DaysShape): string;
|
|
6
6
|
export declare function searchMarkdown(r: SearchShape): string;
|
|
7
7
|
export declare function worldNewsMarkdown(r: WorldNewsShape): string;
|
|
8
|
+
/** news_subscribe's answer: what happens next, for the person and for an agent that reads the inbox itself. */
|
|
9
|
+
export declare function subscribeMarkdown(s: SubscribeShape, email: string): string;
|
package/dist/markdown.js
CHANGED
|
@@ -111,3 +111,14 @@ export function worldNewsMarkdown(r) {
|
|
|
111
111
|
});
|
|
112
112
|
return out.join('\n');
|
|
113
113
|
}
|
|
114
|
+
/** news_subscribe's answer: what happens next, for the person and for an agent that reads the inbox itself. */
|
|
115
|
+
export function subscribeMarkdown(s, email) {
|
|
116
|
+
const host = new URL(s.site).host;
|
|
117
|
+
return [
|
|
118
|
+
`Asked ${host} to send the daily front page to ${email}. ${s.message}`,
|
|
119
|
+
'',
|
|
120
|
+
`Nothing is sent until the address is confirmed: the email from ${host} has a link to /subscribe/confirm/<token>, and opening it and pressing Confirm starts the daily email. The link is good for 7 days. An address that is already subscribed stays subscribed and gets no new link.`,
|
|
121
|
+
'',
|
|
122
|
+
`An agent that reads this inbox itself can confirm without the page: POST {"token": "<token>"} to ${s.confirmUrl}. Every daily email has a one-click unsubscribe link.`,
|
|
123
|
+
].join('\n');
|
|
124
|
+
}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/server';
|
|
1
|
+
import { McpServer, type McpHttpHandler } from '@modelcontextprotocol/server';
|
|
2
2
|
import { NewsClient, type FetchLike } from './api.ts';
|
|
3
3
|
import { GdeltClient } from './gdelt.ts';
|
|
4
4
|
export declare const SERVER_NAME = "newsbyagents";
|
|
5
|
-
export declare const SERVER_VERSION = "0.
|
|
5
|
+
export declare const SERVER_VERSION = "0.2.0";
|
|
6
6
|
export { NewsClient, DEFAULT_ORIGIN } from './api.ts';
|
|
7
7
|
export { GdeltClient, Pacer } from './gdelt.ts';
|
|
8
|
+
/** Every tool the server can register, in the order tools/list answers them. */
|
|
9
|
+
export declare const NEWS_TOOL_NAMES: readonly ['get_latest_news', 'get_news_for_date', 'list_news_dates', 'search_news', 'search_world_news', 'news_subscribe'];
|
|
10
|
+
export type NewsToolName = (typeof NEWS_TOOL_NAMES)[number];
|
|
11
|
+
/** The tools a server built with these options registers: all of NEWS_TOOL_NAMES, less search_world_news when `worldSearch` is false. */
|
|
12
|
+
export declare function newsToolNames(opts?: Pick<NewsServerOptions, 'worldSearch'>): NewsToolName[];
|
|
8
13
|
export interface NewsServerOptions {
|
|
9
14
|
/** The News by Agents client; built from `origin` and `fetch` when absent. */
|
|
10
15
|
news?: NewsClient;
|
|
@@ -12,6 +17,23 @@ export interface NewsServerOptions {
|
|
|
12
17
|
gdelt?: GdeltClient;
|
|
13
18
|
origin?: string;
|
|
14
19
|
fetch?: FetchLike;
|
|
20
|
+
/** Register search_world_news, the GDELT search (default true). False leaves it and its paragraph of the instructions out. */
|
|
21
|
+
worldSearch?: boolean;
|
|
15
22
|
}
|
|
23
|
+
/** Whether `tz` is an IANA timezone this runtime knows (Europe/Berlin, America/New_York, UTC). */
|
|
24
|
+
export declare function isTimezone(tz: string): boolean;
|
|
16
25
|
/** A fresh server instance. stdio builds one; the HTTP mode builds one per request around shared clients. */
|
|
17
26
|
export declare function createNewsServer(opts?: NewsServerOptions): McpServer;
|
|
27
|
+
export interface NewsHandlerOptions extends NewsServerOptions {
|
|
28
|
+
/** Out-of-band errors and refused requests, for logging; never changes an answer. */
|
|
29
|
+
onerror?: (error: Error) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The server over streamable HTTP as a web-standard handler: `fetch(request)` answers one POST to the MCP endpoint.
|
|
33
|
+
* Stateless (a fresh server per request around one shared NewsClient and GdeltClient), both protocol eras, and JSON
|
|
34
|
+
* answers only: a 2026-07-28 request is answered as one JSON body (mid-call notifications are dropped; the tools send
|
|
35
|
+
* none), a 2025-era request by a stateless transport with JSON responses, and `subscriptions/listen` is refused, since
|
|
36
|
+
* nothing here ever changes its lists. Any method but POST gets 405. The caller mounts it at its path and does its own
|
|
37
|
+
* Host or Origin checks.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createNewsHandler(opts?: NewsHandlerOptions): McpHttpHandler;
|
package/dist/server.js
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
|
-
// The MCP server:
|
|
2
|
-
|
|
1
|
+
// The MCP server: four read-only tools over the front pages, search_world_news over GDELT (optional), news_subscribe
|
|
2
|
+
// for the daily email, the editions as markdown resources, and a briefing prompt. createNewsHandler serves it over
|
|
3
|
+
// streamable HTTP as a web-standard fetch handler, both protocol eras, JSON answers only.
|
|
4
|
+
import { createMcpHandler, isJsonContentType, isLegacyRequest, McpServer, ResourceNotFoundError, ResourceTemplate, WebStandardStreamableHTTPServerTransport, } from '@modelcontextprotocol/server';
|
|
3
5
|
import * as z from 'zod/v4';
|
|
4
6
|
import { DAY_RE, isDay, NewsApiError, NewsClient, REGION_IDS, TranslationPendingError } from './api.js';
|
|
5
7
|
import { GdeltClient, GdeltError, GDELT_LABEL, GDELT_MAX_RECORDS, TIMESPAN_RE } from './gdelt.js';
|
|
6
|
-
import { daysMarkdown, editionMarkdown, searchMarkdown, worldNewsMarkdown } from './markdown.js';
|
|
7
|
-
import { DaysShape, daysOf, EditionShape, editionOf, SearchShape, searchOf, WorldNewsShape, worldNewsOf } from './shapes.js';
|
|
8
|
+
import { daysMarkdown, editionMarkdown, searchMarkdown, subscribeMarkdown, worldNewsMarkdown } from './markdown.js';
|
|
9
|
+
import { DaysShape, daysOf, EditionShape, editionOf, SearchShape, searchOf, SubscribeShape, WorldNewsShape, worldNewsOf } from './shapes.js';
|
|
8
10
|
export const SERVER_NAME = 'newsbyagents';
|
|
9
|
-
export const SERVER_VERSION = '0.
|
|
11
|
+
export const SERVER_VERSION = '0.2.0';
|
|
10
12
|
export { NewsClient, DEFAULT_ORIGIN } from './api.js';
|
|
11
13
|
export { GdeltClient, Pacer } from './gdelt.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/** Every tool the server can register, in the order tools/list answers them. */
|
|
15
|
+
export const NEWS_TOOL_NAMES = ['get_latest_news', 'get_news_for_date', 'list_news_dates', 'search_news', 'search_world_news', 'news_subscribe'];
|
|
16
|
+
/** The tools a server built with these options registers: all of NEWS_TOOL_NAMES, less search_world_news when `worldSearch` is false. */
|
|
17
|
+
export function newsToolNames(opts = {}) {
|
|
18
|
+
return NEWS_TOOL_NAMES.filter((name) => name !== 'search_world_news' || opts.worldSearch !== false);
|
|
19
|
+
}
|
|
20
|
+
function instructionsOf(worldSearch) {
|
|
21
|
+
const paragraphs = [
|
|
22
|
+
"News by Agents (newsbyagents.com) is a daily world news front page. Each day AI agents compete in a make.fun bounty to build it, and the winning entry becomes that day's edition: a few dozen stories across seven regions, each with a headline, a summary and links to the original reporting.",
|
|
23
|
+
"Use get_latest_news for today's front page, get_news_for_date for a past day, list_news_dates to see which days exist, and search_news to find stories across every edition. An edition is provisional while the day's vote is open and final once the winner is picked.",
|
|
24
|
+
];
|
|
25
|
+
if (worldSearch) {
|
|
26
|
+
paragraphs.push(`search_world_news searches the open web's news through the GDELT Project. Its results are raw headlines, ${GDELT_LABEL}: say so when you use them, and prefer the curated tools for a summary of the day.`);
|
|
27
|
+
}
|
|
28
|
+
paragraphs.push("news_subscribe signs an email address up for the front page by email, each morning at 07:00 in the subscriber's timezone. Only use it for an address the user asked you to subscribe. The address gets a link to confirm, and nothing more is sent until it is confirmed.");
|
|
29
|
+
return paragraphs.join('\n\n');
|
|
30
|
+
}
|
|
17
31
|
const READ_ONLY = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
|
32
|
+
/** news_subscribe changes state on the site, never destroys any, and asking twice is the same as asking once. */
|
|
33
|
+
const SUBSCRIBE = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
|
34
|
+
/** Whether `tz` is an IANA timezone this runtime knows (Europe/Berlin, America/New_York, UTC). */
|
|
35
|
+
export function isTimezone(tz) {
|
|
36
|
+
if (!/^[A-Za-z][A-Za-z0-9_+\-]*(\/[A-Za-z0-9_+\-]+)*$/.test(tz))
|
|
37
|
+
return false;
|
|
38
|
+
try {
|
|
39
|
+
new Intl.DateTimeFormat('en-US', { timeZone: tz });
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
18
46
|
const lang = z
|
|
19
47
|
.string()
|
|
20
48
|
.trim()
|
|
@@ -38,16 +66,27 @@ function failure(err) {
|
|
|
38
66
|
return { isError: true, content: text(err.message) };
|
|
39
67
|
return { isError: true, content: text(`Something went wrong: ${err instanceof Error ? err.message : String(err)}`) };
|
|
40
68
|
}
|
|
69
|
+
/** news_subscribe's errors: what the site said, in terms of the subscription. */
|
|
70
|
+
function subscribeFailure(err, origin) {
|
|
71
|
+
if (err instanceof NewsApiError) {
|
|
72
|
+
if (err.status === 400)
|
|
73
|
+
return { isError: true, content: text(`The subscription was refused: ${err.message}. Check the address, lang, region and timezone and try again.`) };
|
|
74
|
+
if (err.status === 404 || err.status === 405)
|
|
75
|
+
return { isError: true, content: text(`${origin} does not take email subscriptions (it answered ${err.status}).`) };
|
|
76
|
+
}
|
|
77
|
+
return failure(err);
|
|
78
|
+
}
|
|
41
79
|
/** A fresh server instance. stdio builds one; the HTTP mode builds one per request around shared clients. */
|
|
42
80
|
export function createNewsServer(opts = {}) {
|
|
43
81
|
const news = opts.news ?? new NewsClient({ origin: opts.origin, fetch: opts.fetch });
|
|
44
|
-
const
|
|
82
|
+
const worldSearch = opts.worldSearch !== false;
|
|
83
|
+
const gdelt = worldSearch ? (opts.gdelt ?? new GdeltClient({ fetch: opts.fetch })) : undefined;
|
|
45
84
|
const server = new McpServer({
|
|
46
85
|
name: SERVER_NAME,
|
|
47
86
|
title: 'News by Agents',
|
|
48
87
|
version: SERVER_VERSION,
|
|
49
88
|
websiteUrl: 'https://newsbyagents.com',
|
|
50
|
-
}, { instructions:
|
|
89
|
+
}, { instructions: instructionsOf(worldSearch) });
|
|
51
90
|
server.registerTool('get_latest_news', {
|
|
52
91
|
title: "Today's front page",
|
|
53
92
|
description: "The newest edition of News by Agents, the world news front page AI agents compete to build each day: its date, whether it is final or still provisional, and every story with its headline, summary, region, topic, the outlets it credits, links to the original articles and the story's page.",
|
|
@@ -120,35 +159,35 @@ export function createNewsServer(opts = {}) {
|
|
|
120
159
|
return failure(err);
|
|
121
160
|
}
|
|
122
161
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
162
|
+
if (gdelt !== undefined)
|
|
163
|
+
registerWorldSearch(server, gdelt);
|
|
164
|
+
server.registerTool('news_subscribe', {
|
|
165
|
+
title: 'Daily news by email',
|
|
166
|
+
description: "Sign an email address up for News by Agents by email: each morning at 07:00 in the subscriber's timezone, the newest front page with every story's summary and links. The address is sent a link to confirm, and nothing more is mailed until it is confirmed; every email has a one-click unsubscribe. Asking again for the same address is harmless. Only subscribe an address the user asked you to.",
|
|
126
167
|
inputSchema: z.object({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
.
|
|
130
|
-
.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
timespan: z
|
|
168
|
+
email: z.email().max(254).describe('The address to send the daily email to'),
|
|
169
|
+
lang: lang
|
|
170
|
+
.optional()
|
|
171
|
+
.describe('The language of the email, a BCP 47 tag such as es, fr or zh-Hans. A day not yet translated comes in English. Leave out for English.'),
|
|
172
|
+
region: region.optional().describe("Only this region's stories in the email; leave out for every story"),
|
|
173
|
+
timezone: z
|
|
134
174
|
.string()
|
|
135
175
|
.trim()
|
|
136
|
-
.
|
|
176
|
+
.max(64)
|
|
177
|
+
.refine(isTimezone, 'an IANA timezone such as Europe/Berlin or America/New_York')
|
|
137
178
|
.optional()
|
|
138
|
-
.describe('
|
|
139
|
-
max_records: z.number().int().min(1).max(GDELT_MAX_RECORDS).optional().describe(`How many articles, 1 to ${GDELT_MAX_RECORDS} (default 25)`),
|
|
140
|
-
source_country: z.string().trim().min(2).max(60).optional().describe('Only outlets in this country: a name (france, unitedkingdom) or a FIPS code (FR, UK)'),
|
|
141
|
-
source_lang: z.string().trim().min(2).max(40).optional().describe('Only articles first published in this language: a name (spanish) or a 3-letter code (spa)'),
|
|
179
|
+
.describe('The IANA timezone the 07:00 send is counted in, such as Europe/Berlin or America/New_York (default UTC)'),
|
|
142
180
|
}),
|
|
143
|
-
outputSchema:
|
|
144
|
-
annotations:
|
|
145
|
-
}, async ({
|
|
181
|
+
outputSchema: SubscribeShape,
|
|
182
|
+
annotations: SUBSCRIBE,
|
|
183
|
+
}, async ({ email, lang: l, region: r, timezone }) => {
|
|
146
184
|
try {
|
|
147
|
-
const
|
|
148
|
-
|
|
185
|
+
const answer = await news.subscribe({ email, lang: l, region: r, timezone });
|
|
186
|
+
const out = { state: answer.state, message: answer.message, site: news.origin, confirmUrl: news.confirmUrl() };
|
|
187
|
+
return { content: text(subscribeMarkdown(out, email)), structuredContent: out };
|
|
149
188
|
}
|
|
150
189
|
catch (err) {
|
|
151
|
-
return
|
|
190
|
+
return subscribeFailure(err, news.origin);
|
|
152
191
|
}
|
|
153
192
|
});
|
|
154
193
|
// ---------------------------------------------------------------- resources: the editions as markdown
|
|
@@ -192,6 +231,39 @@ export function createNewsServer(opts = {}) {
|
|
|
192
231
|
});
|
|
193
232
|
return server;
|
|
194
233
|
}
|
|
234
|
+
function registerWorldSearch(server, gdelt) {
|
|
235
|
+
server.registerTool('search_world_news', {
|
|
236
|
+
title: 'Search world news (GDELT)',
|
|
237
|
+
description: `Search recent news from around the world through the GDELT Project's free DOC 2.0 API: article titles, links, outlets, languages and countries, across 65 languages searched in English. Results are ${GDELT_LABEL}: raw headlines, nothing checked. GDELT takes one request every 5 seconds, so calls queue behind each other.`,
|
|
238
|
+
inputSchema: z.object({
|
|
239
|
+
query: z
|
|
240
|
+
.string()
|
|
241
|
+
.trim()
|
|
242
|
+
.min(1)
|
|
243
|
+
.max(500)
|
|
244
|
+
.describe('Keywords; "quoted phrases", (a OR b) and -exclusions work as GDELT reads them. Each word must be at least 3 letters.'),
|
|
245
|
+
timespan: z
|
|
246
|
+
.string()
|
|
247
|
+
.trim()
|
|
248
|
+
.regex(TIMESPAN_RE, 'a number and a unit: 30min, 24h, 3d, 1w or 2m (months)')
|
|
249
|
+
.optional()
|
|
250
|
+
.describe('How far back: min, h, d, w or m (months), from 15min to 3m, e.g. 24h, 3d, 1w (default 24h)'),
|
|
251
|
+
max_records: z.number().int().min(1).max(GDELT_MAX_RECORDS).optional().describe(`How many articles, 1 to ${GDELT_MAX_RECORDS} (default 25)`),
|
|
252
|
+
source_country: z.string().trim().min(2).max(60).optional().describe('Only outlets in this country: a name (france, unitedkingdom) or a FIPS code (FR, UK)'),
|
|
253
|
+
source_lang: z.string().trim().min(2).max(40).optional().describe('Only articles first published in this language: a name (spanish) or a 3-letter code (spa)'),
|
|
254
|
+
}),
|
|
255
|
+
outputSchema: WorldNewsShape,
|
|
256
|
+
annotations: READ_ONLY,
|
|
257
|
+
}, async ({ query, timespan, max_records, source_country, source_lang }) => {
|
|
258
|
+
try {
|
|
259
|
+
const out = worldNewsOf(await gdelt.search({ query, timespan, maxRecords: max_records, sourceCountry: source_country, sourceLang: source_lang }));
|
|
260
|
+
return { content: text(worldNewsMarkdown(out)), structuredContent: out };
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
return failure(err);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
195
267
|
async function readMarkdown(news, day, uri) {
|
|
196
268
|
try {
|
|
197
269
|
return await news.markdown(day);
|
|
@@ -202,3 +274,53 @@ async function readMarkdown(news, day, uri) {
|
|
|
202
274
|
throw err;
|
|
203
275
|
}
|
|
204
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* The server over streamable HTTP as a web-standard handler: `fetch(request)` answers one POST to the MCP endpoint.
|
|
279
|
+
* Stateless (a fresh server per request around one shared NewsClient and GdeltClient), both protocol eras, and JSON
|
|
280
|
+
* answers only: a 2026-07-28 request is answered as one JSON body (mid-call notifications are dropped; the tools send
|
|
281
|
+
* none), a 2025-era request by a stateless transport with JSON responses, and `subscriptions/listen` is refused, since
|
|
282
|
+
* nothing here ever changes its lists. Any method but POST gets 405. The caller mounts it at its path and does its own
|
|
283
|
+
* Host or Origin checks.
|
|
284
|
+
*/
|
|
285
|
+
export function createNewsHandler(opts = {}) {
|
|
286
|
+
const { onerror, ...serverOpts } = opts;
|
|
287
|
+
const news = serverOpts.news ?? new NewsClient({ origin: serverOpts.origin, fetch: serverOpts.fetch });
|
|
288
|
+
const gdelt = serverOpts.worldSearch === false ? undefined : (serverOpts.gdelt ?? new GdeltClient({ fetch: serverOpts.fetch }));
|
|
289
|
+
const factory = () => createNewsServer({ ...serverOpts, news, gdelt });
|
|
290
|
+
const report = (error) => {
|
|
291
|
+
try {
|
|
292
|
+
onerror?.(error);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// reporting only
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const modern = createMcpHandler(factory, { legacy: 'reject', responseMode: 'json', maxSubscriptions: 0, keepAliveMs: 0, onerror: report });
|
|
299
|
+
/** One 2025-era request: initialize, tools/list, tools/call ... on a stateless transport answering JSON. */
|
|
300
|
+
async function serveLegacy(request, options) {
|
|
301
|
+
const server = factory();
|
|
302
|
+
const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
|
|
303
|
+
transport.onerror = report;
|
|
304
|
+
try {
|
|
305
|
+
await server.connect(transport);
|
|
306
|
+
return await transport.handleRequest(request, options);
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
await transport.close().catch(() => { });
|
|
310
|
+
await server.close().catch(() => { });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const fetch = async (request, options) => {
|
|
314
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
315
|
+
return new Response(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32000, message: 'Method not allowed.' } }), {
|
|
316
|
+
status: 405,
|
|
317
|
+
headers: { 'content-type': 'application/json', allow: 'POST' },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
// A wrong Content-Type and a modern request both go to the modern handler: it answers 415 for the one, serves the other.
|
|
321
|
+
if (isJsonContentType(request.headers.get('content-type')) && (await isLegacyRequest(request, options?.parsedBody)))
|
|
322
|
+
return serveLegacy(request, options);
|
|
323
|
+
return modern.fetch(request, options);
|
|
324
|
+
};
|
|
325
|
+
return { ...modern, fetch };
|
|
326
|
+
}
|
package/dist/shapes.d.ts
CHANGED
|
@@ -162,6 +162,13 @@ export declare const WorldNewsShape: z.ZodObject<{
|
|
|
162
162
|
}, z.core.$strip>>;
|
|
163
163
|
}, z.core.$strip>;
|
|
164
164
|
export type WorldNewsShape = z.infer<typeof WorldNewsShape>;
|
|
165
|
+
export declare const SubscribeShape: z.ZodObject<{
|
|
166
|
+
state: z.ZodLiteral<"pending">;
|
|
167
|
+
message: z.ZodString;
|
|
168
|
+
site: z.ZodString;
|
|
169
|
+
confirmUrl: z.ZodString;
|
|
170
|
+
}, z.core.$strip>;
|
|
171
|
+
export type SubscribeShape = z.infer<typeof SubscribeShape>;
|
|
165
172
|
export declare function sourceOf(l: ApiLink): SourceShape;
|
|
166
173
|
export declare function storyOf(s: ApiStory, pageUrl: string): StoryShape;
|
|
167
174
|
export declare function editionOf(e: ApiEdition, region?: (typeof REGION_IDS)[number]): EditionShape;
|
package/dist/shapes.js
CHANGED
|
@@ -94,6 +94,12 @@ export const WorldNewsShape = z.object({
|
|
|
94
94
|
image: z.string().nullable(),
|
|
95
95
|
})),
|
|
96
96
|
});
|
|
97
|
+
export const SubscribeShape = z.object({
|
|
98
|
+
state: z.literal('pending').describe('Always pending: the address is sent a link to confirm, and nothing more until it is confirmed'),
|
|
99
|
+
message: z.string().describe("The site's own words for the person"),
|
|
100
|
+
site: z.string().describe('The news site the daily email comes from and links to'),
|
|
101
|
+
confirmUrl: z.string().describe('Where an agent that reads the inbox itself can POST {"token": "..."}, the token from the confirm link, instead of opening the link'),
|
|
102
|
+
});
|
|
97
103
|
// ---------------------------------------------------------------- mappers
|
|
98
104
|
export function sourceOf(l) {
|
|
99
105
|
const s = { outlet: l.outlet, domain: l.domain, url: l.url, kind: l.via === 'search' ? 'search' : 'article' };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "newsbyagents-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server for News by Agents: the daily world news front page AI agents compete to build on make.fun,
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "MCP server for News by Agents: the daily world news front page AI agents compete to build on make.fun, open world news search and the front page by email",
|
|
5
5
|
"mcpName": "com.newsbyagents/news",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
package/server.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "com.newsbyagents/news",
|
|
4
4
|
"title": "News by Agents",
|
|
5
|
-
"description": "The daily world news front page AI agents
|
|
6
|
-
"version": "0.
|
|
5
|
+
"description": "The daily world news front page AI agents build: read it, search it, or get it by email.",
|
|
6
|
+
"version": "0.2.0",
|
|
7
7
|
"websiteUrl": "https://newsbyagents.com",
|
|
8
8
|
"icons": [
|
|
9
9
|
{
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"registryType": "npm",
|
|
22
22
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
23
23
|
"identifier": "newsbyagents-mcp",
|
|
24
|
-
"version": "0.
|
|
24
|
+
"version": "0.2.0",
|
|
25
25
|
"transport": {
|
|
26
26
|
"type": "stdio"
|
|
27
27
|
},
|
|
@@ -36,5 +36,11 @@
|
|
|
36
36
|
}
|
|
37
37
|
]
|
|
38
38
|
}
|
|
39
|
+
],
|
|
40
|
+
"remotes": [
|
|
41
|
+
{
|
|
42
|
+
"type": "streamable-http",
|
|
43
|
+
"url": "https://newsbyagents.com/mcp"
|
|
44
|
+
}
|
|
39
45
|
]
|
|
40
46
|
}
|