Skip to content
Draft
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
51 changes: 50 additions & 1 deletion examples/servers/typescript/everything-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { toJsonSchemaCompat } from '@modelcontextprotocol/sdk/server/zod-json-sc
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import cors from 'cors';
import { randomUUID, createHmac } from 'crypto';
import { randomUUID, createHmac, createHash } from 'crypto';

// Server state
const resourceSubscriptions = new Set<string>();
Expand Down Expand Up @@ -1216,6 +1216,55 @@ function notifyListenStreams(
}
}

// SEP-2127 Server Card at the reserved location, <streamable-http-url>/server-card.
// Registered before the global CORS middleware: the card has its own CORS rules
// (ext-server-card discovery.md § CORS Requirements), and its values mirror what
// server/discover reports, so the card does not contradict the live server.
const SERVER_CARD_MEDIA_TYPE = 'application/mcp-server-card+json';
function serverCardBody(req: {
protocol: string;
get(name: string): string | undefined;
}): string {
const origin = `${req.protocol}://${req.get('host')}`;
return JSON.stringify({
$schema:
'https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json',
name: 'io.modelcontextprotocol/everything-server',
version: '1.0.0',
description: 'MCP conformance everything-server',
remotes: [
{
type: 'streamable-http',
url: `${origin}/mcp`,
supportedProtocolVersions: ['2026-07-28']
}
]
});
}
app.options('/mcp/server-card', (_req, res) => {
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type, If-None-Match'
});
res.sendStatus(204);
});
app.get('/mcp/server-card', (req, res) => {
const body = serverCardBody(req);
const etag = `"${createHash('sha256').update(body).digest('hex').slice(0, 32)}"`;
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Expose-Headers': 'ETag',
'Cache-Control': 'public, max-age=3600',
ETag: etag
});
if (req.get('if-none-match') === etag) {
res.status(304).end();
return;
}
res.type(SERVER_CARD_MEDIA_TYPE).send(body);
});

// Configure CORS to expose Mcp-Session-Id header for browser-based clients
app.use(
cors({
Expand Down
148 changes: 148 additions & 0 deletions examples/servers/typescript/sep-2127-server-card-fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env node

/**
* Fixture for the SEP-2127 Server Card scenario (sep-2127-server-card).
* Five MCP endpoints, each answering server/discover, each with a different card:
*
* - /good/mcp — a correct card, served correctly, that agrees with
* server/discover on every field the scenario compares.
* - /html/mcp — the card location answers 200 with an HTML page, no
* CORS and no Cache-Control (a catch-all page, not a card).
* Express still adds an ETag and answers If-None-Match.
* - /contradict/mcp — a valid card with the required CORS headers that
* contradicts server/discover: transport, protocol
* versions, version, reverse-DNS name, title, description.
* - /none/mcp — no card (404): the optional feature is not offered.
* - /auth/mcp — 401 at the card location: also not a hosted card.
*
* Run: PORT=3000 npx tsx sep-2127-server-card-fixture.ts
*/

import express from 'express';

const app = express();
app.use(express.json());

const SERVER_INFO = {
good: {
name: 'com.example/good-server',
version: '1.0.0',
title: 'Good Server',
description: 'A card that agrees with its server'
},
html: { name: 'sep-2127-html', version: '1.0.0' },
contradict: {
name: 'com.example/live-server',
version: '2.0.0',
title: 'Live Server',
description: 'What the server says about itself'
},
none: { name: 'sep-2127-none', version: '1.0.0' }
} as const;

for (const [prefix, serverInfo] of Object.entries(SERVER_INFO)) {
app.post(`/${prefix}/mcp`, (req, res) => {
const id = req.body?.id ?? null;
if (req.body?.method !== 'server/discover') {
res.status(404).json({
jsonrpc: '2.0',
id,
error: { code: -32601, message: 'Method not found' }
});
return;
}
res.json({
jsonrpc: '2.0',
id,
result: {
supportedVersions: ['2026-07-28'],
capabilities: {},
resultType: 'complete',
ttlMs: 0,
cacheScope: 'public',
_meta: { 'io.modelcontextprotocol/serverInfo': serverInfo }
}
});
});
}

/** Serve a card at /<prefix>/mcp/server-card with the CORS and caching headers the spec asks for. */
function serveCard(prefix: string, card: (origin: string) => object) {
const path = `/${prefix}/mcp/server-card`;
const etag = `"sep-2127-${prefix}"`;
app.options(path, (_req, res) => {
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type, If-None-Match'
});
res.sendStatus(204);
});
app.get(path, (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Expose-Headers': 'ETag',
'Cache-Control': 'public, max-age=3600',
ETag: etag
});
if (req.get('if-none-match') === etag) {
res.status(304).end();
return;
}
const origin = `${req.protocol}://${req.get('host')}`;
res
.type('application/mcp-server-card+json')
.send(JSON.stringify(card(origin)));
});
}

