Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ jobs:
grep -q "Ready" /tmp/mcpb-smoke.log
working-directory: examples/pdf-server

# import.meta.filename/dirname are undefined before Node 20.11; servers
# must still start on the oldest Node their package.json engines allows.
- uses: actions/setup-node@v6
if: runner.os == 'Linux' && matrix.name == 'Linux x64'
with:
node-version: "20.0.0"

- name: Smoke-test pdf-server starts on the oldest supported Node
if: runner.os == 'Linux' && matrix.name == 'Linux x64'
run: |
node --version
node .mcpb-smoke/dist/index.js --stdio < /dev/null 2>&1 | tee /tmp/mcpb-smoke-node20.log
grep -q "Ready" /tmp/mcpb-smoke-node20.log
working-directory: examples/pdf-server

dependency-isolation:
name: Dependency isolation
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ import {
import { McpServer } from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";

const DIST_DIR = path.join(import.meta.dirname, "dist");
const DIST_DIR = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"dist",
);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-server-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/basic-server-preact"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-server-preact/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
import { z } from "zod";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-server-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/basic-server-react"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"types": "dist/server.d.ts",
"bin": {
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-server-react/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";

// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-server-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/basic-server-solid"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-server-solid/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
import { z } from "zod";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-server-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/basic-server-svelte"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-server-svelte/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
import { z } from "zod";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-server-vanillajs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/basic-server-vanillajs"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-server-vanillajs/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-server-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/basic-server-vue"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-server-vue/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
import { z } from "zod";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

/**
* Creates a new MCP server instance with tools and resources registered.
Expand Down
3 changes: 3 additions & 0 deletions examples/budget-allocator-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/budget-allocator-server"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/budget-allocator-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
import {
RESOURCE_MIME_TYPE,
registerAppResource,
registerAppTool,
} from "@modelcontextprotocol/ext-apps/server";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

// ---------------------------------------------------------------------------
// Schemas - types are derived from these using z.infer
Expand Down
3 changes: 3 additions & 0 deletions examples/cohort-heatmap-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/cohort-heatmap-server"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/cohort-heatmap-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
import {
RESOURCE_MIME_TYPE,
registerAppResource,
registerAppTool,
} from "@modelcontextprotocol/ext-apps/server";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

// Schemas - types are derived from these using z.infer
const GetCohortDataInputSchema = z.object({
Expand Down
3 changes: 3 additions & 0 deletions examples/customer-segmentation-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/customer-segmentation-server"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
12 changes: 8 additions & 4 deletions examples/customer-segmentation-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
import {
RESOURCE_MIME_TYPE,
Expand All @@ -17,10 +18,13 @@ import {
} from "./src/data-generator.js";
import { SEGMENTS, type Customer, type SegmentSummary } from "./src/types.js";

// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

// Schemas - types are derived from these using z.infer
const GetCustomerDataInputSchema = z.object({
Expand Down
3 changes: 3 additions & 0 deletions examples/debug-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/debug-server"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"types": "dist/server.d.ts",
"bin": {
Expand Down
12 changes: 8 additions & 4 deletions examples/debug-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import {
import fs from "node:fs/promises";
import { appendFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";

// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);

// Track call counter across requests (stateful for demo purposes)
let callCounter = 0;
Expand Down
12 changes: 8 additions & 4 deletions examples/integration-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import {
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
? path.join(import.meta.dirname, "dist")
: import.meta.dirname;
// Works both from source (server.ts) and compiled (dist/server.js). Derived
// from import.meta.url rather than import.meta.filename/dirname, which are
// undefined on Node older than 20.11.
const SERVER_FILE = fileURLToPath(import.meta.url);
const DIST_DIR = SERVER_FILE.endsWith(".ts")
? path.join(path.dirname(SERVER_FILE), "dist")
: path.dirname(SERVER_FILE);
const RESOURCE_URI = "ui://get-time/mcp-app.html";
const SAMPLE_DOWNLOAD_URI = "resource:///sample-report.txt";

Expand Down
3 changes: 3 additions & 0 deletions examples/lazy-auth-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/lazy-auth-server"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
3 changes: 3 additions & 0 deletions examples/map-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"directory": "examples/map-server"
},
"license": "MIT",
"engines": {
"node": ">=20"
},
"main": "dist/server.js",
"files": [
"dist"
Expand Down
Loading
Loading