mlb-mcp 1.0.0 → 1.0.1

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
@@ -20,3 +20,22 @@ node dist/index.js
20
20
  ```
21
21
 
22
22
  Data comes from the official public MLB Stats API.
23
+
24
+ <!-- paywall -->
25
+ ## Premium tools
26
+
27
+ These tools need a license key:
28
+
29
+ * `player_search`
30
+ * `team_roster`
31
+
32
+ Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-mlb-mcp and set it in your MCP client config:
33
+
34
+ ```json
35
+ "env": { "MCP_LICENSE_KEY": "mcp_live_..." }
36
+ ```
37
+
38
+ The key is checked against MCP Marketplace, cached for 24 hours, and keeps
39
+ working offline once one check has succeeded. Every other tool on this server
40
+ stays free.
41
+ <!-- /paywall -->
package/dist/api.js CHANGED
@@ -62,3 +62,39 @@ export async function standings(args) {
62
62
  }
63
63
  return `MLB standings ${season}:` + lines.join("\n");
64
64
  }
65
+ export async function playerSearch(args) {
66
+ const name = (args.name ?? "").trim();
67
+ if (!name)
68
+ throw new MlbError("Provide a player name to look up, e.g. Ohtani");
69
+ const limit = Math.max(1, Math.min(args.limit ?? 8, 25));
70
+ const d = await get(`${BASE}/people/search?names=${encodeURIComponent(name)}&limit=${limit}`);
71
+ const people = (d?.people ?? []);
72
+ if (!people.length)
73
+ return `No MLB player matches "${name}".`;
74
+ return `MLB players matching "${name}" (${people.length} shown):\n` +
75
+ people
76
+ .map((p, i) => {
77
+ const primary = p.primaryPosition?.abbreviation;
78
+ return `${i + 1}. ${p.fullName ?? "?"} (id ${p.id ?? "?"})${primary ? ` | ${primary}` : " | position not reported"} | ${p.draftYear ? `draft ${p.draftYear}` : "undrafted"} | ${p.link ?? ""}`.trim();
79
+ })
80
+ .join("\n");
81
+ }
82
+ export async function teamRoster(args) {
83
+ const teamId = (args.team_id ?? "").trim();
84
+ if (!/^\d+$/.test(teamId))
85
+ throw new MlbError("Provide a numeric MLB team id, e.g. 133 for the Los Angeles Angels");
86
+ const rosterType = (args.roster_type ?? "active").trim() || "active";
87
+ const limit = Math.max(1, Math.min(args.limit ?? 15, 40));
88
+ const d = await get(`${BASE}/teams/${teamId}/roster?rosterType=${encodeURIComponent(rosterType)}`);
89
+ const rows = (d?.roster ?? []);
90
+ if (!rows.length)
91
+ return `MLB team ${teamId} has no ${rosterType} roster published.`;
92
+ const slice = rows.slice(0, limit);
93
+ return `Active roster of MLB team ${teamId} (${rosterType}, ${slice.length} of ${rows.length} shown):\n` +
94
+ slice
95
+ .map((r, i) => {
96
+ const p = r.person ?? {};
97
+ return `${i + 1}. ${p.fullName ?? "?"} | position ${p.primaryPosition?.abbreviation ?? "not reported"} | jersey ${p.jerseyNumber ?? "not reported"} | status ${r.status?.description ?? "not reported"}`;
98
+ })
99
+ .join("\n");
100
+ }
@@ -0,0 +1,79 @@
1
+ // Premium tools on this server need a license key bought from MCP Marketplace.
2
+ // Buyers put the key in their MCP client config as MCP_LICENSE_KEY. Every tool
3
+ // that is not listed in PREMIUM keeps working without a key.
4
+ const SLUG = "mlb-mcp";
5
+ // Tools that need a key. Everything else is free.
6
+ const PREMIUM = new Set([
7
+ "player_search",
8
+ "team_roster",
9
+ ]);
10
+ const BUY_URL = `https://mcp-marketplace.io/server/io-github-mrfentmen-${SLUG}`;
11
+ // The license check calls the marketplace's verify endpoint directly instead of
12
+ // using @mcp_marketplace/license. That SDK sends no `apikey` header, so every
13
+ // check it makes is rejected by Supabase before it reaches the function. The
14
+ // publishable key below is public by design - it ships in mcp-marketplace.io's
15
+ // own JavaScript and only ever reaches their licence check.
16
+ const DEFAULT_VERIFY_URL = "https://virupvwhtkpkjsiskckg.supabase.co/functions/v1/verify-key";
17
+ const PUBLISHABLE_KEY = "sb_publishable_BuqlW96Ke8C_zzJG-LQv1Q_YHi_r_4h";
18
+ const OK_CACHE_MS = 60 * 60 * 1000;
19
+ const BAD_CACHE_MS = 60 * 1000;
20
+ const seen = new Map();
21
+ const REASONS = {
22
+ missing_key: "no key is set",
23
+ invalid_format: "that key is not a valid MCP Marketplace key",
24
+ not_found: "that key was not found",
25
+ revoked: "that key has been revoked",
26
+ rotated: "that key was rotated, use your new one",
27
+ expired: "that key has expired, renew it",
28
+ rate_limited: "there were too many checks just now, try again shortly",
29
+ network_error: "the license server could not be reached",
30
+ };
31
+ function blocked(tool, reason) {
32
+ const why = REASONS[reason] ?? `the license server answered "${reason}"`;
33
+ return `"${tool}" needs a license key, but ${why}. ` +
34
+ `Set MCP_LICENSE_KEY in your MCP client config. Get a key: ${BUY_URL}`;
35
+ }
36
+ async function verify(key) {
37
+ const res = await fetch(process.env.MCP_LICENSE_VERIFY_URL || DEFAULT_VERIFY_URL, {
38
+ method: "POST",
39
+ headers: {
40
+ apikey: PUBLISHABLE_KEY,
41
+ Authorization: `Bearer ${PUBLISHABLE_KEY}`,
42
+ "Content-Type": "application/json",
43
+ },
44
+ body: JSON.stringify({ key, slug: SLUG }),
45
+ // an unusable key answers 400 with a JSON body, so read the body either way
46
+ signal: AbortSignal.timeout(15000),
47
+ });
48
+ const data = (await res.json());
49
+ if (typeof data?.valid !== "boolean")
50
+ return { valid: false, reason: "unexpected_response" };
51
+ return data;
52
+ }
53
+ /**
54
+ * Returns null when the caller may run the tool, or a short message telling
55
+ * them how to get a key.
56
+ *
57
+ * A good key is remembered for an hour, so a busy session does not hit the
58
+ * license server on every call and keeps working through a brief outage.
59
+ */
60
+ export async function premiumRequired(tool) {
61
+ if (!PREMIUM.has(tool))
62
+ return null;
63
+ const key = process.env.MCP_LICENSE_KEY;
64
+ if (!key)
65
+ return blocked(tool, "missing_key");
66
+ const hit = seen.get(key);
67
+ if (hit && Date.now() - hit.at < (hit.valid ? OK_CACHE_MS : BAD_CACHE_MS)) {
68
+ return hit.valid ? null : blocked(tool, hit.reason ?? "invalid");
69
+ }
70
+ let result;
71
+ try {
72
+ result = await verify(key);
73
+ }
74
+ catch {
75
+ result = { valid: false, reason: "network_error" };
76
+ }
77
+ seen.set(key, { ...result, at: Date.now() });
78
+ return result.valid ? null : blocked(tool, result.reason ?? "invalid");
79
+ }
package/dist/server.js CHANGED
@@ -2,7 +2,8 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { schedule } from "./api.js";
4
4
  import { standings } from "./api.js";