const SCHEMA =
'https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json';

// A card that agrees with server/discover.
serveCard('good', (origin) => ({
$schema: SCHEMA,
...SERVER_INFO.good,
remotes: [
{
type: 'streamable-http',
url: `${origin}/good/mcp`,
supportedProtocolVersions: ['2026-07-28']
}
]
}));

// A well-formed card, served correctly, that contradicts the live server.
serveCard('contradict', (origin) => ({
$schema: SCHEMA,
name: 'com.example/card-says-otherwise',
version: '1.0.0',
title: 'Card Title',
description: 'A card that contradicts its server',
remotes: [
{
type: 'sse',
url: `${origin}/contradict/mcp`,
supportedProtocolVersions: ['2025-03-26', '2026-07-28']
}
]
}));

// A catch-all web page at the card location: no card, no CORS, no Cache-Control.
app.get('/html/mcp/server-card', (_req, res) => {
res
.type('text/html')
.send('<!doctype html><title>Not a card</title><p>Welcome</p>');
});

// An auth challenge at the card location: not a hosted card, so the checks skip.
app.get('/auth/mcp/server-card', (_req, res) => {
res.status(401).set('WWW-Authenticate', 'Bearer').end();
});

const PORT = parseInt(process.env.PORT || '3000', 10);
app.listen(PORT, () => {
console.log(
`SEP-2127 server card fixture running on http://localhost:${PORT}`
);
});
12 changes: 11 additions & 1 deletion src/scenarios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
import { SkillsDirectoryReadScenario } from './server/skills/directory';
import { SkillsEnumerationScenario } from './server/skills/enumeration';
import { SkillsManifestScenario } from './server/skills/manifest';
import { ServerCardScenario } from './server/server-card';

import {
PromptsListScenario,
Expand Down Expand Up @@ -166,7 +167,12 @@ const pendingClientScenariosList: ClientScenario[] = [
// `npm start -- server --scenario sep-2640-skills-* --url <fixture>`.
new SkillsDirectoryReadScenario(),
new SkillsEnumerationScenario(),
new SkillsManifestScenario()
new SkillsManifestScenario(),

// SEP-2127 Server Card extension. Pending so a default run does not grade an
// optional extension; targeted runs use
// `npm start -- server --scenario sep-2127-server-card --url <server>`.
new ServerCardScenario()
];

// All client scenarios
Expand Down Expand Up @@ -224,6 +230,10 @@ const allClientScenariosList: ClientScenario[] = [
new SkillsEnumerationScenario(),
new SkillsManifestScenario(),

// Server Card extension (SEP-2127). Hosting a card is optional (MAY): the
// checks SKIP unless <url>/server-card answers 2xx.
new ServerCardScenario(),

// Prompts scenarios
new PromptsListScenario(),
new PromptsGetSimpleScenario(),
Expand Down
109 changes: 109 additions & 0 deletions src/scenarios/server/negative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from 'path';
import { DNSRebindingProtectionScenario } from './dns-rebinding';
import { ResourcesNotFoundErrorScenario } from './resources';
import { CachingScenario } from './caching';
import { ServerCardScenario } from './server-card';
import { ToolsListScenario } from './tools';
import {
JsonSchema2020_12Scenario,
Expand Down Expand Up @@ -519,4 +520,112 @@ describe('Server scenario negative tests', () => {
);
});
});

