@specstream/mcp 0.0.0-stage → 1.0.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 CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @specstream/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ SpecStream is the live web data engine. One platform to build, search, extract, enrich, map, and monitor data across the entire web.
4
+
5
+ This package runs SpecStream as a local stdio MCP server. Claude Desktop, Cursor, Windsurf, Cline, Zed, Continue and any other MCP client start it with `npx -y @specstream/mcp`, and it connects to `https://api.specstream.ai/mcp` with no other dependencies.
6
+
7
+ ## Quick start
8
+
9
+ 1. Create an API key under **Agents & API** at [specstream.ai/workspace](https://specstream.ai/workspace). A new account gets $2 of credit with no card, enough for 2,000 fast searches.
10
+ 2. Add SpecStream to your MCP client configuration:
11
+
12
+ ```json
13
+ {
14
+ "mcpServers": {
15
+ "specstream": {
16
+ "command": "npx",
17
+ "args": ["-y", "@specstream/mcp"],
18
+ "env": {
19
+ "SPECSTREAM_API_KEY": "your_api_key_here"
20
+ }
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Without a key the server still lists every tool, so clients and registries can read them, and a tool call explains how to get a key.
27
+
28
+ ## The three products
29
+
30
+ * **Search API (`search_web`)**: the most accurate web search API in the world ([scores and method](https://specstream.ai/benchmarks)). $5 per 1,000 searches of up to 10 results, or $1 per 1,000 on the fast tier.
31
+ * **Extract API (`read_pages`)**: clean Markdown or text from up to 20 URLs per call, web pages, PDF, Word and Excel files included. $0.80 per 1,000 pages, and a page with no text is not charged.
32
+ * **Deep Search (`compile`, `quote_capacity_work`, `authorize_capacity_work`)**: describe the data in plain words, read the quote with its maximum before anything runs, and receive structured rows with a source URL on each value.
33
+
34
+ The full list of 143 tools is in `tools.json`, including domain authority, backlinks, EU DORA sub-processors with their LEIs, ready lists and research reports.
35
+
36
+ ## Environment variables
37
+
38
+ * `SPECSTREAM_API_KEY`: your SpecStream API key, required to run tools.
39
+ * `SPECSTREAM_MCP_URL`: optional endpoint override, `https://api.specstream.ai/mcp` by default.
40
+
41
+ ## License
42
+
43
+ MIT. Source and issues: [github.com/specstream/specstream-tools](https://github.com/specstream/specstream-tools).
@@ -0,0 +1,251 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Stdio to Streamable HTTP MCP proxy for SpecStream (https://api.specstream.ai/mcp).
4
+ * Zero external dependencies. Requires Node.js 18+.
5
+ *
6
+ * Without SPECSTREAM_API_KEY, responds to initialize and tools/list from the bundled
7
+ * tools.json manifest so MCP clients and registries can inspect every tool, and explains
8
+ * how to create a free API key ($2 credit, no card) on tool calls.
9
+ */
10
+
11
+ import fs from "node:fs";
12
+ import readline from "node:readline";
13
+ import { fileURLToPath } from "node:url";
14
+
15
+ export const DEFAULT_MCP_URL = "https://api.specstream.ai/mcp";
16
+ export const PROTOCOL_VERSION = "2025-11-25";
17
+ export const KNOWN_VERSIONS = ["2024-11-05", "2025-03-26", "2025-06-18", PROTOCOL_VERSION];
18
+ const VERSION_KEY = "io.modelcontextprotocol/protocolVersion";
19
+ const NAMED_METHODS = { "tools/call": "name", "prompts/get": "name", "resources/read": "uri" };
20
+ const MISSING_KEY =
21
+ "SPECSTREAM_API_KEY is not set, so SpecStream lists its tools but cannot run them. " +
22
+ "Create a key under Agents & API at https://specstream.ai/workspace ($2 free credit, no card) " +
23
+ "and set SPECSTREAM_API_KEY in your MCP client environment.";
24
+
25
+ const SERVER_INFO = {
26
+ name: "specstream",
27
+ title: "SpecStream",
28
+ version: "1.0.0",
29
+ websiteUrl: "https://specstream.ai",
30
+ };
31
+
32
+ const TOOLS_PATH = new URL("../tools.json", import.meta.url);
33
+
34
+ export function loadBundledTools() {
35
+ try {
36
+ const raw = JSON.parse(fs.readFileSync(TOOLS_PATH, "utf8"));
37
+ return Array.isArray(raw) ? raw : Array.isArray(raw?.tools) ? raw.tools : [];
38
+ } catch {
39
+ return [];
40
+ }
41
+ }
42
+
43
+ export function authorizationFromEnv(env = process.env) {
44
+ for (const name of ["SPECSTREAM_API_KEY", "SPECSTREAM_AUTHORIZATION", "AUTHORIZATION"]) {
45
+ const value = String(env[name] || "").trim();
46
+ if (value) {
47
+ if (/[^\x20-\x7e]/.test(value)) {
48
+ throw new Error("The configured authorization header contains invalid characters");
49
+ }
50
+ return value.toLowerCase().startsWith("bearer ") ? value : `Bearer ${value}`;
51
+ }
52
+ }
53
+ return "";
54
+ }
55
+
56
+ export function resolveMcpUrl(env = process.env) {
57
+ const value = String(env.SPECSTREAM_MCP_URL || DEFAULT_MCP_URL).trim() || DEFAULT_MCP_URL;
58
+ let parsed;
59
+ try {
60
+ parsed = new URL(value);
61
+ } catch {
62
+ throw new Error("SPECSTREAM_MCP_URL must be a valid HTTPS URL (or loopback HTTP).");
63
+ }
64
+ const loopback = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "::1";
65
+ if (
66
+ (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && loopback)) ||
67
+ parsed.username ||
68
+ parsed.password ||
69
+ parsed.search ||
70
+ parsed.hash
71
+ ) {
72
+ throw new Error("SPECSTREAM_MCP_URL must use HTTPS (or loopback HTTP) without credentials, query, or fragment.");
73
+ }
74
+ return parsed.toString();
75
+ }
76
+
77
+ function headerValue(value) {
78
+ if (value === value.trim() && !/[^\x20-\x7e]/.test(value) && !(value.startsWith("=?base64?") && value.endsWith("?="))) {
79
+ return value;
80
+ }
81
+ return `=?base64?${Buffer.from(value, "utf8").toString("base64")}?=`;
82
+ }
83
+
84
+ function parseSseJson(text, requestId) {
85
+ const events = text.replace(/\r\n/g, "\n").split("\n\n");
86
+ for (const event of events) {
87
+ const blob = event
88
+ .split("\n")
89
+ .filter((line) => line.startsWith("data:"))
90
+ .map((line) => line.slice(5).trimStart())
91
+ .join("\n");
92
+ if (!blob) continue;
93
+ try {
94
+ const payload = JSON.parse(blob);
95
+ if (payload && typeof payload === "object" && "id" in payload && payload.id === requestId) {
96
+ return payload;
97
+ }
98
+ } catch {
99
+ // ignore non-JSON SSE keepalives
100
+ }
101
+ }
102
+ throw new Error("MCP endpoint returned no JSON-RPC response in SSE stream");
103
+ }
104
+
105
+ export function handleOfflineMessage(message) {
106
+ const id = message?.id;
107
+ const method = String(message?.method || "");
108
+ if (method === "notifications/initialized" || id === undefined) {
109
+ return null;
110
+ }
111
+ if (method === "initialize") {
112
+ const asked = String(message?.params?.protocolVersion || "");
113
+ const version = KNOWN_VERSIONS.includes(asked) ? asked : PROTOCOL_VERSION;
114
+ return {
115
+ jsonrpc: "2.0",
116
+ id,
117
+ result: {
118
+ protocolVersion: version,
119
+ capabilities: { tools: {} },
120
+ serverInfo: SERVER_INFO,
121
+ },
122
+ };
123
+ }
124
+ if (method === "ping") {
125
+ return { jsonrpc: "2.0", id, result: {} };
126
+ }
127
+ if (method === "tools/list") {
128
+ return { jsonrpc: "2.0", id, result: { tools: loadBundledTools() } };
129
+ }
130
+ if (method === "tools/call") {
131
+ return {
132
+ jsonrpc: "2.0",
133
+ id,
134
+ result: {
135
+ isError: true,
136
+ content: [{ type: "text", text: MISSING_KEY }],
137
+ },
138
+ };
139
+ }
140
+ return {
141
+ jsonrpc: "2.0",
142
+ id,
143
+ error: { code: -32601, message: MISSING_KEY },
144
+ };
145
+ }
146
+
147
+ export async function runStdioProxy(env = process.env) {
148
+ const mcpUrl = resolveMcpUrl(env);
149
+ const auth = authorizationFromEnv(env);
150
+ let sessionId = null;
151
+ let sessionVersion = PROTOCOL_VERSION;
152
+
153
+ const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
154
+ const writeOut = (obj) => {
155
+ if (obj !== null && obj !== undefined) {
156
+ process.stdout.write(`${JSON.stringify(obj)}\n`);
157
+ }
158
+ };
159
+
160
+ for await (const line of rl) {
161
+ const trimmed = line.trim();
162
+ if (!trimmed) continue;
163
+ let message;
164
+ try {
165
+ message = JSON.parse(trimmed);
166
+ } catch {
167
+ writeOut({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } });
168
+ continue;
169
+ }
170
+
171
+ if (!auth) {
172
+ writeOut(handleOfflineMessage(message));
173
+ continue;
174
+ }
175
+
176
+ const method = String(message?.method || "");
177
+ const stateless = message?.params?._meta?.[VERSION_KEY];
178
+ const headers = {
179
+ Authorization: auth,
180
+ Accept: "application/json, text/event-stream",
181
+ "Content-Type": "application/json",
182
+ "X-SpecStream-Client": "npm-mcp",
183
+ };
184
+ if (typeof stateless === "string" && stateless) {
185
+ headers["MCP-Protocol-Version"] = stateless;
186
+ headers["Mcp-Method"] = method;
187
+ const field = NAMED_METHODS[method];
188
+ const targetName = field && message?.params?.[field];
189
+ if (typeof targetName === "string") {
190
+ headers["Mcp-Name"] = headerValue(targetName);
191
+ }
192
+ } else {
193
+ headers["MCP-Protocol-Version"] = sessionVersion;
194
+ if (sessionId) headers["MCP-Session-Id"] = sessionId;
195
+ }
196
+
197
+ try {
198
+ const response = await fetch(mcpUrl, {
199
+ method: "POST",
200
+ headers,
201
+ body: JSON.stringify(message),
202
+ redirect: "manual",
203
+ });
204
+ const sid = response.headers.get("mcp-session-id");
205
+ if (sid) sessionId = sid;
206
+ const raw = await response.text();
207
+ if (response.status === 202) {
208
+ if ("id" in message) {
209
+ writeOut({ jsonrpc: "2.0", id: message.id, error: { code: -32603, message: "Empty 202 response for request" } });
210
+ }
211
+ continue;
212
+ }
213
+ if (!response.ok) {
214
+ let parsedErr = null;
215
+ try {
216
+ parsedErr = JSON.parse(raw);
217
+ } catch {
218
+ parsedErr = null;
219
+ }
220
+ if (parsedErr && typeof parsedErr === "object" && "error" in parsedErr) {
221
+ writeOut({ ...parsedErr, id: message.id ?? parsedErr.id ?? null });
222
+ } else if ("id" in message) {
223
+ writeOut({ jsonrpc: "2.0", id: message.id, error: { code: -32603, message: `SpecStream MCP HTTP ${response.status}` } });
224
+ }
225
+ continue;
226
+ }
227
+ const ctype = (response.headers.get("content-type") || "").toLowerCase();
228
+ const payload = ctype.includes("text/event-stream") ? parseSseJson(raw, message.id) : JSON.parse(raw);
229
+ if (method === "initialize" && payload?.result?.protocolVersion) {
230
+ sessionVersion = String(payload.result.protocolVersion);
231
+ }
232
+ writeOut(payload);
233
+ } catch (err) {
234
+ if ("id" in message) {
235
+ writeOut({
236
+ jsonrpc: "2.0",
237
+ id: message.id,
238
+ error: { code: -32603, message: err instanceof Error ? err.message : "MCP proxy error" },
239
+ });
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+ const isMain = process.argv[1] && fileURLToPath(import.meta.url) === fs.realpathSync(process.argv[1]);
246
+ if (isMain) {
247
+ runStdioProxy().catch((err) => {
248
+ process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
249
+ process.exit(1);
250
+ });
251
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@specstream/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "SpecStream MCP server, the live web data engine: Search API, the most accurate web search API in the world, Extract API and Deep Search for any local MCP client, each result with its source. $2 free credit, no card.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "specstream-mcp": "./bin/specstream-mcp.mjs"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "tools.json",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "test": "node --test test/*.test.mjs"
17
+ },
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "homepage": "https://specstream.ai/docs/mcp",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/specstream/specstream-tools.git",
25
+ "directory": "packages/mcp"
26
+ },
27
+ "keywords": [
28
+ "mcp",
29
+ "model-context-protocol",
30
+ "specstream",
31
+ "web-search",
32
+ "extract",
33
+ "deep-search",
34
+ "ai-agents",
35
+ "live-web-data"
36
+ ]
37
+ }