Skip to content

Commit 30a7d5e

Browse files
authored
Merge branch 'main' into parse-tool-arg
2 parents 55edb40 + 113b612 commit 30a7d5e

File tree

20 files changed

+869
-54
lines changed

20 files changed

+869
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ sdk
1515
client/playwright-report/
1616
client/results.json
1717
client/test-results/
18+
mcp.json

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ packages
22
server/build
33
CODE_OF_CONDUCT.md
44
SECURITY.md
5+
mcp.json

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,78 @@ Example server configuration file:
234234
}
235235
```
236236

237+
#### Transport Types in Config Files
238+
239+
The inspector automatically detects the transport type from your config file. You can specify different transport types:
240+
241+
**STDIO (default):**
242+
243+
```json
244+
{
245+
"mcpServers": {
246+
"my-stdio-server": {
247+
"type": "stdio",
248+
"command": "npx",
249+
"args": ["@modelcontextprotocol/server-everything"]
250+
}
251+
}
252+
}
253+
```
254+
255+
**SSE (Server-Sent Events):**
256+
257+
```json
258+
{
259+
"mcpServers": {
260+
"my-sse-server": {
261+
"type": "sse",
262+
"url": "http://localhost:3000/sse"
263+
}
264+
}
265+
}
266+
```
267+
268+
**Streamable HTTP:**
269+
270+
```json
271+
{
272+
"mcpServers": {
273+
"my-http-server": {
274+
"type": "streamable-http",
275+
"url": "http://localhost:3000/mcp"
276+
}
277+
}
278+
}
279+
```
280+
281+
#### Default Server Selection
282+
283+
You can launch the inspector without specifying a server name if your config has:
284+
285+
1. **A single server** - automatically selected:
286+
287+
```bash
288+
# Automatically uses "my-server" if it's the only one
289+
npx @modelcontextprotocol/inspector --config mcp.json
290+
```
291+
292+
2. **A server named "default-server"** - automatically selected:
293+
294+
```json
295+
{
296+
"mcpServers": {
297+
"default-server": {
298+
"command": "npx",
299+
"args": ["@modelcontextprotocol/server-everything"]
300+
},
301+
"other-server": {
302+
"command": "node",
303+
"args": ["other.js"]
304+
}
305+
}
306+
}
307+
```
308+
237309
> **Tip:** You can easily generate this configuration format using the **Server Entry** and **Servers File** buttons in the Inspector UI, as described in the Servers File Export section above.
238310
239311
You can also set the initial `transport` type, `serverUrl`, `serverCommand`, and `serverArgs` via query params, for example:

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/inspector-cli",
3-
"version": "0.16.2",
3+
"version": "0.16.3",
44
"description": "CLI for the Model Context Protocol inspector",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",

cli/scripts/cli-tests.js

Lines changed: 239 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,85 @@ try {
117117
const invalidConfigPath = path.join(TEMP_DIR, "invalid-config.json");
118118
fs.writeFileSync(invalidConfigPath, '{\n "mcpServers": {\n "invalid": {');
119119

120+
// Create config files with different transport types for testing
121+
const sseConfigPath = path.join(TEMP_DIR, "sse-config.json");
122+
fs.writeFileSync(
123+
sseConfigPath,
124+
JSON.stringify(
125+
{
126+
mcpServers: {
127+
"test-sse": {
128+
type: "sse",
129+
url: "http://localhost:3000/sse",
130+
note: "Test SSE server",
131+
},
132+
},
133+
},
134+
null,
135+
2,
136+
),
137+
);
138+
139+
const httpConfigPath = path.join(TEMP_DIR, "http-config.json");
140+
fs.writeFileSync(
141+
httpConfigPath,
142+
JSON.stringify(
143+
{
144+
mcpServers: {
145+
"test-http": {
146+
type: "streamable-http",
147+
url: "http://localhost:3000/mcp",
148+
note: "Test HTTP server",
149+
},
150+
},
151+
},
152+
null,
153+
2,
154+
),
155+
);
156+
157+
const stdioConfigPath = path.join(TEMP_DIR, "stdio-config.json");
158+
fs.writeFileSync(
159+
stdioConfigPath,
160+
JSON.stringify(
161+
{
162+
mcpServers: {
163+
"test-stdio": {
164+
type: "stdio",
165+
command: "npx",
166+
args: ["@modelcontextprotocol/server-everything"],
167+
env: {
168+
TEST_ENV: "test-value",
169+
},
170+
},
171+
},
172+
},
173+
null,
174+
2,
175+
),
176+
);
177+
178+
// Config without type field (backward compatibility)
179+
const legacyConfigPath = path.join(TEMP_DIR, "legacy-config.json");
180+
fs.writeFileSync(
181+
legacyConfigPath,
182+
JSON.stringify(
183+
{
184+
mcpServers: {
185+
"test-legacy": {
186+
command: "npx",
187+
args: ["@modelcontextprotocol/server-everything"],
188+
env: {
189+
LEGACY_ENV: "legacy-value",
190+
},
191+
},
192+
},
193+
},
194+
null,
195+
2,
196+
),
197+
);
198+
120199
// Function to run a basic test
121200
async function runBasicTest(testName, ...args) {
122201
const outputFile = path.join(
@@ -587,6 +666,160 @@ async function runTests() {
587666
"debug",
588667
);
589668

669+
console.log(
670+
`\n${colors.YELLOW}=== Running Config Transport Type Tests ===${colors.NC}`,
671+
);
672+
673+
// Test 25: Config with stdio transport type
674+
await runBasicTest(
675+
"config_stdio_type",
676+
"--config",
677+
stdioConfigPath,
678+
"--server",
679+
"test-stdio",
680+
"--cli",
681+
"--method",
682+
"tools/list",
683+
);
684+
685+
// Test 26: Config with SSE transport type (CLI mode) - expects connection error
686+
await runErrorTest(
687+
"config_sse_type_cli",
688+
"--config",
689+
sseConfigPath,
690+
"--server",
691+
"test-sse",
692+
"--cli",
693+
"--method",
694+
"tools/list",
695+
);
696+
697+
// Test 27: Config with streamable-http transport type (CLI mode) - expects connection error
698+
await runErrorTest(
699+
"config_http_type_cli",
700+
"--config",
701+
httpConfigPath,
702+
"--server",
703+
"test-http",
704+
"--cli",
705+
"--method",
706+
"tools/list",
707+
);
708+
709+
// Test 28: Legacy config without type field (backward compatibility)
710+
await runBasicTest(
711+
"config_legacy_no_type",
712+
"--config",
713+
legacyConfigPath,
714+
"--server",
715+
"test-legacy",
716+
"--cli",
717+
"--method",
718+
"tools/list",
719+
);
720+
721+
console.log(
722+
`\n${colors.YELLOW}=== Running Default Server Tests ===${colors.NC}`,
723+
);
724+
725+
// Create config with single server for auto-selection
726+
const singleServerConfigPath = path.join(
727+
TEMP_DIR,
728+
"single-server-config.json",
729+
);
730+
fs.writeFileSync(
731+
singleServerConfigPath,
732+
JSON.stringify(
733+
{
734+
mcpServers: {
735+
"only-server": {
736+
command: "npx",
737+
args: ["@modelcontextprotocol/server-everything"],
738+
},
739+
},
740+
},
741+
null,
742+
2,
743+
),
744+
);
745+
746+
// Create config with default-server
747+
const defaultServerConfigPath = path.join(
748+
TEMP_DIR,
749+
"default-server-config.json",
750+
);
751+
fs.writeFileSync(
752+
defaultServerConfigPath,
753+
JSON.stringify(
754+
{
755+
mcpServers: {
756+
"default-server": {
757+
command: "npx",
758+
args: ["@modelcontextprotocol/server-everything"],
759+
},
760+
"other-server": {
761+
command: "node",
762+
args: ["other.js"],
763+
},
764+
},
765+
},
766+
null,
767+
2,
768+
),
769+
);
770+
771+
// Create config with multiple servers (no default)
772+
const multiServerConfigPath = path.join(TEMP_DIR, "multi-server-config.json");
773+
fs.writeFileSync(
774+
multiServerConfigPath,
775+
JSON.stringify(
776+
{
777+
mcpServers: {
778+
server1: {
779+
command: "npx",
780+
args: ["@modelcontextprotocol/server-everything"],
781+
},
782+
server2: {
783+
command: "node",
784+
args: ["other.js"],
785+
},
786+
},
787+
},
788+
null,
789+
2,
790+
),
791+
);
792+
793+
// Test 29: Config with single server auto-selection
794+
await runBasicTest(
795+
"single_server_auto_select",
796+
"--config",
797+
singleServerConfigPath,
798+
"--cli",
799+
"--method",
800+
"tools/list",
801+
);
802+
803+
// Test 30: Config with default-server should now require explicit selection (multiple servers)
804+
await runErrorTest(
805+
"default_server_requires_explicit_selection",
806+
"--config",
807+
defaultServerConfigPath,
808+
"--cli",
809+
"--method",
810+
"tools/list",
811+
);
812+
813+
// Test 31: Config with multiple servers and no default (should fail)
814+
await runErrorTest(
815+
"multi_server_no_default",
816+
"--config",
817+
multiServerConfigPath,
818+
"--cli",
819+
"--method",
820+
"tools/list",
821+
);
822+
590823
console.log(
591824
`\n${colors.YELLOW}=== Running HTTP Transport Tests ===${colors.NC}`,
592825
);
@@ -606,7 +839,7 @@ async function runTests() {
606839

607840
await new Promise((resolve) => setTimeout(resolve, 3000));
608841

609-
// Test 25: HTTP transport inferred from URL ending with /mcp
842+
// Test 32: HTTP transport inferred from URL ending with /mcp
610843
await runBasicTest(
611844
"http_transport_inferred",
612845
"http://127.0.0.1:3001/mcp",
@@ -615,7 +848,7 @@ async function runTests() {
615848
"tools/list",
616849
);
617850

618-
// Test 26: HTTP transport with explicit --transport http flag
851+
// Test 33: HTTP transport with explicit --transport http flag
619852
await runBasicTest(
620853
"http_transport_with_explicit_flag",
621854
"http://127.0.0.1:3001/mcp",
@@ -626,7 +859,7 @@ async function runTests() {
626859
"tools/list",
627860
);
628861

629-
// Test 27: HTTP transport with suffix and --transport http flag
862+
// Test 34: HTTP transport with suffix and --transport http flag
630863
await runBasicTest(
631864
"http_transport_with_explicit_flag_and_suffix",
632865
"http://127.0.0.1:3001/mcp",
@@ -637,7 +870,7 @@ async function runTests() {
637870
"tools/list",
638871
);
639872

640-
// Test 28: SSE transport given to HTTP server (should fail)
873+
// Test 35: SSE transport given to HTTP server (should fail)
641874
await runErrorTest(
642875
"sse_transport_given_to_http_server",
643876
"http://127.0.0.1:3001",
@@ -648,7 +881,7 @@ async function runTests() {
648881
"tools/list",
649882
);
650883

651-
// Test 29: HTTP transport without URL (should fail)
884+
// Test 36: HTTP transport without URL (should fail)
652885
await runErrorTest(
653886
"http_transport_without_url",
654887
"--transport",
@@ -658,7 +891,7 @@ async function runTests() {
658891
"tools/list",
659892
);
660893

661-
// Test 30: SSE transport without URL (should fail)
894+
// Test 37: SSE transport without URL (should fail)
662895
await runErrorTest(
663896
"sse_transport_without_url",
664897
"--transport",

0 commit comments

Comments
 (0)