@olaservo/scryfall-mcp-server 1.0.2 → 2.1.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.
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ import { CitationList, SCRYFALL, WIZARDS } from "../citations.js";
3
+ import { fetchCard, fetchCardByName, fetchRulings, isScryfallError, } from "../scryfall-api.js";
4
+ const RulingsSchema = z.object({
5
+ id: z.uuid().optional().describe("Scryfall card UUID, from the search tool"),
6
+ name: z.string().min(1).optional().describe("Card name. Misspellings and partial words are allowed if they match one card."),
7
+ });
8
+ function errorResult(error) {
9
+ return {
10
+ content: [{ type: "text", text: JSON.stringify({ error: true, status: error.status, body: error.body }) }],
11
+ isError: true,
12
+ };
13
+ }
14
+ export const registerRulingsTool = (server) => {
15
+ server.registerTool("get_rulings", {
16
+ title: "Get Card Rulings",
17
+ description: "Get a Magic: The Gathering card's Oracle text and its rulings from Scryfall, by Scryfall UUID or by name. " +
18
+ "Each ruling says whether it came from Wizards of the Coast or from Scryfall, and when it was published. " +
19
+ "Carries citation markers to quote when answering a rules question about the card.",
20
+ inputSchema: RulingsSchema,
21
+ annotations: {
22
+ readOnlyHint: true,
23
+ destructiveHint: false,
24
+ idempotentHint: true,
25
+ openWorldHint: true,
26
+ },
27
+ }, async ({ id, name }, ctx) => {
28
+ if (!id && !name) {
29
+ return { content: [{ type: "text", text: "Give a card id or name." }], isError: true };
30
+ }
31
+ const card = id ? await fetchCard(id) : await fetchCardByName(name);
32
+ if (isScryfallError(card))
33
+ return errorResult(card);
34
+ const rulings = await fetchRulings(card.id);
35
+ if (isScryfallError(rulings))
36
+ return errorResult(rulings);
37
+ const page = new URL(card.scryfall_uri);
38
+ page.searchParams.delete("utm_source");
39
+ const url = page.href;
40
+ const list = new CitationList();
41
+ const faces = card.oracle_text !== undefined
42
+ ? [{ name: card.name, oracle_text: card.oracle_text }]
43
+ : (card.card_faces ?? []).map((f) => ({ name: f.name ?? card.name, oracle_text: f.oracle_text ?? "" }));
44
+ const oracle = faces.map((f) => `${f.name}\n${f.oracle_text} ` +
45
+ list.cite({ name: `${f.name} Oracle text`, url, text: f.oracle_text, author: WIZARDS, publisher: SCRYFALL }));
46
+ const lines = rulings.map((r) => {
47
+ const by = r.source === "wotc" ? WIZARDS : SCRYFALL;
48
+ const marker = list.cite({
49
+ name: `Ruling on ${card.name}, ${r.published_at}`,
50
+ url,
51
+ text: r.comment,
52
+ datePublished: r.published_at,
53
+ author: by,
54
+ publisher: SCRYFALL,
55
+ });
56
+ return `- ${r.published_at} (${by.name}): ${r.comment} ${marker}`;
57
+ });
58
+ const text = [
59
+ `Oracle text:\n${oracle.join("\n\n")}`,
60
+ rulings.length > 0 ? `Rulings (${rulings.length}):\n${lines.join("\n")}` : "No rulings.",
61
+ ].join("\n\n");
62
+ return list.result(server, ctx, text, {
63
+ name: card.name,
64
+ id: card.id,
65
+ oracle_id: card.oracle_id,
66
+ scryfall_uri: url,
67
+ oracle: faces,
68
+ rulings: rulings.map((r) => ({ source: r.source, published_at: r.published_at, comment: r.comment })),
69
+ });
70
+ });
71
+ };
@@ -1,2 +1,2 @@
1
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import { McpServer } from "@modelcontextprotocol/server";
2
2
  export declare const registerSearchTool: (server: McpServer) => void;
@@ -21,8 +21,7 @@ export const registerSearchTool = (server) => {
21
21
  idempotentHint: true,
22
22
  openWorldHint: true,
23
23
  },
