Skip to content

Commit 62926b6

Browse files
authored
Merge branch 'main' into bump-version
2 parents b89b10b + 7b3e2c1 commit 62926b6

File tree

9 files changed

+524
-28
lines changed

9 files changed

+524
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ sdk
1414
client/playwright-report/
1515
client/results.json
1616
client/test-results/
17+
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/scripts/cli-tests.js

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

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

731+
console.log(
732+
`\n${colors.YELLOW}=== Running Config Transport Type Tests ===${colors.NC}`,
733+
);
734+
735+
// Test 25: Config with stdio transport type
736+
await runBasicTest(
737+
"config_stdio_type",
738+
"--config",
739+
stdioConfigPath,
740+
"--server",
741+
"test-stdio",
742+
"--cli",
743+
"--method",
744+
"tools/list",
745+
);
746+
747+
// Test 26: Config with SSE transport type (CLI mode) - expects connection error
748+
await runErrorTest(
749+
"config_sse_type_cli",
750+
"--config",
751+
sseConfigPath,
752+
"--server",
753+
"test-sse",
754+
"--cli",
755+
"--method",
756+
"tools/list",
757+
);
758+
759+
// Test 27: Config with streamable-http transport type (CLI mode) - expects connection error
760+
await runErrorTest(
761+
"config_http_type_cli",
762+
"--config",
763+
httpConfigPath,
764+
"--server",
765+
"test-http",
766+
"--cli",
767+
"--method",
768+
"tools/list",
769+
);
770+
771+
// Test 28: Legacy config without type field (backward compatibility)
772+
await runBasicTest(
773+
"config_legacy_no_type",
774+
"--config",
775+
legacyConfigPath,
776+
"--server",
777+
"test-legacy",
778+
"--cli",
779+
"--method",
780+
"tools/list",
781+
);
782+
783+
console.log(
784+
`\n${colors.YELLOW}=== Running Default Server Tests ===${colors.NC}`,
785+
);
786+
787+
// Create config with single server for auto-selection
788+
const singleServerConfigPath = path.join(
789+
TEMP_DIR,
790+
"single-server-config.json",
791+
);
792+
fs.writeFileSync(
793+
singleServerConfigPath,
794+
JSON.stringify(
795+
{
796+
mcpServers: {
797+
"only-server": {
798+
command: "npx",
799+
args: ["@modelcontextprotocol/server-everything"],
800+
},
801+
},
802+
},
803+
null,
804+
2,
805+
),
806+
);
807+
808+
// Create config with default-server
809+
const defaultServerConfigPath = path.join(
810+
TEMP_DIR,
811+
"default-server-config.json",
812+
);
813+
fs.writeFileSync(
814+
defaultServerConfigPath,
815+
JSON.stringify(
816+
{
817+
mcpServers: {
818+
"default-server": {
819+
command: "npx",
820+
args: ["@modelcontextprotocol/server-everything"],
821+
},
822+
"other-server": {
823+
command: "node",
824+
args: ["other.js"],
825+
},
826+
},
827+
},
828+
null,
829+
2,
830+
),
831+
);
832+
833+
// Create config with multiple servers (no default)
834+
const multiServerConfigPath = path.join(TEMP_DIR, "multi-server-config.json");
835+
fs.writeFileSync(
836+
multiServerConfigPath,
837+
JSON.stringify(
838+
{
839+
mcpServers: {
840+
server1: {
841+
command: "npx",
842+
args: ["@modelcontextprotocol/server-everything"],
843+
},
844+
server2: {
845+
command: "node",
846+
args: ["other.js"],
847+
},
848+
},
849+
},
850+
null,
851+
2,
852+
),
853+
);
854+
855+
// Test 29: Config with single server auto-selection
856+
await runBasicTest(
857+
"single_server_auto_select",
858+
"--config",
859+
singleServerConfigPath,
860+
"--cli",
861+
"--method",
862+
"tools/list",
863+
);
864+
865+
// Test 30: Config with default-server should now require explicit selection (multiple servers)
866+
await runErrorTest(
867+
"default_server_requires_explicit_selection",
868+
"--config",
869+
defaultServerConfigPath,
870+
"--cli",
871+
"--method",
872+
"tools/list",
873+
);
874+
875+
// Test 31: Config with multiple servers and no default (should fail)
876+
await runErrorTest(
877+
"multi_server_no_default",
878+
"--config",
879+
multiServerConfigPath,
880+
"--cli",
881+
"--method",
882+
"tools/list",
883+
);
884+
652885
console.log(
653886
`\n${colors.YELLOW}=== Running HTTP Transport Tests ===${colors.NC}`,
654887
);
@@ -668,7 +901,7 @@ async function runTests() {
668901

669902
await new Promise((resolve) => setTimeout(resolve, 3000));
670903

671-
// Test 25: HTTP transport inferred from URL ending with /mcp
904+
// Test 32: HTTP transport inferred from URL ending with /mcp
672905
await runBasicTest(
673906
"http_transport_inferred",
674907
"http://127.0.0.1:3001/mcp",
@@ -677,7 +910,7 @@ async function runTests() {
677910
"tools/list",
678911
);
679912

680-
// Test 26: HTTP transport with explicit --transport http flag
913+
// Test 33: HTTP transport with explicit --transport http flag
681914
await runBasicTest(
682915
"http_transport_with_explicit_flag",
683916
"http://127.0.0.1:3001/mcp",
@@ -688,7 +921,7 @@ async function runTests() {
688921
"tools/list",
689922
);
690923

691-
// Test 27: HTTP transport with suffix and --transport http flag
924+
// Test 34: HTTP transport with suffix and --transport http flag
692925
await runBasicTest(
693926
"http_transport_with_explicit_flag_and_suffix",
694927
"http://127.0.0.1:3001/mcp",
@@ -699,7 +932,7 @@ async function runTests() {
699932
"tools/list",
700933
);
701934

702-
// Test 28: SSE transport given to HTTP server (should fail)
935+
// Test 35: SSE transport given to HTTP server (should fail)
703936
await runErrorTest(
704937
"sse_transport_given_to_http_server",
705938
"http://127.0.0.1:3001",
@@ -710,7 +943,7 @@ async function runTests() {
710943
"tools/list",
711944
);
712945

713-
// Test 29: HTTP transport without URL (should fail)
946+
// Test 36: HTTP transport without URL (should fail)
714947
await runErrorTest(
715948
"http_transport_without_url",
716949
"--transport",
@@ -720,7 +953,7 @@ async function runTests() {
720953
"tools/list",
721954
);
722955

723-
// Test 30: SSE transport without URL (should fail)
956+
// Test 37: SSE transport without URL (should fail)
724957
await runErrorTest(
725958
"sse_transport_without_url",
726959
"--transport",

0 commit comments

Comments
 (0)