straitly-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.
Files changed (3) hide show
  1. package/README.md +13 -3
  2. package/index.js +263 -15
  3. package/package.json +22 -4
package/README.md CHANGED
@@ -2,14 +2,18 @@
2
2
 
3
3
  [![Straitly MCP server](https://glama.ai/mcp/servers/Straitly-ai/straitly-mcp/badges/score.svg)](https://glama.ai/mcp/servers/Straitly-ai/straitly-mcp)
4
4
 
5
- Official Model Context Protocol (MCP) server for [Straitly](https://straitly.ai) — one OpenAI-compatible API gateway for 150+ models (Claude, GPT, Gemini, Grok, DeepSeek, Kimi, Qwen).
5
+ Official Model Context Protocol (MCP) server for [Straitly](https://straitly.ai): one OpenAI-compatible API gateway for 100+ models (Claude, GPT, Gemini, Grok, DeepSeek, Kimi, Qwen).
6
6
 
7
7
  ## Tools
8
8
 
9
- - `list_models`: Search Straitly's live catalog of 150+ models by lab, name, or ID with context window and per-million-token pricing.
9
+ - `list_models`: Search Straitly's live catalog of 100+ models by lab, name, or ID with context window and per-million-token pricing.
10
10
  - `get_model`: Fetch live metadata, pricing, and documentation URL for a specific model.
11
+ - `model_prices`: The maker's list price and the Straitly price per 1M tokens for one or more models, read live from the [Straitly catalog](https://straitly.ai/api/catalog). Some models show only the maker price and a link to their Straitly page.
12
+ - `compare_models`: Compare 2 to 5 models side by side: live prices, benchmark rows from Straitly's LLM value index when it is published, and links to Straitly's [head-to-head comparison pages](https://straitly.ai/compare).
11
13
  - `chat_completion`: Run a completion against any model on `https://api.straitly.ai/v1` using your `STRAITLY_API_KEY`.
12
14
 
15
+ Example questions an agent can answer with no key: "What does Claude Opus cost per million tokens from the maker and on Straitly?", "Compare GPT Astra and Claude Opus."
16
+
13
17
  ## Setup (Claude Desktop, Cursor, Claude Code)
14
18
 
15
19
  ```json
@@ -28,7 +32,13 @@ Official Model Context Protocol (MCP) server for [Straitly](https://straitly.ai)
28
32
 
29
33
  Claude Code: `claude mcp add straitly -e STRAITLY_API_KEY=sk-... -- npx -y straitly-mcp`
30
34
 
31
- `list_models` and `get_model` work with no API key. `chat_completion` requires `STRAITLY_API_KEY` from [straitly.ai](https://straitly.ai).
35
+ Docker: `docker build -t straitly-mcp . && docker run -i --rm -e STRAITLY_API_KEY straitly-mcp`
36
+
37
+ `list_models`, `get_model`, `model_prices` and `compare_models` work with no API key. `chat_completion` requires `STRAITLY_API_KEY` from [straitly.ai](https://straitly.ai).
38
+
39
+ ## Development
40
+
41
+ `npm test` runs the server against a local mock of straitly.ai (Node 18+, no dependencies).
32
42
 
33
43
  ## Links
34
44
 
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // Straitly MCP server (stdio JSON-RPC 2.0, zero external dependencies).
3
- // Exposes live model catalog lookup, price comparison, and chat completions via https://api.straitly.ai/v1.
3
+ // Exposes live model catalog lookup, maker vs Straitly prices, model comparison, and chat completions
4
+ // via https://api.straitly.ai/v1.
4
5
 
5
6
  import readline from "node:readline";
6
7
 
@@ -9,15 +10,30 @@ process.stdout.on("error", (err) => {
9
10
  throw err;
10
11
  });
11
12
 
13
+ const VERSION = "0.2.0";
12
14
  const BASE_URL = process.env.STRAITLY_BASE_URL || "https://api.straitly.ai/v1";
13
- const CATALOG_URL = "https://straitly.ai/api/catalog";
14
- const SERVER_INFO = { name: "straitly-mcp", version: "0.1.0" };
15
+ const SITE_URL = (process.env.STRAITLY_SITE_URL || "https://straitly.ai").replace(/\/+$/, "");
16
+ const CATALOG_URL = `${SITE_URL}/api/catalog`;
17
+ const VALUE_INDEX_URL = `${SITE_URL}/llm-value-index.json`;
18
+ const SITEMAP_URL = `${SITE_URL}/sitemap.xml`;
19
+ // Public links in tool output always point at the real site, even when tests read a local mock.
20
+ const PUBLIC_SITE = "https://straitly.ai";
21
+ const SERVER_INFO = { name: "straitly-mcp", version: VERSION };
15
22
  const PROTOCOL_VERSION = "2024-11-05";
23
+ const UA = { "User-Agent": `straitly-mcp/${VERSION}` };
24
+
25
+ // Models whose Straitly rate is not published anywhere (mirrors straitly.ai's held list). For these the
26
+ // tools return the maker's price and a link to the model page, never a Straitly figure.
27
+ const HELD_IDS = new Set(["gemini-4-neon"]);
28
+
29
+ const slugOf = (id) => String(id || "").slice(String(id || "").lastIndexOf("/") + 1).toLowerCase();
30
+ const isHeld = (m) => HELD_IDS.has(slugOf(m?.id)) || HELD_IDS.has(slugOf(m?.key));
31
+ const modelUrl = (m) => `${PUBLIC_SITE}/models/${m.id}`;
16
32
 
17
33
  const TOOLS = [
18
34
  {
19
35
  name: "list_models",
20
- description: "Search Straitly's live catalog of 150+ LLM models by name, lab, or ID. Returns context length and per-million-token pricing.",
36
+ description: "Search Straitly's live catalog of 100+ LLM models by name, lab, or ID. Returns context length and per-million-token pricing.",
21
37
  inputSchema: {
22
38
  type: "object",
23
39
  properties: {
@@ -37,6 +53,40 @@ const TOOLS = [
37
53
  required: ["model"],
38
54
  },
39
55
  },
56
+ {
57
+ name: "model_prices",
58
+ description: "Free, no API key. Maker list price and Straitly price per 1M tokens for one or more models, read live from the Straitly catalog. Some models show only the maker price plus a link to their Straitly page.",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {
62
+ models: {
63
+ type: "array",
64
+ items: { type: "string" },
65
+ description: "Model IDs, slugs, or names (e.g. claude-opus-5-5, gpt-6-astra, deepseek). Each entry may match several models.",
66
+ maxItems: 20,
67
+ },
68
+ query: { type: "string", description: "Alternative to models: filter by ID, name, or lab (e.g. anthropic, gemini)." },
69
+ limit: { type: "integer", description: "Max rows to return (default 20, max 100).", minimum: 1, maximum: 100 },
70
+ },
71
+ },
72
+ },
73
+ {
74
+ name: "compare_models",
75
+ description: "Free, no API key. Compare 2 to 5 models side by side: live maker and Straitly prices, benchmark rows from Straitly's LLM value index when published, and links to Straitly's head-to-head comparison pages.",
76
+ inputSchema: {
77
+ type: "object",
78
+ properties: {
79
+ models: {
80
+ type: "array",
81
+ items: { type: "string" },
82
+ minItems: 2,
83
+ maxItems: 5,
84
+ description: "Model IDs or slugs to compare (e.g. [\"claude-opus-5-5\", \"gpt-6-astra\"]).",
85
+ },
86
+ },
87
+ required: ["models"],
88
+ },
89
+ },
40
90
  {
41
91
  name: "chat_completion",
42
92
  description: "Run a chat completion through Straitly (requires STRAITLY_API_KEY env var).",
@@ -54,14 +104,40 @@ const TOOLS = [
54
104
  ];
55
105
 
56
106
  async function fetchCatalog() {
57
- const res = await fetch(CATALOG_URL, { headers: { "User-Agent": "straitly-mcp/0.1.0" } });
107
+ const res = await fetch(CATALOG_URL, { headers: UA });
58
108
  if (!res.ok) throw new Error(`Catalog HTTP ${res.status}`);
59
109
  const data = await res.json();
60
110
  const models = Array.isArray(data?.models) ? data.models : [];
61
- return models.filter((m) => String(m?.id || "") !== "gemini-4-neon" && !String(m?.key || "").includes("gemini-4-neon"));
111
+ return { models: models.filter((m) => m && m.id), generatedAt: data?.meta?.generatedAt ?? null };
112
+ }
113
+
114
+ const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : null);
115
+
116
+ // The maker's own list price: the catalog's list field, else its official direct price.
117
+ function makerPrice(m) {
118
+ if (m.list && (num(m.list.input) !== null || num(m.list.output) !== null)) {
119
+ return { input: num(m.list.input), output: num(m.list.output), source: "maker list price (Straitly catalog)" };
120
+ }
121
+ const d = m.direct;
122
+ if (d?.basis === "official" && d.price && (num(d.price.input) !== null || num(d.price.output) !== null)) {
123
+ return {
124
+ input: num(d.price.input),
125
+ output: num(d.price.output),
126
+ cache_read: num(d.price.cacheRead),
127
+ source: `${d.provider || "maker"} official price (Straitly catalog)`,
128
+ };
129
+ }
130
+ return null;
131
+ }
132
+
133
+ function straitlyPrice(m) {
134
+ if (isHeld(m) || !m.price) return null;
135
+ return { input: num(m.price.input), output: num(m.price.output), cache_read: num(m.price.cacheRead) };
62
136
  }
63
137
 
64
138
  function formatModel(m) {
139
+ const held = isHeld(m);
140
+ const maker = makerPrice(m);
65
141
  return {
66
142
  key: m.key,
67
143
  id: m.id,
@@ -69,17 +145,122 @@ function formatModel(m) {
69
145
  author: m.author?.label || m.author?.slug || null,
70
146
  context: m.context ?? null,
71
147
  released: m.released ?? null,
72
- price_per_1m_usd: m.price ? { input: m.price.input ?? null, output: m.price.output ?? null } : null,
73
- list_per_1m_usd: m.list ? { input: m.list.input ?? null, output: m.list.output ?? null } : null,
74
- url: `https://straitly.ai/models/${m.id}`,
148
+ price_per_1m_usd: held ? null : m.price ? { input: num(m.price.input), output: num(m.price.output) } : null,
149
+ list_per_1m_usd: maker ? { input: maker.input, output: maker.output } : null,
150
+ ...(held ? { straitly_price: `See ${modelUrl(m)}` } : {}),
151
+ url: modelUrl(m),
75
152
  };
76
153
  }
77
154
 
155
+ function priceRow(m) {
156
+ const held = isHeld(m);
157
+ const maker = makerPrice(m);
158
+ const row = {
159
+ id: m.id,
160
+ key: m.key,
161
+ name: m.name,
162
+ lab: m.author?.label || m.author?.slug || null,
163
+ maker_price_per_1m_usd: maker ? { input: maker.input, output: maker.output, ...(maker.cache_read != null ? { cache_read: maker.cache_read } : {}) } : null,
164
+ maker_price_source: maker ? maker.source : "No maker list price in the Straitly catalog for this model",
165
+ straitly_price_per_1m_usd: straitlyPrice(m),
166
+ url: modelUrl(m),
167
+ };
168
+ if (held) row.straitly_price = `See ${modelUrl(m)}`;
169
+ return row;
170
+ }
171
+
172
+ const lc = (v) => String(v || "").toLowerCase();
173
+
174
+ // Exact ID, key, or slug match first; otherwise a substring match on ID, key, name, or lab.
175
+ function findModels(models, needle) {
176
+ const n = lc(needle).trim();
177
+ if (!n) return [];
178
+ const exact = models.filter((m) => lc(m.id) === n || lc(m.key) === n || slugOf(m.id) === n || slugOf(m.key) === n);
179
+ if (exact.length) return exact;
180
+ return models.filter((m) =>
181
+ [m.key, m.id, m.name, m.author?.label, m.author?.slug].filter(Boolean).some((v) => lc(v).includes(n)));
182
+ }
183
+
184
+ // Family name used in /compare/<a>-vs-<b> slugs: the ID's words without version tokens
185
+ // (claude-opus-5-5 -> claude-opus, gpt-6.2-astra -> gpt-astra, deepseek-v4-1-flash-1017 -> deepseek-flash).
186
+ function familySlug(m) {
187
+ return slugOf(m.id)
188
+ .split("-")
189
+ .filter((t) => t && !/\d/.test(t))
190
+ .join("-");
191
+ }
192
+
193
+ async function fetchText(url) {
194
+ try {
195
+ const res = await fetch(url, { headers: UA });
196
+ return { status: res.status, text: res.ok ? await res.text() : null };
197
+ } catch (err) {
198
+ return { status: 0, text: null, error: err?.message || String(err) };
199
+ }
200
+ }
201
+
202
+ async function comparePages(families) {
203
+ const { text } = await fetchText(SITEMAP_URL);
204
+ if (!text) return [];
205
+ const urls = [...new Set(text.match(/https?:\/\/[^<\s]*\/compare\/[^<\s]+-vs-[^<\s]+/g) || [])];
206
+ const want = new Set(families.filter(Boolean));
207
+ const out = [];
208
+ for (const u of urls) {
209
+ const slug = u.slice(u.lastIndexOf("/compare/") + 9).replace(/\/$/, "");
210
+ const [a, b] = slug.split("-vs-");
211
+ if (a && b && a !== b && want.has(a) && want.has(b)) {
212
+ out.push({ pair: [a, b], url: `${PUBLIC_SITE}/compare/${slug}` });
213
+ }
214
+ }
215
+ return out;
216
+ }
217
+
218
+ // Rows from /llm-value-index.json for the requested models, or null when it is not published.
219
+ async function valueIndexRows(models) {
220
+ const { status, text } = await fetchText(VALUE_INDEX_URL);
221
+ if (!text) return { status, rows: null };
222
+ let data;
223
+ try {
224
+ data = JSON.parse(text);
225
+ } catch {
226
+ return { status, rows: null };
227
+ }
228
+ const list = Array.isArray(data) ? data : data?.models || data?.rows || data?.data || [];
229
+ if (!Array.isArray(list)) return { status, rows: null };
230
+ const rows = [];
231
+ for (const m of models) {
232
+ const ids = new Set([lc(m.id), lc(m.key), slugOf(m.id)]);
233
+ const hit = list.find((r) => r && [r.id, r.key, r.model, r.slug, r.model_id].some((v) => v && (ids.has(lc(v)) || ids.has(slugOf(v)))));
234
+ if (!hit) continue;
235
+ const row = { ...hit };
236
+ // A held model's row keeps only its benchmark facts: anything priced or per-dollar is dropped.
237
+ if (isHeld(m)) {
238
+ for (const k of Object.keys(row)) {
239
+ if (/straitly|price|cost|usd|dollar|value|per_\$|rate/i.test(k)) delete row[k];
240
+ }
241
+ row.straitly_price = `See ${modelUrl(m)}`;
242
+ }
243
+ rows.push(row);
244
+ }
245
+ return { status, rows, meta: Array.isArray(data) ? null : { updated: data?.updated || data?.updatedAt || data?.generatedAt || null, source: data?.source || null } };
246
+ }
247
+
248
+ const json = (obj) => ({ content: [{ type: "text", text: JSON.stringify(obj, null, 2) }] });
249
+
250
+ function clampLimit(v) {
251
+ return Math.min(Math.max(Number(v) || 20, 1), 100);
252
+ }
253
+
254
+ function dedupe(models) {
255
+ const seen = new Set();
256
+ return models.filter((m) => (seen.has(m.id) ? false : (seen.add(m.id), true)));
257
+ }
258
+
78
259
  async function handleToolCall(name, args = {}) {
79
260
  if (name === "list_models") {
80
- const models = await fetchCatalog();
261
+ const { models } = await fetchCatalog();
81
262
  const q = String(args.query || "").trim().toLowerCase();
82
- const limit = Math.min(Math.max(Number(args.limit) || 20, 1), 100);
263
+ const limit = clampLimit(args.limit);
83
264
  const filtered = q
84
265
  ? models.filter((m) =>
85
266
  [m.key, m.id, m.name, m.author?.label, m.author?.slug]
@@ -93,18 +274,85 @@ async function handleToolCall(name, args = {}) {
93
274
 
94
275
  if (name === "get_model") {
95
276
  const needle = String(args.model || "").trim().toLowerCase();
96
- const models = await fetchCatalog();
97
- const found = models.find((m) => String(m.key || "").toLowerCase() === needle || String(m.id || "").toLowerCase() === needle);
277
+ const { models } = await fetchCatalog();
278
+ const found = models.find((m) => lc(m.key) === needle || lc(m.id) === needle || slugOf(m.id) === needle);
98
279
  if (!found) {
99
- return { isError: true, content: [{ type: "text", text: `Model not found: ${args.model}. Browse https://straitly.ai/models` }] };
280
+ return { isError: true, content: [{ type: "text", text: `Model not found: ${args.model}. Browse ${PUBLIC_SITE}/models` }] };
100
281
  }
101
282
  return { content: [{ type: "text", text: JSON.stringify(formatModel(found), null, 2) }] };
102
283
  }
103
284
 
285
+ if (name === "model_prices") {
286
+ const { models, generatedAt } = await fetchCatalog();
287
+ const limit = clampLimit(args.limit);
288
+ const wanted = Array.isArray(args.models) ? args.models.map(String).filter((s) => s.trim()).slice(0, 20) : [];
289
+ let matched;
290
+ const notFound = [];
291
+ if (wanted.length) {
292
+ matched = [];
293
+ for (const w of wanted) {
294
+ const hits = findModels(models, w);
295
+ if (hits.length) matched.push(...hits);
296
+ else notFound.push(w);
297
+ }
298
+ } else if (String(args.query || "").trim()) {
299
+ matched = findModels(models, args.query);
300
+ } else {
301
+ matched = [...models].sort((a, b) => lc(b.released).localeCompare(lc(a.released)));
302
+ }
303
+ matched = dedupe(matched);
304
+ return json({
305
+ source: `${PUBLIC_SITE}/api/catalog`,
306
+ catalog_generated_at: generatedAt,
307
+ unit: "USD per 1M tokens",
308
+ total_matched: matched.length,
309
+ models: matched.slice(0, limit).map(priceRow),
310
+ ...(notFound.length ? { not_found: notFound, browse: `${PUBLIC_SITE}/models` } : {}),
311
+ });
312
+ }
313
+
314
+ if (name === "compare_models") {
315
+ const wanted = Array.isArray(args.models) ? args.models.map(String).filter((s) => s.trim()) : [];
316
+ if (wanted.length < 2 || wanted.length > 5) {
317
+ return { isError: true, content: [{ type: "text", text: "compare_models needs 2 to 5 model IDs in `models`." }] };
318
+ }
319
+ const { models, generatedAt } = await fetchCatalog();
320
+ const resolved = [];
321
+ const notFound = [];
322
+ for (const w of wanted) {
323
+ const hits = findModels(models, w);
324
+ if (!hits.length) {
325
+ notFound.push(w);
326
+ continue;
327
+ }
328
+ // Prefer the newest match when a name is ambiguous ("opus" -> newest Opus).
329
+ resolved.push([...hits].sort((a, b) => lc(b.released).localeCompare(lc(a.released)))[0]);
330
+ }
331
+ const picked = dedupe(resolved);
332
+ if (picked.length < 2) {
333
+ return { isError: true, content: [{ type: "text", text: `Need at least 2 known models. Not found: ${notFound.join(", ") || "(duplicates)"}. Browse ${PUBLIC_SITE}/models` }] };
334
+ }
335
+ const [vi, pages] = await Promise.all([valueIndexRows(picked), comparePages(picked.map(familySlug))]);
336
+ return json({
337
+ prices: {
338
+ source: `${PUBLIC_SITE}/api/catalog`,
339
+ catalog_generated_at: generatedAt,
340
+ unit: "USD per 1M tokens",
341
+ models: picked.map(priceRow),
342
+ },
343
+ benchmarks: vi.rows
344
+ ? { source: `${PUBLIC_SITE}/llm-value-index`, data: `${PUBLIC_SITE}/llm-value-index.json`, ...(vi.meta || {}), rows: vi.rows }
345
+ : { available: false, note: "Benchmark index not published yet; see the comparison pages below." },
346
+ comparison_pages: pages,
347
+ all_comparisons: `${PUBLIC_SITE}/compare`,
348
+ ...(notFound.length ? { not_found: notFound } : {}),
349
+ });
350
+ }
351
+
104
352
  if (name === "chat_completion") {
105
353
  const apiKey = process.env.STRAITLY_API_KEY;
106
354
  if (!apiKey) {
107
- return { isError: true, content: [{ type: "text", text: "STRAITLY_API_KEY is not set. Create a key at https://straitly.ai" }] };
355
+ return { isError: true, content: [{ type: "text", text: `STRAITLY_API_KEY is not set. Create a key at ${PUBLIC_SITE}` }] };
108
356
  }
109
357
  const messages = [];
110
358
  if (args.system) messages.push({ role: "system", content: String(args.system) });
package/package.json CHANGED
@@ -1,22 +1,40 @@
1
1
  {
2
2
  "name": "straitly-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "mcpName": "io.github.Straitly-ai/straitly-mcp",
5
- "description": "MCP server for Straitly: search 150+ LLM models, check live API pricing, and run chat completions via one OpenAI-compatible key.",
5
+ "description": "MCP server for Straitly: search 100+ LLM models, compare maker and Straitly prices per model, and run chat completions via one OpenAI-compatible key.",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "straitly-mcp": "./index.js"
9
9
  },
10
10
  "main": "./index.js",
11
- "files": ["index.js", "README.md", "LICENSE"],
11
+ "files": [
12
+ "index.js",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
12
16
  "license": "MIT",
13
17
  "homepage": "https://straitly.ai",
14
18
  "repository": {
15
19
  "type": "git",
16
20
  "url": "https://github.com/Straitly-ai/straitly-mcp.git"
17
21
  },
18
- "keywords": ["mcp", "model-context-protocol", "straitly", "llm", "ai-gateway", "openai", "claude", "gemini"],
22
+ "keywords": [
23
+ "mcp",
24
+ "model-context-protocol",
25
+ "straitly",
26
+ "llm",
27
+ "ai-gateway",
28
+ "openai",
29
+ "claude",
30
+ "gemini",
31
+ "llm-pricing",
32
+ "model-comparison"
33
+ ],
19
34
  "engines": {
20
35
  "node": ">=18"
36
+ },
37
+ "scripts": {
38
+ "test": "node --test test/"
21
39
  }
22
40
  }