24
- }, async (args) => {
25
- const { query } = SearchSchema.parse(args);
24
+ }, async ({ query }) => {
26
25
  const result = await searchCards(query);
27
26
  if (isScryfallError(result)) {
28
27
  return {
@@ -1,4 +1,4 @@
1
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
1
+ import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
2
2
  import { createServer } from "../server.js";
3
3
  const transport = new StdioServerTransport();
4
4
  const server = createServer();
@@ -1,8 +1,8 @@
1
1
  import express from "express";
2
2
  import cors from "cors";
3
3
  import { randomUUID } from "node:crypto";
4
- import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
5
- import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
4
+ import { isInitializeRequest } from "@modelcontextprotocol/server";
5
+ import { NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
6
6
  import { createServer } from "../server.js";
7
7
  const app = express();
8
8
  app.use(cors({ origin: "*", exposedHeaders: ["Mcp-Session-Id"] }));
@@ -15,7 +15,7 @@ app.post("/mcp", async (req, res) => {
15
15
  transport = transports[sessionId];
16
16
  }
17
17
  else if (!sessionId && isInitializeRequest(req.body)) {
18
- transport = new StreamableHTTPServerTransport({
18
+ transport = new NodeStreamableHTTPServerTransport({
19
19
  sessionIdGenerator: () => randomUUID(),
20
20
  onsessioninitialized: (id) => {
21
21
  transports[id] = transport;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Vendored MCP Apps (`ui`) server helpers.
3
+ *
4
+ * WHY THIS FILE EXISTS
5
+ * --------------------
6
+ * `@modelcontextprotocol/ext-apps` has no release that is compatible with the
7
+ * MCP TypeScript SDK v2: its `/server` entry point is typed against v1's
8
+ * `McpServer` and imports `@modelcontextprotocol/sdk/server/zod-compat.js`, a
9
+ * module that was removed in v2, and its peerDependency is
10
+ * `@modelcontextprotocol/sdk@^1.x`.
11
+ *
12
+ * The server half of this package is on SDK v2, so it cannot import
13
+ * `@modelcontextprotocol/ext-apps/server`. This module is a faithful port of the
14
+ * only two behaviours those helpers add on top of the plain SDK calls — `_meta`
15
+ * normalization for tools and a default MIME type for resources — retyped
16
+ * against the v2 SDK.
17
+ *
18
+ * The browser half (`src/ui/**`) still uses `@modelcontextprotocol/ext-apps` and
19
+ * SDK v1; it is compiled into a self-contained HTML bundle by a separate vite
20
+ * pass and only ever talks to this server over the MCP wire, so no object ever
21
+ * crosses the v1/v2 boundary in-process.
22
+ *
23
+ * DELETE THIS FILE and go back to `@modelcontextprotocol/ext-apps/server` once
24
+ * upstream ships a v2-compatible release.
25
+ *
26
+ * Ported verbatim from `@modelcontextprotocol/ext-apps` `dist/src/server/index.js`.
27
+ */
28
+ import type { ClientCapabilities, McpServer, ReadResourceCallback, RegisteredResource, RegisteredTool, ResourceMetadata, StandardSchemaWithJSON, ToolAnnotations, ToolCallback } from "@modelcontextprotocol/server";
29
+ /**
30
+ * Legacy `_meta` key hosts read to find a tool's UI resource.
31
+ *
32
+ * Deprecated upstream in favour of `_meta.ui.resourceUri`, but still written
33
+ * (and still read by older hosts), so both keys are always emitted.
34
+ */
35
+ export declare const RESOURCE_URI_META_KEY = "ui/resourceUri";
36
+ /** MIME type identifying an MCP Apps HTML resource. */
37
+ export declare const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
38
+ /** Extension identifier used for MCP Apps capability negotiation. */
39
+ export declare const EXTENSION_ID = "io.modelcontextprotocol/ui";
40
+ /** Who may call a UI-backed tool. */
41
+ export type McpUiToolVisibility = "model" | "app";
42
+ /** `_meta.ui` on a tool declaration. */
43
+ export interface McpUiToolMeta {
44
+ /** URI of the UI resource to display for this tool. */
45
+ resourceUri?: string;
46
+ /** Who can access this tool. Default: `["model", "app"]`. */
47
+ visibility?: McpUiToolVisibility[];
48
+ [key: string]: unknown;
49
+ }
50
+ /**
51
+ * `_meta` for a UI-backed tool. The UI resource may be given either as
52
+ * `_meta.ui.resourceUri` (preferred) or `_meta["ui/resourceUri"]` (legacy);
53
+ * {@link normalizeAppToolMeta} fills in whichever one is missing.
54
+ */
55
+ export type McpUiAppToolMeta = {
56
+ [key: string]: unknown;
57
+ } & ({
58
+ ui: McpUiToolMeta;
59
+ } | {
60
+ "ui/resourceUri"?: string;
61
+ });
62
+ /** Config accepted by {@link registerAppTool}, mirroring `McpServer.registerTool`. */
63
+ export interface McpUiAppToolConfig<InputArgs extends StandardSchemaWithJSON | undefined> {
64
+ title?: string;
65
+ description?: string;
66
+ inputSchema?: InputArgs;
67
+ outputSchema?: StandardSchemaWithJSON;
68
+ annotations?: ToolAnnotations;
69
+ _meta: McpUiAppToolMeta;
70
+ }
71
+ /**
72
+ * Normalize a UI tool's `_meta` so both the modern (`_meta.ui.resourceUri`) and
73
+ * the legacy (`_meta["ui/resourceUri"]`) keys are present.
74
+ *
75
+ * This is byte-for-byte the normalization ext-apps' `registerAppTool` applied.
76
+ * Hosts (including Claude) look at either key to find the UI resource, so the
77
+ * output must not drift.
78
+ */
79
+ export declare function normalizeAppToolMeta(meta: Record<string, unknown>): Record<string, unknown>;
80
+ /**
81
+ * `server.registerTool` plus the `_meta` normalization described in
82
+ * {@link normalizeAppToolMeta}. Nothing else.
83
+ */
84
+ export declare function registerAppTool<InputArgs extends StandardSchemaWithJSON | undefined = undefined>(server: Pick<McpServer, "registerTool">, name: string, config: McpUiAppToolConfig<InputArgs>, cb: ToolCallback<InputArgs>): RegisteredTool;
85
+ /**
86
+ * `server.registerResource` with the MCP Apps MIME type as a default. Nothing
87
+ * else — a caller-supplied `mimeType` still wins, because the default is spread
88
+ * first.
89
+ */
90
+ export declare function registerAppResource(server: Pick<McpServer, "registerResource">, name: string, uri: string, config: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource;
91
+ /**
92
+ * Read the MCP Apps capability out of the client's declared capabilities.
93
+ *
94
+ * `extensions` is not part of the SDK's `ClientCapabilities` yet (SEP-1724), so
95
+ * it is intersected in here, exactly as ext-apps did.
96
+ */
97
+ export declare function getUiCapability(clientCapabilities: (ClientCapabilities & {
98
+ extensions?: Record<string, unknown>;
99
+ }) | null | undefined): unknown;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Vendored MCP Apps (`ui`) server helpers.
3
+ *
4
+ * WHY THIS FILE EXISTS
5
+ * --------------------
6
+ * `@modelcontextprotocol/ext-apps` has no release that is compatible with the
7
+ * MCP TypeScript SDK v2: its `/server` entry point is typed against v1's
8
+ * `McpServer` and imports `@modelcontextprotocol/sdk/server/zod-compat.js`, a
9
+ * module that was removed in v2, and its peerDependency is
10
+ * `@modelcontextprotocol/sdk@^1.x`.
11
+ *
12
+ * The server half of this package is on SDK v2, so it cannot import
13
+ * `@modelcontextprotocol/ext-apps/server`. This module is a faithful port of the
14
+ * only two behaviours those helpers add on top of the plain SDK calls — `_meta`
15
+ * normalization for tools and a default MIME type for resources — retyped
16
+ * against the v2 SDK.
17
+ *
18
+ * The browser half (`src/ui/**`) still uses `@modelcontextprotocol/ext-apps` and
19
+ * SDK v1; it is compiled into a self-contained HTML bundle by a separate vite
20
+ * pass and only ever talks to this server over the MCP wire, so no object ever
21
+ * crosses the v1/v2 boundary in-process.
22
+ *
23
+ * DELETE THIS FILE and go back to `@modelcontextprotocol/ext-apps/server` once
24
+ * upstream ships a v2-compatible release.
25
+ *
26
+ * Ported verbatim from `@modelcontextprotocol/ext-apps` `dist/src/server/index.js`.
27
+ */
28
+ /**
29
+ * Legacy `_meta` key hosts read to find a tool's UI resource.
30
+ *
31
+ * Deprecated upstream in favour of `_meta.ui.resourceUri`, but still written
32
+ * (and still read by older hosts), so both keys are always emitted.
33
+ */
34
+ export const RESOURCE_URI_META_KEY = "ui/resourceUri";
35
+ /** MIME type identifying an MCP Apps HTML resource. */
36
+ export const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
37
+ /** Extension identifier used for MCP Apps capability negotiation. */
38
+ export const EXTENSION_ID = "io.modelcontextprotocol/ui";
39
+ /**
40
+ * Normalize a UI tool's `_meta` so both the modern (`_meta.ui.resourceUri`) and
41
+ * the legacy (`_meta["ui/resourceUri"]`) keys are present.
42
+ *
43
+ * This is byte-for-byte the normalization ext-apps' `registerAppTool` applied.
44
+ * Hosts (including Claude) look at either key to find the UI resource, so the
45
+ * output must not drift.
46
+ */
47
+ export function normalizeAppToolMeta(meta) {
48
+ const ui = meta.ui;
49
+ const legacy = meta[RESOURCE_URI_META_KEY];
50
+ if (ui?.resourceUri && !legacy) {
51
+ return { ...meta, [RESOURCE_URI_META_KEY]: ui.resourceUri };
52
+ }
53
+ if (legacy && !ui?.resourceUri) {
54
+ return { ...meta, ui: { ...ui, resourceUri: legacy } };
55
+ }
56
+ return meta;
57
+ }
58
+ /**
59
+ * `server.registerTool` plus the `_meta` normalization described in
60
+ * {@link normalizeAppToolMeta}. Nothing else.
61
+ */
62
+ export function registerAppTool(server, name, config, cb) {
63
+ return server.registerTool(name, { ...config, _meta: normalizeAppToolMeta(config._meta) }, cb);
64
+ }
65
+ /**
66
+ * `server.registerResource` with the MCP Apps MIME type as a default. Nothing
67
+ * else — a caller-supplied `mimeType` still wins, because the default is spread
68
+ * first.
69
+ */
70
+ export function registerAppResource(server, name, uri, config, readCallback) {
71
+ return server.registerResource(name, uri, { mimeType: RESOURCE_MIME_TYPE, ...config }, readCallback);
72
+ }
73
+ /**
74
+ * Read the MCP Apps capability out of the client's declared capabilities.
75
+ *
76
+ * `extensions` is not part of the SDK's `ClientCapabilities` yet (SEP-1724), so
77
+ * it is intersected in here, exactly as ext-apps did.
78
+ */
79
+ export function getUiCapability(clientCapabilities) {
80
+ if (!clientCapabilities)
81
+ return undefined;
82
+ return clientCapabilities.extensions?.[EXTENSION_ID];
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olaservo/scryfall-mcp-server",
3
- "version": "1.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Community MCP server to search and fetch Magic: The Gathering card data from Scryfall with a rich card viewer UI. Not affiliated with or endorsed by Scryfall.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,12 +27,14 @@
27
27
  },
28
28
  "homepage": "https://github.com/olaservo/scryfall-mcp-app#readme",
29
29
  "engines": {
30
- "node": ">=18.0.0"
30
+ "node": ">=24.0.0"
31
31
  },
32
32
  "scripts": {
33
33
  "build:ui": "cross-env INPUT=src/ui/card-viewer.html vite build",
34
34
  "build:server": "tsc",
35
35
  "build": "npm run build:ui && npm run build:server",
36
+ "typecheck": "tsc --noEmit",
37
+ "test": "tsx --test test/*.test.ts",
36
38
  "prepublishOnly": "npm run build",
37
39
  "start": "node dist/index.js",
38
40
  "start:http": "node dist/index.js streamableHttp",
@@ -42,16 +44,18 @@
42
44
  "pack": "npm run build && rm -rf node_modules && npm install --omit=dev --omit=optional && npx --yes @anthropic-ai/mcpb -- pack . scryfall-mcp-server.mcpb; npm install"
43
45
  },
44
46
  "dependencies": {
45
- "@modelcontextprotocol/ext-apps": "^1.1.0",
46
- "@modelcontextprotocol/sdk": "^1.24.3",
47
+ "@modelcontextprotocol/node": "^2.0.0",
48
+ "@modelcontextprotocol/server": "^2.0.0",
47
49
  "cors": "^2.8.6",
48
50
  "express": "^5.2.1",
49
- "zod": "^3.25.0"
51
+ "zod": "^4.2.0"
50
52
  },
51
53
  "devDependencies": {
54
+ "@modelcontextprotocol/ext-apps": "^1.7.5",
55
+ "@modelcontextprotocol/sdk": "^1.30.0",
52
56
  "@types/cors": "^2.8.19",
53
57
  "@types/express": "^5.0.6",
54
- "@types/node": "^22.10.0",
58
+ "@types/node": "^24.19.2",
55
59
  "cross-env": "^10.1.0",
56
60
  "tsx": "^4.19.2",
57
61
  "typescript": "^5.7.2",