describe('sep-2127-server-card', () => {
let serverProcess: ChildProcess | null = null;
const PORT = 3010;
const base = `http://localhost:${PORT}`;
const statusOf = (checks: { id: string; status: string }[], id: string) =>
checks.find((c) => c.id === id)?.status;
const run = (url: string) =>
new ServerCardScenario().run(testContext(url, DRAFT_PROTOCOL_VERSION));

beforeAll(async () => {
serverProcess = await startServer(
path.join(
process.cwd(),
'examples/servers/typescript/sep-2127-server-card-fixture.ts'
),
PORT
);
}, 35000);

afterAll(async () => {
await stopServer(serverProcess);
});

it('passes every check against a correct card that agrees with server/discover', async () => {
const checks = await run(`${base}/good/mcp`);
expect(checks.length).toBe(17);
for (const c of checks)
expect([c.id, c.status]).toEqual([c.id, 'SUCCESS']);
expect(takeWireViolations().violations).toEqual([]);
}, 15000);

it('passes every check with a trailing slash on the server URL', async () => {
const checks = await run(`${base}/good/mcp/`);
expect(checks.length).toBe(17);
for (const c of checks)
expect([c.id, c.status]).toEqual([c.id, 'SUCCESS']);
takeWireViolations();
}, 15000);

it('fails an HTML page at the card location instead of skipping it', async () => {
const checks = await run(`${base}/html/mcp`);
expect(statusOf(checks, 'sep-2127-card-schema-valid')).toBe('FAILURE');
expect(statusOf(checks, 'sep-2127-card-media-type')).toBe('WARNING');
for (const id of [
'sep-2127-cors-allow-origin',
'sep-2127-cors-expose-headers',
'sep-2127-cors-preflight',
'sep-2127-cors-allow-methods',
'sep-2127-cors-allow-headers'
]) {
expect(statusOf(checks, id)).toBe('FAILURE');
}
expect(statusOf(checks, 'sep-2127-cache-control')).toBe('WARNING');
expect(checks.some((c) => c.status === 'SKIPPED')).toBe(false);
takeWireViolations();
}, 15000);

it('warns on every field where the card contradicts server/discover', async () => {
const checks = await run(`${base}/contradict/mcp`);
for (const id of [
'sep-2127-card-schema-valid',
'sep-2127-cors-allow-origin',
'sep-2127-cors-preflight',
'sep-2127-cors-allow-methods',
'sep-2127-cors-allow-headers',
'sep-2127-if-none-match'
]) {
expect(statusOf(checks, id)).toBe('SUCCESS');
}
for (const id of [
'sep-2127-consistent-transport',
'sep-2127-consistent-protocol-version',
'sep-2127-consistent-version',
'sep-2127-consistent-name',
'sep-2127-consistent-title',
'sep-2127-consistent-description'
]) {
expect(statusOf(checks, id)).toBe('WARNING');
}
// The fixture's server/discover is wire-valid: only the card is wrong.
expect(takeWireViolations().violations).toEqual([]);
}, 15000);

it('skips every check when no card is hosted (404 or 401)', async () => {
for (const p of ['none', 'auth']) {
const checks = await run(`${base}/${p}/mcp`);
expect(checks.length).toBe(17);
expect(checks.every((c) => c.status === 'SKIPPED')).toBe(true);
}
}, 15000);

it('fails, rather than throws, when nothing answers', async () => {
// A port the OS just handed out and we closed: nothing listens on it.
// `localhost` makes undici try ::1 and 127.0.0.1, whose AggregateError
// has an empty message; the check must still name the cause.
const probe = createServer();
await new Promise<void>((r) => probe.listen(0, r));
const freePort = (probe.address() as AddressInfo).port;
await new Promise<void>((r) => probe.close(() => r()));

const checks = await run(`http://localhost:${freePort}/mcp`);
expect(checks.length).toBe(17);
const schema = checks.find((c) => c.id === 'sep-2127-card-schema-valid');
expect(schema?.status).toBe('FAILURE');
expect(schema?.errorMessage).toMatch(/failed: \S/);
}, 15000);
});
});
1 change: 1 addition & 0 deletions src/scenarios/server/server-card/SOURCE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
modelcontextprotocol/ext-server-card@28db12c9b4a379489d46e49bf1bd4a991f05c9b7 schema.json
Loading