5
- import { teams } from "./api.js";
5
+ import { teams, playerSearch, teamRoster } from "./api.js";
6
+ import { premiumRequired } from "./license.js";
6
7
  const text = (value) => ({ content: [{ type: "text", text: value }] });
7
8
  const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
8
9
  const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
@@ -48,5 +49,41 @@ export function createServer() {
48
49
  return textError(error(e));
49
50
  }
50
51
  });
52
+ server.registerTool("player_search", {
53
+ title: "Player search",
54
+ description: "Find MLB players by name, with their MLB Stats API id, primary position, draft year and profile link.",
55
+ inputSchema: z.object({ name: z.string().describe("Player name, e.g. Ohtani."), limit: z.number().int().min(1).max(25).default(8) }),
56
+ annotations: READ_ONLY,
57
+ }, async (args) => {
58
+ // ---- paywall: player_search ----
59
+ const paywallMessage = await premiumRequired("player_search");
60
+ if (paywallMessage)
61
+ return { content: [{ type: "text", text: paywallMessage }], isError: true };
62
+ // ---- paywall: end ----
63
+ try {
64
+ return text(await playerSearch(args));
65
+ }
66
+ catch (e) {
67
+ return textError(error(e));
68
+ }
69
+ });
70
+ server.registerTool("team_roster", {
71
+ title: "Team roster",
72
+ description: "The active roster of one MLB team id, with each player's position, jersey number and status.",
73
+ inputSchema: z.object({ team_id: z.string().describe("Numeric MLB team id, e.g. 133 for the Los Angeles Angels."), roster_type: z.string().describe("active, 40Man, fullSeason, nonRosterInvitees or coach.").optional(), limit: z.number().int().min(1).max(40).default(15) }),
74
+ annotations: READ_ONLY,
75
+ }, async (args) => {
76
+ // ---- paywall: team_roster ----
77
+ const paywallMessage = await premiumRequired("team_roster");
78
+ if (paywallMessage)
79
+ return { content: [{ type: "text", text: paywallMessage }], isError: true };
80
+ // ---- paywall: end ----
81
+ try {
82
+ return text(await teamRoster(args));
83
+ }
84
+ catch (e) {
85
+ return textError(error(e));
86
+ }
87
+ });
51
88
  return server;
52
89
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0",
2
+ "version": "1.0.1",
3
3
  "type": "module",
4
4
  "repository": {
5
5
  "type": "git",