Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/cli_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: npm run build

- name: Explicitly pre-install test dependencies
run: npx -y @modelcontextprotocol/server-everything --help || true
run: npx -y @modelcontextprotocol/server-everything@2026.1.14 --help || true

- name: Run tests
run: npm test
Expand Down
5 changes: 3 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"scripts": {
"build": "tsc",
"postbuild": "node scripts/make-executable.js",
"test": "node scripts/cli-tests.js && node scripts/cli-tool-tests.js && node scripts/cli-header-tests.js",
"test": "node scripts/cli-tests.js && node scripts/cli-tool-tests.js && node scripts/cli-header-tests.js && node scripts/cli-metadata-tests.js",
"test:cli": "node scripts/cli-tests.js",
"test:cli-tools": "node scripts/cli-tool-tests.js",
"test:cli-headers": "node scripts/cli-header-tests.js"
"test:cli-headers": "node scripts/cli-header-tests.js",
"test:cli-metadata": "node scripts/cli-metadata-tests.js"
},
"devDependencies": {},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions cli/scripts/cli-metadata-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const BUILD_DIR = path.resolve(SCRIPTS_DIR, "../build");

// Define the test server command using npx
const TEST_CMD = "npx";
const TEST_ARGS = ["@modelcontextprotocol/server-everything"];
const TEST_ARGS = ["@modelcontextprotocol/server-everything@2026.1.14"];

// Create output directory for test results
const OUTPUT_DIR = path.join(SCRIPTS_DIR, "metadata-test-output");
Expand Down Expand Up @@ -335,7 +335,7 @@ async function runTests() {
"--method",
"resources/read",
"--uri",
"test://static/resource/1",
"demo://resource/static/document/architecture.md",
"--metadata",
"client=test-client",
);
Expand All @@ -349,7 +349,7 @@ async function runTests() {
"--method",
"prompts/get",
"--prompt-name",
"simple_prompt",
"simple-prompt",
"--metadata",
"client=test-client",
);
Expand Down Expand Up @@ -383,7 +383,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"add",
"get-sum",
"--tool-arg",
"a=10",
"b=20",
Expand Down Expand Up @@ -566,7 +566,7 @@ async function runTests() {
"--method",
"prompts/get",
"--prompt-name",
"simple_prompt",
"simple-prompt",
"--metadata",
"prompt_client=test-prompt-client",
);
Expand Down
35 changes: 16 additions & 19 deletions cli/scripts/cli-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ const PROJECT_ROOT = path.join(SCRIPTS_DIR, "../../");
const BUILD_DIR = path.resolve(SCRIPTS_DIR, "../build");

// Define the test server command using npx
const EVERYTHING_SERVER = "@modelcontextprotocol/server-everything@2026.1.14";
const TEST_CMD = "npx";
const TEST_ARGS = ["@modelcontextprotocol/server-everything"];
const TEST_ARGS = [EVERYTHING_SERVER];

// Create output directory for test results
const OUTPUT_DIR = path.join(SCRIPTS_DIR, "test-output");
Expand Down Expand Up @@ -163,7 +164,7 @@ fs.writeFileSync(
"test-stdio": {
type: "stdio",
command: "npx",
args: ["@modelcontextprotocol/server-everything"],
args: [EVERYTHING_SERVER],
env: {
TEST_ENV: "test-value",
},
Expand All @@ -184,7 +185,7 @@ fs.writeFileSync(
mcpServers: {
"test-legacy": {
command: "npx",
args: ["@modelcontextprotocol/server-everything"],
args: [EVERYTHING_SERVER],
env: {
LEGACY_ENV: "legacy-value",
},
Expand Down Expand Up @@ -543,7 +544,7 @@ async function runTests() {
"--method",
"resources/read",
"--uri",
"test://static/resource/1",
"demo://resource/static/document/architecture.md",
);

// Test 17: CLI mode with resource read but missing URI (should fail)
Expand All @@ -569,7 +570,7 @@ async function runTests() {
"--method",
"prompts/get",
"--prompt-name",
"simple_prompt",
"simple-prompt",
);

// Test 19: CLI mode with prompt get and args
Expand All @@ -581,10 +582,10 @@ async function runTests() {
"--method",
"prompts/get",
"--prompt-name",
"complex_prompt",
"args-prompt",
"--prompt-args",
"temperature=0.7",
"style=concise",
"city=New York",
"state=NY",
);

// Test 20: CLI mode with prompt get but missing prompt name (should fail)
Expand Down Expand Up @@ -734,7 +735,7 @@ async function runTests() {
mcpServers: {
"only-server": {
command: "npx",
args: ["@modelcontextprotocol/server-everything"],
args: [EVERYTHING_SERVER],
},
},
},
Expand All @@ -755,7 +756,7 @@ async function runTests() {
mcpServers: {
"default-server": {
command: "npx",
args: ["@modelcontextprotocol/server-everything"],
args: [EVERYTHING_SERVER],
},
"other-server": {
command: "node",
Expand All @@ -777,7 +778,7 @@ async function runTests() {
mcpServers: {
server1: {
command: "npx",
args: ["@modelcontextprotocol/server-everything"],
args: [EVERYTHING_SERVER],
},
server2: {
command: "node",
Expand Down Expand Up @@ -827,14 +828,10 @@ async function runTests() {
console.log(
`${colors.BLUE}Starting server-everything in streamableHttp mode.${colors.NC}`,
);
const httpServer = spawn(
"npx",
["@modelcontextprotocol/server-everything", "streamableHttp"],
{
detached: true,
stdio: "ignore",
},
);
const httpServer = spawn("npx", [EVERYTHING_SERVER, "streamableHttp"], {
detached: true,
stdio: "ignore",
});
runningServers.push(httpServer);

await new Promise((resolve) => setTimeout(resolve, 3000));
Expand Down
55 changes: 41 additions & 14 deletions cli/scripts/cli-tool-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const BUILD_DIR = path.resolve(SCRIPTS_DIR, "../build");

// Define the test server command using npx
const TEST_CMD = "npx";
const TEST_ARGS = ["@modelcontextprotocol/server-everything"];
const TEST_ARGS = ["@modelcontextprotocol/server-everything@2026.1.14"];

// Create output directory for test results
const OUTPUT_DIR = path.join(SCRIPTS_DIR, "tool-test-output");
Expand Down Expand Up @@ -137,7 +137,21 @@ async function runBasicTest(testName, ...args) {
clearTimeout(timeout);
outputStream.end();

// Check for JSON errors even if exit code is 0
let hasJsonError = false;
if (code === 0) {
try {
const jsonMatch = output.match(/\{[\s\S]*\}/);
if (jsonMatch) {
const parsed = JSON.parse(jsonMatch[0]);
hasJsonError = parsed.isError === true;
}
} catch (e) {
// Not valid JSON or parse failed, continue with original check
}
}

if (code === 0 && !hasJsonError) {
console.log(`${colors.GREEN}✓ Test passed: ${testName}${colors.NC}`);
console.log(`${colors.BLUE}First few lines of output:${colors.NC}`);
const firstFewLines = output
Expand Down Expand Up @@ -225,8 +239,22 @@ async function runErrorTest(testName, ...args) {
clearTimeout(timeout);
outputStream.end();

// For error tests, we expect a non-zero exit code
if (code !== 0) {
// For error tests, we expect a non-zero exit code OR JSON with isError: true
let hasJsonError = false;
if (code === 0) {
// Try to parse JSON and check for isError field
try {
const jsonMatch = output.match(/\{[\s\S]*\}/);
if (jsonMatch) {
const parsed = JSON.parse(jsonMatch[0]);
hasJsonError = parsed.isError === true;
}
} catch (e) {
// Not valid JSON or parse failed, continue with original check
}
}

if (code !== 0 || hasJsonError) {
console.log(
`${colors.GREEN}✓ Error test passed: ${testName}${colors.NC}`,
);
Expand Down Expand Up @@ -312,7 +340,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"add",
"get-sum",
"--tool-arg",
"a=42",
"b=58",
Expand All @@ -327,7 +355,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"add",
"get-sum",
"--tool-arg",
"a=19.99",
"b=20.01",
Expand All @@ -342,7 +370,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"annotatedMessage",
"get-annotated-message",
"--tool-arg",
"messageType=success",
"includeImage=true",
Expand All @@ -357,7 +385,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"annotatedMessage",
"get-annotated-message",
"--tool-arg",
"messageType=error",
"includeImage=false",
Expand Down Expand Up @@ -386,7 +414,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"add",
"get-sum",
"--tool-arg",
"a=42.5",
"b=57.5",
Expand Down Expand Up @@ -537,11 +565,10 @@ async function runTests() {
"--method",
"prompts/get",
"--prompt-name",
"complex_prompt",
"args-prompt",
"--prompt-args",
"temperature=0.7",
'style="concise"',
'options={"format":"json","max_tokens":100}',
"city=New York",
"state=NY",
);

// Test 25: Prompt with simple arguments
Expand All @@ -553,7 +580,7 @@ async function runTests() {
"--method",
"prompts/get",
"--prompt-name",
"simple_prompt",
"simple-prompt",
"--prompt-args",
"name=test",
"count=5",
Expand Down Expand Up @@ -586,7 +613,7 @@ async function runTests() {
"--method",
"tools/call",
"--tool-name",
"add",
"get-sum",
"--tool-arg",
"a=10",
"b=20",
Expand Down