Compare commits
488 Commits
0.6.0
...
create_doc
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b754fb08e | |||
|
|
05e41d2ccc | ||
|
|
1e48310bcb | ||
|
|
d40140c2e8 | ||
|
|
faf3efc19b | ||
|
|
e3076ae05c | ||
|
|
5e8e78c31d | ||
|
|
8ca5a34d12 | ||
|
|
283371c313 | ||
|
|
5b54ce1281 | ||
|
|
ad39ec27e7 | ||
|
|
f2003b30c6 | ||
|
|
0014ca5e12 | ||
|
|
8a8deb6d39 | ||
|
|
8597100d54 | ||
|
|
89d721e56d | ||
|
|
0c15c54b99 | ||
|
|
a60764e649 | ||
|
|
eb3737d110 | ||
|
|
1067f4d22f | ||
|
|
24e8861a88 | ||
|
|
b09d0e1eb6 | ||
|
|
2731b5f7fa | ||
|
|
7083c7c9f2 | ||
|
|
6223839251 | ||
|
|
f5739971bb | ||
|
|
e33a6b806d | ||
|
|
fe9ab40994 | ||
|
|
8373795804 | ||
|
|
3473c8156d | ||
|
|
2915cccd85 | ||
|
|
3c5c38462b | ||
|
|
db3f7a3542 | ||
|
|
f7b936e102 | ||
|
|
3e41520688 | ||
|
|
2b963ce1ce | ||
|
|
af27fa2b8e | ||
|
|
549a4ec65a | ||
|
|
fef37483ba | ||
|
|
bf402e5eb4 | ||
|
|
a57e707a0b | ||
|
|
be7fa9baf9 | ||
|
|
73a8e2dee6 | ||
|
|
f05c27f6ab | ||
|
|
2609996ce6 | ||
|
|
b00b271d65 | ||
|
|
7a1fb0cfd9 | ||
|
|
63cb034943 | ||
|
|
60ffece84b | ||
|
|
42e6f0afe1 | ||
|
|
04e24916b1 | ||
|
|
c9d2f0761e | ||
|
|
f19b382e72 | ||
|
|
e8e2dd0618 | ||
|
|
9998298dfe | ||
|
|
5393f2e04c | ||
|
|
f9cbfbe822 | ||
|
|
b7ec3829d4 | ||
|
|
8b38d6b18f | ||
|
|
ae87292d7c | ||
|
|
163356f855 | ||
|
|
3b090d02e4 | ||
|
|
358f276b9b | ||
|
|
70016bf3b6 | ||
|
|
4d98b4a8bd | ||
|
|
5ad2c3c146 | ||
|
|
dd6f5287ca | ||
|
|
59cc89dbe9 | ||
|
|
79a09f8316 | ||
|
|
cfe82c81a1 | ||
|
|
82b3257028 | ||
|
|
45d135a426 | ||
|
|
fa458702ab | ||
|
|
173a45a200 | ||
|
|
745991b8ef | ||
|
|
42b0a77505 | ||
|
|
b3fc199d25 | ||
|
|
cdab12a8e5 | ||
|
|
966f95b5af | ||
|
|
2e4a52250a | ||
|
|
102fce5570 | ||
|
|
d1bff49deb | ||
|
|
5d0c3c48f6 | ||
|
|
7b9cd1e74d | ||
|
|
bf1026b6ec | ||
|
|
498e49e2d8 | ||
|
|
1dd99d651e | ||
|
|
1ec4e3b556 | ||
|
|
29b465fe45 | ||
|
|
6e4dcd6120 | ||
|
|
3a2e248527 | ||
|
|
e5f6524eb6 | ||
|
|
c843ac6e49 | ||
|
|
6ab7ac3e1a | ||
|
|
fa6fc62ecb | ||
|
|
b9c58252a1 | ||
|
|
114df8ac30 | ||
|
|
8213402185 | ||
|
|
36178632fc | ||
|
|
d82e06fe65 | ||
|
|
0e5a232967 | ||
|
|
bbe4924c88 | ||
|
|
d90940ab8f | ||
|
|
8ed2651ffd | ||
|
|
0f33c87ed4 | ||
|
|
2720d68417 | ||
|
|
b3971259d2 | ||
|
|
15fb99b644 | ||
|
|
958c9a36f1 | ||
|
|
92bf9abb40 | ||
|
|
bb7834543b | ||
|
|
d7dff30cdb | ||
|
|
2fb2f0fbaf | ||
|
|
214e5e4c25 | ||
|
|
d45d8c9125 | ||
|
|
7cad9a018c | ||
|
|
7c8f2926a0 | ||
|
|
3aa8753f7c | ||
|
|
014acecf77 | ||
|
|
d2dc959307 | ||
|
|
eba153847e | ||
|
|
1345a50011 | ||
|
|
15960f5aa4 | ||
|
|
0dc6df57d6 | ||
|
|
c8e9a772e4 | ||
|
|
cd28370f2c | ||
|
|
4adf4b1e51 | ||
|
|
880cb4a1de | ||
|
|
78cd701dc9 | ||
|
|
e31ee74842 | ||
|
|
9996be166f | ||
|
|
0b1c00baab | ||
|
|
8b0daef4ce | ||
|
|
49dddfb12b | ||
|
|
e878538d05 | ||
|
|
8901beb73e | ||
|
|
c65b5f8132 | ||
|
|
befa209935 | ||
|
|
8e8a5bb866 | ||
|
|
33309f351c | ||
|
|
d9100c8ed4 | ||
|
|
e4b4039e90 | ||
|
|
e798504867 | ||
|
|
6b57f7ce11 | ||
|
|
a4e6daae15 | ||
|
|
61614052e5 | ||
|
|
5696c19df9 | ||
|
|
fa7eba23b7 | ||
|
|
df0b526a41 | ||
|
|
0229aed948 | ||
|
|
a16a94537a | ||
|
|
9854409ece | ||
|
|
b19c78bc0a | ||
|
|
6a99feaf33 | ||
|
|
f7272d8d8c | ||
|
|
fd7dbba7a8 | ||
|
|
5fa76a7e02 | ||
|
|
fe02efd017 | ||
|
|
24418bc2cd | ||
|
|
22eb81350a | ||
|
|
0b37722ad1 | ||
|
|
485e703043 | ||
|
|
6420605d30 | ||
|
|
25cc0f69fd | ||
|
|
f1d5824a25 | ||
|
|
d332352968 | ||
|
|
d0622d3eb5 | ||
|
|
33aad8a271 | ||
|
|
352f5af7f8 | ||
|
|
3784816374 | ||
|
|
de233c9b30 | ||
|
|
dcef9dd068 | ||
|
|
204a90b1d1 | ||
|
|
8f7680d72b | ||
|
|
e20c4fb4ff | ||
|
|
5bcc1fd77b | ||
|
|
52564dd7c5 | ||
|
|
d2cb2338a0 | ||
|
|
a1fa0df0e6 | ||
|
|
f461f29f18 | ||
|
|
87fad79e7d | ||
|
|
cd1bcfb15f | ||
|
|
e4bfc058b2 | ||
|
|
bbff5c5883 | ||
|
|
8423776873 | ||
|
|
645a256994 | ||
|
|
1175af1074 | ||
|
|
c4cc4144d9 | ||
|
|
80854d9183 | ||
|
|
98ea4a12d6 | ||
|
|
2e8cc56744 | ||
|
|
3e95d9d42a | ||
|
|
a010f10c26 | ||
|
|
70dc1b766e | ||
|
|
d798d1a132 | ||
|
|
eab6b42ac6 | ||
|
|
53152e3fb1 | ||
|
|
4a2ba7ce6e | ||
|
|
aeac3ac914 | ||
|
|
a98db777c5 | ||
|
|
f43a9140ef | ||
|
|
638603c0f3 | ||
|
|
4f6c30904a | ||
|
|
a3a1ad47fa | ||
|
|
1596973b05 | ||
|
|
6c07559573 | ||
|
|
727e0753e4 | ||
|
|
aad3262940 | ||
|
|
7bc1088159 | ||
|
|
256972a366 | ||
|
|
a15df913fe | ||
|
|
068d43226f | ||
|
|
fe74dbea74 | ||
|
|
f6ed09e9fb | ||
|
|
4bc44c4d19 | ||
|
|
da4e2fa844 | ||
|
|
9c6663c4c2 | ||
|
|
cf20fe9142 | ||
|
|
6659d549ea | ||
|
|
48917ca4e5 | ||
|
|
779ca20568 | ||
|
|
f71613227f | ||
|
|
6a16e7cd24 | ||
|
|
3f9500f954 | ||
|
|
4053aa122d | ||
|
|
ad7865a6ab | ||
|
|
d69934afcb | ||
|
|
c5dc4ded5c | ||
|
|
4a3f032f59 | ||
|
|
6bcf1531c3 | ||
|
|
a506e4c419 | ||
|
|
a524f17d80 | ||
|
|
71bb89ddf2 | ||
|
|
ca1854b071 | ||
|
|
a3be8f6376 | ||
|
|
8d20044b33 | ||
|
|
eb9b2dd027 | ||
|
|
91633de80f | ||
|
|
6be05c5278 | ||
|
|
f36061e4b9 | ||
|
|
e35343537c | ||
|
|
402cde025b | ||
|
|
0fd2e12c7b | ||
|
|
b8ab30fdf3 | ||
|
|
3032a67d4e | ||
|
|
f0651baf4a | ||
|
|
3f73ec83a2 | ||
|
|
06f237b1de | ||
|
|
a8ffc704f0 | ||
|
|
bdab26dbeb | ||
|
|
0f075af42c | ||
|
|
06fcc74638 | ||
|
|
9092c780f7 | ||
|
|
a75dd7ba1f | ||
|
|
a414033354 | ||
|
|
ce1a9d3905 | ||
|
|
0bd51fa84a | ||
|
|
2a544294ba | ||
|
|
897e637db4 | ||
|
|
5db5fc26c7 | ||
|
|
8b31f495ba | ||
|
|
c964ff5cfe | ||
|
|
e69bfc58bc | ||
|
|
debb00344a | ||
|
|
c9ee22b781 | ||
|
|
cc70fbd0f5 | ||
|
|
8586d63e6d | ||
|
|
539de0fd85 | ||
|
|
f9cb2c1bd0 | ||
|
|
80f2986fd6 | ||
|
|
1504d1307e | ||
|
|
d1e155f984 | ||
|
|
c48670f426 | ||
|
|
e9a90b9caf | ||
|
|
affd207c9e | ||
|
|
4afe2d6adb | ||
|
|
e4d4ff0148 | ||
|
|
d127ee86ce | ||
|
|
f7d39fb252 | ||
|
|
8faadc0588 | ||
|
|
0dcd10c1dd | ||
|
|
65f38a4827 | ||
|
|
51f2f72677 | ||
|
|
d2db697d89 | ||
|
|
93c9c74dc9 | ||
|
|
dada1c4ba6 | ||
|
|
c3117d0fea | ||
|
|
992fdb33ed | ||
|
|
2a9230d507 | ||
|
|
51c7eda6a6 | ||
|
|
b82c744583 | ||
|
|
9ab213bc89 | ||
|
|
2ee0a53e36 | ||
|
|
fa7f9c80cd | ||
|
|
7dc2c6fb58 | ||
|
|
f49b2d1442 | ||
|
|
d1746f53a4 | ||
|
|
b99cf276ae | ||
|
|
6c67bf6d6d | ||
|
|
80f5ab1136 | ||
|
|
2f854304a7 | ||
|
|
6b63bacbcd | ||
|
|
fb29ca0113 | ||
|
|
83ceefca79 | ||
|
|
c3bd1fb1c6 | ||
|
|
45d8202de8 | ||
|
|
180760c4db | ||
|
|
538fc97289 | ||
|
|
04442b52a2 | ||
|
|
73d4cecdb1 | ||
|
|
952e13edc1 | ||
|
|
6eb6b3f82e | ||
|
|
7753b275e5 | ||
|
|
7ac1e40c9d | ||
|
|
d2696e48a5 | ||
|
|
3fc63017df | ||
|
|
cf86040df9 | ||
|
|
86a1adefd9 | ||
|
|
1832be2f84 | ||
|
|
7b055b6b9a | ||
|
|
da9dd09765 | ||
|
|
1dfe10bf42 | ||
|
|
65c589c193 | ||
|
|
5b22143c85 | ||
|
|
a63de622f8 | ||
|
|
539f32bf3b | ||
|
|
c6174116b0 | ||
|
|
65fc6d0490 | ||
|
|
834eb0c934 | ||
|
|
054741be03 | ||
|
|
eaa8055fd1 | ||
|
|
9e1186f5ac | ||
|
|
81c0ef29ab | ||
|
|
75537c7cae | ||
|
|
dbaa731097 | ||
|
|
dd0434c4ed | ||
|
|
ed31f9893f | ||
|
|
38fb710f2f | ||
|
|
240c67037c | ||
|
|
02155570df | ||
|
|
7227909df3 | ||
|
|
84335ae5f4 | ||
|
|
8486696240 | ||
|
|
6a6b15ab45 | ||
|
|
804a144ffb | ||
|
|
1d4ca435b8 | ||
|
|
1b754f52ca | ||
|
|
e47b1d8f4d | ||
|
|
d2e211a597 | ||
|
|
205e70736c | ||
|
|
827d867aae | ||
|
|
da0c855ef5 | ||
|
|
8180b0bd6f | ||
|
|
f09d2b6096 | ||
|
|
f846c154f5 | ||
|
|
9244ecf859 | ||
|
|
0891077402 | ||
|
|
353d6b549b | ||
|
|
18ca6e28a7 | ||
|
|
2d252a389c | ||
|
|
e6f5da8383 | ||
|
|
196fd67ce9 | ||
|
|
4d4bb9110c | ||
|
|
0d17082480 | ||
|
|
cdf1f1508a | ||
|
|
b97233f43a | ||
|
|
885932ac70 | ||
|
|
00118f7cf9 | ||
|
|
806cdb204f | ||
|
|
fcc06ab556 | ||
|
|
03c1ba3092 | ||
|
|
029823bb92 | ||
|
|
2588f3aeb3 | ||
|
|
88ffb5087e | ||
|
|
1f17132ca1 | ||
|
|
c031831e71 | ||
|
|
0e667acf7d | ||
|
|
8e9e5facaf | ||
|
|
16b38071e7 | ||
|
|
25f5bb7620 | ||
|
|
731cee8511 | ||
|
|
6efdcb626f | ||
|
|
0656e15a22 | ||
|
|
30e7a4d7b7 | ||
|
|
d204dd6e7e | ||
|
|
f2f209dbd3 | ||
|
|
f0b28d4760 | ||
|
|
65a0d46816 | ||
|
|
951db44bad | ||
|
|
379486b5ea | ||
|
|
40213bb1ed | ||
|
|
f8b7b88a25 | ||
|
|
b7fa23676a | ||
|
|
a7f25153c4 | ||
|
|
fa3e2867c9 | ||
|
|
5735f2347a | ||
|
|
cab1ed3dd8 | ||
|
|
61e229a552 | ||
|
|
451704471c | ||
|
|
668cc915e4 | ||
|
|
85f0e21679 | ||
|
|
fc76a7c7d4 | ||
|
|
210975e385 | ||
|
|
ec73831487 | ||
|
|
9b0da1f892 | ||
|
|
3ac00598ff | ||
|
|
484e2820bc | ||
|
|
2890e036ed | ||
|
|
008204fda5 | ||
|
|
af44efb236 | ||
|
|
51f3135c76 | ||
|
|
4a23585066 | ||
|
|
3488bdb613 | ||
|
|
043f6040c6 | ||
|
|
74d0fcf5a3 | ||
|
|
de8795106c | ||
|
|
c726c53b00 | ||
|
|
20db043b40 | ||
|
|
dcbd1dad41 | ||
|
|
dfc9cf7629 | ||
|
|
4fdbcee706 | ||
|
|
ce81fb976b | ||
|
|
029e482e05 | ||
|
|
27b54104c1 | ||
|
|
536b7e0a99 | ||
|
|
c463dc58c2 | ||
|
|
a85d5e7050 | ||
|
|
7ddba51b36 | ||
|
|
dd460bd877 | ||
|
|
50131c6960 | ||
|
|
28978ea24f | ||
|
|
cae7c76358 | ||
|
|
50a65d0c7a | ||
|
|
e1b015e40d | ||
|
|
7c4ed6abca | ||
|
|
a3740c4798 | ||
|
|
d8b5bdb613 | ||
|
|
5104952239 | ||
|
|
67722aea71 | ||
|
|
cedf02d152 | ||
|
|
f01f02d5be | ||
|
|
56932e8a93 | ||
|
|
aeaf32fa45 | ||
|
|
090b7efdea | ||
|
|
cda3905e5a | ||
|
|
fb667fd4d0 | ||
|
|
d70e6dc0e8 | ||
|
|
1f214deeab | ||
|
|
c77252900a | ||
|
|
498c02b0f1 | ||
|
|
60c4645eaf | ||
|
|
fe8b1ee88b | ||
|
|
04a90e8d89 | ||
|
|
e5ee00bf89 | ||
|
|
dae389034a | ||
|
|
397a0f651f | ||
|
|
f4e6f4d4ea | ||
|
|
9f42629b34 | ||
|
|
4c4c8a0884 | ||
|
|
1ff410ca3d | ||
|
|
b9b116a5f2 | ||
|
|
4efe7d7899 | ||
|
|
00836dbf9e | ||
|
|
dd02b69036 | ||
|
|
f9b105c0ef | ||
|
|
1ae77e9ef8 | ||
|
|
06773bb6dd | ||
|
|
b01e386659 | ||
|
|
e7f55f083f | ||
|
|
36aa7316ea | ||
|
|
0e50b68f96 | ||
|
|
a1eb343b79 | ||
|
|
82bbe58a46 | ||
|
|
44982e6c97 | ||
|
|
6ec82e21b1 | ||
|
|
abd4877dae | ||
|
|
d1f5b3b933 | ||
|
|
720480cbbb | ||
|
|
8ac7ef0985 | ||
|
|
238c22830b | ||
|
|
426fb87640 | ||
|
|
90ce628040 | ||
|
|
d4a64fb5d8 | ||
|
|
ede1ea0faa | ||
|
|
0747479694 | ||
|
|
0b105b29c1 | ||
|
|
0e29e2c1cf | ||
|
|
592dacad39 |
9
.github/workflows/main.yml
vendored
9
.github/workflows/main.yml
vendored
@@ -25,6 +25,15 @@ jobs:
|
|||||||
# Working around https://github.com/npm/cli/issues/4828
|
# Working around https://github.com/npm/cli/issues/4828
|
||||||
# - run: npm ci
|
# - run: npm ci
|
||||||
- run: npm install --no-package-lock
|
- run: npm install --no-package-lock
|
||||||
|
|
||||||
|
- name: Check linting
|
||||||
|
working-directory: ./client
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Run client tests
|
||||||
|
working-directory: ./client
|
||||||
|
run: npm test
|
||||||
|
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
|
|||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,6 +1,11 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules
|
.vscode
|
||||||
|
.idea
|
||||||
|
node_modules/
|
||||||
|
*-workspace/
|
||||||
server/build
|
server/build
|
||||||
client/dist
|
client/dist
|
||||||
client/tsconfig.app.tsbuildinfo
|
client/tsconfig.app.tsbuildinfo
|
||||||
client/tsconfig.node.tsbuildinfo
|
client/tsconfig.node.tsbuildinfo
|
||||||
|
cli/build
|
||||||
|
test-output
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ Thanks for your interest in contributing! This guide explains how to get involve
|
|||||||
1. Fork the repository and clone it locally
|
1. Fork the repository and clone it locally
|
||||||
2. Install dependencies with `npm install`
|
2. Install dependencies with `npm install`
|
||||||
3. Run `npm run dev` to start both client and server in development mode
|
3. Run `npm run dev` to start both client and server in development mode
|
||||||
4. Use the web UI at http://localhost:5173 to interact with the inspector
|
4. Use the web UI at http://127.0.0.1:6274 to interact with the inspector
|
||||||
|
|
||||||
## Development Process & Pull Requests
|
## Development Process & Pull Requests
|
||||||
|
|
||||||
1. Create a new branch for your changes
|
1. Create a new branch for your changes
|
||||||
2. Make your changes following existing code style and conventions
|
2. Make your changes following existing code style and conventions. You can run `npm run prettier-check` and `npm run prettier-fix` as applicable.
|
||||||
3. Test changes locally
|
3. Test changes locally by running `npm test`
|
||||||
4. Update documentation as needed
|
4. Update documentation as needed
|
||||||
5. Use clear commit messages explaining your changes
|
5. Use clear commit messages explaining your changes
|
||||||
6. Verify all changes work as expected
|
6. Verify all changes work as expected
|
||||||
|
|||||||
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN npm ci --ignore-scripts && \
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=builder /app/client/bin ./client/bin
|
||||||
|
COPY --from=builder /app/client/dist ./client/dist
|
||||||
|
COPY --from=builder /app/server/build ./server/build
|
||||||
|
COPY --from=builder /app/cli/build ./cli/build
|
||||||
|
COPY --from=builder /app/package*.json ./
|
||||||
|
COPY --from=builder /app/sample-config.json ./
|
||||||
|
|
||||||
|
RUN npm ci --omit=dev --ignore-scripts
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["node", "client/bin/start.js"]
|
||||||
203
README.md
203
README.md
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
The MCP inspector is a developer tool for testing and debugging MCP servers.
|
The MCP inspector is a developer tool for testing and debugging MCP servers.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Running the Inspector
|
## Running the Inspector
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
- Node.js: ^22.7.5
|
||||||
|
|
||||||
### From an MCP server repository
|
### From an MCP server repository
|
||||||
|
|
||||||
To inspect an MCP server implementation, there's no need to clone this repo. Instead, use `npx`. For example, if your server is built at `build/index.js`:
|
To inspect an MCP server implementation, there's no need to clone this repo. Instead, use `npx`. For example, if your server is built at `build/index.js`:
|
||||||
@@ -18,19 +22,19 @@ You can pass both arguments and environment variables to your MCP server. Argume
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Pass arguments only
|
# Pass arguments only
|
||||||
npx @modelcontextprotocol/inspector build/index.js arg1 arg2
|
npx @modelcontextprotocol/inspector node build/index.js arg1 arg2
|
||||||
|
|
||||||
# Pass environment variables only
|
# Pass environment variables only
|
||||||
npx @modelcontextprotocol/inspector -e KEY=value -e KEY2=$VALUE2 node build/index.js
|
npx @modelcontextprotocol/inspector -e key=value -e key2=$VALUE2 node build/index.js
|
||||||
|
|
||||||
# Pass both environment variables and arguments
|
# Pass both environment variables and arguments
|
||||||
npx @modelcontextprotocol/inspector -e KEY=value -e KEY2=$VALUE2 node build/index.js arg1 arg2
|
npx @modelcontextprotocol/inspector -e key=value -e key2=$VALUE2 node build/index.js arg1 arg2
|
||||||
|
|
||||||
# Use -- to separate inspector flags from server arguments
|
# Use -- to separate inspector flags from server arguments
|
||||||
npx @modelcontextprotocol/inspector -e KEY=$VALUE -- node build/index.js -e server-flag
|
npx @modelcontextprotocol/inspector -e key=$VALUE -- node build/index.js -e server-flag
|
||||||
```
|
```
|
||||||
|
|
||||||
The inspector runs both a client UI (default port 5173) and an MCP proxy server (default port 3000). Open the client UI in your browser to use the inspector. You can customize the ports if needed:
|
The inspector runs both an MCP Inspector (MCPI) client UI (default port 6274) and an MCP Proxy (MCPP) server (default port 6277). Open the MCPI client UI in your browser to use the inspector. (These ports are derived from the T9 dialpad mapping of MCPI and MCPP respectively, as a mnemonic). You can customize the ports if needed:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node build/index.js
|
CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node build/index.js
|
||||||
@@ -38,9 +42,143 @@ CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node build
|
|||||||
|
|
||||||
For more details on ways to use the inspector, see the [Inspector section of the MCP docs site](https://modelcontextprotocol.io/docs/tools/inspector). For help with debugging, see the [Debugging guide](https://modelcontextprotocol.io/docs/tools/debugging).
|
For more details on ways to use the inspector, see the [Inspector section of the MCP docs site](https://modelcontextprotocol.io/docs/tools/inspector). For help with debugging, see the [Debugging guide](https://modelcontextprotocol.io/docs/tools/debugging).
|
||||||
|
|
||||||
|
### Servers File Export
|
||||||
|
|
||||||
|
The MCP Inspector provides convenient buttons to export server launch configurations for use in clients such as Cursor, Claude Code, or the Inspector's CLI. The file is usually called `mcp.json`.
|
||||||
|
|
||||||
|
- **Server Entry** - Copies a single server configuration entry to your clipboard. This can be added to your `mcp.json` file inside the `mcpServers` object with your preferred server name.
|
||||||
|
|
||||||
|
**STDIO transport example:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"command": "node",
|
||||||
|
"args": ["build/index.js", "--debug"],
|
||||||
|
"env": {
|
||||||
|
"API_KEY": "your-api-key",
|
||||||
|
"DEBUG": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**SSE transport example:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "sse",
|
||||||
|
"url": "http://localhost:3000/events",
|
||||||
|
"note": "For SSE connections, add this URL directly in Client"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Servers File** - Copies a complete MCP configuration file structure to your clipboard, with your current server configuration added as `default-server`. This can be saved directly as `mcp.json`.
|
||||||
|
|
||||||
|
**STDIO transport example:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"default-server": {
|
||||||
|
"command": "node",
|
||||||
|
"args": ["build/index.js", "--debug"],
|
||||||
|
"env": {
|
||||||
|
"API_KEY": "your-api-key",
|
||||||
|
"DEBUG": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**SSE transport example:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"default-server": {
|
||||||
|
"type": "sse",
|
||||||
|
"url": "http://localhost:3000/events",
|
||||||
|
"note": "For SSE connections, add this URL directly in Client"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
These buttons appear in the Inspector UI after you've configured your server settings, making it easy to save and reuse your configurations.
|
||||||
|
|
||||||
|
For SSE transport connections, the Inspector provides similar functionality for both buttons. The "Server Entry" button copies the SSE URL configuration that can be added to your existing configuration file, while the "Servers File" button creates a complete configuration file containing the SSE URL for direct use in clients.
|
||||||
|
|
||||||
|
You can paste the Server Entry into your existing `mcp.json` file under your chosen server name, or use the complete Servers File payload to create a new configuration file.
|
||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
The inspector supports bearer token authentication for SSE connections. Enter your token in the UI when connecting to an MCP server, and it will be sent in the Authorization header.
|
The inspector supports bearer token authentication for SSE connections. Enter your token in the UI when connecting to an MCP server, and it will be sent in the Authorization header. You can override the header name using the input field in the sidebar.
|
||||||
|
|
||||||
|
### Security Considerations
|
||||||
|
|
||||||
|
The MCP Inspector includes a proxy server that can run and communicate with local MCP processes. The proxy server should not be exposed to untrusted networks as it has permissions to spawn local processes and can connect to any specified MCP server.
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
The MCP Inspector supports the following configuration settings. To change them, click on the `Configuration` button in the MCP Inspector UI:
|
||||||
|
|
||||||
|
| Setting | Description | Default |
|
||||||
|
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------- |
|
||||||
|
| `MCP_SERVER_REQUEST_TIMEOUT` | Timeout for requests to the MCP server (ms) | 10000 |
|
||||||
|
| `MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS` | Reset timeout on progress notifications | true |
|
||||||
|
| `MCP_REQUEST_MAX_TOTAL_TIMEOUT` | Maximum total timeout for requests sent to the MCP server (ms) (Use with progress notifications) | 60000 |
|
||||||
|
| `MCP_PROXY_FULL_ADDRESS` | Set this if you are running the MCP Inspector Proxy on a non-default address. Example: http://10.1.1.22:5577 | "" |
|
||||||
|
| `MCP_AUTO_OPEN_ENABLED` | Enable automatic browser opening when inspector starts. Only as environment var, not configurable in browser. | true |
|
||||||
|
|
||||||
|
These settings can be adjusted in real-time through the UI and will persist across sessions.
|
||||||
|
|
||||||
|
The inspector also supports configuration files to store settings for different MCP servers. This is useful when working with multiple servers or complex configurations:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx @modelcontextprotocol/inspector --config path/to/config.json --server everything
|
||||||
|
```
|
||||||
|
|
||||||
|
Example server configuration file:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"everything": {
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["@modelcontextprotocol/server-everything"],
|
||||||
|
"env": {
|
||||||
|
"hello": "Hello MCP!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"my-server": {
|
||||||
|
"command": "node",
|
||||||
|
"args": ["build/index.js", "arg1", "arg2"],
|
||||||
|
"env": {
|
||||||
|
"key": "value",
|
||||||
|
"key2": "value2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> **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.
|
||||||
|
|
||||||
|
You can also set the initial `transport` type, `serverUrl`, `serverCommand`, and `serverArgs` via query params, for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:6274/?transport=sse&serverUrl=http://localhost:8787/sse
|
||||||
|
http://localhost:6274/?transport=streamable-http&serverUrl=http://localhost:8787/mcp
|
||||||
|
http://localhost:6274/?transport=stdio&serverCommand=npx&serverArgs=arg1%20arg2
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also set initial config settings via query params, for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:6274/?MCP_SERVER_REQUEST_TIMEOUT=10000&MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS=false&MCP_PROXY_FULL_ADDRESS=http://10.1.1.22:5577
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that if both the query param and the corresponding localStorage item are set, the query param will take precedence.
|
||||||
|
|
||||||
### From this repository
|
### From this repository
|
||||||
|
|
||||||
@@ -66,6 +204,57 @@ npm run build
|
|||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### CLI Mode
|
||||||
|
|
||||||
|
CLI mode enables programmatic interaction with MCP servers from the command line, ideal for scripting, automation, and integration with coding assistants. This creates an efficient feedback loop for MCP server development.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx @modelcontextprotocol/inspector --cli node build/index.js
|
||||||
|
```
|
||||||
|
|
||||||
|
The CLI mode supports most operations across tools, resources, and prompts. A few examples:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Basic usage
|
||||||
|
npx @modelcontextprotocol/inspector --cli node build/index.js
|
||||||
|
|
||||||
|
# With config file
|
||||||
|
npx @modelcontextprotocol/inspector --cli --config path/to/config.json --server myserver
|
||||||
|
|
||||||
|
# List available tools
|
||||||
|
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list
|
||||||
|
|
||||||
|
# Call a specific tool
|
||||||
|
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg key=value --tool-arg another=value2
|
||||||
|
|
||||||
|
# List available resources
|
||||||
|
npx @modelcontextprotocol/inspector --cli node build/index.js --method resources/list
|
||||||
|
|
||||||
|
# List available prompts
|
||||||
|
npx @modelcontextprotocol/inspector --cli node build/index.js --method prompts/list
|
||||||
|
|
||||||
|
# Connect to a remote MCP server
|
||||||
|
npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com
|
||||||
|
|
||||||
|
# Call a tool on a remote server
|
||||||
|
npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --method tools/call --tool-name remotetool --tool-arg param=value
|
||||||
|
|
||||||
|
# List resources from a remote server
|
||||||
|
npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --method resources/list
|
||||||
|
```
|
||||||
|
|
||||||
|
### UI Mode vs CLI Mode: When to Use Each
|
||||||
|
|
||||||
|
| Use Case | UI Mode | CLI Mode |
|
||||||
|
| ------------------------ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| **Server Development** | Visual interface for interactive testing and debugging during development | Scriptable commands for quick testing and continuous integration; creates feedback loops with AI coding assistants like Cursor for rapid development |
|
||||||
|
| **Resource Exploration** | Interactive browser with hierarchical navigation and JSON visualization | Programmatic listing and reading for automation and scripting |
|
||||||
|
| **Tool Testing** | Form-based parameter input with real-time response visualization | Command-line tool execution with JSON output for scripting |
|
||||||
|
| **Prompt Engineering** | Interactive sampling with streaming responses and visual comparison | Batch processing of prompts with machine-readable output |
|
||||||
|
| **Debugging** | Request history, visualized errors, and real-time notifications | Direct JSON output for log analysis and integration with other tools |
|
||||||
|
| **Automation** | N/A | Ideal for CI/CD pipelines, batch processing, and integration with coding assistants |
|
||||||
|
| **Learning MCP** | Rich visual interface helps new users understand server capabilities | Simplified commands for focused learning of specific endpoints |
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License—see the [LICENSE](LICENSE) file for details.
|
This project is licensed under the MIT License—see the [LICENSE](LICENSE) file for details.
|
||||||
|
|||||||
116
bin/cli.js
116
bin/cli.js
@@ -1,116 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
import { resolve, dirname } from "path";
|
|
||||||
import { spawnPromise } from "spawn-rx";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
||||||
|
|
||||||
function delay(ms) {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
// Parse command line arguments
|
|
||||||
const args = process.argv.slice(2);
|
|
||||||
const envVars = {};
|
|
||||||
const mcpServerArgs = [];
|
|
||||||
let command = null;
|
|
||||||
let parsingFlags = true;
|
|
||||||
|
|
||||||
for (let i = 0; i < args.length; i++) {
|
|
||||||
const arg = args[i];
|
|
||||||
|
|
||||||
if (parsingFlags && arg === "--") {
|
|
||||||
parsingFlags = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parsingFlags && arg === "-e" && i + 1 < args.length) {
|
|
||||||
const [key, value] = args[++i].split("=");
|
|
||||||
if (key && value) {
|
|
||||||
envVars[key] = value;
|
|
||||||
}
|
|
||||||
} else if (!command) {
|
|
||||||
command = arg;
|
|
||||||
} else {
|
|
||||||
mcpServerArgs.push(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const inspectorServerPath = resolve(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"server",
|
|
||||||
"build",
|
|
||||||
"index.js",
|
|
||||||
);
|
|
||||||
|
|
||||||
// Path to the client entry point
|
|
||||||
const inspectorClientPath = resolve(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"client",
|
|
||||||
"bin",
|
|
||||||
"cli.js",
|
|
||||||
);
|
|
||||||
|
|
||||||
const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
|
|
||||||
const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
|
|
||||||
|
|
||||||
console.log("Starting MCP inspector...");
|
|
||||||
|
|
||||||
const abort = new AbortController();
|
|
||||||
|
|
||||||
let cancelled = false;
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
cancelled = true;
|
|
||||||
abort.abort();
|
|
||||||
});
|
|
||||||
|
|
||||||
const server = spawnPromise(
|
|
||||||
"node",
|
|
||||||
[
|
|
||||||
inspectorServerPath,
|
|
||||||
...(command ? [`--env`, command] : []),
|
|
||||||
...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []),
|
|
||||||
],
|
|
||||||
{
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
PORT: SERVER_PORT,
|
|
||||||
MCP_ENV_VARS: JSON.stringify(envVars),
|
|
||||||
},
|
|
||||||
signal: abort.signal,
|
|
||||||
echoOutput: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const client = spawnPromise("node", [inspectorClientPath], {
|
|
||||||
env: { ...process.env, PORT: CLIENT_PORT },
|
|
||||||
signal: abort.signal,
|
|
||||||
echoOutput: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Make sure our server/client didn't immediately fail
|
|
||||||
await Promise.any([server, client, delay(2 * 1000)]);
|
|
||||||
const portParam = SERVER_PORT === "3000" ? "" : `?proxyPort=${SERVER_PORT}`;
|
|
||||||
console.log(
|
|
||||||
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT}${portParam} 🚀`,
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await Promise.any([server, client]);
|
|
||||||
} catch (e) {
|
|
||||||
if (!cancelled || process.env.DEBUG) throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
.then((_) => process.exit(0))
|
|
||||||
.catch((e) => {
|
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
28
cli/package.json
Normal file
28
cli/package.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "@modelcontextprotocol/inspector-cli",
|
||||||
|
"version": "0.12.0",
|
||||||
|
"description": "CLI for the Model Context Protocol inspector",
|
||||||
|
"license": "MIT",
|
||||||
|
"author": "Anthropic, PBC (https://anthropic.com)",
|
||||||
|
"homepage": "https://modelcontextprotocol.io",
|
||||||
|
"bugs": "https://github.com/modelcontextprotocol/inspector/issues",
|
||||||
|
"main": "build/cli.js",
|
||||||
|
"type": "module",
|
||||||
|
"bin": {
|
||||||
|
"mcp-inspector-cli": "build/cli.js"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"build"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"postbuild": "node scripts/make-executable.js",
|
||||||
|
"test": "node scripts/cli-tests.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {},
|
||||||
|
"dependencies": {
|
||||||
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
|
"commander": "^13.1.0",
|
||||||
|
"spawn-rx": "^5.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
633
cli/scripts/cli-tests.js
Executable file
633
cli/scripts/cli-tests.js
Executable file
@@ -0,0 +1,633 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
// Colors for output
|
||||||
|
const colors = {
|
||||||
|
GREEN: "\x1b[32m",
|
||||||
|
YELLOW: "\x1b[33m",
|
||||||
|
RED: "\x1b[31m",
|
||||||
|
BLUE: "\x1b[34m",
|
||||||
|
ORANGE: "\x1b[33m",
|
||||||
|
NC: "\x1b[0m", // No Color
|
||||||
|
};
|
||||||
|
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import { execSync, spawn } from "child_process";
|
||||||
|
import os from "os";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
// Get directory paths with ESM compatibility
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
// Track test results
|
||||||
|
let PASSED_TESTS = 0;
|
||||||
|
let FAILED_TESTS = 0;
|
||||||
|
let SKIPPED_TESTS = 0;
|
||||||
|
let TOTAL_TESTS = 0;
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${colors.YELLOW}=== MCP Inspector CLI Test Script ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}This script tests the MCP Inspector CLI's ability to handle various command line options:${colors.NC}`,
|
||||||
|
);
|
||||||
|
console.log(`${colors.BLUE}- Basic CLI mode${colors.NC}`);
|
||||||
|
console.log(`${colors.BLUE}- Environment variables (-e)${colors.NC}`);
|
||||||
|
console.log(`${colors.BLUE}- Config file (--config)${colors.NC}`);
|
||||||
|
console.log(`${colors.BLUE}- Server selection (--server)${colors.NC}`);
|
||||||
|
console.log(`${colors.BLUE}- Method selection (--method)${colors.NC}`);
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}- Tool-related options (--tool-name, --tool-arg)${colors.NC}`,
|
||||||
|
);
|
||||||
|
console.log(`${colors.BLUE}- Resource-related options (--uri)${colors.NC}`);
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}- Prompt-related options (--prompt-name, --prompt-args)${colors.NC}`,
|
||||||
|
);
|
||||||
|
console.log(`${colors.BLUE}- Logging options (--log-level)${colors.NC}\n`);
|
||||||
|
|
||||||
|
// Get directory paths
|
||||||
|
const SCRIPTS_DIR = __dirname;
|
||||||
|
const PROJECT_ROOT = path.join(SCRIPTS_DIR, "../../");
|
||||||
|
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"];
|
||||||
|
|
||||||
|
// Create output directory for test results
|
||||||
|
const OUTPUT_DIR = path.join(SCRIPTS_DIR, "test-output");
|
||||||
|
if (!fs.existsSync(OUTPUT_DIR)) {
|
||||||
|
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary directory for test files
|
||||||
|
const TEMP_DIR = fs.mkdirSync(path.join(os.tmpdir(), "mcp-inspector-tests"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("exit", () => {
|
||||||
|
try {
|
||||||
|
fs.rmSync(TEMP_DIR, { recursive: true, force: true });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
`${colors.RED}Failed to remove temp directory: ${err.message}${colors.NC}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use the existing sample config file
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}Using existing sample config file: ${PROJECT_ROOT}/sample-config.json${colors.NC}`,
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
const sampleConfig = fs.readFileSync(
|
||||||
|
path.join(PROJECT_ROOT, "sample-config.json"),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
console.log(sampleConfig);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`${colors.RED}Error reading sample config: ${error.message}${colors.NC}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an invalid config file for testing
|
||||||
|
const invalidConfigPath = path.join(TEMP_DIR, "invalid-config.json");
|
||||||
|
fs.writeFileSync(invalidConfigPath, '{\n "mcpServers": {\n "invalid": {');
|
||||||
|
|
||||||
|
// Function to run a basic test
|
||||||
|
async function runBasicTest(testName, ...args) {
|
||||||
|
const outputFile = path.join(
|
||||||
|
OUTPUT_DIR,
|
||||||
|
`${testName.replace(/\//g, "_")}.log`,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`\n${colors.YELLOW}Testing: ${testName}${colors.NC}`);
|
||||||
|
TOTAL_TESTS++;
|
||||||
|
|
||||||
|
// Run the command and capture output
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}Command: node ${BUILD_DIR}/cli.js ${args.join(" ")}${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create a write stream for the output file
|
||||||
|
const outputStream = fs.createWriteStream(outputFile);
|
||||||
|
|
||||||
|
// Spawn the process
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const child = spawn("node", [path.join(BUILD_DIR, "cli.js"), ...args], {
|
||||||
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pipe stdout and stderr to the output file
|
||||||
|
child.stdout.pipe(outputStream);
|
||||||
|
child.stderr.pipe(outputStream);
|
||||||
|
|
||||||
|
// Also capture output for display
|
||||||
|
let output = "";
|
||||||
|
child.stdout.on("data", (data) => {
|
||||||
|
output += data.toString();
|
||||||
|
});
|
||||||
|
child.stderr.on("data", (data) => {
|
||||||
|
output += data.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on("close", (code) => {
|
||||||
|
outputStream.end();
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
|
console.log(`${colors.GREEN}✓ Test passed: ${testName}${colors.NC}`);
|
||||||
|
console.log(`${colors.BLUE}First few lines of output:${colors.NC}`);
|
||||||
|
const firstFewLines = output
|
||||||
|
.split("\n")
|
||||||
|
.slice(0, 5)
|
||||||
|
.map((line) => ` ${line}`)
|
||||||
|
.join("\n");
|
||||||
|
console.log(firstFewLines);
|
||||||
|
PASSED_TESTS++;
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
console.log(`${colors.RED}✗ Test failed: ${testName}${colors.NC}`);
|
||||||
|
console.log(`${colors.RED}Error output:${colors.NC}`);
|
||||||
|
console.log(
|
||||||
|
output
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => ` ${line}`)
|
||||||
|
.join("\n"),
|
||||||
|
);
|
||||||
|
FAILED_TESTS++;
|
||||||
|
|
||||||
|
// Stop after any error is encountered
|
||||||
|
console.log(
|
||||||
|
`${colors.YELLOW}Stopping tests due to error. Please validate and fix before continuing.${colors.NC}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`${colors.RED}Error running test: ${error.message}${colors.NC}`,
|
||||||
|
);
|
||||||
|
FAILED_TESTS++;
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to run an error test (expected to fail)
|
||||||
|
async function runErrorTest(testName, ...args) {
|
||||||
|
const outputFile = path.join(
|
||||||
|
OUTPUT_DIR,
|
||||||
|
`${testName.replace(/\//g, "_")}.log`,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`\n${colors.YELLOW}Testing error case: ${testName}${colors.NC}`);
|
||||||
|
TOTAL_TESTS++;
|
||||||
|
|
||||||
|
// Run the command and capture output
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}Command: node ${BUILD_DIR}/cli.js ${args.join(" ")}${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create a write stream for the output file
|
||||||
|
const outputStream = fs.createWriteStream(outputFile);
|
||||||
|
|
||||||
|
// Spawn the process
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const child = spawn("node", [path.join(BUILD_DIR, "cli.js"), ...args], {
|
||||||
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pipe stdout and stderr to the output file
|
||||||
|
child.stdout.pipe(outputStream);
|
||||||
|
child.stderr.pipe(outputStream);
|
||||||
|
|
||||||
|
// Also capture output for display
|
||||||
|
let output = "";
|
||||||
|
child.stdout.on("data", (data) => {
|
||||||
|
output += data.toString();
|
||||||
|
});
|
||||||
|
child.stderr.on("data", (data) => {
|
||||||
|
output += data.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on("close", (code) => {
|
||||||
|
outputStream.end();
|
||||||
|
|
||||||
|
// For error tests, we expect a non-zero exit code
|
||||||
|
if (code !== 0) {
|
||||||
|
console.log(
|
||||||
|
`${colors.GREEN}✓ Error test passed: ${testName}${colors.NC}`,
|
||||||
|
);
|
||||||
|
console.log(`${colors.BLUE}Error output (expected):${colors.NC}`);
|
||||||
|
const firstFewLines = output
|
||||||
|
.split("\n")
|
||||||
|
.slice(0, 5)
|
||||||
|
.map((line) => ` ${line}`)
|
||||||
|
.join("\n");
|
||||||
|
console.log(firstFewLines);
|
||||||
|
PASSED_TESTS++;
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`${colors.RED}✗ Error test failed: ${testName} (expected error but got success)${colors.NC}`,
|
||||||
|
);
|
||||||
|
console.log(`${colors.RED}Output:${colors.NC}`);
|
||||||
|
console.log(
|
||||||
|
output
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => ` ${line}`)
|
||||||
|
.join("\n"),
|
||||||
|
);
|
||||||
|
FAILED_TESTS++;
|
||||||
|
|
||||||
|
// Stop after any error is encountered
|
||||||
|
console.log(
|
||||||
|
`${colors.YELLOW}Stopping tests due to error. Please validate and fix before continuing.${colors.NC}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`${colors.RED}Error running test: ${error.message}${colors.NC}`,
|
||||||
|
);
|
||||||
|
FAILED_TESTS++;
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run all tests
|
||||||
|
async function runTests() {
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Basic CLI Mode Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 1: Basic CLI mode with method
|
||||||
|
await runBasicTest(
|
||||||
|
"basic_cli_mode",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 2: CLI mode with non-existent method (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"nonexistent_method",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"nonexistent/method",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 3: CLI mode without method (should fail)
|
||||||
|
await runErrorTest("missing_method", TEST_CMD, ...TEST_ARGS, "--cli");
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Environment Variable Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 4: CLI mode with environment variables
|
||||||
|
await runBasicTest(
|
||||||
|
"env_variables",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"-e",
|
||||||
|
"KEY1=value1",
|
||||||
|
"-e",
|
||||||
|
"KEY2=value2",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 5: CLI mode with invalid environment variable format (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"invalid_env_format",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"-e",
|
||||||
|
"INVALID_FORMAT",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 5b: CLI mode with environment variable containing equals sign in value
|
||||||
|
await runBasicTest(
|
||||||
|
"env_variable_with_equals",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"-e",
|
||||||
|
"API_KEY=abc123=xyz789==",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 5c: CLI mode with environment variable containing base64-encoded value
|
||||||
|
await runBasicTest(
|
||||||
|
"env_variable_with_base64",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"-e",
|
||||||
|
"JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0=",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Config File Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 6: Using config file with CLI mode
|
||||||
|
await runBasicTest(
|
||||||
|
"config_file",
|
||||||
|
"--config",
|
||||||
|
path.join(PROJECT_ROOT, "sample-config.json"),
|
||||||
|
"--server",
|
||||||
|
"everything",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 7: Using config file without server name (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"config_without_server",
|
||||||
|
"--config",
|
||||||
|
path.join(PROJECT_ROOT, "sample-config.json"),
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 8: Using server name without config file (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"server_without_config",
|
||||||
|
"--server",
|
||||||
|
"everything",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 9: Using non-existent config file (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"nonexistent_config",
|
||||||
|
"--config",
|
||||||
|
"./nonexistent-config.json",
|
||||||
|
"--server",
|
||||||
|
"everything",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 10: Using invalid config file format (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"invalid_config",
|
||||||
|
"--config",
|
||||||
|
invalidConfigPath,
|
||||||
|
"--server",
|
||||||
|
"everything",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 11: Using config file with non-existent server (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"nonexistent_server",
|
||||||
|
"--config",
|
||||||
|
path.join(PROJECT_ROOT, "sample-config.json"),
|
||||||
|
"--server",
|
||||||
|
"nonexistent",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Tool-Related Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 12: CLI mode with tool call
|
||||||
|
await runBasicTest(
|
||||||
|
"tool_call",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/call",
|
||||||
|
"--tool-name",
|
||||||
|
"echo",
|
||||||
|
"--tool-arg",
|
||||||
|
"message=Hello",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 13: CLI mode with tool call but missing tool name (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"missing_tool_name",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/call",
|
||||||
|
"--tool-arg",
|
||||||
|
"message=Hello",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 14: CLI mode with tool call but invalid tool args format (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"invalid_tool_args",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/call",
|
||||||
|
"--tool-name",
|
||||||
|
"echo",
|
||||||
|
"--tool-arg",
|
||||||
|
"invalid_format",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 15: CLI mode with multiple tool args
|
||||||
|
await runBasicTest(
|
||||||
|
"multiple_tool_args",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/call",
|
||||||
|
"--tool-name",
|
||||||
|
"add",
|
||||||
|
"--tool-arg",
|
||||||
|
"a=1",
|
||||||
|
"b=2",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Resource-Related Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 16: CLI mode with resource read
|
||||||
|
await runBasicTest(
|
||||||
|
"resource_read",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"resources/read",
|
||||||
|
"--uri",
|
||||||
|
"test://static/resource/1",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 17: CLI mode with resource read but missing URI (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"missing_uri",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"resources/read",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Prompt-Related Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 18: CLI mode with prompt get
|
||||||
|
await runBasicTest(
|
||||||
|
"prompt_get",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"prompts/get",
|
||||||
|
"--prompt-name",
|
||||||
|
"simple_prompt",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 19: CLI mode with prompt get and args
|
||||||
|
await runBasicTest(
|
||||||
|
"prompt_get_with_args",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"prompts/get",
|
||||||
|
"--prompt-name",
|
||||||
|
"complex_prompt",
|
||||||
|
"--prompt-args",
|
||||||
|
"temperature=0.7",
|
||||||
|
"style=concise",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 20: CLI mode with prompt get but missing prompt name (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"missing_prompt_name",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"prompts/get",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`\n${colors.YELLOW}=== Running Logging Tests ===${colors.NC}`);
|
||||||
|
|
||||||
|
// Test 21: CLI mode with log level
|
||||||
|
await runBasicTest(
|
||||||
|
"log_level",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"logging/setLevel",
|
||||||
|
"--log-level",
|
||||||
|
"debug",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 22: CLI mode with invalid log level (should fail)
|
||||||
|
await runErrorTest(
|
||||||
|
"invalid_log_level",
|
||||||
|
TEST_CMD,
|
||||||
|
...TEST_ARGS,
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"logging/setLevel",
|
||||||
|
"--log-level",
|
||||||
|
"invalid",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.YELLOW}=== Running Combined Option Tests ===${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Note about the combined options issue
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}Testing combined options with environment variables and config file.${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 23: CLI mode with config file, environment variables, and tool call
|
||||||
|
await runBasicTest(
|
||||||
|
"combined_options",
|
||||||
|
"--config",
|
||||||
|
path.join(PROJECT_ROOT, "sample-config.json"),
|
||||||
|
"--server",
|
||||||
|
"everything",
|
||||||
|
"-e",
|
||||||
|
"CLI_ENV_VAR=cli_value",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/list",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test 24: CLI mode with all possible options (that make sense together)
|
||||||
|
await runBasicTest(
|
||||||
|
"all_options",
|
||||||
|
"--config",
|
||||||
|
path.join(PROJECT_ROOT, "sample-config.json"),
|
||||||
|
"--server",
|
||||||
|
"everything",
|
||||||
|
"-e",
|
||||||
|
"CLI_ENV_VAR=cli_value",
|
||||||
|
"--cli",
|
||||||
|
"--method",
|
||||||
|
"tools/call",
|
||||||
|
"--tool-name",
|
||||||
|
"echo",
|
||||||
|
"--tool-arg",
|
||||||
|
"message=Hello",
|
||||||
|
"--log-level",
|
||||||
|
"debug",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Print test summary
|
||||||
|
console.log(`\n${colors.YELLOW}=== Test Summary ===${colors.NC}`);
|
||||||
|
console.log(`${colors.GREEN}Passed: ${PASSED_TESTS}${colors.NC}`);
|
||||||
|
console.log(`${colors.RED}Failed: ${FAILED_TESTS}${colors.NC}`);
|
||||||
|
console.log(`${colors.ORANGE}Skipped: ${SKIPPED_TESTS}${colors.NC}`);
|
||||||
|
console.log(`Total: ${TOTAL_TESTS}`);
|
||||||
|
console.log(
|
||||||
|
`${colors.BLUE}Detailed logs saved to: ${OUTPUT_DIR}${colors.NC}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`\n${colors.GREEN}All tests completed!${colors.NC}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run all tests
|
||||||
|
runTests().catch((error) => {
|
||||||
|
console.error(
|
||||||
|
`${colors.RED}Tests failed with error: ${error.message}${colors.NC}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
29
cli/scripts/make-executable.js
Executable file
29
cli/scripts/make-executable.js
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Cross-platform script to make a file executable
|
||||||
|
*/
|
||||||
|
import { promises as fs } from "fs";
|
||||||
|
import { platform } from "os";
|
||||||
|
import { execSync } from "child_process";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const TARGET_FILE = path.resolve("build/cli.js");
|
||||||
|
|
||||||
|
async function makeExecutable() {
|
||||||
|
try {
|
||||||
|
// On Unix-like systems (Linux, macOS), use chmod
|
||||||
|
if (platform() !== "win32") {
|
||||||
|
execSync(`chmod +x "${TARGET_FILE}"`);
|
||||||
|
console.log("Made file executable with chmod");
|
||||||
|
} else {
|
||||||
|
// On Windows, no need to make files "executable" in the Unix sense
|
||||||
|
// Just ensure the file exists
|
||||||
|
await fs.access(TARGET_FILE);
|
||||||
|
console.log("File exists and is accessible on Windows");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error making file executable:", error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
makeExecutable();
|
||||||
287
cli/src/cli.ts
Normal file
287
cli/src/cli.ts
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { Command } from "commander";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import { dirname, resolve } from "path";
|
||||||
|
import { spawnPromise } from "spawn-rx";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
type Args = {
|
||||||
|
command: string;
|
||||||
|
args: string[];
|
||||||
|
envArgs: Record<string, string>;
|
||||||
|
cli: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CliOptions = {
|
||||||
|
e?: Record<string, string>;
|
||||||
|
config?: string;
|
||||||
|
server?: string;
|
||||||
|
cli?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ServerConfig = {
|
||||||
|
command: string;
|
||||||
|
args?: string[];
|
||||||
|
env?: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function handleError(error: unknown): never {
|
||||||
|
let message: string;
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
message = error.message;
|
||||||
|
} else if (typeof error === "string") {
|
||||||
|
message = error;
|
||||||
|
} else {
|
||||||
|
message = "Unknown error";
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(message);
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delay(ms: number): Promise<void> {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runWebClient(args: Args): Promise<void> {
|
||||||
|
const inspectorServerPath = resolve(
|
||||||
|
__dirname,
|
||||||
|
"../../",
|
||||||
|
"server",
|
||||||
|
"build",
|
||||||
|
"index.js",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Path to the client entry point
|
||||||
|
const inspectorClientPath = resolve(
|
||||||
|
__dirname,
|
||||||
|
"../../",
|
||||||
|
"client",
|
||||||
|
"bin",
|
||||||
|
"client.js",
|
||||||
|
);
|
||||||
|
|
||||||
|
const CLIENT_PORT: string = process.env.CLIENT_PORT ?? "6274";
|
||||||
|
const SERVER_PORT: string = process.env.SERVER_PORT ?? "6277";
|
||||||
|
|
||||||
|
console.log("Starting MCP inspector...");
|
||||||
|
|
||||||
|
const abort = new AbortController();
|
||||||
|
let cancelled: boolean = false;
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
cancelled = true;
|
||||||
|
abort.abort();
|
||||||
|
});
|
||||||
|
|
||||||
|
let server: ReturnType<typeof spawnPromise>;
|
||||||
|
let serverOk: unknown;
|
||||||
|
|
||||||
|
try {
|
||||||
|
server = spawnPromise(
|
||||||
|
"node",
|
||||||
|
[
|
||||||
|
inspectorServerPath,
|
||||||
|
...(args.command ? [`--env`, args.command] : []),
|
||||||
|
...(args.args ? [`--args=${args.args.join(" ")}`] : []),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
PORT: SERVER_PORT,
|
||||||
|
MCP_ENV_VARS: JSON.stringify(args.envArgs),
|
||||||
|
},
|
||||||
|
signal: abort.signal,
|
||||||
|
echoOutput: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure server started before starting client
|
||||||
|
serverOk = await Promise.race([server, delay(2 * 1000)]);
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
|
if (serverOk) {
|
||||||
|
try {
|
||||||
|
await spawnPromise("node", [inspectorClientPath], {
|
||||||
|
env: { ...process.env, PORT: CLIENT_PORT },
|
||||||
|
signal: abort.signal,
|
||||||
|
echoOutput: true,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!cancelled || process.env.DEBUG) throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runCli(args: Args): Promise<void> {
|
||||||
|
const projectRoot = resolve(__dirname, "..");
|
||||||
|
const cliPath = resolve(projectRoot, "build", "index.js");
|
||||||
|
|
||||||
|
const abort = new AbortController();
|
||||||
|
|
||||||
|
let cancelled = false;
|
||||||
|
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
cancelled = true;
|
||||||
|
abort.abort();
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await spawnPromise("node", [cliPath, args.command, ...args.args], {
|
||||||
|
env: { ...process.env, ...args.envArgs },
|
||||||
|
signal: abort.signal,
|
||||||
|
echoOutput: true,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!cancelled || process.env.DEBUG) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadConfigFile(configPath: string, serverName: string): ServerConfig {
|
||||||
|
try {
|
||||||
|
const resolvedConfigPath = path.isAbsolute(configPath)
|
||||||
|
? configPath
|
||||||
|
: path.resolve(process.cwd(), configPath);
|
||||||
|
|
||||||
|
if (!fs.existsSync(resolvedConfigPath)) {
|
||||||
|
throw new Error(`Config file not found: ${resolvedConfigPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const configContent = fs.readFileSync(resolvedConfigPath, "utf8");
|
||||||
|
const parsedConfig = JSON.parse(configContent);
|
||||||
|
|
||||||
|
if (!parsedConfig.mcpServers || !parsedConfig.mcpServers[serverName]) {
|
||||||
|
const availableServers = Object.keys(parsedConfig.mcpServers || {}).join(
|
||||||
|
", ",
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Server '${serverName}' not found in config file. Available servers: ${availableServers}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const serverConfig = parsedConfig.mcpServers[serverName];
|
||||||
|
|
||||||
|
return serverConfig;
|
||||||
|
} catch (err: unknown) {
|
||||||
|
if (err instanceof SyntaxError) {
|
||||||
|
throw new Error(`Invalid JSON in config file: ${err.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseKeyValuePair(
|
||||||
|
value: string,
|
||||||
|
previous: Record<string, string> = {},
|
||||||
|
): Record<string, string> {
|
||||||
|
const parts = value.split("=");
|
||||||
|
const key = parts[0];
|
||||||
|
const val = parts.slice(1).join("=");
|
||||||
|
|
||||||
|
if (val === undefined || val === "") {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid parameter format: ${value}. Use key=value format.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...previous, [key as string]: val };
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseArgs(): Args {
|
||||||
|
const program = new Command();
|
||||||
|
|
||||||
|
const argSeparatorIndex = process.argv.indexOf("--");
|
||||||
|
let preArgs = process.argv;
|
||||||
|
let postArgs: string[] = [];
|
||||||
|
|
||||||
|
if (argSeparatorIndex !== -1) {
|
||||||
|
preArgs = process.argv.slice(0, argSeparatorIndex);
|
||||||
|
postArgs = process.argv.slice(argSeparatorIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
program
|
||||||
|
.name("inspector-bin")
|
||||||
|
.allowExcessArguments()
|
||||||
|
.allowUnknownOption()
|
||||||
|
.option(
|
||||||
|
"-e <env>",
|
||||||
|
"environment variables in KEY=VALUE format",
|
||||||
|
parseKeyValuePair,
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
.option("--config <path>", "config file path")
|
||||||
|
.option("--server <n>", "server name from config file")
|
||||||
|
.option("--cli", "enable CLI mode");
|
||||||
|
|
||||||
|
// Parse only the arguments before --
|
||||||
|
program.parse(preArgs);
|
||||||
|
|
||||||
|
const options = program.opts() as CliOptions;
|
||||||
|
const remainingArgs = program.args;
|
||||||
|
|
||||||
|
// Add back any arguments that came after --
|
||||||
|
const finalArgs = [...remainingArgs, ...postArgs];
|
||||||
|
|
||||||
|
// Validate that config and server are provided together
|
||||||
|
if (
|
||||||
|
(options.config && !options.server) ||
|
||||||
|
(!options.config && options.server)
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"Both --config and --server must be provided together. If you specify one, you must specify the other.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If config file is specified, load and use the options from the file. We must merge the args
|
||||||
|
// from the command line and the file together, or we will miss the method options (--method,
|
||||||
|
// etc.)
|
||||||
|
if (options.config && options.server) {
|
||||||
|
const config = loadConfigFile(options.config, options.server);
|
||||||
|
|
||||||
|
return {
|
||||||
|
command: config.command,
|
||||||
|
args: [...(config.args || []), ...finalArgs],
|
||||||
|
envArgs: { ...(config.env || {}), ...(options.e || {}) },
|
||||||
|
cli: options.cli || false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise use command line arguments
|
||||||
|
const command = finalArgs[0] || "";
|
||||||
|
const args = finalArgs.slice(1);
|
||||||
|
|
||||||
|
return {
|
||||||
|
command,
|
||||||
|
args,
|
||||||
|
envArgs: options.e || {},
|
||||||
|
cli: options.cli || false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
process.on("uncaughtException", (error) => {
|
||||||
|
handleError(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const args = parseArgs();
|
||||||
|
|
||||||
|
if (args.cli) {
|
||||||
|
runCli(args);
|
||||||
|
} else {
|
||||||
|
await runWebClient(args);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
51
cli/src/client/connection.ts
Normal file
51
cli/src/client/connection.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
||||||
|
import { McpResponse } from "./types.js";
|
||||||
|
|
||||||
|
export const validLogLevels = [
|
||||||
|
"trace",
|
||||||
|
"debug",
|
||||||
|
"info",
|
||||||
|
"warn",
|
||||||
|
"error",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type LogLevel = (typeof validLogLevels)[number];
|
||||||
|
|
||||||
|
export async function connect(
|
||||||
|
client: Client,
|
||||||
|
transport: Transport,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
await client.connect(transport);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to connect to MCP server: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function disconnect(transport: Transport): Promise<void> {
|
||||||
|
try {
|
||||||
|
await transport.close();
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to disconnect from MCP server: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set logging level
|
||||||
|
export async function setLoggingLevel(
|
||||||
|
client: Client,
|
||||||
|
level: LogLevel,
|
||||||
|
): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.setLoggingLevel(level as any);
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to set logging level: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
cli/src/client/index.ts
Normal file
6
cli/src/client/index.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// Re-export everything from the client modules
|
||||||
|
export * from "./connection.js";
|
||||||
|
export * from "./prompts.js";
|
||||||
|
export * from "./resources.js";
|
||||||
|
export * from "./tools.js";
|
||||||
|
export * from "./types.js";
|
||||||
34
cli/src/client/prompts.ts
Normal file
34
cli/src/client/prompts.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
|
import { McpResponse } from "./types.js";
|
||||||
|
|
||||||
|
// List available prompts
|
||||||
|
export async function listPrompts(client: Client): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.listPrompts();
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to list prompts: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a prompt
|
||||||
|
export async function getPrompt(
|
||||||
|
client: Client,
|
||||||
|
name: string,
|
||||||
|
args?: Record<string, string>,
|
||||||
|
): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.getPrompt({
|
||||||
|
name,
|
||||||
|
arguments: args || {},
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to get prompt: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
cli/src/client/resources.ts
Normal file
43
cli/src/client/resources.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
|
import { McpResponse } from "./types.js";
|
||||||
|
|
||||||
|
// List available resources
|
||||||
|
export async function listResources(client: Client): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.listResources();
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to list resources: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read a resource
|
||||||
|
export async function readResource(
|
||||||
|
client: Client,
|
||||||
|
uri: string,
|
||||||
|
): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.readResource({ uri });
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to read resource ${uri}: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// List resource templates
|
||||||
|
export async function listResourceTemplates(
|
||||||
|
client: Client,
|
||||||
|
): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.listResourceTemplates();
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to list resource templates: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
95
cli/src/client/tools.ts
Normal file
95
cli/src/client/tools.ts
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
|
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { McpResponse } from "./types.js";
|
||||||
|
|
||||||
|
type JsonSchemaType = {
|
||||||
|
type: "string" | "number" | "integer" | "boolean" | "array" | "object";
|
||||||
|
description?: string;
|
||||||
|
properties?: Record<string, JsonSchemaType>;
|
||||||
|
items?: JsonSchemaType;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function listTools(client: Client): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const response = await client.listTools();
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to list tools: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertParameterValue(value: string, schema: JsonSchemaType): unknown {
|
||||||
|
if (!value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.type === "number" || schema.type === "integer") {
|
||||||
|
return Number(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.type === "boolean") {
|
||||||
|
return value.toLowerCase() === "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.type === "object" || schema.type === "array") {
|
||||||
|
try {
|
||||||
|
return JSON.parse(value);
|
||||||
|
} catch (error) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertParameters(
|
||||||
|
tool: Tool,
|
||||||
|
params: Record<string, string>,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const result: Record<string, unknown> = {};
|
||||||
|
const properties = tool.inputSchema.properties || {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(params)) {
|
||||||
|
const paramSchema = properties[key] as JsonSchemaType | undefined;
|
||||||
|
|
||||||
|
if (paramSchema) {
|
||||||
|
result[key] = convertParameterValue(value, paramSchema);
|
||||||
|
} else {
|
||||||
|
// If no schema is found for this parameter, keep it as string
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function callTool(
|
||||||
|
client: Client,
|
||||||
|
name: string,
|
||||||
|
args: Record<string, string>,
|
||||||
|
): Promise<McpResponse> {
|
||||||
|
try {
|
||||||
|
const toolsResponse = await listTools(client);
|
||||||
|
const tools = toolsResponse.tools as Tool[];
|
||||||
|
const tool = tools.find((t) => t.name === name);
|
||||||
|
|
||||||
|
let convertedArgs: Record<string, unknown> = args;
|
||||||
|
|
||||||
|
if (tool) {
|
||||||
|
// Convert parameters based on the tool's schema
|
||||||
|
convertedArgs = convertParameters(tool, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await client.callTool({
|
||||||
|
name: name,
|
||||||
|
arguments: convertedArgs,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to call tool ${name}: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
cli/src/client/types.ts
Normal file
1
cli/src/client/types.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export type McpResponse = Record<string, unknown>;
|
||||||
20
cli/src/error-handler.ts
Normal file
20
cli/src/error-handler.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
function formatError(error: unknown): string {
|
||||||
|
let message: string;
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
message = error.message;
|
||||||
|
} else if (typeof error === "string") {
|
||||||
|
message = error;
|
||||||
|
} else {
|
||||||
|
message = "Unknown error";
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleError(error: unknown): never {
|
||||||
|
const errorMessage = formatError(error);
|
||||||
|
console.error(errorMessage);
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
253
cli/src/index.ts
Normal file
253
cli/src/index.ts
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
|
import { Command } from "commander";
|
||||||
|
import {
|
||||||
|
callTool,
|
||||||
|
connect,
|
||||||
|
disconnect,
|
||||||
|
getPrompt,
|
||||||
|
listPrompts,
|
||||||
|
listResources,
|
||||||
|
listResourceTemplates,
|
||||||
|
listTools,
|
||||||
|
LogLevel,
|
||||||
|
McpResponse,
|
||||||
|
readResource,
|
||||||
|
setLoggingLevel,
|
||||||
|
validLogLevels,
|
||||||
|
} from "./client/index.js";
|
||||||
|
import { handleError } from "./error-handler.js";
|
||||||
|
import { createTransport, TransportOptions } from "./transport.js";
|
||||||
|
|
||||||
|
type Args = {
|
||||||
|
target: string[];
|
||||||
|
method?: string;
|
||||||
|
promptName?: string;
|
||||||
|
promptArgs?: Record<string, string>;
|
||||||
|
uri?: string;
|
||||||
|
logLevel?: LogLevel;
|
||||||
|
toolName?: string;
|
||||||
|
toolArg?: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createTransportOptions(target: string[]): TransportOptions {
|
||||||
|
if (target.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
"Target is required. Specify a URL or a command to execute.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [command, ...commandArgs] = target;
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
throw new Error("Command is required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUrl = command.startsWith("http://") || command.startsWith("https://");
|
||||||
|
|
||||||
|
if (isUrl && commandArgs.length > 0) {
|
||||||
|
throw new Error("Arguments cannot be passed to a URL-based MCP server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
transportType: isUrl ? "sse" : "stdio",
|
||||||
|
command: isUrl ? undefined : command,
|
||||||
|
args: isUrl ? undefined : commandArgs,
|
||||||
|
url: isUrl ? command : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function callMethod(args: Args): Promise<void> {
|
||||||
|
const transportOptions = createTransportOptions(args.target);
|
||||||
|
const transport = createTransport(transportOptions);
|
||||||
|
const client = new Client({
|
||||||
|
name: "inspector-cli",
|
||||||
|
version: "0.5.1",
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(client, transport);
|
||||||
|
|
||||||
|
let result: McpResponse;
|
||||||
|
|
||||||
|
// Tools methods
|
||||||
|
if (args.method === "tools/list") {
|
||||||
|
result = await listTools(client);
|
||||||
|
} else if (args.method === "tools/call") {
|
||||||
|
if (!args.toolName) {
|
||||||
|
throw new Error(
|
||||||
|
"Tool name is required for tools/call method. Use --tool-name to specify the tool name.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = await callTool(client, args.toolName, args.toolArg || {});
|
||||||
|
}
|
||||||
|
// Resources methods
|
||||||
|
else if (args.method === "resources/list") {
|
||||||
|
result = await listResources(client);
|
||||||
|
} else if (args.method === "resources/read") {
|
||||||
|
if (!args.uri) {
|
||||||
|
throw new Error(
|
||||||
|
"URI is required for resources/read method. Use --uri to specify the resource URI.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = await readResource(client, args.uri);
|
||||||
|
} else if (args.method === "resources/templates/list") {
|
||||||
|
result = await listResourceTemplates(client);
|
||||||
|
}
|
||||||
|
// Prompts methods
|
||||||
|
else if (args.method === "prompts/list") {
|
||||||
|
result = await listPrompts(client);
|
||||||
|
} else if (args.method === "prompts/get") {
|
||||||
|
if (!args.promptName) {
|
||||||
|
throw new Error(
|
||||||
|
"Prompt name is required for prompts/get method. Use --prompt-name to specify the prompt name.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = await getPrompt(client, args.promptName, args.promptArgs || {});
|
||||||
|
}
|
||||||
|
// Logging methods
|
||||||
|
else if (args.method === "logging/setLevel") {
|
||||||
|
if (!args.logLevel) {
|
||||||
|
throw new Error(
|
||||||
|
"Log level is required for logging/setLevel method. Use --log-level to specify the log level.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = await setLoggingLevel(client, args.logLevel);
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`Unsupported method: ${args.method}. Supported methods include: tools/list, tools/call, resources/list, resources/read, resources/templates/list, prompts/list, prompts/get, logging/setLevel`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(JSON.stringify(result, null, 2));
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
await disconnect(transport);
|
||||||
|
} catch (disconnectError) {
|
||||||
|
throw disconnectError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseKeyValuePair(
|
||||||
|
value: string,
|
||||||
|
previous: Record<string, string> = {},
|
||||||
|
): Record<string, string> {
|
||||||
|
const parts = value.split("=");
|
||||||
|
const key = parts[0];
|
||||||
|
const val = parts.slice(1).join("=");
|
||||||
|
|
||||||
|
if (val === undefined || val === "") {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid parameter format: ${value}. Use key=value format.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...previous, [key as string]: val };
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseArgs(): Args {
|
||||||
|
const program = new Command();
|
||||||
|
|
||||||
|
// Find if there's a -- in the arguments and split them
|
||||||
|
const argSeparatorIndex = process.argv.indexOf("--");
|
||||||
|
let preArgs = process.argv;
|
||||||
|
let postArgs: string[] = [];
|
||||||
|
|
||||||
|
if (argSeparatorIndex !== -1) {
|
||||||
|
preArgs = process.argv.slice(0, argSeparatorIndex);
|
||||||
|
postArgs = process.argv.slice(argSeparatorIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
program
|
||||||
|
.name("inspector-cli")
|
||||||
|
.allowUnknownOption()
|
||||||
|
.argument("<target...>", "Command and arguments or URL of the MCP server")
|
||||||
|
//
|
||||||
|
// Method selection
|
||||||
|
//
|
||||||
|
.option("--method <method>", "Method to invoke")
|
||||||
|
//
|
||||||
|
// Tool-related options
|
||||||
|
//
|
||||||
|
.option("--tool-name <toolName>", "Tool name (for tools/call method)")
|
||||||
|
.option(
|
||||||
|
"--tool-arg <pairs...>",
|
||||||
|
"Tool argument as key=value pair",
|
||||||
|
parseKeyValuePair,
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
//
|
||||||
|
// Resource-related options
|
||||||
|
//
|
||||||
|
.option("--uri <uri>", "URI of the resource (for resources/read method)")
|
||||||
|
//
|
||||||
|
// Prompt-related options
|
||||||
|
//
|
||||||
|
.option(
|
||||||
|
"--prompt-name <promptName>",
|
||||||
|
"Name of the prompt (for prompts/get method)",
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
"--prompt-args <pairs...>",
|
||||||
|
"Prompt arguments as key=value pairs",
|
||||||
|
parseKeyValuePair,
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
//
|
||||||
|
// Logging options
|
||||||
|
//
|
||||||
|
.option(
|
||||||
|
"--log-level <level>",
|
||||||
|
"Logging level (for logging/setLevel method)",
|
||||||
|
(value: string) => {
|
||||||
|
if (!validLogLevels.includes(value as any)) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid log level: ${value}. Valid levels are: ${validLogLevels.join(", ")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value as LogLevel;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Parse only the arguments before --
|
||||||
|
program.parse(preArgs);
|
||||||
|
|
||||||
|
const options = program.opts() as Omit<Args, "target">;
|
||||||
|
let remainingArgs = program.args;
|
||||||
|
|
||||||
|
// Add back any arguments that came after --
|
||||||
|
const finalArgs = [...remainingArgs, ...postArgs];
|
||||||
|
|
||||||
|
if (!options.method) {
|
||||||
|
throw new Error(
|
||||||
|
"Method is required. Use --method to specify the method to invoke.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
target: finalArgs,
|
||||||
|
...options,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
process.on("uncaughtException", (error) => {
|
||||||
|
handleError(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const args = parseArgs();
|
||||||
|
await callMethod(args);
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
76
cli/src/transport.ts
Normal file
76
cli/src/transport.ts
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
||||||
|
import {
|
||||||
|
getDefaultEnvironment,
|
||||||
|
StdioClientTransport,
|
||||||
|
} from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||||
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
||||||
|
import { findActualExecutable } from "spawn-rx";
|
||||||
|
|
||||||
|
export type TransportOptions = {
|
||||||
|
transportType: "sse" | "stdio";
|
||||||
|
command?: string;
|
||||||
|
args?: string[];
|
||||||
|
url?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createSSETransport(options: TransportOptions): Transport {
|
||||||
|
const baseUrl = new URL(options.url ?? "");
|
||||||
|
const sseUrl = new URL("/sse", baseUrl);
|
||||||
|
|
||||||
|
return new SSEClientTransport(sseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createStdioTransport(options: TransportOptions): Transport {
|
||||||
|
let args: string[] = [];
|
||||||
|
|
||||||
|
if (options.args !== undefined) {
|
||||||
|
args = options.args;
|
||||||
|
}
|
||||||
|
|
||||||
|
const processEnv: Record<string, string> = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(process.env)) {
|
||||||
|
if (value !== undefined) {
|
||||||
|
processEnv[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultEnv = getDefaultEnvironment();
|
||||||
|
|
||||||
|
const env: Record<string, string> = {
|
||||||
|
...processEnv,
|
||||||
|
...defaultEnv,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { cmd: actualCommand, args: actualArgs } = findActualExecutable(
|
||||||
|
options.command ?? "",
|
||||||
|
args,
|
||||||
|
);
|
||||||
|
|
||||||
|
return new StdioClientTransport({
|
||||||
|
command: actualCommand,
|
||||||
|
args: actualArgs,
|
||||||
|
env,
|
||||||
|
stderr: "pipe",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTransport(options: TransportOptions): Transport {
|
||||||
|
const { transportType } = options;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (transportType === "stdio") {
|
||||||
|
return createStdioTransport(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transportType === "sse") {
|
||||||
|
return createSSETransport(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Unsupported transport type: ${transportType}`);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to create transport: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
cli/tsconfig.json
Normal file
17
cli/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"outDir": "./build",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"noUncheckedIndexedAccess": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "packages", "**/*.spec.ts", "build"]
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
import { join, dirname } from "path";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
import handler from "serve-handler";
|
|
||||||
import http from "http";
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
||||||
const distPath = join(__dirname, "../dist");
|
|
||||||
|
|
||||||
const server = http.createServer((request, response) => {
|
|
||||||
return handler(request, response, {
|
|
||||||
public: distPath,
|
|
||||||
rewrites: [{ source: "/**", destination: "/index.html" }],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const port = process.env.PORT || 5173;
|
|
||||||
server.listen(port, () => {});
|
|
||||||
57
client/bin/client.js
Executable file
57
client/bin/client.js
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { join, dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import handler from "serve-handler";
|
||||||
|
import http from "http";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const distPath = join(__dirname, "../dist");
|
||||||
|
|
||||||
|
const server = http.createServer((request, response) => {
|
||||||
|
const handlerOptions = {
|
||||||
|
public: distPath,
|
||||||
|
rewrites: [{ source: "/**", destination: "/index.html" }],
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
// Ensure index.html is never cached
|
||||||
|
source: "index.html",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "no-cache, no-store, max-age=0",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Allow long-term caching for hashed assets
|
||||||
|
source: "assets/**",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "public, max-age=31536000, immutable",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
return handler(request, response, handlerOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
const port = process.env.PORT || 6274;
|
||||||
|
server.on("listening", () => {
|
||||||
|
console.log(
|
||||||
|
`🔍 MCP Inspector is up and running at http://127.0.0.1:${port} 🚀`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
server.on("error", (err) => {
|
||||||
|
if (err.message.includes(`EADDRINUSE`)) {
|
||||||
|
console.error(
|
||||||
|
`❌ MCP Inspector PORT IS IN USE at http://127.0.0.1:${port} ❌ `,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
server.listen(port);
|
||||||
124
client/bin/start.js
Executable file
124
client/bin/start.js
Executable file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import open from "open";
|
||||||
|
import { resolve, dirname } from "path";
|
||||||
|
import { spawnPromise } from "spawn-rx";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
function delay(ms) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
// Parse command line arguments
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const envVars = {};
|
||||||
|
const mcpServerArgs = [];
|
||||||
|
let command = null;
|
||||||
|
let parsingFlags = true;
|
||||||
|
|
||||||
|
for (let i = 0; i < args.length; i++) {
|
||||||
|
const arg = args[i];
|
||||||
|
|
||||||
|
if (parsingFlags && arg === "--") {
|
||||||
|
parsingFlags = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsingFlags && arg === "-e" && i + 1 < args.length) {
|
||||||
|
const envVar = args[++i];
|
||||||
|
const equalsIndex = envVar.indexOf("=");
|
||||||
|
|
||||||
|
if (equalsIndex !== -1) {
|
||||||
|
const key = envVar.substring(0, equalsIndex);
|
||||||
|
const value = envVar.substring(equalsIndex + 1);
|
||||||
|
envVars[key] = value;
|
||||||
|
} else {
|
||||||
|
envVars[envVar] = "";
|
||||||
|
}
|
||||||
|
} else if (!command) {
|
||||||
|
command = arg;
|
||||||
|
} else {
|
||||||
|
mcpServerArgs.push(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const inspectorServerPath = resolve(
|
||||||
|
__dirname,
|
||||||
|
"../..",
|
||||||
|
"server",
|
||||||
|
"build",
|
||||||
|
"index.js",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Path to the client entry point
|
||||||
|
const inspectorClientPath = resolve(
|
||||||
|
__dirname,
|
||||||
|
"../..",
|
||||||
|
"client",
|
||||||
|
"bin",
|
||||||
|
"client.js",
|
||||||
|
);
|
||||||
|
|
||||||
|
const CLIENT_PORT = process.env.CLIENT_PORT ?? "6274";
|
||||||
|
const SERVER_PORT = process.env.SERVER_PORT ?? "6277";
|
||||||
|
|
||||||
|
console.log("Starting MCP inspector...");
|
||||||
|
|
||||||
|
const abort = new AbortController();
|
||||||
|
|
||||||
|
let cancelled = false;
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
cancelled = true;
|
||||||
|
abort.abort();
|
||||||
|
});
|
||||||
|
let server, serverOk;
|
||||||
|
try {
|
||||||
|
server = spawnPromise(
|
||||||
|
"node",
|
||||||
|
[
|
||||||
|
inspectorServerPath,
|
||||||
|
...(command ? [`--env`, command] : []),
|
||||||
|
...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
PORT: SERVER_PORT,
|
||||||
|
MCP_ENV_VARS: JSON.stringify(envVars),
|
||||||
|
},
|
||||||
|
signal: abort.signal,
|
||||||
|
echoOutput: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure server started before starting client
|
||||||
|
serverOk = await Promise.race([server, delay(2 * 1000)]);
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
|
if (serverOk) {
|
||||||
|
try {
|
||||||
|
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
|
||||||
|
open(`http://127.0.0.1:${CLIENT_PORT}`);
|
||||||
|
}
|
||||||
|
await spawnPromise("node", [inspectorClientPath], {
|
||||||
|
env: { ...process.env, PORT: CLIENT_PORT },
|
||||||
|
signal: abort.signal,
|
||||||
|
echoOutput: true,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!cancelled || process.env.DEBUG) throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.then((_) => process.exit(0))
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
33
client/jest.config.cjs
Normal file
33
client/jest.config.cjs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: "ts-jest",
|
||||||
|
testEnvironment: "jest-fixed-jsdom",
|
||||||
|
moduleNameMapper: {
|
||||||
|
"^@/(.*)$": "<rootDir>/src/$1",
|
||||||
|
"\\.css$": "<rootDir>/src/__mocks__/styleMock.js",
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
"^.+\\.tsx?$": [
|
||||||
|
"ts-jest",
|
||||||
|
{
|
||||||
|
jsx: "react-jsx",
|
||||||
|
tsconfig: "tsconfig.jest.json",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
extensionsToTreatAsEsm: [".ts", ".tsx"],
|
||||||
|
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||||
|
// Exclude directories and files that don't need to be tested
|
||||||
|
testPathIgnorePatterns: [
|
||||||
|
"/node_modules/",
|
||||||
|
"/dist/",
|
||||||
|
"/bin/",
|
||||||
|
"\\.config\\.(js|ts|cjs|mjs)$",
|
||||||
|
],
|
||||||
|
// Exclude the same patterns from coverage reports
|
||||||
|
coveragePathIgnorePatterns: [
|
||||||
|
"/node_modules/",
|
||||||
|
"/dist/",
|
||||||
|
"/bin/",
|
||||||
|
"\\.config\\.(js|ts|cjs|mjs)$",
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@modelcontextprotocol/inspector-client",
|
"name": "@modelcontextprotocol/inspector-client",
|
||||||
"version": "0.6.0",
|
"version": "0.12.0",
|
||||||
"description": "Client-side application for the Model Context Protocol inspector",
|
"description": "Client-side application for the Model Context Protocol inspector",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Anthropic, PBC (https://anthropic.com)",
|
"author": "Anthropic, PBC (https://anthropic.com)",
|
||||||
@@ -8,39 +8,41 @@
|
|||||||
"bugs": "https://github.com/modelcontextprotocol/inspector/issues",
|
"bugs": "https://github.com/modelcontextprotocol/inspector/issues",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"mcp-inspector-client": "./bin/cli.js"
|
"mcp-inspector-client": "./bin/start.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
"bin",
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite --port 6274",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview --port 6274",
|
||||||
|
"test": "jest --config jest.config.cjs",
|
||||||
|
"test:watch": "jest --config jest.config.cjs --watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.6.1",
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
"@radix-ui/react-dialog": "^1.1.3",
|
|
||||||
"@radix-ui/react-checkbox": "^1.1.4",
|
"@radix-ui/react-checkbox": "^1.1.4",
|
||||||
|
"@radix-ui/react-dialog": "^1.1.3",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
"@radix-ui/react-label": "^2.1.0",
|
"@radix-ui/react-label": "^2.1.0",
|
||||||
"@radix-ui/react-popover": "^1.1.3",
|
"@radix-ui/react-popover": "^1.1.3",
|
||||||
"@radix-ui/react-select": "^2.1.2",
|
"@radix-ui/react-select": "^2.1.2",
|
||||||
"@radix-ui/react-slot": "^1.1.0",
|
"@radix-ui/react-slot": "^1.1.0",
|
||||||
"@radix-ui/react-tabs": "^1.1.1",
|
"@radix-ui/react-tabs": "^1.1.1",
|
||||||
"@types/prismjs": "^1.26.5",
|
"@radix-ui/react-toast": "^1.2.6",
|
||||||
|
"@radix-ui/react-tooltip": "^1.1.8",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "^1.0.4",
|
"cmdk": "^1.0.4",
|
||||||
"lucide-react": "^0.447.0",
|
"lucide-react": "^0.447.0",
|
||||||
"prismjs": "^1.29.0",
|
|
||||||
"pkce-challenge": "^4.1.0",
|
"pkce-challenge": "^4.1.0",
|
||||||
|
"prismjs": "^1.30.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-simple-code-editor": "^0.14.1",
|
"react-simple-code-editor": "^0.14.1",
|
||||||
"react-toastify": "^10.0.6",
|
|
||||||
"serve-handler": "^6.1.6",
|
"serve-handler": "^6.1.6",
|
||||||
"tailwind-merge": "^2.5.3",
|
"tailwind-merge": "^2.5.3",
|
||||||
"tailwindcss-animate": "^1.0.7",
|
"tailwindcss-animate": "^1.0.7",
|
||||||
@@ -48,20 +50,28 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.11.1",
|
"@eslint/js": "^9.11.1",
|
||||||
|
"@testing-library/jest-dom": "^6.6.3",
|
||||||
|
"@testing-library/react": "^16.2.0",
|
||||||
|
"@types/jest": "^29.5.14",
|
||||||
"@types/node": "^22.7.5",
|
"@types/node": "^22.7.5",
|
||||||
|
"@types/prismjs": "^1.26.5",
|
||||||
"@types/react": "^18.3.10",
|
"@types/react": "^18.3.10",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@types/serve-handler": "^6.1.4",
|
"@types/serve-handler": "^6.1.4",
|
||||||
"@vitejs/plugin-react": "^4.3.2",
|
"@vitejs/plugin-react": "^4.3.2",
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
|
"co": "^4.6.0",
|
||||||
"eslint": "^9.11.1",
|
"eslint": "^9.11.1",
|
||||||
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
|
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.12",
|
"eslint-plugin-react-refresh": "^0.4.12",
|
||||||
"globals": "^15.9.0",
|
"globals": "^15.9.0",
|
||||||
|
"jest": "^29.7.0",
|
||||||
|
"jest-environment-jsdom": "^29.7.0",
|
||||||
"postcss": "^8.4.47",
|
"postcss": "^8.4.47",
|
||||||
"tailwindcss": "^3.4.13",
|
"tailwindcss": "^3.4.13",
|
||||||
|
"ts-jest": "^29.2.6",
|
||||||
"typescript": "^5.5.3",
|
"typescript": "^5.5.3",
|
||||||
"typescript-eslint": "^8.7.0",
|
"typescript-eslint": "^8.7.0",
|
||||||
"vite": "^5.4.8"
|
"vite": "^6.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,26 +15,37 @@ import {
|
|||||||
Root,
|
Root,
|
||||||
ServerNotification,
|
ServerNotification,
|
||||||
Tool,
|
Tool,
|
||||||
|
LoggingLevel,
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
import React, { Suspense, useEffect, useRef, useState } from "react";
|
import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
|
import { SESSION_KEYS, getServerSpecificKey } from "./lib/constants";
|
||||||
|
import { AuthDebuggerState } from "./lib/auth-types";
|
||||||
|
import React, {
|
||||||
|
Suspense,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
import { useConnection } from "./lib/hooks/useConnection";
|
import { useConnection } from "./lib/hooks/useConnection";
|
||||||
import { useDraggablePane } from "./lib/hooks/useDraggablePane";
|
import { useDraggablePane } from "./lib/hooks/useDraggablePane";
|
||||||
|
|
||||||
import { StdErrNotification } from "./lib/notificationTypes";
|
import { StdErrNotification } from "./lib/notificationTypes";
|
||||||
|
|
||||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Bell,
|
Bell,
|
||||||
Files,
|
Files,
|
||||||
FolderTree,
|
FolderTree,
|
||||||
Hammer,
|
Hammer,
|
||||||
Hash,
|
Hash,
|
||||||
|
Key,
|
||||||
MessageSquare,
|
MessageSquare,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
import { toast } from "react-toastify";
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
|
import AuthDebugger from "./components/AuthDebugger";
|
||||||
import ConsoleTab from "./components/ConsoleTab";
|
import ConsoleTab from "./components/ConsoleTab";
|
||||||
import HistoryAndNotifications from "./components/History";
|
import HistoryAndNotifications from "./components/History";
|
||||||
import PingTab from "./components/PingTab";
|
import PingTab from "./components/PingTab";
|
||||||
@@ -44,23 +55,19 @@ import RootsTab from "./components/RootsTab";
|
|||||||
import SamplingTab, { PendingRequest } from "./components/SamplingTab";
|
import SamplingTab, { PendingRequest } from "./components/SamplingTab";
|
||||||
import Sidebar from "./components/Sidebar";
|
import Sidebar from "./components/Sidebar";
|
||||||
import ToolsTab from "./components/ToolsTab";
|
import ToolsTab from "./components/ToolsTab";
|
||||||
|
import { InspectorConfig } from "./lib/configurationTypes";
|
||||||
|
import {
|
||||||
|
getMCPProxyAddress,
|
||||||
|
getInitialSseUrl,
|
||||||
|
getInitialTransportType,
|
||||||
|
getInitialCommand,
|
||||||
|
getInitialArgs,
|
||||||
|
initializeInspectorConfig,
|
||||||
|
} from "./utils/configUtils";
|
||||||
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
const CONFIG_LOCAL_STORAGE_KEY = "inspectorConfig_v1";
|
||||||
const PROXY_PORT = params.get("proxyPort") ?? "3000";
|
|
||||||
const PROXY_SERVER_URL = `http://localhost:${PROXY_PORT}`;
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
// Handle OAuth callback route
|
|
||||||
if (window.location.pathname === "/oauth/callback") {
|
|
||||||
const OAuthCallback = React.lazy(
|
|
||||||
() => import("./components/OAuthCallback"),
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
<Suspense fallback={<div>Loading...</div>}>
|
|
||||||
<OAuthCallback />
|
|
||||||
</Suspense>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const [resources, setResources] = useState<Resource[]>([]);
|
const [resources, setResources] = useState<Resource[]>([]);
|
||||||
const [resourceTemplates, setResourceTemplates] = useState<
|
const [resourceTemplates, setResourceTemplates] = useState<
|
||||||
ResourceTemplate[]
|
ResourceTemplate[]
|
||||||
@@ -76,31 +83,32 @@ const App = () => {
|
|||||||
prompts: null,
|
prompts: null,
|
||||||
tools: null,
|
tools: null,
|
||||||
});
|
});
|
||||||
const [command, setCommand] = useState<string>(() => {
|
const [command, setCommand] = useState<string>(getInitialCommand);
|
||||||
return localStorage.getItem("lastCommand") || "mcp-server-everything";
|
const [args, setArgs] = useState<string>(getInitialArgs);
|
||||||
});
|
|
||||||
const [args, setArgs] = useState<string>(() => {
|
|
||||||
return localStorage.getItem("lastArgs") || "";
|
|
||||||
});
|
|
||||||
|
|
||||||
const [sseUrl, setSseUrl] = useState<string>(() => {
|
const [sseUrl, setSseUrl] = useState<string>(getInitialSseUrl);
|
||||||
return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse";
|
const [transportType, setTransportType] = useState<
|
||||||
});
|
"stdio" | "sse" | "streamable-http"
|
||||||
const [transportType, setTransportType] = useState<"stdio" | "sse">(() => {
|
>(getInitialTransportType);
|
||||||
return (
|
const [logLevel, setLogLevel] = useState<LoggingLevel>("debug");
|
||||||
(localStorage.getItem("lastTransportType") as "stdio" | "sse") || "stdio"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
const [notifications, setNotifications] = useState<ServerNotification[]>([]);
|
const [notifications, setNotifications] = useState<ServerNotification[]>([]);
|
||||||
const [stdErrNotifications, setStdErrNotifications] = useState<
|
const [stdErrNotifications, setStdErrNotifications] = useState<
|
||||||
StdErrNotification[]
|
StdErrNotification[]
|
||||||
>([]);
|
>([]);
|
||||||
const [roots, setRoots] = useState<Root[]>([]);
|
const [roots, setRoots] = useState<Root[]>([]);
|
||||||
const [env, setEnv] = useState<Record<string, string>>({});
|
const [env, setEnv] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
|
const [config, setConfig] = useState<InspectorConfig>(() =>
|
||||||
|
initializeInspectorConfig(CONFIG_LOCAL_STORAGE_KEY),
|
||||||
|
);
|
||||||
const [bearerToken, setBearerToken] = useState<string>(() => {
|
const [bearerToken, setBearerToken] = useState<string>(() => {
|
||||||
return localStorage.getItem("lastBearerToken") || "";
|
return localStorage.getItem("lastBearerToken") || "";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [headerName, setHeaderName] = useState<string>(() => {
|
||||||
|
return localStorage.getItem("lastHeaderName") || "";
|
||||||
|
});
|
||||||
|
|
||||||
const [pendingSampleRequests, setPendingSampleRequests] = useState<
|
const [pendingSampleRequests, setPendingSampleRequests] = useState<
|
||||||
Array<
|
Array<
|
||||||
PendingRequest & {
|
PendingRequest & {
|
||||||
@@ -109,25 +117,30 @@ const App = () => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
>([]);
|
>([]);
|
||||||
|
const [isAuthDebuggerVisible, setIsAuthDebuggerVisible] = useState(false);
|
||||||
|
|
||||||
|
// Auth debugger state
|
||||||
|
const [authState, setAuthState] = useState<AuthDebuggerState>({
|
||||||
|
isInitiatingAuth: false,
|
||||||
|
oauthTokens: null,
|
||||||
|
loading: true,
|
||||||
|
oauthStep: "metadata_discovery",
|
||||||
|
oauthMetadata: null,
|
||||||
|
oauthClientInfo: null,
|
||||||
|
authorizationUrl: null,
|
||||||
|
authorizationCode: "",
|
||||||
|
latestError: null,
|
||||||
|
statusMessage: null,
|
||||||
|
validationError: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Helper function to update specific auth state properties
|
||||||
|
const updateAuthState = (updates: Partial<AuthDebuggerState>) => {
|
||||||
|
setAuthState((prev) => ({ ...prev, ...updates }));
|
||||||
|
};
|
||||||
const nextRequestId = useRef(0);
|
const nextRequestId = useRef(0);
|
||||||
const rootsRef = useRef<Root[]>([]);
|
const rootsRef = useRef<Root[]>([]);
|
||||||
|
|
||||||
const handleApproveSampling = (id: number, result: CreateMessageResult) => {
|
|
||||||
setPendingSampleRequests((prev) => {
|
|
||||||
const request = prev.find((r) => r.id === id);
|
|
||||||
request?.resolve(result);
|
|
||||||
return prev.filter((r) => r.id !== id);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRejectSampling = (id: number) => {
|
|
||||||
setPendingSampleRequests((prev) => {
|
|
||||||
const request = prev.find((r) => r.id === id);
|
|
||||||
request?.reject(new Error("Sampling request rejected"));
|
|
||||||
return prev.filter((r) => r.id !== id);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const [selectedResource, setSelectedResource] = useState<Resource | null>(
|
const [selectedResource, setSelectedResource] = useState<Resource | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
@@ -156,11 +169,12 @@ const App = () => {
|
|||||||
serverCapabilities,
|
serverCapabilities,
|
||||||
mcpClient,
|
mcpClient,
|
||||||
requestHistory,
|
requestHistory,
|
||||||
makeRequest: makeConnectionRequest,
|
makeRequest,
|
||||||
sendNotification,
|
sendNotification,
|
||||||
handleCompletion,
|
handleCompletion,
|
||||||
completionsSupported,
|
completionsSupported,
|
||||||
connect: connectMcpServer,
|
connect: connectMcpServer,
|
||||||
|
disconnect: disconnectMcpServer,
|
||||||
} = useConnection({
|
} = useConnection({
|
||||||
transportType,
|
transportType,
|
||||||
command,
|
command,
|
||||||
@@ -168,7 +182,8 @@ const App = () => {
|
|||||||
sseUrl,
|
sseUrl,
|
||||||
env,
|
env,
|
||||||
bearerToken,
|
bearerToken,
|
||||||
proxyServerUrl: PROXY_SERVER_URL,
|
headerName,
|
||||||
|
config,
|
||||||
onNotification: (notification) => {
|
onNotification: (notification) => {
|
||||||
setNotifications((prev) => [...prev, notification as ServerNotification]);
|
setNotifications((prev) => [...prev, notification as ServerNotification]);
|
||||||
},
|
},
|
||||||
@@ -207,25 +222,79 @@ const App = () => {
|
|||||||
localStorage.setItem("lastBearerToken", bearerToken);
|
localStorage.setItem("lastBearerToken", bearerToken);
|
||||||
}, [bearerToken]);
|
}, [bearerToken]);
|
||||||
|
|
||||||
// Auto-connect if serverUrl is provided in URL params (e.g. after OAuth callback)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const serverUrl = params.get("serverUrl");
|
localStorage.setItem("lastHeaderName", headerName);
|
||||||
if (serverUrl) {
|
}, [headerName]);
|
||||||
setSseUrl(serverUrl);
|
|
||||||
setTransportType("sse");
|
|
||||||
// Remove serverUrl from URL without reloading the page
|
|
||||||
const newUrl = new URL(window.location.href);
|
|
||||||
newUrl.searchParams.delete("serverUrl");
|
|
||||||
window.history.replaceState({}, "", newUrl.toString());
|
|
||||||
// Show success toast for OAuth
|
|
||||||
toast.success("Successfully authenticated with OAuth");
|
|
||||||
// Connect to the server
|
|
||||||
connectMcpServer();
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${PROXY_SERVER_URL}/config`)
|
localStorage.setItem(CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
|
// Auto-connect to previously saved serverURL after OAuth callback
|
||||||
|
const onOAuthConnect = useCallback(
|
||||||
|
(serverUrl: string) => {
|
||||||
|
setSseUrl(serverUrl);
|
||||||
|
setTransportType("sse");
|
||||||
|
setIsAuthDebuggerVisible(false);
|
||||||
|
void connectMcpServer();
|
||||||
|
},
|
||||||
|
[connectMcpServer],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update OAuth debug state during debug callback
|
||||||
|
const onOAuthDebugConnect = useCallback(
|
||||||
|
({
|
||||||
|
authorizationCode,
|
||||||
|
errorMsg,
|
||||||
|
}: {
|
||||||
|
authorizationCode?: string;
|
||||||
|
errorMsg?: string;
|
||||||
|
}) => {
|
||||||
|
setIsAuthDebuggerVisible(true);
|
||||||
|
if (authorizationCode) {
|
||||||
|
updateAuthState({
|
||||||
|
authorizationCode,
|
||||||
|
oauthStep: "token_request",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (errorMsg) {
|
||||||
|
updateAuthState({
|
||||||
|
latestError: new Error(errorMsg),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Load OAuth tokens when sseUrl changes
|
||||||
|
useEffect(() => {
|
||||||
|
const loadOAuthTokens = async () => {
|
||||||
|
try {
|
||||||
|
if (sseUrl) {
|
||||||
|
const key = getServerSpecificKey(SESSION_KEYS.TOKENS, sseUrl);
|
||||||
|
const tokens = sessionStorage.getItem(key);
|
||||||
|
if (tokens) {
|
||||||
|
const parsedTokens = await OAuthTokensSchema.parseAsync(
|
||||||
|
JSON.parse(tokens),
|
||||||
|
);
|
||||||
|
updateAuthState({
|
||||||
|
oauthTokens: parsedTokens,
|
||||||
|
oauthStep: "complete",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading OAuth tokens:", error);
|
||||||
|
} finally {
|
||||||
|
updateAuthState({ loading: false });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadOAuthTokens();
|
||||||
|
}, [sseUrl]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch(`${getMCPProxyAddress(config)}/config`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setEnv(data.defaultEnvironment);
|
setEnv(data.defaultEnvironment);
|
||||||
@@ -239,6 +308,7 @@ const App = () => {
|
|||||||
.catch((error) =>
|
.catch((error) =>
|
||||||
console.error("Error fetching default environment:", error),
|
console.error("Error fetching default environment:", error),
|
||||||
);
|
);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -251,17 +321,33 @@ const App = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleApproveSampling = (id: number, result: CreateMessageResult) => {
|
||||||
|
setPendingSampleRequests((prev) => {
|
||||||
|
const request = prev.find((r) => r.id === id);
|
||||||
|
request?.resolve(result);
|
||||||
|
return prev.filter((r) => r.id !== id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRejectSampling = (id: number) => {
|
||||||
|
setPendingSampleRequests((prev) => {
|
||||||
|
const request = prev.find((r) => r.id === id);
|
||||||
|
request?.reject(new Error("Sampling request rejected"));
|
||||||
|
return prev.filter((r) => r.id !== id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const clearError = (tabKey: keyof typeof errors) => {
|
const clearError = (tabKey: keyof typeof errors) => {
|
||||||
setErrors((prev) => ({ ...prev, [tabKey]: null }));
|
setErrors((prev) => ({ ...prev, [tabKey]: null }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeRequest = async <T extends z.ZodType>(
|
const sendMCPRequest = async <T extends z.ZodType>(
|
||||||
request: ClientRequest,
|
request: ClientRequest,
|
||||||
schema: T,
|
schema: T,
|
||||||
tabKey?: keyof typeof errors,
|
tabKey?: keyof typeof errors,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const response = await makeConnectionRequest(request, schema);
|
const response = await makeRequest(request, schema);
|
||||||
if (tabKey !== undefined) {
|
if (tabKey !== undefined) {
|
||||||
clearError(tabKey);
|
clearError(tabKey);
|
||||||
}
|
}
|
||||||
@@ -279,7 +365,7 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const listResources = async () => {
|
const listResources = async () => {
|
||||||
const response = await makeRequest(
|
const response = await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "resources/list" as const,
|
method: "resources/list" as const,
|
||||||
params: nextResourceCursor ? { cursor: nextResourceCursor } : {},
|
params: nextResourceCursor ? { cursor: nextResourceCursor } : {},
|
||||||
@@ -292,7 +378,7 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const listResourceTemplates = async () => {
|
const listResourceTemplates = async () => {
|
||||||
const response = await makeRequest(
|
const response = await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "resources/templates/list" as const,
|
method: "resources/templates/list" as const,
|
||||||
params: nextResourceTemplateCursor
|
params: nextResourceTemplateCursor
|
||||||
@@ -309,7 +395,7 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const readResource = async (uri: string) => {
|
const readResource = async (uri: string) => {
|
||||||
const response = await makeRequest(
|
const response = await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "resources/read" as const,
|
method: "resources/read" as const,
|
||||||
params: { uri },
|
params: { uri },
|
||||||
@@ -322,7 +408,7 @@ const App = () => {
|
|||||||
|
|
||||||
const subscribeToResource = async (uri: string) => {
|
const subscribeToResource = async (uri: string) => {
|
||||||
if (!resourceSubscriptions.has(uri)) {
|
if (!resourceSubscriptions.has(uri)) {
|
||||||
await makeRequest(
|
await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "resources/subscribe" as const,
|
method: "resources/subscribe" as const,
|
||||||
params: { uri },
|
params: { uri },
|
||||||
@@ -338,7 +424,7 @@ const App = () => {
|
|||||||
|
|
||||||
const unsubscribeFromResource = async (uri: string) => {
|
const unsubscribeFromResource = async (uri: string) => {
|
||||||
if (resourceSubscriptions.has(uri)) {
|
if (resourceSubscriptions.has(uri)) {
|
||||||
await makeRequest(
|
await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "resources/unsubscribe" as const,
|
method: "resources/unsubscribe" as const,
|
||||||
params: { uri },
|
params: { uri },
|
||||||
@@ -353,7 +439,7 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const listPrompts = async () => {
|
const listPrompts = async () => {
|
||||||
const response = await makeRequest(
|
const response = await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "prompts/list" as const,
|
method: "prompts/list" as const,
|
||||||
params: nextPromptCursor ? { cursor: nextPromptCursor } : {},
|
params: nextPromptCursor ? { cursor: nextPromptCursor } : {},
|
||||||
@@ -366,7 +452,7 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getPrompt = async (name: string, args: Record<string, string> = {}) => {
|
const getPrompt = async (name: string, args: Record<string, string> = {}) => {
|
||||||
const response = await makeRequest(
|
const response = await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "prompts/get" as const,
|
method: "prompts/get" as const,
|
||||||
params: { name, arguments: args },
|
params: { name, arguments: args },
|
||||||
@@ -378,7 +464,7 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const listTools = async () => {
|
const listTools = async () => {
|
||||||
const response = await makeRequest(
|
const response = await sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "tools/list" as const,
|
method: "tools/list" as const,
|
||||||
params: nextToolCursor ? { cursor: nextToolCursor } : {},
|
params: nextToolCursor ? { cursor: nextToolCursor } : {},
|
||||||
@@ -391,27 +477,90 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const callTool = async (name: string, params: Record<string, unknown>) => {
|
const callTool = async (name: string, params: Record<string, unknown>) => {
|
||||||
const response = await makeRequest(
|
try {
|
||||||
{
|
const response = await sendMCPRequest(
|
||||||
method: "tools/call" as const,
|
{
|
||||||
params: {
|
method: "tools/call" as const,
|
||||||
name,
|
params: {
|
||||||
arguments: params,
|
name,
|
||||||
_meta: {
|
arguments: params,
|
||||||
progressToken: progressTokenRef.current++,
|
_meta: {
|
||||||
|
progressToken: progressTokenRef.current++,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
CompatibilityCallToolResultSchema,
|
||||||
CompatibilityCallToolResultSchema,
|
"tools",
|
||||||
"tools",
|
);
|
||||||
);
|
setToolResult(response);
|
||||||
setToolResult(response);
|
} catch (e) {
|
||||||
|
const toolResult: CompatibilityCallToolResult = {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: (e as Error).message ?? String(e),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
isError: true,
|
||||||
|
};
|
||||||
|
setToolResult(toolResult);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRootsChange = async () => {
|
const handleRootsChange = async () => {
|
||||||
await sendNotification({ method: "notifications/roots/list_changed" });
|
await sendNotification({ method: "notifications/roots/list_changed" });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sendLogLevelRequest = async (level: LoggingLevel) => {
|
||||||
|
await sendMCPRequest(
|
||||||
|
{
|
||||||
|
method: "logging/setLevel" as const,
|
||||||
|
params: { level },
|
||||||
|
},
|
||||||
|
z.object({}),
|
||||||
|
);
|
||||||
|
setLogLevel(level);
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearStdErrNotifications = () => {
|
||||||
|
setStdErrNotifications([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper component for rendering the AuthDebugger
|
||||||
|
const AuthDebuggerWrapper = () => (
|
||||||
|
<TabsContent value="auth">
|
||||||
|
<AuthDebugger
|
||||||
|
serverUrl={sseUrl}
|
||||||
|
onBack={() => setIsAuthDebuggerVisible(false)}
|
||||||
|
authState={authState}
|
||||||
|
updateAuthState={updateAuthState}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Helper function to render OAuth callback components
|
||||||
|
if (window.location.pathname === "/oauth/callback") {
|
||||||
|
const OAuthCallback = React.lazy(
|
||||||
|
() => import("./components/OAuthCallback"),
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
|
<OAuthCallback onConnect={onOAuthConnect} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.location.pathname === "/oauth/callback/debug") {
|
||||||
|
const OAuthDebugCallback = React.lazy(
|
||||||
|
() => import("./components/OAuthDebugCallback"),
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
|
<OAuthDebugCallback onConnect={onOAuthDebugConnect} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-background">
|
<div className="flex h-screen bg-background">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
@@ -426,10 +575,19 @@ const App = () => {
|
|||||||
setSseUrl={setSseUrl}
|
setSseUrl={setSseUrl}
|
||||||
env={env}
|
env={env}
|
||||||
setEnv={setEnv}
|
setEnv={setEnv}
|
||||||
|
config={config}
|
||||||
|
setConfig={setConfig}
|
||||||
bearerToken={bearerToken}
|
bearerToken={bearerToken}
|
||||||
setBearerToken={setBearerToken}
|
setBearerToken={setBearerToken}
|
||||||
|
headerName={headerName}
|
||||||
|
setHeaderName={setHeaderName}
|
||||||
onConnect={connectMcpServer}
|
onConnect={connectMcpServer}
|
||||||
|
onDisconnect={disconnectMcpServer}
|
||||||
stdErrNotifications={stdErrNotifications}
|
stdErrNotifications={stdErrNotifications}
|
||||||
|
logLevel={logLevel}
|
||||||
|
sendLogLevelRequest={sendLogLevelRequest}
|
||||||
|
loggingSupported={!!serverCapabilities?.logging || false}
|
||||||
|
clearStdErrNotifications={clearStdErrNotifications}
|
||||||
/>
|
/>
|
||||||
<div className="flex-1 flex flex-col overflow-hidden">
|
<div className="flex-1 flex flex-col overflow-hidden">
|
||||||
<div className="flex-1 overflow-auto">
|
<div className="flex-1 overflow-auto">
|
||||||
@@ -490,17 +648,34 @@ const App = () => {
|
|||||||
<FolderTree className="w-4 h-4 mr-2" />
|
<FolderTree className="w-4 h-4 mr-2" />
|
||||||
Roots
|
Roots
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="auth">
|
||||||
|
<Key className="w-4 h-4 mr-2" />
|
||||||
|
Auth
|
||||||
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
{!serverCapabilities?.resources &&
|
{!serverCapabilities?.resources &&
|
||||||
!serverCapabilities?.prompts &&
|
!serverCapabilities?.prompts &&
|
||||||
!serverCapabilities?.tools ? (
|
!serverCapabilities?.tools ? (
|
||||||
<div className="flex items-center justify-center p-4">
|
<>
|
||||||
<p className="text-lg text-gray-500">
|
<div className="flex items-center justify-center p-4">
|
||||||
The connected server does not support any MCP capabilities
|
<p className="text-lg text-gray-500">
|
||||||
</p>
|
The connected server does not support any MCP
|
||||||
</div>
|
capabilities
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<PingTab
|
||||||
|
onPingClick={() => {
|
||||||
|
void sendMCPRequest(
|
||||||
|
{
|
||||||
|
method: "ping" as const,
|
||||||
|
},
|
||||||
|
EmptyResultSchema,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<ResourcesTab
|
<ResourcesTab
|
||||||
@@ -568,6 +743,7 @@ const App = () => {
|
|||||||
setSelectedPrompt={(prompt) => {
|
setSelectedPrompt={(prompt) => {
|
||||||
clearError("prompts");
|
clearError("prompts");
|
||||||
setSelectedPrompt(prompt);
|
setSelectedPrompt(prompt);
|
||||||
|
setPromptContent("");
|
||||||
}}
|
}}
|
||||||
handleCompletion={handleCompletion}
|
handleCompletion={handleCompletion}
|
||||||
completionsSupported={completionsSupported}
|
completionsSupported={completionsSupported}
|
||||||
@@ -585,9 +761,10 @@ const App = () => {
|
|||||||
setTools([]);
|
setTools([]);
|
||||||
setNextToolCursor(undefined);
|
setNextToolCursor(undefined);
|
||||||
}}
|
}}
|
||||||
callTool={(name, params) => {
|
callTool={async (name, params) => {
|
||||||
clearError("tools");
|
clearError("tools");
|
||||||
callTool(name, params);
|
setToolResult(null);
|
||||||
|
await callTool(name, params);
|
||||||
}}
|
}}
|
||||||
selectedTool={selectedTool}
|
selectedTool={selectedTool}
|
||||||
setSelectedTool={(tool) => {
|
setSelectedTool={(tool) => {
|
||||||
@@ -602,7 +779,7 @@ const App = () => {
|
|||||||
<ConsoleTab />
|
<ConsoleTab />
|
||||||
<PingTab
|
<PingTab
|
||||||
onPingClick={() => {
|
onPingClick={() => {
|
||||||
void makeRequest(
|
void sendMCPRequest(
|
||||||
{
|
{
|
||||||
method: "ping" as const,
|
method: "ping" as const,
|
||||||
},
|
},
|
||||||
@@ -620,15 +797,36 @@ const App = () => {
|
|||||||
setRoots={setRoots}
|
setRoots={setRoots}
|
||||||
onRootsChange={handleRootsChange}
|
onRootsChange={handleRootsChange}
|
||||||
/>
|
/>
|
||||||
|
<AuthDebuggerWrapper />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
) : isAuthDebuggerVisible ? (
|
||||||
|
<Tabs
|
||||||
|
defaultValue={"auth"}
|
||||||
|
className="w-full p-4"
|
||||||
|
onValueChange={(value) => (window.location.hash = value)}
|
||||||
|
>
|
||||||
|
<AuthDebuggerWrapper />
|
||||||
|
</Tabs>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex items-center justify-center h-full">
|
<div className="flex flex-col items-center justify-center h-full gap-4">
|
||||||
<p className="text-lg text-gray-500">
|
<p className="text-lg text-gray-500">
|
||||||
Connect to an MCP server to start inspecting
|
Connect to an MCP server to start inspecting
|
||||||
</p>
|
</p>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Need to configure authentication?
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setIsAuthDebuggerVisible(true)}
|
||||||
|
>
|
||||||
|
Open Auth Settings
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
1
client/src/__mocks__/styleMock.js
Normal file
1
client/src/__mocks__/styleMock.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {};
|
||||||
260
client/src/components/AuthDebugger.tsx
Normal file
260
client/src/components/AuthDebugger.tsx
Normal file
@@ -0,0 +1,260 @@
|
|||||||
|
import { useCallback, useMemo } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { DebugInspectorOAuthClientProvider } from "../lib/auth";
|
||||||
|
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
||||||
|
import { AlertCircle } from "lucide-react";
|
||||||
|
import { AuthDebuggerState } from "../lib/auth-types";
|
||||||
|
import { OAuthFlowProgress } from "./OAuthFlowProgress";
|
||||||
|
import { OAuthStateMachine } from "../lib/oauth-state-machine";
|
||||||
|
|
||||||
|
export interface AuthDebuggerProps {
|
||||||
|
serverUrl: string;
|
||||||
|
onBack: () => void;
|
||||||
|
authState: AuthDebuggerState;
|
||||||
|
updateAuthState: (updates: Partial<AuthDebuggerState>) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StatusMessageProps {
|
||||||
|
message: { type: "error" | "success" | "info"; message: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatusMessage = ({ message }: StatusMessageProps) => {
|
||||||
|
let bgColor: string;
|
||||||
|
let textColor: string;
|
||||||
|
let borderColor: string;
|
||||||
|
|
||||||
|
switch (message.type) {
|
||||||
|
case "error":
|
||||||
|
bgColor = "bg-red-50";
|
||||||
|
textColor = "text-red-700";
|
||||||
|
borderColor = "border-red-200";
|
||||||
|
break;
|
||||||
|
case "success":
|
||||||
|
bgColor = "bg-green-50";
|
||||||
|
textColor = "text-green-700";
|
||||||
|
borderColor = "border-green-200";
|
||||||
|
break;
|
||||||
|
case "info":
|
||||||
|
default:
|
||||||
|
bgColor = "bg-blue-50";
|
||||||
|
textColor = "text-blue-700";
|
||||||
|
borderColor = "border-blue-200";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`p-3 rounded-md border ${bgColor} ${borderColor} ${textColor} mb-4`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<p className="text-sm">{message.message}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const AuthDebugger = ({
|
||||||
|
serverUrl: serverUrl,
|
||||||
|
onBack,
|
||||||
|
authState,
|
||||||
|
updateAuthState,
|
||||||
|
}: AuthDebuggerProps) => {
|
||||||
|
const startOAuthFlow = useCallback(() => {
|
||||||
|
if (!serverUrl) {
|
||||||
|
updateAuthState({
|
||||||
|
statusMessage: {
|
||||||
|
type: "error",
|
||||||
|
message:
|
||||||
|
"Please enter a server URL in the sidebar before authenticating",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateAuthState({
|
||||||
|
oauthStep: "metadata_discovery",
|
||||||
|
authorizationUrl: null,
|
||||||
|
statusMessage: null,
|
||||||
|
latestError: null,
|
||||||
|
});
|
||||||
|
}, [serverUrl, updateAuthState]);
|
||||||
|
|
||||||
|
const stateMachine = useMemo(
|
||||||
|
() => new OAuthStateMachine(serverUrl, updateAuthState),
|
||||||
|
[serverUrl, updateAuthState],
|
||||||
|
);
|
||||||
|
|
||||||
|
const proceedToNextStep = useCallback(async () => {
|
||||||
|
if (!serverUrl) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateAuthState({
|
||||||
|
isInitiatingAuth: true,
|
||||||
|
statusMessage: null,
|
||||||
|
latestError: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
await stateMachine.executeStep(authState);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("OAuth flow error:", error);
|
||||||
|
updateAuthState({
|
||||||
|
latestError: error instanceof Error ? error : new Error(String(error)),
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
updateAuthState({ isInitiatingAuth: false });
|
||||||
|
}
|
||||||
|
}, [serverUrl, authState, updateAuthState, stateMachine]);
|
||||||
|
|
||||||
|
const handleQuickOAuth = useCallback(async () => {
|
||||||
|
if (!serverUrl) {
|
||||||
|
updateAuthState({
|
||||||
|
statusMessage: {
|
||||||
|
type: "error",
|
||||||
|
message:
|
||||||
|
"Please enter a server URL in the sidebar before authenticating",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateAuthState({ isInitiatingAuth: true, statusMessage: null });
|
||||||
|
try {
|
||||||
|
const serverAuthProvider = new DebugInspectorOAuthClientProvider(
|
||||||
|
serverUrl,
|
||||||
|
);
|
||||||
|
await auth(serverAuthProvider, { serverUrl: serverUrl });
|
||||||
|
updateAuthState({
|
||||||
|
statusMessage: {
|
||||||
|
type: "info",
|
||||||
|
message: "Starting OAuth authentication process...",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("OAuth initialization error:", error);
|
||||||
|
updateAuthState({
|
||||||
|
statusMessage: {
|
||||||
|
type: "error",
|
||||||
|
message: `Failed to start OAuth flow: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
updateAuthState({ isInitiatingAuth: false });
|
||||||
|
}
|
||||||
|
}, [serverUrl, updateAuthState]);
|
||||||
|
|
||||||
|
const handleClearOAuth = useCallback(() => {
|
||||||
|
if (serverUrl) {
|
||||||
|
const serverAuthProvider = new DebugInspectorOAuthClientProvider(
|
||||||
|
serverUrl,
|
||||||
|
);
|
||||||
|
serverAuthProvider.clear();
|
||||||
|
updateAuthState({
|
||||||
|
oauthTokens: null,
|
||||||
|
oauthStep: "metadata_discovery",
|
||||||
|
latestError: null,
|
||||||
|
oauthClientInfo: null,
|
||||||
|
authorizationCode: "",
|
||||||
|
validationError: null,
|
||||||
|
oauthMetadata: null,
|
||||||
|
statusMessage: {
|
||||||
|
type: "success",
|
||||||
|
message: "OAuth tokens cleared successfully",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear success message after 3 seconds
|
||||||
|
setTimeout(() => {
|
||||||
|
updateAuthState({ statusMessage: null });
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
}, [serverUrl, updateAuthState]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full p-4">
|
||||||
|
<div className="flex justify-between items-center mb-6">
|
||||||
|
<h2 className="text-2xl font-bold">Authentication Settings</h2>
|
||||||
|
<Button variant="outline" onClick={onBack}>
|
||||||
|
Back to Connect
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-full space-y-6">
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<div className="grid w-full gap-2">
|
||||||
|
<p className="text-muted-foreground mb-4">
|
||||||
|
Configure authentication settings for your MCP server connection.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="rounded-md border p-6 space-y-6">
|
||||||
|
<h3 className="text-lg font-medium">OAuth Authentication</h3>
|
||||||
|
<p className="text-sm text-muted-foreground mb-2">
|
||||||
|
Use OAuth to securely authenticate with the MCP server.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{authState.statusMessage && (
|
||||||
|
<StatusMessage message={authState.statusMessage} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{authState.loading ? (
|
||||||
|
<p>Loading authentication status...</p>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{authState.oauthTokens && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-sm font-medium">Access Token:</p>
|
||||||
|
<div className="bg-muted p-2 rounded-md text-xs overflow-x-auto">
|
||||||
|
{authState.oauthTokens.access_token.substring(0, 25)}...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex gap-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={startOAuthFlow}
|
||||||
|
disabled={authState.isInitiatingAuth}
|
||||||
|
>
|
||||||
|
{authState.oauthTokens
|
||||||
|
? "Guided Token Refresh"
|
||||||
|
: "Guided OAuth Flow"}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleQuickOAuth}
|
||||||
|
disabled={authState.isInitiatingAuth}
|
||||||
|
>
|
||||||
|
{authState.isInitiatingAuth
|
||||||
|
? "Initiating..."
|
||||||
|
: authState.oauthTokens
|
||||||
|
? "Quick Refresh"
|
||||||
|
: "Quick OAuth Flow"}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button variant="outline" onClick={handleClearOAuth}>
|
||||||
|
Clear OAuth State
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Choose "Guided" for step-by-step instructions or "Quick" for
|
||||||
|
the standard automatic flow.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<OAuthFlowProgress
|
||||||
|
serverUrl={serverUrl}
|
||||||
|
authState={authState}
|
||||||
|
updateAuthState={updateAuthState}
|
||||||
|
proceedToNextStep={proceedToNextStep}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AuthDebugger;
|
||||||
@@ -1,25 +1,10 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
|
||||||
import JsonEditor from "./JsonEditor";
|
import JsonEditor from "./JsonEditor";
|
||||||
|
import { updateValueAtPath } from "@/utils/jsonUtils";
|
||||||
export type JsonValue =
|
import { generateDefaultValue } from "@/utils/schemaUtils";
|
||||||
| string
|
import type { JsonValue, JsonSchemaType } from "@/utils/jsonUtils";
|
||||||
| number
|
|
||||||
| boolean
|
|
||||||
| null
|
|
||||||
| JsonValue[]
|
|
||||||
| { [key: string]: JsonValue };
|
|
||||||
|
|
||||||
export type JsonSchemaType = {
|
|
||||||
type: "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
||||||
description?: string;
|
|
||||||
properties?: Record<string, JsonSchemaType>;
|
|
||||||
items?: JsonSchemaType;
|
|
||||||
};
|
|
||||||
|
|
||||||
type JsonObject = { [key: string]: JsonValue };
|
|
||||||
|
|
||||||
interface DynamicJsonFormProps {
|
interface DynamicJsonFormProps {
|
||||||
schema: JsonSchemaType;
|
schema: JsonSchemaType;
|
||||||
@@ -28,11 +13,13 @@ interface DynamicJsonFormProps {
|
|||||||
maxDepth?: number;
|
maxDepth?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatFieldLabel = (key: string): string => {
|
const isSimpleObject = (schema: JsonSchemaType): boolean => {
|
||||||
return key
|
const supportedTypes = ["string", "number", "integer", "boolean", "null"];
|
||||||
.replace(/([A-Z])/g, " $1") // Insert space before capital letters
|
if (supportedTypes.includes(schema.type)) return true;
|
||||||
.replace(/_/g, " ") // Replace underscores with spaces
|
if (schema.type !== "object") return false;
|
||||||
.replace(/^\w/, (c) => c.toUpperCase()); // Capitalize first letter
|
return Object.values(schema.properties ?? {}).every((prop) =>
|
||||||
|
supportedTypes.includes(prop.type),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const DynamicJsonForm = ({
|
const DynamicJsonForm = ({
|
||||||
@@ -41,31 +28,83 @@ const DynamicJsonForm = ({
|
|||||||
onChange,
|
onChange,
|
||||||
maxDepth = 3,
|
maxDepth = 3,
|
||||||
}: DynamicJsonFormProps) => {
|
}: DynamicJsonFormProps) => {
|
||||||
const [isJsonMode, setIsJsonMode] = useState(false);
|
const isOnlyJSON = !isSimpleObject(schema);
|
||||||
|
const [isJsonMode, setIsJsonMode] = useState(isOnlyJSON);
|
||||||
const [jsonError, setJsonError] = useState<string>();
|
const [jsonError, setJsonError] = useState<string>();
|
||||||
|
// Store the raw JSON string to allow immediate feedback during typing
|
||||||
|
// while deferring parsing until the user stops typing
|
||||||
|
const [rawJsonValue, setRawJsonValue] = useState<string>(
|
||||||
|
JSON.stringify(value ?? generateDefaultValue(schema), null, 2),
|
||||||
|
);
|
||||||
|
|
||||||
const generateDefaultValue = (propSchema: JsonSchemaType): JsonValue => {
|
// Use a ref to manage debouncing timeouts to avoid parsing JSON
|
||||||
switch (propSchema.type) {
|
// on every keystroke which would be inefficient and error-prone
|
||||||
case "string":
|
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
||||||
return "";
|
|
||||||
case "number":
|
// Debounce JSON parsing and parent updates to handle typing gracefully
|
||||||
case "integer":
|
const debouncedUpdateParent = useCallback(
|
||||||
return 0;
|
(jsonString: string) => {
|
||||||
case "boolean":
|
// Clear any existing timeout
|
||||||
return false;
|
if (timeoutRef.current) {
|
||||||
case "array":
|
clearTimeout(timeoutRef.current);
|
||||||
return [];
|
|
||||||
case "object": {
|
|
||||||
const obj: JsonObject = {};
|
|
||||||
if (propSchema.properties) {
|
|
||||||
Object.entries(propSchema.properties).forEach(([key, prop]) => {
|
|
||||||
obj[key] = generateDefaultValue(prop);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
return null;
|
// Set a new timeout
|
||||||
|
timeoutRef.current = setTimeout(() => {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(jsonString);
|
||||||
|
onChange(parsed);
|
||||||
|
setJsonError(undefined);
|
||||||
|
} catch {
|
||||||
|
// Don't set error during normal typing
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
},
|
||||||
|
[onChange, setJsonError],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update rawJsonValue when value prop changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isJsonMode) {
|
||||||
|
setRawJsonValue(
|
||||||
|
JSON.stringify(value ?? generateDefaultValue(schema), null, 2),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [value, schema, isJsonMode]);
|
||||||
|
|
||||||
|
const handleSwitchToFormMode = () => {
|
||||||
|
if (isJsonMode) {
|
||||||
|
// When switching to Form mode, ensure we have valid JSON
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(rawJsonValue);
|
||||||
|
// Update the parent component's state with the parsed value
|
||||||
|
onChange(parsed);
|
||||||
|
// Switch to form mode
|
||||||
|
setIsJsonMode(false);
|
||||||
|
} catch (err) {
|
||||||
|
setJsonError(err instanceof Error ? err.message : "Invalid JSON");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Update raw JSON value when switching to JSON mode
|
||||||
|
setRawJsonValue(
|
||||||
|
JSON.stringify(value ?? generateDefaultValue(schema), null, 2),
|
||||||
|
);
|
||||||
|
setIsJsonMode(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatJson = () => {
|
||||||
|
try {
|
||||||
|
const jsonStr = rawJsonValue.trim();
|
||||||
|
if (!jsonStr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const formatted = JSON.stringify(JSON.parse(jsonStr), null, 2);
|
||||||
|
setRawJsonValue(formatted);
|
||||||
|
debouncedUpdateParent(formatted);
|
||||||
|
setJsonError(undefined);
|
||||||
|
} catch (err) {
|
||||||
|
setJsonError(err instanceof Error ? err.message : "Invalid JSON");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,21 +142,68 @@ const DynamicJsonForm = ({
|
|||||||
|
|
||||||
switch (propSchema.type) {
|
switch (propSchema.type) {
|
||||||
case "string":
|
case "string":
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
value={(currentValue as string) ?? ""}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
// Allow clearing non-required fields by setting undefined
|
||||||
|
// This preserves the distinction between empty string and unset
|
||||||
|
if (!val && !propSchema.required) {
|
||||||
|
handleFieldChange(path, undefined);
|
||||||
|
} else {
|
||||||
|
handleFieldChange(path, val);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder={propSchema.description}
|
||||||
|
required={propSchema.required}
|
||||||
|
/>
|
||||||
|
);
|
||||||
case "number":
|
case "number":
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={(currentValue as number)?.toString() ?? ""}
|
||||||
|
onChange={(e) => {
|
||||||
|
const val = e.target.value;
|
||||||
|
// Allow clearing non-required number fields
|
||||||
|
// This preserves the distinction between 0 and unset
|
||||||
|
if (!val && !propSchema.required) {
|
||||||
|
handleFieldChange(path, undefined);
|
||||||
|
} else {
|
||||||
|
const num = Number(val);
|
||||||
|
if (!isNaN(num)) {
|
||||||
|
handleFieldChange(path, num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder={propSchema.description}
|
||||||
|
required={propSchema.required}
|
||||||
|
/>
|
||||||
|
);
|
||||||
case "integer":
|
case "integer":
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
type={propSchema.type === "string" ? "text" : "number"}
|
type="number"
|
||||||
value={(currentValue as string | number) ?? ""}
|
step="1"
|
||||||
onChange={(e) =>
|
value={(currentValue as number)?.toString() ?? ""}
|
||||||
handleFieldChange(
|
onChange={(e) => {
|
||||||
path,
|
const val = e.target.value;
|
||||||
propSchema.type === "string"
|
// Allow clearing non-required integer fields
|
||||||
? e.target.value
|
// This preserves the distinction between 0 and unset
|
||||||
: Number(e.target.value),
|
if (!val && !propSchema.required) {
|
||||||
)
|
handleFieldChange(path, undefined);
|
||||||
}
|
} else {
|
||||||
|
const num = Number(val);
|
||||||
|
// Only update if it's a valid integer
|
||||||
|
if (!isNaN(num) && Number.isInteger(num)) {
|
||||||
|
handleFieldChange(path, num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
placeholder={propSchema.description}
|
placeholder={propSchema.description}
|
||||||
|
required={propSchema.required}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "boolean":
|
case "boolean":
|
||||||
@@ -127,83 +213,9 @@ const DynamicJsonForm = ({
|
|||||||
checked={(currentValue as boolean) ?? false}
|
checked={(currentValue as boolean) ?? false}
|
||||||
onChange={(e) => handleFieldChange(path, e.target.checked)}
|
onChange={(e) => handleFieldChange(path, e.target.checked)}
|
||||||
className="w-4 h-4"
|
className="w-4 h-4"
|
||||||
|
required={propSchema.required}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "object":
|
|
||||||
if (!propSchema.properties) return null;
|
|
||||||
return (
|
|
||||||
<div className="space-y-4 border rounded-md p-4">
|
|
||||||
{Object.entries(propSchema.properties).map(([key, prop]) => (
|
|
||||||
<div key={key} className="space-y-2">
|
|
||||||
<Label>{formatFieldLabel(key)}</Label>
|
|
||||||
{renderFormFields(
|
|
||||||
prop,
|
|
||||||
(currentValue as JsonObject)?.[key],
|
|
||||||
[...path, key],
|
|
||||||
depth + 1,
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
case "array": {
|
|
||||||
const arrayValue = Array.isArray(currentValue) ? currentValue : [];
|
|
||||||
if (!propSchema.items) return null;
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
{propSchema.description && (
|
|
||||||
<p className="text-sm text-gray-600">{propSchema.description}</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{propSchema.items?.description && (
|
|
||||||
<p className="text-sm text-gray-500">
|
|
||||||
Items: {propSchema.items.description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
{arrayValue.map((item, index) => (
|
|
||||||
<div key={index} className="flex items-center gap-2">
|
|
||||||
{renderFormFields(
|
|
||||||
propSchema.items as JsonSchemaType,
|
|
||||||
item,
|
|
||||||
[...path, index.toString()],
|
|
||||||
depth + 1,
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => {
|
|
||||||
const newArray = [...arrayValue];
|
|
||||||
newArray.splice(index, 1);
|
|
||||||
handleFieldChange(path, newArray);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => {
|
|
||||||
handleFieldChange(path, [
|
|
||||||
...arrayValue,
|
|
||||||
generateDefaultValue(propSchema.items as JsonSchemaType),
|
|
||||||
]);
|
|
||||||
}}
|
|
||||||
title={
|
|
||||||
propSchema.items?.description
|
|
||||||
? `Add new ${propSchema.items.description}`
|
|
||||||
: "Add new item"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Add Item
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -215,139 +227,77 @@ const DynamicJsonForm = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateArray = (
|
|
||||||
array: JsonValue[],
|
|
||||||
path: string[],
|
|
||||||
value: JsonValue,
|
|
||||||
): JsonValue[] => {
|
|
||||||
const [index, ...restPath] = path;
|
|
||||||
const arrayIndex = Number(index);
|
|
||||||
|
|
||||||
// Validate array index
|
|
||||||
if (isNaN(arrayIndex)) {
|
|
||||||
console.error(`Invalid array index: ${index}`);
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check array bounds
|
|
||||||
if (arrayIndex < 0) {
|
|
||||||
console.error(`Array index out of bounds: ${arrayIndex} < 0`);
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newArray = [...array];
|
|
||||||
|
|
||||||
if (restPath.length === 0) {
|
|
||||||
newArray[arrayIndex] = value;
|
|
||||||
} else {
|
|
||||||
// Ensure index position exists
|
|
||||||
if (arrayIndex >= array.length) {
|
|
||||||
console.warn(`Extending array to index ${arrayIndex}`);
|
|
||||||
newArray.length = arrayIndex + 1;
|
|
||||||
newArray.fill(null, array.length, arrayIndex);
|
|
||||||
}
|
|
||||||
newArray[arrayIndex] = updateValue(
|
|
||||||
newArray[arrayIndex],
|
|
||||||
restPath,
|
|
||||||
value,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return newArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateObject = (
|
|
||||||
obj: JsonObject,
|
|
||||||
path: string[],
|
|
||||||
value: JsonValue,
|
|
||||||
): JsonObject => {
|
|
||||||
const [key, ...restPath] = path;
|
|
||||||
|
|
||||||
// Validate object key
|
|
||||||
if (typeof key !== "string") {
|
|
||||||
console.error(`Invalid object key: ${key}`);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newObj = { ...obj };
|
|
||||||
|
|
||||||
if (restPath.length === 0) {
|
|
||||||
newObj[key] = value;
|
|
||||||
} else {
|
|
||||||
// Ensure key exists
|
|
||||||
if (!(key in newObj)) {
|
|
||||||
console.warn(`Creating new key in object: ${key}`);
|
|
||||||
newObj[key] = {};
|
|
||||||
}
|
|
||||||
newObj[key] = updateValue(newObj[key], restPath, value);
|
|
||||||
}
|
|
||||||
return newObj;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateValue = (
|
|
||||||
current: JsonValue,
|
|
||||||
path: string[],
|
|
||||||
value: JsonValue,
|
|
||||||
): JsonValue => {
|
|
||||||
if (path.length === 0) return value;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!current) {
|
|
||||||
current = !isNaN(Number(path[0])) ? [] : {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type checking
|
|
||||||
if (Array.isArray(current)) {
|
|
||||||
return updateArray(current, path, value);
|
|
||||||
} else if (typeof current === "object" && current !== null) {
|
|
||||||
return updateObject(current, path, value);
|
|
||||||
} else {
|
|
||||||
console.error(
|
|
||||||
`Cannot update path ${path.join(".")} in non-object/array value:`,
|
|
||||||
current,
|
|
||||||
);
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error updating value at path ${path.join(".")}:`, error);
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newValue = updateValue(value, path, fieldValue);
|
const newValue = updateValueAtPath(value, path, fieldValue);
|
||||||
onChange(newValue);
|
onChange(newValue);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update form value:", error);
|
console.error("Failed to update form value:", error);
|
||||||
// Keep the original value unchanged
|
|
||||||
onChange(value);
|
onChange(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const shouldUseJsonMode =
|
||||||
|
schema.type === "object" &&
|
||||||
|
(!schema.properties || Object.keys(schema.properties).length === 0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (shouldUseJsonMode && !isJsonMode) {
|
||||||
|
setIsJsonMode(true);
|
||||||
|
}
|
||||||
|
}, [shouldUseJsonMode, isJsonMode]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end space-x-2">
|
||||||
<Button
|
{isJsonMode && (
|
||||||
variant="outline"
|
<Button
|
||||||
size="sm"
|
type="button"
|
||||||
onClick={() => setIsJsonMode(!isJsonMode)}
|
variant="outline"
|
||||||
>
|
size="sm"
|
||||||
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
|
onClick={formatJson}
|
||||||
</Button>
|
>
|
||||||
|
Format JSON
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{!isOnlyJSON && (
|
||||||
|
<Button variant="outline" size="sm" onClick={handleSwitchToFormMode}>
|
||||||
|
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isJsonMode ? (
|
{isJsonMode ? (
|
||||||
<JsonEditor
|
<JsonEditor
|
||||||
value={JSON.stringify(value ?? generateDefaultValue(schema), null, 2)}
|
value={rawJsonValue}
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
try {
|
// Always update local state
|
||||||
onChange(JSON.parse(newValue));
|
setRawJsonValue(newValue);
|
||||||
setJsonError(undefined);
|
|
||||||
} catch (err) {
|
// Use the debounced function to attempt parsing and updating parent
|
||||||
setJsonError(err instanceof Error ? err.message : "Invalid JSON");
|
debouncedUpdateParent(newValue);
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
error={jsonError}
|
error={jsonError}
|
||||||
/>
|
/>
|
||||||
|
) : // If schema type is object but value is not an object or is empty, and we have actual JSON data,
|
||||||
|
// render a simple representation of the JSON data
|
||||||
|
schema.type === "object" &&
|
||||||
|
(typeof value !== "object" ||
|
||||||
|
value === null ||
|
||||||
|
Object.keys(value).length === 0) &&
|
||||||
|
rawJsonValue &&
|
||||||
|
rawJsonValue !== "{}" ? (
|
||||||
|
<div className="space-y-4 border rounded-md p-4">
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Form view not available for this JSON structure. Using simplified
|
||||||
|
view:
|
||||||
|
</p>
|
||||||
|
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto">
|
||||||
|
{rawJsonValue}
|
||||||
|
</pre>
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Use JSON mode for full editing capabilities.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
renderFormFields(schema, value)
|
renderFormFields(schema, value)
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ServerNotification } from "@modelcontextprotocol/sdk/types.js";
|
import { ServerNotification } from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { Copy } from "lucide-react";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import JsonView from "./JsonView";
|
||||||
|
|
||||||
const HistoryAndNotifications = ({
|
const HistoryAndNotifications = ({
|
||||||
requestHistory,
|
requestHistory,
|
||||||
@@ -24,10 +24,6 @@ const HistoryAndNotifications = ({
|
|||||||
setExpandedNotifications((prev) => ({ ...prev, [index]: !prev[index] }));
|
setExpandedNotifications((prev) => ({ ...prev, [index]: !prev[index] }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyToClipboard = (text: string) => {
|
|
||||||
navigator.clipboard.writeText(text);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-card overflow-hidden flex h-full">
|
<div className="bg-card overflow-hidden flex h-full">
|
||||||
<div className="flex-1 overflow-y-auto p-4 border-r">
|
<div className="flex-1 overflow-y-auto p-4 border-r">
|
||||||
@@ -67,16 +63,12 @@ const HistoryAndNotifications = ({
|
|||||||
<span className="font-semibold text-blue-600">
|
<span className="font-semibold text-blue-600">
|
||||||
Request:
|
Request:
|
||||||
</span>
|
</span>
|
||||||
<button
|
|
||||||
onClick={() => copyToClipboard(request.request)}
|
|
||||||
className="text-blue-500 hover:text-blue-700"
|
|
||||||
>
|
|
||||||
<Copy size={16} />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<pre className="whitespace-pre-wrap break-words bg-background p-2 rounded">
|
|
||||||
{JSON.stringify(JSON.parse(request.request), null, 2)}
|
<JsonView
|
||||||
</pre>
|
data={request.request}
|
||||||
|
className="bg-background"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{request.response && (
|
{request.response && (
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
@@ -84,20 +76,11 @@ const HistoryAndNotifications = ({
|
|||||||
<span className="font-semibold text-green-600">
|
<span className="font-semibold text-green-600">
|
||||||
Response:
|
Response:
|
||||||
</span>
|
</span>
|
||||||
<button
|
|
||||||
onClick={() => copyToClipboard(request.response!)}
|
|
||||||
className="text-blue-500 hover:text-blue-700"
|
|
||||||
>
|
|
||||||
<Copy size={16} />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<pre className="whitespace-pre-wrap break-words bg-background p-2 rounded">
|
<JsonView
|
||||||
{JSON.stringify(
|
data={request.response}
|
||||||
JSON.parse(request.response),
|
className="bg-background"
|
||||||
null,
|
/>
|
||||||
2,
|
|
||||||
)}
|
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -137,18 +120,11 @@ const HistoryAndNotifications = ({
|
|||||||
<span className="font-semibold text-purple-600">
|
<span className="font-semibold text-purple-600">
|
||||||
Details:
|
Details:
|
||||||
</span>
|
</span>
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
copyToClipboard(JSON.stringify(notification))
|
|
||||||
}
|
|
||||||
className="text-blue-500 hover:text-blue-700"
|
|
||||||
>
|
|
||||||
<Copy size={16} />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<pre className="whitespace-pre-wrap break-words bg-background p-2 rounded">
|
<JsonView
|
||||||
{JSON.stringify(notification, null, 2)}
|
data={JSON.stringify(notification, null, 2)}
|
||||||
</pre>
|
className="bg-background"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
import Editor from "react-simple-code-editor";
|
import Editor from "react-simple-code-editor";
|
||||||
import Prism from "prismjs";
|
import Prism from "prismjs";
|
||||||
import "prismjs/components/prism-json";
|
import "prismjs/components/prism-json";
|
||||||
import "prismjs/themes/prism.css";
|
import "prismjs/themes/prism.css";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
|
|
||||||
interface JsonEditorProps {
|
interface JsonEditorProps {
|
||||||
value: string;
|
value: string;
|
||||||
@@ -10,34 +10,40 @@ interface JsonEditorProps {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonEditor = ({ value, onChange, error }: JsonEditorProps) => {
|
const JsonEditor = ({
|
||||||
const formatJson = (json: string): string => {
|
value,
|
||||||
try {
|
onChange,
|
||||||
return JSON.stringify(JSON.parse(json), null, 2);
|
error: externalError,
|
||||||
} catch {
|
}: JsonEditorProps) => {
|
||||||
return json;
|
const [editorContent, setEditorContent] = useState(value || "");
|
||||||
}
|
const [internalError, setInternalError] = useState<string | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setEditorContent(value || "");
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
const handleEditorChange = (newContent: string) => {
|
||||||
|
setEditorContent(newContent);
|
||||||
|
setInternalError(undefined);
|
||||||
|
onChange(newContent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const displayError = internalError || externalError;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative space-y-2">
|
<div className="relative">
|
||||||
<div className="flex justify-end">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => onChange(formatJson(value))}
|
|
||||||
>
|
|
||||||
Format JSON
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
className={`border rounded-md ${
|
className={`border rounded-md ${
|
||||||
error ? "border-red-500" : "border-gray-200 dark:border-gray-800"
|
displayError
|
||||||
|
? "border-red-500"
|
||||||
|
: "border-gray-200 dark:border-gray-800"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Editor
|
<Editor
|
||||||
value={value}
|
value={editorContent}
|
||||||
onValueChange={onChange}
|
onValueChange={handleEditorChange}
|
||||||
highlight={(code) =>
|
highlight={(code) =>
|
||||||
Prism.highlight(code, Prism.languages.json, "json")
|
Prism.highlight(code, Prism.languages.json, "json")
|
||||||
}
|
}
|
||||||
@@ -51,7 +57,9 @@ const JsonEditor = ({ value, onChange, error }: JsonEditorProps) => {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{error && <p className="text-sm text-red-500 mt-1">{error}</p>}
|
{displayError && (
|
||||||
|
<p className="text-sm text-red-500 mt-1">{displayError}</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
286
client/src/components/JsonView.tsx
Normal file
286
client/src/components/JsonView.tsx
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
import { useState, memo, useMemo, useCallback, useEffect } from "react";
|
||||||
|
import type { JsonValue } from "@/utils/jsonUtils";
|
||||||
|
import clsx from "clsx";
|
||||||
|
import { Copy, CheckCheck } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
|
import { getDataType, tryParseJson } from "@/utils/jsonUtils";
|
||||||
|
|
||||||
|
interface JsonViewProps {
|
||||||
|
data: unknown;
|
||||||
|
name?: string;
|
||||||
|
initialExpandDepth?: number;
|
||||||
|
className?: string;
|
||||||
|
withCopyButton?: boolean;
|
||||||
|
isError?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const JsonView = memo(
|
||||||
|
({
|
||||||
|
data,
|
||||||
|
name,
|
||||||
|
initialExpandDepth = 3,
|
||||||
|
className,
|
||||||
|
withCopyButton = true,
|
||||||
|
isError = false,
|
||||||
|
}: JsonViewProps) => {
|
||||||
|
const { toast } = useToast();
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let timeoutId: NodeJS.Timeout;
|
||||||
|
if (copied) {
|
||||||
|
timeoutId = setTimeout(() => {
|
||||||
|
setCopied(false);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [copied]);
|
||||||
|
|
||||||
|
const normalizedData = useMemo(() => {
|
||||||
|
return typeof data === "string"
|
||||||
|
? tryParseJson(data).success
|
||||||
|
? tryParseJson(data).data
|
||||||
|
: data
|
||||||
|
: data;
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const handleCopy = useCallback(() => {
|
||||||
|
try {
|
||||||
|
navigator.clipboard.writeText(
|
||||||
|
typeof normalizedData === "string"
|
||||||
|
? normalizedData
|
||||||
|
: JSON.stringify(normalizedData, null, 2),
|
||||||
|
);
|
||||||
|
setCopied(true);
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: `There was an error coping result into the clipboard: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [toast, normalizedData]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={clsx("p-4 border rounded relative", className)}>
|
||||||
|
{withCopyButton && (
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="absolute top-2 right-2"
|
||||||
|
onClick={handleCopy}
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
<CheckCheck className="size-4 dark:text-green-700 text-green-600" />
|
||||||
|
) : (
|
||||||
|
<Copy className="size-4 text-foreground" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<div className="font-mono text-sm transition-all duration-300">
|
||||||
|
<JsonNode
|
||||||
|
data={normalizedData as JsonValue}
|
||||||
|
name={name}
|
||||||
|
depth={0}
|
||||||
|
initialExpandDepth={initialExpandDepth}
|
||||||
|
isError={isError}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
JsonView.displayName = "JsonView";
|
||||||
|
|
||||||
|
interface JsonNodeProps {
|
||||||
|
data: JsonValue;
|
||||||
|
name?: string;
|
||||||
|
depth: number;
|
||||||
|
initialExpandDepth: number;
|
||||||
|
isError?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const JsonNode = memo(
|
||||||
|
({
|
||||||
|
data,
|
||||||
|
name,
|
||||||
|
depth = 0,
|
||||||
|
initialExpandDepth,
|
||||||
|
isError = false,
|
||||||
|
}: JsonNodeProps) => {
|
||||||
|
const [isExpanded, setIsExpanded] = useState(depth < initialExpandDepth);
|
||||||
|
const [typeStyleMap] = useState<Record<string, string>>({
|
||||||
|
number: "text-blue-600",
|
||||||
|
boolean: "text-amber-600",
|
||||||
|
null: "text-purple-600",
|
||||||
|
undefined: "text-gray-600",
|
||||||
|
string: "text-green-600 group-hover:text-green-500",
|
||||||
|
error: "text-red-600 group-hover:text-red-500",
|
||||||
|
default: "text-gray-700",
|
||||||
|
});
|
||||||
|
const dataType = getDataType(data);
|
||||||
|
|
||||||
|
const renderCollapsible = (isArray: boolean) => {
|
||||||
|
const items = isArray
|
||||||
|
? (data as JsonValue[])
|
||||||
|
: Object.entries(data as Record<string, JsonValue>);
|
||||||
|
const itemCount = items.length;
|
||||||
|
const isEmpty = itemCount === 0;
|
||||||
|
|
||||||
|
const symbolMap = {
|
||||||
|
open: isArray ? "[" : "{",
|
||||||
|
close: isArray ? "]" : "}",
|
||||||
|
collapsed: isArray ? "[ ... ]" : "{ ... }",
|
||||||
|
empty: isArray ? "[]" : "{}",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEmpty) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center">
|
||||||
|
{name && (
|
||||||
|
<span className="mr-1 text-gray-600 dark:text-gray-400">
|
||||||
|
{name}:
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span className="text-gray-500">{symbolMap.empty}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<div
|
||||||
|
className="flex items-center mr-1 rounded cursor-pointer group hover:bg-gray-800/10 dark:hover:bg-gray-800/20"
|
||||||
|
onClick={() => setIsExpanded(!isExpanded)}
|
||||||
|
>
|
||||||
|
{name && (
|
||||||
|
<span className="mr-1 text-gray-600 dark:text-gray-400 dark:group-hover:text-gray-100 group-hover:text-gray-400">
|
||||||
|
{name}:
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{isExpanded ? (
|
||||||
|
<span className="text-gray-600 dark:text-gray-400 dark:group-hover:text-gray-100 group-hover:text-gray-400">
|
||||||
|
{symbolMap.open}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="text-gray-600 dark:group-hover:text-gray-100 group-hover:text-gray-400">
|
||||||
|
{symbolMap.collapsed}
|
||||||
|
</span>
|
||||||
|
<span className="ml-1 text-gray-700 dark:group-hover:text-gray-100 group-hover:text-gray-400">
|
||||||
|
{itemCount} {itemCount === 1 ? "item" : "items"}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{isExpanded && (
|
||||||
|
<>
|
||||||
|
<div className="pl-2 ml-4 border-l border-gray-200 dark:border-gray-800">
|
||||||
|
{isArray
|
||||||
|
? (items as JsonValue[]).map((item, index) => (
|
||||||
|
<div key={index} className="my-1">
|
||||||
|
<JsonNode
|
||||||
|
data={item}
|
||||||
|
name={`${index}`}
|
||||||
|
depth={depth + 1}
|
||||||
|
initialExpandDepth={initialExpandDepth}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
: (items as [string, JsonValue][]).map(([key, value]) => (
|
||||||
|
<div key={key} className="my-1">
|
||||||
|
<JsonNode
|
||||||
|
data={value}
|
||||||
|
name={key}
|
||||||
|
depth={depth + 1}
|
||||||
|
initialExpandDepth={initialExpandDepth}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="text-gray-600 dark:text-gray-400">
|
||||||
|
{symbolMap.close}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderString = (value: string) => {
|
||||||
|
const maxLength = 100;
|
||||||
|
const isTooLong = value.length > maxLength;
|
||||||
|
|
||||||
|
if (!isTooLong) {
|
||||||
|
return (
|
||||||
|
<div className="flex mr-1 rounded hover:bg-gray-800/20">
|
||||||
|
{name && (
|
||||||
|
<span className="mr-1 text-gray-600 dark:text-gray-400">
|
||||||
|
{name}:
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<pre
|
||||||
|
className={clsx(
|
||||||
|
isError ? typeStyleMap.error : typeStyleMap.string,
|
||||||
|
"break-all whitespace-pre-wrap",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
"{value}"
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex mr-1 rounded group hover:bg-gray-800/20">
|
||||||
|
{name && (
|
||||||
|
<span className="mr-1 text-gray-600 dark:text-gray-400 dark:group-hover:text-gray-100 group-hover:text-gray-400">
|
||||||
|
{name}:
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<pre
|
||||||
|
className={clsx(
|
||||||
|
isError ? typeStyleMap.error : typeStyleMap.string,
|
||||||
|
"cursor-pointer break-all whitespace-pre-wrap",
|
||||||
|
)}
|
||||||
|
onClick={() => setIsExpanded(!isExpanded)}
|
||||||
|
title={isExpanded ? "Click to collapse" : "Click to expand"}
|
||||||
|
>
|
||||||
|
{isExpanded ? `"${value}"` : `"${value.slice(0, maxLength)}..."`}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (dataType) {
|
||||||
|
case "object":
|
||||||
|
case "array":
|
||||||
|
return renderCollapsible(dataType === "array");
|
||||||
|
case "string":
|
||||||
|
return renderString(data as string);
|
||||||
|
default:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center mr-1 rounded hover:bg-gray-800/20">
|
||||||
|
{name && (
|
||||||
|
<span className="mr-1 text-gray-600 dark:text-gray-400">
|
||||||
|
{name}:
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span className={typeStyleMap[dataType] || typeStyleMap.default}>
|
||||||
|
{data === null ? "null" : String(data)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
JsonNode.displayName = "JsonNode";
|
||||||
|
|
||||||
|
export default JsonView;
|
||||||
@@ -22,7 +22,7 @@ const ListPane = <T extends object>({
|
|||||||
isButtonDisabled,
|
isButtonDisabled,
|
||||||
}: ListPaneProps<T>) => (
|
}: ListPaneProps<T>) => (
|
||||||
<div className="bg-card rounded-lg shadow">
|
<div className="bg-card rounded-lg shadow">
|
||||||
<div className="p-4 border-b border-gray-200 dark:border-gray-700">
|
<div className="p-4 border-b border-gray-200 dark:border-gray-800">
|
||||||
<h3 className="font-semibold dark:text-white">{title}</h3>
|
<h3 className="font-semibold dark:text-white">{title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { authProvider } from "../lib/auth";
|
import { InspectorOAuthClientProvider } from "../lib/auth";
|
||||||
import { SESSION_KEYS } from "../lib/constants";
|
import { SESSION_KEYS } from "../lib/constants";
|
||||||
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
||||||
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
|
import {
|
||||||
|
generateOAuthErrorDescription,
|
||||||
|
parseOAuthCallbackParams,
|
||||||
|
} from "@/utils/oauthUtils.ts";
|
||||||
|
|
||||||
const OAuthCallback = () => {
|
interface OAuthCallbackProps {
|
||||||
|
onConnect: (serverUrl: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const OAuthCallback = ({ onConnect }: OAuthCallbackProps) => {
|
||||||
|
const { toast } = useToast();
|
||||||
const hasProcessedRef = useRef(false);
|
const hasProcessedRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -14,37 +24,56 @@ const OAuthCallback = () => {
|
|||||||
}
|
}
|
||||||
hasProcessedRef.current = true;
|
hasProcessedRef.current = true;
|
||||||
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
const notifyError = (description: string) =>
|
||||||
const code = params.get("code");
|
void toast({
|
||||||
const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
|
title: "OAuth Authorization Error",
|
||||||
|
description,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
|
||||||
if (!code || !serverUrl) {
|
const params = parseOAuthCallbackParams(window.location.search);
|
||||||
console.error("Missing code or server URL");
|
if (!params.successful) {
|
||||||
window.location.href = "/";
|
return notifyError(generateOAuthErrorDescription(params));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
|
||||||
const result = await auth(authProvider, {
|
if (!serverUrl) {
|
||||||
serverUrl,
|
return notifyError("Missing Server URL");
|
||||||
authorizationCode: code,
|
}
|
||||||
});
|
|
||||||
if (result !== "AUTHORIZED") {
|
|
||||||
throw new Error(
|
|
||||||
`Expected to be authorized after providing auth code, got: ${result}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect back to the main app with server URL to trigger auto-connect
|
let result;
|
||||||
window.location.href = `/?serverUrl=${encodeURIComponent(serverUrl)}`;
|
try {
|
||||||
|
// Create an auth provider with the current server URL
|
||||||
|
const serverAuthProvider = new InspectorOAuthClientProvider(serverUrl);
|
||||||
|
|
||||||
|
result = await auth(serverAuthProvider, {
|
||||||
|
serverUrl,
|
||||||
|
authorizationCode: params.code,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("OAuth callback error:", error);
|
console.error("OAuth callback error:", error);
|
||||||
window.location.href = "/";
|
return notifyError(`Unexpected error occurred: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result !== "AUTHORIZED") {
|
||||||
|
return notifyError(
|
||||||
|
`Expected to be authorized after providing auth code, got: ${result}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, trigger auto-connect
|
||||||
|
toast({
|
||||||
|
title: "Success",
|
||||||
|
description: "Successfully authenticated with OAuth",
|
||||||
|
variant: "default",
|
||||||
|
});
|
||||||
|
onConnect(serverUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
void handleCallback();
|
handleCallback().finally(() => {
|
||||||
}, []);
|
window.history.replaceState({}, document.title, "/");
|
||||||
|
});
|
||||||
|
}, [toast, onConnect]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center h-screen">
|
<div className="flex items-center justify-center h-screen">
|
||||||
|
|||||||
92
client/src/components/OAuthDebugCallback.tsx
Normal file
92
client/src/components/OAuthDebugCallback.tsx
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { SESSION_KEYS } from "../lib/constants";
|
||||||
|
import {
|
||||||
|
generateOAuthErrorDescription,
|
||||||
|
parseOAuthCallbackParams,
|
||||||
|
} from "@/utils/oauthUtils.ts";
|
||||||
|
|
||||||
|
interface OAuthCallbackProps {
|
||||||
|
onConnect: ({
|
||||||
|
authorizationCode,
|
||||||
|
errorMsg,
|
||||||
|
}: {
|
||||||
|
authorizationCode?: string;
|
||||||
|
errorMsg?: string;
|
||||||
|
}) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
|
||||||
|
useEffect(() => {
|
||||||
|
let isProcessed = false;
|
||||||
|
|
||||||
|
const handleCallback = async () => {
|
||||||
|
// Skip if we've already processed this callback
|
||||||
|
if (isProcessed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isProcessed = true;
|
||||||
|
|
||||||
|
const params = parseOAuthCallbackParams(window.location.search);
|
||||||
|
if (!params.successful) {
|
||||||
|
const errorMsg = generateOAuthErrorDescription(params);
|
||||||
|
onConnect({ errorMsg });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
|
||||||
|
|
||||||
|
// ServerURL isn't set, this can happen if we've opened the
|
||||||
|
// authentication request in a new tab, so we don't have the same
|
||||||
|
// session storage
|
||||||
|
if (!serverUrl) {
|
||||||
|
// If there's no server URL, we're likely in a new tab
|
||||||
|
// Just display the code for manual copying
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!params.code) {
|
||||||
|
onConnect({ errorMsg: "Missing authorization code" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instead of storing in sessionStorage, pass the code directly
|
||||||
|
// to the auth state manager through onConnect
|
||||||
|
onConnect({ authorizationCode: params.code });
|
||||||
|
};
|
||||||
|
|
||||||
|
handleCallback().finally(() => {
|
||||||
|
// Only redirect if we have the URL set, otherwise assume this was
|
||||||
|
// in a new tab
|
||||||
|
if (sessionStorage.getItem(SESSION_KEYS.SERVER_URL)) {
|
||||||
|
window.history.replaceState({}, document.title, "/");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isProcessed = true;
|
||||||
|
};
|
||||||
|
}, [onConnect]);
|
||||||
|
|
||||||
|
const callbackParams = parseOAuthCallbackParams(window.location.search);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center h-screen">
|
||||||
|
<div className="mt-4 p-4 bg-secondary rounded-md max-w-md">
|
||||||
|
<p className="mb-2 text-sm">
|
||||||
|
Please copy this authorization code and return to the Auth Debugger:
|
||||||
|
</p>
|
||||||
|
<code className="block p-2 bg-muted rounded-sm overflow-x-auto text-xs">
|
||||||
|
{callbackParams.successful && "code" in callbackParams
|
||||||
|
? callbackParams.code
|
||||||
|
: `No code found: ${callbackParams.error}, ${callbackParams.error_description}`}
|
||||||
|
</code>
|
||||||
|
<p className="mt-4 text-xs text-muted-foreground">
|
||||||
|
Close this tab and paste the code in the OAuth flow to complete
|
||||||
|
authentication.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OAuthDebugCallback;
|
||||||
259
client/src/components/OAuthFlowProgress.tsx
Normal file
259
client/src/components/OAuthFlowProgress.tsx
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
import { AuthDebuggerState, OAuthStep } from "@/lib/auth-types";
|
||||||
|
import { CheckCircle2, Circle, ExternalLink } from "lucide-react";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { DebugInspectorOAuthClientProvider } from "@/lib/auth";
|
||||||
|
|
||||||
|
interface OAuthStepProps {
|
||||||
|
label: string;
|
||||||
|
isComplete: boolean;
|
||||||
|
isCurrent: boolean;
|
||||||
|
error?: Error | null;
|
||||||
|
children?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const OAuthStepDetails = ({
|
||||||
|
label,
|
||||||
|
isComplete,
|
||||||
|
isCurrent,
|
||||||
|
error,
|
||||||
|
children,
|
||||||
|
}: OAuthStepProps) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
className={`flex items-center p-2 rounded-md ${isCurrent ? "bg-accent" : ""}`}
|
||||||
|
>
|
||||||
|
{isComplete ? (
|
||||||
|
<CheckCircle2 className="h-5 w-5 text-green-500 mr-2" />
|
||||||
|
) : (
|
||||||
|
<Circle className="h-5 w-5 text-muted-foreground mr-2" />
|
||||||
|
)}
|
||||||
|
<span className={`${isCurrent ? "font-medium" : ""}`}>{label}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Show children if current step or complete and children exist */}
|
||||||
|
{(isCurrent || isComplete) && children && (
|
||||||
|
<div className="ml-7 mt-1">{children}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Display error if current step and an error exists */}
|
||||||
|
{isCurrent && error && (
|
||||||
|
<div className="ml-7 mt-2 p-3 border border-red-300 bg-red-50 rounded-md">
|
||||||
|
<p className="text-sm font-medium text-red-700">Error:</p>
|
||||||
|
<p className="text-xs text-red-600 mt-1">{error.message}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface OAuthFlowProgressProps {
|
||||||
|
serverUrl: string;
|
||||||
|
authState: AuthDebuggerState;
|
||||||
|
updateAuthState: (updates: Partial<AuthDebuggerState>) => void;
|
||||||
|
proceedToNextStep: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const OAuthFlowProgress = ({
|
||||||
|
serverUrl,
|
||||||
|
authState,
|
||||||
|
updateAuthState,
|
||||||
|
proceedToNextStep,
|
||||||
|
}: OAuthFlowProgressProps) => {
|
||||||
|
const provider = new DebugInspectorOAuthClientProvider(serverUrl);
|
||||||
|
|
||||||
|
const steps: Array<OAuthStep> = [
|
||||||
|
"metadata_discovery",
|
||||||
|
"client_registration",
|
||||||
|
"authorization_redirect",
|
||||||
|
"authorization_code",
|
||||||
|
"token_request",
|
||||||
|
"complete",
|
||||||
|
];
|
||||||
|
const currentStepIdx = steps.findIndex((s) => s === authState.oauthStep);
|
||||||
|
|
||||||
|
// Helper to get step props
|
||||||
|
const getStepProps = (stepName: OAuthStep) => ({
|
||||||
|
isComplete:
|
||||||
|
currentStepIdx > steps.indexOf(stepName) ||
|
||||||
|
currentStepIdx === steps.length - 1, // last step is "complete"
|
||||||
|
isCurrent: authState.oauthStep === stepName,
|
||||||
|
error: authState.oauthStep === stepName ? authState.latestError : null,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border p-6 space-y-4 mt-4">
|
||||||
|
<h3 className="text-lg font-medium">OAuth Flow Progress</h3>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Follow these steps to complete OAuth authentication with the server.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<OAuthStepDetails
|
||||||
|
label="Metadata Discovery"
|
||||||
|
{...getStepProps("metadata_discovery")}
|
||||||
|
>
|
||||||
|
{provider.getServerMetadata() && (
|
||||||
|
<details className="text-xs mt-2">
|
||||||
|
<summary className="cursor-pointer text-muted-foreground font-medium">
|
||||||
|
Retrieved OAuth Metadata from {serverUrl}
|
||||||
|
/.well-known/oauth-authorization-server
|
||||||
|
</summary>
|
||||||
|
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
|
||||||
|
{JSON.stringify(provider.getServerMetadata(), null, 2)}
|
||||||
|
</pre>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
</OAuthStepDetails>
|
||||||
|
|
||||||
|
<OAuthStepDetails
|
||||||
|
label="Client Registration"
|
||||||
|
{...getStepProps("client_registration")}
|
||||||
|
>
|
||||||
|
{authState.oauthClientInfo && (
|
||||||
|
<details className="text-xs mt-2">
|
||||||
|
<summary className="cursor-pointer text-muted-foreground font-medium">
|
||||||
|
Registered Client Information
|
||||||
|
</summary>
|
||||||
|
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
|
||||||
|
{JSON.stringify(authState.oauthClientInfo, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
</OAuthStepDetails>
|
||||||
|
|
||||||
|
<OAuthStepDetails
|
||||||
|
label="Preparing Authorization"
|
||||||
|
{...getStepProps("authorization_redirect")}
|
||||||
|
>
|
||||||
|
{authState.authorizationUrl && (
|
||||||
|
<div className="mt-2 p-3 border rounded-md bg-muted">
|
||||||
|
<p className="font-medium mb-2 text-sm">Authorization URL:</p>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<p className="text-xs break-all">
|
||||||
|
{authState.authorizationUrl}
|
||||||
|
</p>
|
||||||
|
<a
|
||||||
|
href={authState.authorizationUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="flex items-center text-blue-500 hover:text-blue-700"
|
||||||
|
aria-label="Open authorization URL in new tab"
|
||||||
|
title="Open authorization URL"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-4 w-4" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground mt-2">
|
||||||
|
Click the link to authorize in your browser. After
|
||||||
|
authorization, you'll be redirected back to continue the flow.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</OAuthStepDetails>
|
||||||
|
|
||||||
|
<OAuthStepDetails
|
||||||
|
label="Request Authorization and acquire authorization code"
|
||||||
|
{...getStepProps("authorization_code")}
|
||||||
|
>
|
||||||
|
<div className="mt-3">
|
||||||
|
<label
|
||||||
|
htmlFor="authCode"
|
||||||
|
className="block text-sm font-medium mb-1"
|
||||||
|
>
|
||||||
|
Authorization Code
|
||||||
|
</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
id="authCode"
|
||||||
|
value={authState.authorizationCode}
|
||||||
|
onChange={(e) => {
|
||||||
|
updateAuthState({
|
||||||
|
authorizationCode: e.target.value,
|
||||||
|
validationError: null,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
placeholder="Enter the code from the authorization server"
|
||||||
|
className={`flex h-9 w-full rounded-md border bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${
|
||||||
|
authState.validationError ? "border-red-500" : "border-input"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{authState.validationError && (
|
||||||
|
<p className="text-xs text-red-600 mt-1">
|
||||||
|
{authState.validationError}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
Once you've completed authorization in the link, paste the code
|
||||||
|
here.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</OAuthStepDetails>
|
||||||
|
|
||||||
|
<OAuthStepDetails
|
||||||
|
label="Token Request"
|
||||||
|
{...getStepProps("token_request")}
|
||||||
|
>
|
||||||
|
{authState.oauthMetadata && (
|
||||||
|
<details className="text-xs mt-2">
|
||||||
|
<summary className="cursor-pointer text-muted-foreground font-medium">
|
||||||
|
Token Request Details
|
||||||
|
</summary>
|
||||||
|
<div className="mt-2 p-2 bg-muted rounded-md">
|
||||||
|
<p className="font-medium">Token Endpoint:</p>
|
||||||
|
<code className="block mt-1 text-xs overflow-x-auto">
|
||||||
|
{authState.oauthMetadata.token_endpoint}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
</OAuthStepDetails>
|
||||||
|
|
||||||
|
<OAuthStepDetails
|
||||||
|
label="Authentication Complete"
|
||||||
|
{...getStepProps("complete")}
|
||||||
|
>
|
||||||
|
{authState.oauthTokens && (
|
||||||
|
<details className="text-xs mt-2">
|
||||||
|
<summary className="cursor-pointer text-muted-foreground font-medium">
|
||||||
|
Access Tokens
|
||||||
|
</summary>
|
||||||
|
<p className="mt-1 text-sm">
|
||||||
|
Authentication successful! You can now use the authenticated
|
||||||
|
connection. These tokens will be used automatically for server
|
||||||
|
requests.
|
||||||
|
</p>
|
||||||
|
<pre className="mt-2 p-2 bg-muted rounded-md overflow-auto max-h-[300px]">
|
||||||
|
{JSON.stringify(authState.oauthTokens, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
</OAuthStepDetails>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3 mt-4">
|
||||||
|
{authState.oauthStep !== "complete" && (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
onClick={proceedToNextStep}
|
||||||
|
disabled={authState.isInitiatingAuth}
|
||||||
|
>
|
||||||
|
{authState.isInitiatingAuth ? "Processing..." : "Continue"}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{authState.oauthStep === "authorization_redirect" &&
|
||||||
|
authState.authorizationUrl && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => window.open(authState.authorizationUrl!, "_blank")}
|
||||||
|
>
|
||||||
|
Open in New Tab
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -3,14 +3,16 @@ import { Button } from "@/components/ui/button";
|
|||||||
|
|
||||||
const PingTab = ({ onPingClick }: { onPingClick: () => void }) => {
|
const PingTab = ({ onPingClick }: { onPingClick: () => void }) => {
|
||||||
return (
|
return (
|
||||||
<TabsContent value="ping" className="grid grid-cols-2 gap-4">
|
<TabsContent value="ping">
|
||||||
<div className="col-span-2 flex justify-center items-center">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<Button
|
<div className="col-span-2 flex justify-center items-center">
|
||||||
onClick={onPingClick}
|
<Button
|
||||||
className="font-bold py-6 px-12 rounded-full"
|
onClick={onPingClick}
|
||||||
>
|
className="font-bold py-6 px-12 rounded-full"
|
||||||
Ping Server
|
>
|
||||||
</Button>
|
Ping Server
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { Combobox } from "@/components/ui/combobox";
|
import { Combobox } from "@/components/ui/combobox";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { TabsContent } from "@/components/ui/tabs";
|
import { TabsContent } from "@/components/ui/tabs";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
|
||||||
import {
|
import {
|
||||||
ListPromptsResult,
|
ListPromptsResult,
|
||||||
PromptReference,
|
PromptReference,
|
||||||
@@ -13,6 +13,7 @@ import { AlertCircle } from "lucide-react";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import ListPane from "./ListPane";
|
import ListPane from "./ListPane";
|
||||||
import { useCompletionState } from "@/lib/hooks/useCompletionState";
|
import { useCompletionState } from "@/lib/hooks/useCompletionState";
|
||||||
|
import JsonView from "./JsonView";
|
||||||
|
|
||||||
export type Prompt = {
|
export type Prompt = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -42,7 +43,7 @@ const PromptsTab = ({
|
|||||||
clearPrompts: () => void;
|
clearPrompts: () => void;
|
||||||
getPrompt: (name: string, args: Record<string, string>) => void;
|
getPrompt: (name: string, args: Record<string, string>) => void;
|
||||||
selectedPrompt: Prompt | null;
|
selectedPrompt: Prompt | null;
|
||||||
setSelectedPrompt: (prompt: Prompt) => void;
|
setSelectedPrompt: (prompt: Prompt | null) => void;
|
||||||
handleCompletion: (
|
handleCompletion: (
|
||||||
ref: PromptReference | ResourceReference,
|
ref: PromptReference | ResourceReference,
|
||||||
argName: string,
|
argName: string,
|
||||||
@@ -83,88 +84,91 @@ const PromptsTab = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="prompts" className="grid grid-cols-2 gap-4">
|
<TabsContent value="prompts">
|
||||||
<ListPane
|
<div className="grid grid-cols-2 gap-4">
|
||||||
items={prompts}
|
<ListPane
|
||||||
listItems={listPrompts}
|
items={prompts}
|
||||||
clearItems={clearPrompts}
|
listItems={listPrompts}
|
||||||
setSelectedItem={(prompt) => {
|
clearItems={() => {
|
||||||
setSelectedPrompt(prompt);
|
clearPrompts();
|
||||||
setPromptArgs({});
|
setSelectedPrompt(null);
|
||||||
}}
|
}}
|
||||||
renderItem={(prompt) => (
|
setSelectedItem={(prompt) => {
|
||||||
<>
|
setSelectedPrompt(prompt);
|
||||||
<span className="flex-1">{prompt.name}</span>
|
setPromptArgs({});
|
||||||
<span className="text-sm text-gray-500">{prompt.description}</span>
|
}}
|
||||||
</>
|
renderItem={(prompt) => (
|
||||||
)}
|
<>
|
||||||
title="Prompts"
|
<span className="flex-1">{prompt.name}</span>
|
||||||
buttonText={nextCursor ? "List More Prompts" : "List Prompts"}
|
<span className="text-sm text-gray-500">
|
||||||
isButtonDisabled={!nextCursor && prompts.length > 0}
|
{prompt.description}
|
||||||
/>
|
</span>
|
||||||
|
</>
|
||||||
<div className="bg-card rounded-lg shadow">
|
|
||||||
<div className="p-4 border-b border-gray-200">
|
|
||||||
<h3 className="font-semibold">
|
|
||||||
{selectedPrompt ? selectedPrompt.name : "Select a prompt"}
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
<div className="p-4">
|
|
||||||
{error ? (
|
|
||||||
<Alert variant="destructive">
|
|
||||||
<AlertCircle className="h-4 w-4" />
|
|
||||||
<AlertTitle>Error</AlertTitle>
|
|
||||||
<AlertDescription>{error}</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
) : selectedPrompt ? (
|
|
||||||
<div className="space-y-4">
|
|
||||||
{selectedPrompt.description && (
|
|
||||||
<p className="text-sm text-gray-600">
|
|
||||||
{selectedPrompt.description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{selectedPrompt.arguments?.map((arg) => (
|
|
||||||
<div key={arg.name}>
|
|
||||||
<Label htmlFor={arg.name}>{arg.name}</Label>
|
|
||||||
<Combobox
|
|
||||||
id={arg.name}
|
|
||||||
placeholder={`Enter ${arg.name}`}
|
|
||||||
value={promptArgs[arg.name] || ""}
|
|
||||||
onChange={(value) => handleInputChange(arg.name, value)}
|
|
||||||
onInputChange={(value) =>
|
|
||||||
handleInputChange(arg.name, value)
|
|
||||||
}
|
|
||||||
options={completions[arg.name] || []}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{arg.description && (
|
|
||||||
<p className="text-xs text-gray-500 mt-1">
|
|
||||||
{arg.description}
|
|
||||||
{arg.required && (
|
|
||||||
<span className="text-xs mt-1 ml-1">(Required)</span>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
<Button onClick={handleGetPrompt} className="w-full">
|
|
||||||
Get Prompt
|
|
||||||
</Button>
|
|
||||||
{promptContent && (
|
|
||||||
<Textarea
|
|
||||||
value={promptContent}
|
|
||||||
readOnly
|
|
||||||
className="h-64 font-mono"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Alert>
|
|
||||||
<AlertDescription>
|
|
||||||
Select a prompt from the list to view and use it
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
)}
|
)}
|
||||||
|
title="Prompts"
|
||||||
|
buttonText={nextCursor ? "List More Prompts" : "List Prompts"}
|
||||||
|
isButtonDisabled={!nextCursor && prompts.length > 0}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="bg-card rounded-lg shadow">
|
||||||
|
<div className="p-4 border-b border-gray-200 dark:border-gray-800">
|
||||||
|
<h3 className="font-semibold">
|
||||||
|
{selectedPrompt ? selectedPrompt.name : "Select a prompt"}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div className="p-4">
|
||||||
|
{error ? (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Error</AlertTitle>
|
||||||
|
<AlertDescription>{error}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
) : selectedPrompt ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{selectedPrompt.description && (
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
|
{selectedPrompt.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{selectedPrompt.arguments?.map((arg) => (
|
||||||
|
<div key={arg.name}>
|
||||||
|
<Label htmlFor={arg.name}>{arg.name}</Label>
|
||||||
|
<Combobox
|
||||||
|
id={arg.name}
|
||||||
|
placeholder={`Enter ${arg.name}`}
|
||||||
|
value={promptArgs[arg.name] || ""}
|
||||||
|
onChange={(value) => handleInputChange(arg.name, value)}
|
||||||
|
onInputChange={(value) =>
|
||||||
|
handleInputChange(arg.name, value)
|
||||||
|
}
|
||||||
|
options={completions[arg.name] || []}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{arg.description && (
|
||||||
|
<p className="text-xs text-gray-500 mt-1">
|
||||||
|
{arg.description}
|
||||||
|
{arg.required && (
|
||||||
|
<span className="text-xs mt-1 ml-1">(Required)</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<Button onClick={handleGetPrompt} className="w-full">
|
||||||
|
Get Prompt
|
||||||
|
</Button>
|
||||||
|
{promptContent && (
|
||||||
|
<JsonView data={promptContent} withCopyButton={false} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>
|
||||||
|
Select a prompt from the list to view and use it
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { AlertCircle, ChevronRight, FileText, RefreshCw } from "lucide-react";
|
|||||||
import ListPane from "./ListPane";
|
import ListPane from "./ListPane";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useCompletionState } from "@/lib/hooks/useCompletionState";
|
import { useCompletionState } from "@/lib/hooks/useCompletionState";
|
||||||
|
import JsonView from "./JsonView";
|
||||||
|
|
||||||
const ResourcesTab = ({
|
const ResourcesTab = ({
|
||||||
resources,
|
resources,
|
||||||
@@ -103,161 +104,177 @@ const ResourcesTab = ({
|
|||||||
if (selectedTemplate) {
|
if (selectedTemplate) {
|
||||||
const uri = fillTemplate(selectedTemplate.uriTemplate, templateValues);
|
const uri = fillTemplate(selectedTemplate.uriTemplate, templateValues);
|
||||||
readResource(uri);
|
readResource(uri);
|
||||||
setSelectedTemplate(null);
|
|
||||||
// We don't have the full Resource object here, so we create a partial one
|
// We don't have the full Resource object here, so we create a partial one
|
||||||
setSelectedResource({ uri, name: uri } as Resource);
|
setSelectedResource({ uri, name: uri } as Resource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="resources" className="grid grid-cols-3 gap-4">
|
<TabsContent value="resources">
|
||||||
<ListPane
|
<div className="grid grid-cols-3 gap-4">
|
||||||
items={resources}
|
<ListPane
|
||||||
listItems={listResources}
|
items={resources}
|
||||||
clearItems={clearResources}
|
listItems={listResources}
|
||||||
setSelectedItem={(resource) => {
|
clearItems={() => {
|
||||||
setSelectedResource(resource);
|
clearResources();
|
||||||
readResource(resource.uri);
|
// Condition to check if selected resource is not resource template's resource
|
||||||
setSelectedTemplate(null);
|
if (!selectedTemplate) {
|
||||||
}}
|
setSelectedResource(null);
|
||||||
renderItem={(resource) => (
|
}
|
||||||
<div className="flex items-center w-full">
|
}}
|
||||||
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
|
setSelectedItem={(resource) => {
|
||||||
<span className="flex-1 truncate" title={resource.uri.toString()}>
|
setSelectedResource(resource);
|
||||||
{resource.name}
|
readResource(resource.uri);
|
||||||
</span>
|
setSelectedTemplate(null);
|
||||||
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
|
}}
|
||||||
</div>
|
renderItem={(resource) => (
|
||||||
)}
|
<div className="flex items-center w-full">
|
||||||
title="Resources"
|
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
|
||||||
buttonText={nextCursor ? "List More Resources" : "List Resources"}
|
<span className="flex-1 truncate" title={resource.uri.toString()}>
|
||||||
isButtonDisabled={!nextCursor && resources.length > 0}
|
{resource.name}
|
||||||
/>
|
</span>
|
||||||
|
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
|
||||||
<ListPane
|
|
||||||
items={resourceTemplates}
|
|
||||||
listItems={listResourceTemplates}
|
|
||||||
clearItems={clearResourceTemplates}
|
|
||||||
setSelectedItem={(template) => {
|
|
||||||
setSelectedTemplate(template);
|
|
||||||
setSelectedResource(null);
|
|
||||||
setTemplateValues({});
|
|
||||||
}}
|
|
||||||
renderItem={(template) => (
|
|
||||||
<div className="flex items-center w-full">
|
|
||||||
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
|
|
||||||
<span className="flex-1 truncate" title={template.uriTemplate}>
|
|
||||||
{template.name}
|
|
||||||
</span>
|
|
||||||
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
title="Resource Templates"
|
|
||||||
buttonText={
|
|
||||||
nextTemplateCursor ? "List More Templates" : "List Templates"
|
|
||||||
}
|
|
||||||
isButtonDisabled={!nextTemplateCursor && resourceTemplates.length > 0}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className="bg-card rounded-lg shadow">
|
|
||||||
<div className="p-4 border-b border-gray-200 flex justify-between items-center">
|
|
||||||
<h3
|
|
||||||
className="font-semibold truncate"
|
|
||||||
title={selectedResource?.name || selectedTemplate?.name}
|
|
||||||
>
|
|
||||||
{selectedResource
|
|
||||||
? selectedResource.name
|
|
||||||
: selectedTemplate
|
|
||||||
? selectedTemplate.name
|
|
||||||
: "Select a resource or template"}
|
|
||||||
</h3>
|
|
||||||
{selectedResource && (
|
|
||||||
<div className="flex row-auto gap-1 justify-end w-2/5">
|
|
||||||
{resourceSubscriptionsSupported &&
|
|
||||||
!resourceSubscriptions.has(selectedResource.uri) && (
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => subscribeToResource(selectedResource.uri)}
|
|
||||||
>
|
|
||||||
Subscribe
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{resourceSubscriptionsSupported &&
|
|
||||||
resourceSubscriptions.has(selectedResource.uri) && (
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() =>
|
|
||||||
unsubscribeFromResource(selectedResource.uri)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Unsubscribe
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => readResource(selectedResource.uri)}
|
|
||||||
>
|
|
||||||
<RefreshCw className="w-4 h-4 mr-2" />
|
|
||||||
Refresh
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
title="Resources"
|
||||||
<div className="p-4">
|
buttonText={nextCursor ? "List More Resources" : "List Resources"}
|
||||||
{error ? (
|
isButtonDisabled={!nextCursor && resources.length > 0}
|
||||||
<Alert variant="destructive">
|
/>
|
||||||
<AlertCircle className="h-4 w-4" />
|
|
||||||
<AlertTitle>Error</AlertTitle>
|
<ListPane
|
||||||
<AlertDescription>{error}</AlertDescription>
|
items={resourceTemplates}
|
||||||
</Alert>
|
listItems={listResourceTemplates}
|
||||||
) : selectedResource ? (
|
clearItems={() => {
|
||||||
<pre className="bg-gray-50 dark:bg-gray-800 p-4 rounded text-sm overflow-auto max-h-96 whitespace-pre-wrap break-words text-gray-900 dark:text-gray-100">
|
clearResourceTemplates();
|
||||||
{resourceContent}
|
// Condition to check if selected resource is resource template's resource
|
||||||
</pre>
|
if (selectedTemplate) {
|
||||||
) : selectedTemplate ? (
|
setSelectedResource(null);
|
||||||
<div className="space-y-4">
|
}
|
||||||
<p className="text-sm text-gray-600">
|
setSelectedTemplate(null);
|
||||||
{selectedTemplate.description}
|
}}
|
||||||
</p>
|
setSelectedItem={(template) => {
|
||||||
{selectedTemplate.uriTemplate
|
setSelectedTemplate(template);
|
||||||
.match(/{([^}]+)}/g)
|
setSelectedResource(null);
|
||||||
?.map((param) => {
|
setTemplateValues({});
|
||||||
const key = param.slice(1, -1);
|
}}
|
||||||
return (
|
renderItem={(template) => (
|
||||||
<div key={key}>
|
<div className="flex items-center w-full">
|
||||||
<Label htmlFor={key}>{key}</Label>
|
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
|
||||||
<Combobox
|
<span className="flex-1 truncate" title={template.uriTemplate}>
|
||||||
id={key}
|
{template.name}
|
||||||
placeholder={`Enter ${key}`}
|
</span>
|
||||||
value={templateValues[key] || ""}
|
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
|
||||||
onChange={(value) =>
|
|
||||||
handleTemplateValueChange(key, value)
|
|
||||||
}
|
|
||||||
onInputChange={(value) =>
|
|
||||||
handleTemplateValueChange(key, value)
|
|
||||||
}
|
|
||||||
options={completions[key] || []}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
<Button
|
|
||||||
onClick={handleReadTemplateResource}
|
|
||||||
disabled={Object.keys(templateValues).length === 0}
|
|
||||||
>
|
|
||||||
Read Resource
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<Alert>
|
|
||||||
<AlertDescription>
|
|
||||||
Select a resource or template from the list to view its contents
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
)}
|
)}
|
||||||
|
title="Resource Templates"
|
||||||
|
buttonText={
|
||||||
|
nextTemplateCursor ? "List More Templates" : "List Templates"
|
||||||
|
}
|
||||||
|
isButtonDisabled={!nextTemplateCursor && resourceTemplates.length > 0}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="bg-card rounded-lg shadow">
|
||||||
|
<div className="p-4 border-b border-gray-200 dark:border-gray-800 flex justify-between items-center">
|
||||||
|
<h3
|
||||||
|
className="font-semibold truncate"
|
||||||
|
title={selectedResource?.name || selectedTemplate?.name}
|
||||||
|
>
|
||||||
|
{selectedResource
|
||||||
|
? selectedResource.name
|
||||||
|
: selectedTemplate
|
||||||
|
? selectedTemplate.name
|
||||||
|
: "Select a resource or template"}
|
||||||
|
</h3>
|
||||||
|
{selectedResource && (
|
||||||
|
<div className="flex row-auto gap-1 justify-end w-2/5">
|
||||||
|
{resourceSubscriptionsSupported &&
|
||||||
|
!resourceSubscriptions.has(selectedResource.uri) && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => subscribeToResource(selectedResource.uri)}
|
||||||
|
>
|
||||||
|
Subscribe
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{resourceSubscriptionsSupported &&
|
||||||
|
resourceSubscriptions.has(selectedResource.uri) && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() =>
|
||||||
|
unsubscribeFromResource(selectedResource.uri)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Unsubscribe
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => readResource(selectedResource.uri)}
|
||||||
|
>
|
||||||
|
<RefreshCw className="w-4 h-4 mr-2" />
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="p-4">
|
||||||
|
{error ? (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Error</AlertTitle>
|
||||||
|
<AlertDescription>{error}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
) : selectedResource ? (
|
||||||
|
<JsonView
|
||||||
|
data={resourceContent}
|
||||||
|
className="bg-gray-50 dark:bg-gray-800 p-4 rounded text-sm overflow-auto max-h-96 text-gray-900 dark:text-gray-100"
|
||||||
|
/>
|
||||||
|
) : selectedTemplate ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
|
{selectedTemplate.description}
|
||||||
|
</p>
|
||||||
|
{selectedTemplate.uriTemplate
|
||||||
|
.match(/{([^}]+)}/g)
|
||||||
|
?.map((param) => {
|
||||||
|
const key = param.slice(1, -1);
|
||||||
|
return (
|
||||||
|
<div key={key}>
|
||||||
|
<Label htmlFor={key}>{key}</Label>
|
||||||
|
<Combobox
|
||||||
|
id={key}
|
||||||
|
placeholder={`Enter ${key}`}
|
||||||
|
value={templateValues[key] || ""}
|
||||||
|
onChange={(value) =>
|
||||||
|
handleTemplateValueChange(key, value)
|
||||||
|
}
|
||||||
|
onInputChange={(value) =>
|
||||||
|
handleTemplateValueChange(key, value)
|
||||||
|
}
|
||||||
|
options={completions[key] || []}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<Button
|
||||||
|
onClick={handleReadTemplateResource}
|
||||||
|
disabled={Object.keys(templateValues).length === 0}
|
||||||
|
>
|
||||||
|
Read Resource
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>
|
||||||
|
Select a resource or template from the list to view its
|
||||||
|
contents
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|||||||
@@ -35,40 +35,42 @@ const RootsTab = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="roots" className="space-y-4">
|
<TabsContent value="roots">
|
||||||
<Alert>
|
<div className="space-y-4">
|
||||||
<AlertDescription>
|
<Alert>
|
||||||
Configure the root directories that the server can access
|
<AlertDescription>
|
||||||
</AlertDescription>
|
Configure the root directories that the server can access
|
||||||
</Alert>
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
{roots.map((root, index) => (
|
{roots.map((root, index) => (
|
||||||
<div key={index} className="flex gap-2 items-center">
|
<div key={index} className="flex gap-2 items-center">
|
||||||
<Input
|
<Input
|
||||||
placeholder="file:// URI"
|
placeholder="file:// URI"
|
||||||
value={root.uri}
|
value={root.uri}
|
||||||
onChange={(e) => updateRoot(index, "uri", e.target.value)}
|
onChange={(e) => updateRoot(index, "uri", e.target.value)}
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => removeRoot(index)}
|
onClick={() => removeRoot(index)}
|
||||||
>
|
>
|
||||||
<Minus className="h-4 w-4" />
|
<Minus className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button variant="outline" onClick={addRoot}>
|
||||||
|
<Plus className="h-4 w-4 mr-2" />
|
||||||
|
Add Root
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleSave}>
|
||||||
|
<Save className="h-4 w-4 mr-2" />
|
||||||
|
Save Changes
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
|
||||||
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button variant="outline" onClick={addRoot}>
|
|
||||||
<Plus className="h-4 w-4 mr-2" />
|
|
||||||
Add Root
|
|
||||||
</Button>
|
|
||||||
<Button onClick={handleSave}>
|
|
||||||
<Save className="h-4 w-4 mr-2" />
|
|
||||||
Save Changes
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
);
|
);
|
||||||
|
|||||||
167
client/src/components/SamplingRequest.tsx
Normal file
167
client/src/components/SamplingRequest.tsx
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import JsonView from "./JsonView";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import {
|
||||||
|
CreateMessageResult,
|
||||||
|
CreateMessageResultSchema,
|
||||||
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { PendingRequest } from "./SamplingTab";
|
||||||
|
import DynamicJsonForm from "./DynamicJsonForm";
|
||||||
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
|
import { JsonSchemaType, JsonValue } from "@/utils/jsonUtils";
|
||||||
|
|
||||||
|
export type SamplingRequestProps = {
|
||||||
|
request: PendingRequest;
|
||||||
|
onApprove: (id: number, result: CreateMessageResult) => void;
|
||||||
|
onReject: (id: number) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SamplingRequest = ({
|
||||||
|
onApprove,
|
||||||
|
request,
|
||||||
|
onReject,
|
||||||
|
}: SamplingRequestProps) => {
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const [messageResult, setMessageResult] = useState<JsonValue>({
|
||||||
|
model: "stub-model",
|
||||||
|
stopReason: "endTurn",
|
||||||
|
role: "assistant",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const contentType = (
|
||||||
|
(messageResult as { [key: string]: JsonValue })?.content as {
|
||||||
|
[key: string]: JsonValue;
|
||||||
|
}
|
||||||
|
)?.type;
|
||||||
|
|
||||||
|
const schema = useMemo(() => {
|
||||||
|
const s: JsonSchemaType = {
|
||||||
|
type: "object",
|
||||||
|
description: "Message result",
|
||||||
|
properties: {
|
||||||
|
model: {
|
||||||
|
type: "string",
|
||||||
|
default: "stub-model",
|
||||||
|
description: "model name",
|
||||||
|
},
|
||||||
|
stopReason: {
|
||||||
|
type: "string",
|
||||||
|
default: "endTurn",
|
||||||
|
description: "Stop reason",
|
||||||
|
},
|
||||||
|
role: {
|
||||||
|
type: "string",
|
||||||
|
default: "endTurn",
|
||||||
|
description: "Role of the model",
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
type: {
|
||||||
|
type: "string",
|
||||||
|
default: "text",
|
||||||
|
description: "Type of content",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (contentType === "text" && s.properties) {
|
||||||
|
s.properties.content.properties = {
|
||||||
|
...s.properties.content.properties,
|
||||||
|
text: {
|
||||||
|
type: "string",
|
||||||
|
default: "",
|
||||||
|
description: "text content",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
setMessageResult((prev) => ({
|
||||||
|
...(prev as { [key: string]: JsonValue }),
|
||||||
|
content: {
|
||||||
|
type: contentType,
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
} else if (contentType === "image" && s.properties) {
|
||||||
|
s.properties.content.properties = {
|
||||||
|
...s.properties.content.properties,
|
||||||
|
data: {
|
||||||
|
type: "string",
|
||||||
|
default: "",
|
||||||
|
description: "Base64 encoded image data",
|
||||||
|
},
|
||||||
|
mimeType: {
|
||||||
|
type: "string",
|
||||||
|
default: "",
|
||||||
|
description: "Mime type of the image",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
setMessageResult((prev) => ({
|
||||||
|
...(prev as { [key: string]: JsonValue }),
|
||||||
|
content: {
|
||||||
|
type: contentType,
|
||||||
|
data: "",
|
||||||
|
mimeType: "",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}, [contentType]);
|
||||||
|
|
||||||
|
const handleApprove = (id: number) => {
|
||||||
|
const validationResult = CreateMessageResultSchema.safeParse(messageResult);
|
||||||
|
if (!validationResult.success) {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: `There was an error validating the message result: ${validationResult.error.message}`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onApprove(id, validationResult.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-testid="sampling-request"
|
||||||
|
className="flex gap-4 p-4 border rounded-lg space-y-4"
|
||||||
|
>
|
||||||
|
<div className="flex-1 bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-2 rounded">
|
||||||
|
<JsonView data={JSON.stringify(request.request)} />
|
||||||
|
</div>
|
||||||
|
<form className="flex-1 space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<DynamicJsonForm
|
||||||
|
schema={schema}
|
||||||
|
value={messageResult}
|
||||||
|
onChange={(newValue: JsonValue) => {
|
||||||
|
setMessageResult(newValue);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex space-x-2 mt-1">
|
||||||
|
<Button type="button" onClick={() => handleApprove(request.id)}>
|
||||||
|
Approve
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onReject(request.id)}
|
||||||
|
>
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SamplingRequest;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { TabsContent } from "@/components/ui/tabs";
|
import { TabsContent } from "@/components/ui/tabs";
|
||||||
import {
|
import {
|
||||||
CreateMessageRequest,
|
CreateMessageRequest,
|
||||||
CreateMessageResult,
|
CreateMessageResult,
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import SamplingRequest from "./SamplingRequest";
|
||||||
|
|
||||||
export type PendingRequest = {
|
export type PendingRequest = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -18,45 +18,29 @@ export type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const SamplingTab = ({ pendingRequests, onApprove, onReject }: Props) => {
|
const SamplingTab = ({ pendingRequests, onApprove, onReject }: Props) => {
|
||||||
const handleApprove = (id: number) => {
|
|
||||||
// For now, just return a stub response
|
|
||||||
onApprove(id, {
|
|
||||||
model: "stub-model",
|
|
||||||
stopReason: "endTurn",
|
|
||||||
role: "assistant",
|
|
||||||
content: {
|
|
||||||
type: "text",
|
|
||||||
text: "This is a stub response.",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="sampling" className="h-96">
|
<TabsContent value="sampling">
|
||||||
<Alert>
|
<div className="h-96">
|
||||||
<AlertDescription>
|
<Alert>
|
||||||
When the server requests LLM sampling, requests will appear here for
|
<AlertDescription>
|
||||||
approval.
|
When the server requests LLM sampling, requests will appear here for
|
||||||
</AlertDescription>
|
approval.
|
||||||
</Alert>
|
</AlertDescription>
|
||||||
<div className="mt-4 space-y-4">
|
</Alert>
|
||||||
<h3 className="text-lg font-semibold">Recent Requests</h3>
|
<div className="mt-4 space-y-4">
|
||||||
{pendingRequests.map((request) => (
|
<h3 className="text-lg font-semibold">Recent Requests</h3>
|
||||||
<div key={request.id} className="p-4 border rounded-lg space-y-4">
|
{pendingRequests.map((request) => (
|
||||||
<pre className="bg-gray-50 p-2 rounded">
|
<SamplingRequest
|
||||||
{JSON.stringify(request.request, null, 2)}
|
key={request.id}
|
||||||
</pre>
|
request={request}
|
||||||
<div className="flex space-x-2">
|
onApprove={onApprove}
|
||||||
<Button onClick={() => handleApprove(request.id)}>Approve</Button>
|
onReject={onReject}
|
||||||
<Button variant="outline" onClick={() => onReject(request.id)}>
|
/>
|
||||||
Reject
|
))}
|
||||||
</Button>
|
{pendingRequests.length === 0 && (
|
||||||
</div>
|
<p className="text-gray-500">No pending requests</p>
|
||||||
</div>
|
)}
|
||||||
))}
|
</div>
|
||||||
{pendingRequests.length === 0 && (
|
|
||||||
<p className="text-gray-500">No pending requests</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useState, useCallback } from "react";
|
||||||
import {
|
import {
|
||||||
Play,
|
Play,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
@@ -8,6 +8,12 @@ import {
|
|||||||
Github,
|
Github,
|
||||||
Eye,
|
Eye,
|
||||||
EyeOff,
|
EyeOff,
|
||||||
|
RotateCcw,
|
||||||
|
Settings,
|
||||||
|
HelpCircle,
|
||||||
|
RefreshCwOff,
|
||||||
|
Copy,
|
||||||
|
CheckCheck,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
@@ -19,14 +25,25 @@ import {
|
|||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { StdErrNotification } from "@/lib/notificationTypes";
|
import { StdErrNotification } from "@/lib/notificationTypes";
|
||||||
|
import {
|
||||||
import useTheme from "../lib/useTheme";
|
LoggingLevel,
|
||||||
|
LoggingLevelSchema,
|
||||||
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { InspectorConfig } from "@/lib/configurationTypes";
|
||||||
|
import { ConnectionStatus } from "@/lib/constants";
|
||||||
|
import useTheme from "../lib/hooks/useTheme";
|
||||||
import { version } from "../../../package.json";
|
import { version } from "../../../package.json";
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipTrigger,
|
||||||
|
TooltipContent,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
import { useToast } from "../lib/hooks/useToast";
|
||||||
|
|
||||||
interface SidebarProps {
|
interface SidebarProps {
|
||||||
connectionStatus: "disconnected" | "connected" | "error";
|
connectionStatus: ConnectionStatus;
|
||||||
transportType: "stdio" | "sse";
|
transportType: "stdio" | "sse" | "streamable-http";
|
||||||
setTransportType: (type: "stdio" | "sse") => void;
|
setTransportType: (type: "stdio" | "sse" | "streamable-http") => void;
|
||||||
command: string;
|
command: string;
|
||||||
setCommand: (command: string) => void;
|
setCommand: (command: string) => void;
|
||||||
args: string;
|
args: string;
|
||||||
@@ -37,8 +54,17 @@ interface SidebarProps {
|
|||||||
setEnv: (env: Record<string, string>) => void;
|
setEnv: (env: Record<string, string>) => void;
|
||||||
bearerToken: string;
|
bearerToken: string;
|
||||||
setBearerToken: (token: string) => void;
|
setBearerToken: (token: string) => void;
|
||||||
|
headerName?: string;
|
||||||
|
setHeaderName?: (name: string) => void;
|
||||||
onConnect: () => void;
|
onConnect: () => void;
|
||||||
|
onDisconnect: () => void;
|
||||||
stdErrNotifications: StdErrNotification[];
|
stdErrNotifications: StdErrNotification[];
|
||||||
|
clearStdErrNotifications: () => void;
|
||||||
|
logLevel: LoggingLevel;
|
||||||
|
sendLogLevelRequest: (level: LoggingLevel) => void;
|
||||||
|
loggingSupported: boolean;
|
||||||
|
config: InspectorConfig;
|
||||||
|
setConfig: (config: InspectorConfig) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Sidebar = ({
|
const Sidebar = ({
|
||||||
@@ -55,17 +81,141 @@ const Sidebar = ({
|
|||||||
setEnv,
|
setEnv,
|
||||||
bearerToken,
|
bearerToken,
|
||||||
setBearerToken,
|
setBearerToken,
|
||||||
|
headerName,
|
||||||
|
setHeaderName,
|
||||||
onConnect,
|
onConnect,
|
||||||
|
onDisconnect,
|
||||||
stdErrNotifications,
|
stdErrNotifications,
|
||||||
|
clearStdErrNotifications,
|
||||||
|
logLevel,
|
||||||
|
sendLogLevelRequest,
|
||||||
|
loggingSupported,
|
||||||
|
config,
|
||||||
|
setConfig,
|
||||||
}: SidebarProps) => {
|
}: SidebarProps) => {
|
||||||
const [theme, setTheme] = useTheme();
|
const [theme, setTheme] = useTheme();
|
||||||
const [showEnvVars, setShowEnvVars] = useState(false);
|
const [showEnvVars, setShowEnvVars] = useState(false);
|
||||||
const [showBearerToken, setShowBearerToken] = useState(false);
|
const [showBearerToken, setShowBearerToken] = useState(false);
|
||||||
|
const [showConfig, setShowConfig] = useState(false);
|
||||||
const [shownEnvVars, setShownEnvVars] = useState<Set<string>>(new Set());
|
const [shownEnvVars, setShownEnvVars] = useState<Set<string>>(new Set());
|
||||||
|
const [copiedServerEntry, setCopiedServerEntry] = useState(false);
|
||||||
|
const [copiedServerFile, setCopiedServerFile] = useState(false);
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
// Reusable error reporter for copy actions
|
||||||
|
const reportError = useCallback(
|
||||||
|
(error: unknown) => {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: `Failed to copy config: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[toast],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Shared utility function to generate server config
|
||||||
|
const generateServerConfig = useCallback(() => {
|
||||||
|
if (transportType === "stdio") {
|
||||||
|
return {
|
||||||
|
command,
|
||||||
|
args: args.trim() ? args.split(/\s+/) : [],
|
||||||
|
env: { ...env },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (transportType === "sse") {
|
||||||
|
return {
|
||||||
|
type: "sse",
|
||||||
|
url: sseUrl,
|
||||||
|
note: "For SSE connections, add this URL directly in Client",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (transportType === "streamable-http") {
|
||||||
|
return {
|
||||||
|
type: "streamable-http",
|
||||||
|
url: sseUrl,
|
||||||
|
note: "For Streamable HTTP connections, add this URL directly in Client",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}, [transportType, command, args, env, sseUrl]);
|
||||||
|
|
||||||
|
// Memoized config entry generator
|
||||||
|
const generateMCPServerEntry = useCallback(() => {
|
||||||
|
return JSON.stringify(generateServerConfig(), null, 4);
|
||||||
|
}, [generateServerConfig]);
|
||||||
|
|
||||||
|
// Memoized config file generator
|
||||||
|
const generateMCPServerFile = useCallback(() => {
|
||||||
|
return JSON.stringify(
|
||||||
|
{
|
||||||
|
mcpServers: {
|
||||||
|
"default-server": generateServerConfig(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
}, [generateServerConfig]);
|
||||||
|
|
||||||
|
// Memoized copy handlers
|
||||||
|
const handleCopyServerEntry = useCallback(() => {
|
||||||
|
try {
|
||||||
|
const configJson = generateMCPServerEntry();
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(configJson)
|
||||||
|
.then(() => {
|
||||||
|
setCopiedServerEntry(true);
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Config entry copied",
|
||||||
|
description:
|
||||||
|
transportType === "stdio"
|
||||||
|
? "Server configuration has been copied to clipboard. Add this to your mcp.json inside the 'mcpServers' object with your preferred server name."
|
||||||
|
: "SSE URL has been copied. Use this URL in Cursor directly.",
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setCopiedServerEntry(false);
|
||||||
|
}, 2000);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reportError(error);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
reportError(error);
|
||||||
|
}
|
||||||
|
}, [generateMCPServerEntry, transportType, toast, reportError]);
|
||||||
|
|
||||||
|
const handleCopyServerFile = useCallback(() => {
|
||||||
|
try {
|
||||||
|
const configJson = generateMCPServerFile();
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(configJson)
|
||||||
|
.then(() => {
|
||||||
|
setCopiedServerFile(true);
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Servers file copied",
|
||||||
|
description:
|
||||||
|
"Servers configuration has been copied to clipboard. Add this to your mcp.json file. Current testing server will be added as 'default-server'",
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setCopiedServerFile(false);
|
||||||
|
}, 2000);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reportError(error);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
reportError(error);
|
||||||
|
}
|
||||||
|
}, [generateMCPServerFile, toast, reportError]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-80 bg-card border-r border-border flex flex-col h-full">
|
<div className="w-80 bg-card border-r border-border flex flex-col h-full">
|
||||||
<div className="flex items-center justify-between p-4 border-b border-gray-200">
|
<div className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-800">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<h1 className="ml-2 text-lg font-semibold">
|
<h1 className="ml-2 text-lg font-semibold">
|
||||||
MCP Inspector v{version}
|
MCP Inspector v{version}
|
||||||
@@ -76,19 +226,25 @@ const Sidebar = ({
|
|||||||
<div className="p-4 flex-1 overflow-auto">
|
<div className="p-4 flex-1 overflow-auto">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="text-sm font-medium">Transport Type</label>
|
<label
|
||||||
|
className="text-sm font-medium"
|
||||||
|
htmlFor="transport-type-select"
|
||||||
|
>
|
||||||
|
Transport Type
|
||||||
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={transportType}
|
value={transportType}
|
||||||
onValueChange={(value: "stdio" | "sse") =>
|
onValueChange={(value: "stdio" | "sse" | "streamable-http") =>
|
||||||
setTransportType(value)
|
setTransportType(value)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger id="transport-type-select">
|
||||||
<SelectValue placeholder="Select transport type" />
|
<SelectValue placeholder="Select transport type" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="stdio">STDIO</SelectItem>
|
<SelectItem value="stdio">STDIO</SelectItem>
|
||||||
<SelectItem value="sse">SSE</SelectItem>
|
<SelectItem value="sse">SSE</SelectItem>
|
||||||
|
<SelectItem value="streamable-http">Streamable HTTP</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
@@ -96,8 +252,11 @@ const Sidebar = ({
|
|||||||
{transportType === "stdio" ? (
|
{transportType === "stdio" ? (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="text-sm font-medium">Command</label>
|
<label className="text-sm font-medium" htmlFor="command-input">
|
||||||
|
Command
|
||||||
|
</label>
|
||||||
<Input
|
<Input
|
||||||
|
id="command-input"
|
||||||
placeholder="Command"
|
placeholder="Command"
|
||||||
value={command}
|
value={command}
|
||||||
onChange={(e) => setCommand(e.target.value)}
|
onChange={(e) => setCommand(e.target.value)}
|
||||||
@@ -105,8 +264,14 @@ const Sidebar = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="text-sm font-medium">Arguments</label>
|
<label
|
||||||
|
className="text-sm font-medium"
|
||||||
|
htmlFor="arguments-input"
|
||||||
|
>
|
||||||
|
Arguments
|
||||||
|
</label>
|
||||||
<Input
|
<Input
|
||||||
|
id="arguments-input"
|
||||||
placeholder="Arguments (space-separated)"
|
placeholder="Arguments (space-separated)"
|
||||||
value={args}
|
value={args}
|
||||||
onChange={(e) => setArgs(e.target.value)}
|
onChange={(e) => setArgs(e.target.value)}
|
||||||
@@ -117,8 +282,11 @@ const Sidebar = ({
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="text-sm font-medium">URL</label>
|
<label className="text-sm font-medium" htmlFor="sse-url-input">
|
||||||
|
URL
|
||||||
|
</label>
|
||||||
<Input
|
<Input
|
||||||
|
id="sse-url-input"
|
||||||
placeholder="URL"
|
placeholder="URL"
|
||||||
value={sseUrl}
|
value={sseUrl}
|
||||||
onChange={(e) => setSseUrl(e.target.value)}
|
onChange={(e) => setSseUrl(e.target.value)}
|
||||||
@@ -130,6 +298,8 @@ const Sidebar = ({
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => setShowBearerToken(!showBearerToken)}
|
onClick={() => setShowBearerToken(!showBearerToken)}
|
||||||
className="flex items-center w-full"
|
className="flex items-center w-full"
|
||||||
|
data-testid="auth-button"
|
||||||
|
aria-expanded={showBearerToken}
|
||||||
>
|
>
|
||||||
{showBearerToken ? (
|
{showBearerToken ? (
|
||||||
<ChevronDown className="w-4 h-4 mr-2" />
|
<ChevronDown className="w-4 h-4 mr-2" />
|
||||||
@@ -140,11 +310,28 @@ const Sidebar = ({
|
|||||||
</Button>
|
</Button>
|
||||||
{showBearerToken && (
|
{showBearerToken && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="text-sm font-medium">Bearer Token</label>
|
<label className="text-sm font-medium">Header Name</label>
|
||||||
<Input
|
<Input
|
||||||
|
placeholder="Authorization"
|
||||||
|
onChange={(e) =>
|
||||||
|
setHeaderName && setHeaderName(e.target.value)
|
||||||
|
}
|
||||||
|
data-testid="header-input"
|
||||||
|
className="font-mono"
|
||||||
|
value={headerName}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
className="text-sm font-medium"
|
||||||
|
htmlFor="bearer-token-input"
|
||||||
|
>
|
||||||
|
Bearer Token
|
||||||
|
</label>
|
||||||
|
<Input
|
||||||
|
id="bearer-token-input"
|
||||||
placeholder="Bearer Token"
|
placeholder="Bearer Token"
|
||||||
value={bearerToken}
|
value={bearerToken}
|
||||||
onChange={(e) => setBearerToken(e.target.value)}
|
onChange={(e) => setBearerToken(e.target.value)}
|
||||||
|
data-testid="bearer-token-input"
|
||||||
className="font-mono"
|
className="font-mono"
|
||||||
type="password"
|
type="password"
|
||||||
/>
|
/>
|
||||||
@@ -153,12 +340,15 @@ const Sidebar = ({
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{transportType === "stdio" && (
|
{transportType === "stdio" && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => setShowEnvVars(!showEnvVars)}
|
onClick={() => setShowEnvVars(!showEnvVars)}
|
||||||
className="flex items-center w-full"
|
className="flex items-center w-full"
|
||||||
|
data-testid="env-vars-button"
|
||||||
|
aria-expanded={showEnvVars}
|
||||||
>
|
>
|
||||||
{showEnvVars ? (
|
{showEnvVars ? (
|
||||||
<ChevronDown className="w-4 h-4 mr-2" />
|
<ChevronDown className="w-4 h-4 mr-2" />
|
||||||
@@ -173,13 +363,22 @@ const Sidebar = ({
|
|||||||
<div key={idx} className="space-y-2 pb-4">
|
<div key={idx} className="space-y-2 pb-4">
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Input
|
<Input
|
||||||
|
aria-label={`Environment variable key ${idx + 1}`}
|
||||||
placeholder="Key"
|
placeholder="Key"
|
||||||
value={key}
|
value={key}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const newKey = e.target.value;
|
const newKey = e.target.value;
|
||||||
const newEnv = { ...env };
|
const newEnv = Object.entries(env).reduce(
|
||||||
delete newEnv[key];
|
(acc, [k, v]) => {
|
||||||
newEnv[newKey] = value;
|
if (k === key) {
|
||||||
|
acc[newKey] = value;
|
||||||
|
} else {
|
||||||
|
acc[k] = v;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, string>,
|
||||||
|
);
|
||||||
setEnv(newEnv);
|
setEnv(newEnv);
|
||||||
setShownEnvVars((prev) => {
|
setShownEnvVars((prev) => {
|
||||||
const next = new Set(prev);
|
const next = new Set(prev);
|
||||||
@@ -207,6 +406,7 @@ const Sidebar = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Input
|
<Input
|
||||||
|
aria-label={`Environment variable value ${idx + 1}`}
|
||||||
type={shownEnvVars.has(key) ? "text" : "password"}
|
type={shownEnvVars.has(key) ? "text" : "password"}
|
||||||
placeholder="Value"
|
placeholder="Value"
|
||||||
value={value}
|
value={value}
|
||||||
@@ -266,36 +466,246 @@ const Sidebar = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Always show both copy buttons for all transport types */}
|
||||||
|
<div className="grid grid-cols-2 gap-2 mt-2">
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleCopyServerEntry}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
{copiedServerEntry ? (
|
||||||
|
<CheckCheck className="h-4 w-4 mr-2" />
|
||||||
|
) : (
|
||||||
|
<Copy className="h-4 w-4 mr-2" />
|
||||||
|
)}
|
||||||
|
Server Entry
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Copy Server Entry</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleCopyServerFile}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
{copiedServerFile ? (
|
||||||
|
<CheckCheck className="h-4 w-4 mr-2" />
|
||||||
|
) : (
|
||||||
|
<Copy className="h-4 w-4 mr-2" />
|
||||||
|
)}
|
||||||
|
Servers File
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Copy Servers File</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Configuration */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Button className="w-full" onClick={onConnect}>
|
<Button
|
||||||
<Play className="w-4 h-4 mr-2" />
|
variant="outline"
|
||||||
Connect
|
onClick={() => setShowConfig(!showConfig)}
|
||||||
|
className="flex items-center w-full"
|
||||||
|
data-testid="config-button"
|
||||||
|
aria-expanded={showConfig}
|
||||||
|
>
|
||||||
|
{showConfig ? (
|
||||||
|
<ChevronDown className="w-4 h-4 mr-2" />
|
||||||
|
) : (
|
||||||
|
<ChevronRight className="w-4 h-4 mr-2" />
|
||||||
|
)}
|
||||||
|
<Settings className="w-4 h-4 mr-2" />
|
||||||
|
Configuration
|
||||||
</Button>
|
</Button>
|
||||||
|
{showConfig && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{Object.entries(config).map(([key, configItem]) => {
|
||||||
|
const configKey = key as keyof InspectorConfig;
|
||||||
|
return (
|
||||||
|
<div key={key} className="space-y-2">
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<label
|
||||||
|
className="text-sm font-medium text-green-600 break-all"
|
||||||
|
htmlFor={`${configKey}-input`}
|
||||||
|
>
|
||||||
|
{configItem.label}
|
||||||
|
</label>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<HelpCircle className="h-4 w-4 text-muted-foreground" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
{configItem.description}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
{typeof configItem.value === "number" ? (
|
||||||
|
<Input
|
||||||
|
id={`${configKey}-input`}
|
||||||
|
type="number"
|
||||||
|
data-testid={`${configKey}-input`}
|
||||||
|
value={configItem.value}
|
||||||
|
onChange={(e) => {
|
||||||
|
const newConfig = { ...config };
|
||||||
|
newConfig[configKey] = {
|
||||||
|
...configItem,
|
||||||
|
value: Number(e.target.value),
|
||||||
|
};
|
||||||
|
setConfig(newConfig);
|
||||||
|
}}
|
||||||
|
className="font-mono"
|
||||||
|
/>
|
||||||
|
) : typeof configItem.value === "boolean" ? (
|
||||||
|
<Select
|
||||||
|
data-testid={`${configKey}-select`}
|
||||||
|
value={configItem.value.toString()}
|
||||||
|
onValueChange={(val) => {
|
||||||
|
const newConfig = { ...config };
|
||||||
|
newConfig[configKey] = {
|
||||||
|
...configItem,
|
||||||
|
value: val === "true",
|
||||||
|
};
|
||||||
|
setConfig(newConfig);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id={`${configKey}-input`}>
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="true">True</SelectItem>
|
||||||
|
<SelectItem value="false">False</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
) : (
|
||||||
|
<Input
|
||||||
|
id={`${configKey}-input`}
|
||||||
|
data-testid={`${configKey}-input`}
|
||||||
|
value={configItem.value}
|
||||||
|
onChange={(e) => {
|
||||||
|
const newConfig = { ...config };
|
||||||
|
newConfig[configKey] = {
|
||||||
|
...configItem,
|
||||||
|
value: e.target.value,
|
||||||
|
};
|
||||||
|
setConfig(newConfig);
|
||||||
|
}}
|
||||||
|
className="font-mono"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
{connectionStatus === "connected" && (
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Button
|
||||||
|
data-testid="connect-button"
|
||||||
|
onClick={() => {
|
||||||
|
onDisconnect();
|
||||||
|
onConnect();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RotateCcw className="w-4 h-4 mr-2" />
|
||||||
|
{transportType === "stdio" ? "Restart" : "Reconnect"}
|
||||||
|
</Button>
|
||||||
|
<Button onClick={onDisconnect}>
|
||||||
|
<RefreshCwOff className="w-4 h-4 mr-2" />
|
||||||
|
Disconnect
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{connectionStatus !== "connected" && (
|
||||||
|
<Button className="w-full" onClick={onConnect}>
|
||||||
|
<Play className="w-4 h-4 mr-2" />
|
||||||
|
Connect
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="flex items-center justify-center space-x-2 mb-4">
|
<div className="flex items-center justify-center space-x-2 mb-4">
|
||||||
<div
|
<div
|
||||||
className={`w-2 h-2 rounded-full ${
|
className={`w-2 h-2 rounded-full ${(() => {
|
||||||
connectionStatus === "connected"
|
switch (connectionStatus) {
|
||||||
? "bg-green-500"
|
case "connected":
|
||||||
: connectionStatus === "error"
|
return "bg-green-500";
|
||||||
? "bg-red-500"
|
case "error":
|
||||||
: "bg-gray-500"
|
return "bg-red-500";
|
||||||
}`}
|
case "error-connecting-to-proxy":
|
||||||
|
return "bg-red-500";
|
||||||
|
default:
|
||||||
|
return "bg-gray-500";
|
||||||
|
}
|
||||||
|
})()}`}
|
||||||
/>
|
/>
|
||||||
<span className="text-sm text-gray-600">
|
<span className="text-sm text-gray-600">
|
||||||
{connectionStatus === "connected"
|
{(() => {
|
||||||
? "Connected"
|
switch (connectionStatus) {
|
||||||
: connectionStatus === "error"
|
case "connected":
|
||||||
? "Connection Error"
|
return "Connected";
|
||||||
: "Disconnected"}
|
case "error":
|
||||||
|
return "Connection Error, is your MCP server running?";
|
||||||
|
case "error-connecting-to-proxy":
|
||||||
|
return "Error Connecting to MCP Inspector Proxy - Check Console logs";
|
||||||
|
default:
|
||||||
|
return "Disconnected";
|
||||||
|
}
|
||||||
|
})()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{loggingSupported && connectionStatus === "connected" && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<label
|
||||||
|
className="text-sm font-medium"
|
||||||
|
htmlFor="logging-level-select"
|
||||||
|
>
|
||||||
|
Logging Level
|
||||||
|
</label>
|
||||||
|
<Select
|
||||||
|
value={logLevel}
|
||||||
|
onValueChange={(value: LoggingLevel) =>
|
||||||
|
sendLogLevelRequest(value)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="logging-level-select">
|
||||||
|
<SelectValue placeholder="Select logging level" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{Object.values(LoggingLevelSchema.enum).map((level) => (
|
||||||
|
<SelectItem key={level} value={level}>
|
||||||
|
{level}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{stdErrNotifications.length > 0 && (
|
{stdErrNotifications.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<div className="mt-4 border-t border-gray-200 pt-4">
|
<div className="mt-4 border-t border-gray-200 pt-4">
|
||||||
<h3 className="text-sm font-medium">
|
<div className="flex justify-between items-center">
|
||||||
Error output from MCP server
|
<h3 className="text-sm font-medium">
|
||||||
</h3>
|
Error output from MCP server
|
||||||
|
</h3>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={clearStdErrNotifications}
|
||||||
|
className="h-8 px-2"
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<div className="mt-2 max-h-80 overflow-y-auto">
|
<div className="mt-2 max-h-80 overflow-y-auto">
|
||||||
{stdErrNotifications.map((notification, index) => (
|
{stdErrNotifications.map((notification, index) => (
|
||||||
<div
|
<div
|
||||||
@@ -331,36 +741,37 @@ const Sidebar = ({
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<a
|
<Button variant="ghost" title="Inspector Documentation" asChild>
|
||||||
href="https://modelcontextprotocol.io/docs/tools/inspector"
|
<a
|
||||||
target="_blank"
|
href="https://modelcontextprotocol.io/docs/tools/inspector"
|
||||||
rel="noopener noreferrer"
|
target="_blank"
|
||||||
>
|
rel="noopener noreferrer"
|
||||||
<Button variant="ghost" title="Inspector Documentation">
|
|
||||||
<CircleHelp className="w-4 h-4 text-gray-800" />
|
|
||||||
</Button>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
href="https://modelcontextprotocol.io/docs/tools/debugging"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<Button variant="ghost" title="Debugging Guide">
|
|
||||||
<Bug className="w-4 h-4 text-gray-800" />
|
|
||||||
</Button>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
href="https://github.com/modelcontextprotocol/inspector"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
title="Report bugs or contribute on GitHub"
|
|
||||||
>
|
>
|
||||||
<Github className="w-4 h-4 text-gray-800" />
|
<CircleHelp className="w-4 h-4 text-foreground" />
|
||||||
</Button>
|
</a>
|
||||||
</a>
|
</Button>
|
||||||
|
<Button variant="ghost" title="Debugging Guide" asChild>
|
||||||
|
<a
|
||||||
|
href="https://modelcontextprotocol.io/docs/tools/debugging"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<Bug className="w-4 h-4 text-foreground" />
|
||||||
|
</a>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
title="Report bugs or contribute on GitHub"
|
||||||
|
asChild
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="https://github.com/modelcontextprotocol/inspector"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<Github className="w-4 h-4 text-foreground" />
|
||||||
|
</a>
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { TabsContent } from "@/components/ui/tabs";
|
import { TabsContent } from "@/components/ui/tabs";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import DynamicJsonForm, { JsonSchemaType, JsonValue } from "./DynamicJsonForm";
|
import DynamicJsonForm from "./DynamicJsonForm";
|
||||||
|
import type { JsonValue, JsonSchemaType } from "@/utils/jsonUtils";
|
||||||
|
import { generateDefaultValue } from "@/utils/schemaUtils";
|
||||||
import {
|
import {
|
||||||
|
CallToolResultSchema,
|
||||||
|
CompatibilityCallToolResult,
|
||||||
ListToolsResult,
|
ListToolsResult,
|
||||||
Tool,
|
Tool,
|
||||||
CallToolResultSchema,
|
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { AlertCircle, Send } from "lucide-react";
|
import { Loader2, Send } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import ListPane from "./ListPane";
|
import ListPane from "./ListPane";
|
||||||
|
import JsonView from "./JsonView";
|
||||||
import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
||||||
|
|
||||||
const ToolsTab = ({
|
const ToolsTab = ({
|
||||||
tools,
|
tools,
|
||||||
@@ -26,12 +28,11 @@ const ToolsTab = ({
|
|||||||
setSelectedTool,
|
setSelectedTool,
|
||||||
toolResult,
|
toolResult,
|
||||||
nextCursor,
|
nextCursor,
|
||||||
error,
|
|
||||||
}: {
|
}: {
|
||||||
tools: Tool[];
|
tools: Tool[];
|
||||||
listTools: () => void;
|
listTools: () => void;
|
||||||
clearTools: () => void;
|
clearTools: () => void;
|
||||||
callTool: (name: string, params: Record<string, unknown>) => void;
|
callTool: (name: string, params: Record<string, unknown>) => Promise<void>;
|
||||||
selectedTool: Tool | null;
|
selectedTool: Tool | null;
|
||||||
setSelectedTool: (tool: Tool | null) => void;
|
setSelectedTool: (tool: Tool | null) => void;
|
||||||
toolResult: CompatibilityCallToolResult | null;
|
toolResult: CompatibilityCallToolResult | null;
|
||||||
@@ -39,8 +40,16 @@ const ToolsTab = ({
|
|||||||
error: string | null;
|
error: string | null;
|
||||||
}) => {
|
}) => {
|
||||||
const [params, setParams] = useState<Record<string, unknown>>({});
|
const [params, setParams] = useState<Record<string, unknown>>({});
|
||||||
|
const [isToolRunning, setIsToolRunning] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setParams({});
|
const params = Object.entries(
|
||||||
|
selectedTool?.inputSchema.properties ?? [],
|
||||||
|
).map(([key, value]) => [
|
||||||
|
key,
|
||||||
|
generateDefaultValue(value as JsonSchemaType),
|
||||||
|
]);
|
||||||
|
setParams(Object.fromEntries(params));
|
||||||
}, [selectedTool]);
|
}, [selectedTool]);
|
||||||
|
|
||||||
const renderToolResult = () => {
|
const renderToolResult = () => {
|
||||||
@@ -52,17 +61,10 @@ const ToolsTab = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h4 className="font-semibold mb-2">Invalid Tool Result:</h4>
|
<h4 className="font-semibold mb-2">Invalid Tool Result:</h4>
|
||||||
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64">
|
<JsonView data={toolResult} />
|
||||||
{JSON.stringify(toolResult, null, 2)}
|
|
||||||
</pre>
|
|
||||||
<h4 className="font-semibold mb-2">Errors:</h4>
|
<h4 className="font-semibold mb-2">Errors:</h4>
|
||||||
{parsedResult.error.errors.map((error, idx) => (
|
{parsedResult.error.errors.map((error, idx) => (
|
||||||
<pre
|
<JsonView data={error} key={idx} />
|
||||||
key={idx}
|
|
||||||
className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64"
|
|
||||||
>
|
|
||||||
{JSON.stringify(error, null, 2)}
|
|
||||||
</pre>
|
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -73,14 +75,17 @@ const ToolsTab = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h4 className="font-semibold mb-2">
|
<h4 className="font-semibold mb-2">
|
||||||
Tool Result: {isError ? "Error" : "Success"}
|
Tool Result:{" "}
|
||||||
|
{isError ? (
|
||||||
|
<span className="text-red-600 font-semibold">Error</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-green-600 font-semibold">Success</span>
|
||||||
|
)}
|
||||||
</h4>
|
</h4>
|
||||||
{structuredResult.content.map((item, index) => (
|
{structuredResult.content.map((item, index) => (
|
||||||
<div key={index} className="mb-2">
|
<div key={index} className="mb-2">
|
||||||
{item.type === "text" && (
|
{item.type === "text" && (
|
||||||
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64">
|
<JsonView data={item.text} isError={isError} />
|
||||||
{item.text}
|
|
||||||
</pre>
|
|
||||||
)}
|
)}
|
||||||
{item.type === "image" && (
|
{item.type === "image" && (
|
||||||
<img
|
<img
|
||||||
@@ -99,9 +104,7 @@ const ToolsTab = ({
|
|||||||
<p>Your browser does not support audio playback</p>
|
<p>Your browser does not support audio playback</p>
|
||||||
</audio>
|
</audio>
|
||||||
) : (
|
) : (
|
||||||
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 whitespace-pre-wrap break-words p-4 rounded text-sm overflow-auto max-h-64">
|
<JsonView data={item.resource} />
|
||||||
{JSON.stringify(item.resource, null, 2)}
|
|
||||||
</pre>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -111,153 +114,187 @@ const ToolsTab = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h4 className="font-semibold mb-2">Tool Result (Legacy):</h4>
|
<h4 className="font-semibold mb-2">Tool Result (Legacy):</h4>
|
||||||
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64">
|
|
||||||
{JSON.stringify(toolResult.toolResult, null, 2)}
|
<JsonView data={toolResult.toolResult} />
|
||||||
</pre>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="tools" className="grid grid-cols-2 gap-4">
|
<TabsContent value="tools">
|
||||||
<ListPane
|
<div className="grid grid-cols-2 gap-4">
|
||||||
items={tools}
|
<ListPane
|
||||||
listItems={listTools}
|
items={tools}
|
||||||
clearItems={() => {
|
listItems={listTools}
|
||||||
clearTools();
|
clearItems={() => {
|
||||||
setSelectedTool(null);
|
clearTools();
|
||||||
}}
|
setSelectedTool(null);
|
||||||
setSelectedItem={setSelectedTool}
|
}}
|
||||||
renderItem={(tool) => (
|
setSelectedItem={setSelectedTool}
|
||||||
<>
|
renderItem={(tool) => (
|
||||||
<span className="flex-1">{tool.name}</span>
|
<div className="flex flex-col items-start">
|
||||||
<span className="text-sm text-gray-500 text-right">
|
<span className="flex-1">{tool.name}</span>
|
||||||
{tool.description}
|
<span className="text-sm text-gray-500 text-left">
|
||||||
</span>
|
{tool.description}
|
||||||
</>
|
</span>
|
||||||
)}
|
</div>
|
||||||
title="Tools"
|
)}
|
||||||
buttonText={nextCursor ? "List More Tools" : "List Tools"}
|
title="Tools"
|
||||||
isButtonDisabled={!nextCursor && tools.length > 0}
|
buttonText={nextCursor ? "List More Tools" : "List Tools"}
|
||||||
/>
|
isButtonDisabled={!nextCursor && tools.length > 0}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="bg-card rounded-lg shadow">
|
<div className="bg-card rounded-lg shadow">
|
||||||
<div className="p-4 border-b border-gray-200">
|
<div className="p-4 border-b border-gray-200 dark:border-gray-800">
|
||||||
<h3 className="font-semibold">
|
<h3 className="font-semibold">
|
||||||
{selectedTool ? selectedTool.name : "Select a tool"}
|
{selectedTool ? selectedTool.name : "Select a tool"}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
{error ? (
|
{selectedTool ? (
|
||||||
<Alert variant="destructive">
|
<div className="space-y-4">
|
||||||
<AlertCircle className="h-4 w-4" />
|
<p className="text-sm text-gray-600">
|
||||||
<AlertTitle>Error</AlertTitle>
|
{selectedTool.description}
|
||||||
<AlertDescription>{error}</AlertDescription>
|
</p>
|
||||||
</Alert>
|
{Object.entries(selectedTool.inputSchema.properties ?? []).map(
|
||||||
) : selectedTool ? (
|
([key, value]) => {
|
||||||
<div className="space-y-4">
|
const prop = value as JsonSchemaType;
|
||||||
<p className="text-sm text-gray-600">
|
return (
|
||||||
{selectedTool.description}
|
<div key={key}>
|
||||||
</p>
|
<Label
|
||||||
{Object.entries(selectedTool.inputSchema.properties ?? []).map(
|
htmlFor={key}
|
||||||
([key, value]) => {
|
className="block text-sm font-medium text-gray-700"
|
||||||
const prop = value as JsonSchemaType;
|
>
|
||||||
return (
|
{key}
|
||||||
<div key={key}>
|
</Label>
|
||||||
<Label
|
{prop.type === "boolean" ? (
|
||||||
htmlFor={key}
|
<div className="flex items-center space-x-2 mt-2">
|
||||||
className="block text-sm font-medium text-gray-700"
|
<Checkbox
|
||||||
>
|
id={key}
|
||||||
{key}
|
name={key}
|
||||||
</Label>
|
checked={!!params[key]}
|
||||||
{prop.type === "boolean" ? (
|
onCheckedChange={(checked: boolean) =>
|
||||||
<div className="flex items-center space-x-2 mt-2">
|
setParams({
|
||||||
<Checkbox
|
...params,
|
||||||
|
[key]: checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor={key}
|
||||||
|
className="text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||||
|
>
|
||||||
|
{prop.description || "Toggle this option"}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
) : prop.type === "string" ? (
|
||||||
|
<Textarea
|
||||||
id={key}
|
id={key}
|
||||||
name={key}
|
name={key}
|
||||||
checked={!!params[key]}
|
placeholder={prop.description}
|
||||||
onCheckedChange={(checked: boolean) =>
|
value={(params[key] as string) ?? ""}
|
||||||
|
onChange={(e) =>
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
[key]: checked,
|
[key]: e.target.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
className="mt-1"
|
||||||
/>
|
/>
|
||||||
<label
|
) : prop.type === "object" || prop.type === "array" ? (
|
||||||
htmlFor={key}
|
<div className="mt-1">
|
||||||
className="text-sm font-medium text-gray-700 dark:text-gray-300"
|
<DynamicJsonForm
|
||||||
>
|
schema={{
|
||||||
{prop.description || "Toggle this option"}
|
type: prop.type,
|
||||||
</label>
|
properties: prop.properties,
|
||||||
</div>
|
description: prop.description,
|
||||||
) : prop.type === "string" ? (
|
items: prop.items,
|
||||||
<Textarea
|
}}
|
||||||
id={key}
|
value={
|
||||||
name={key}
|
(params[key] as JsonValue) ??
|
||||||
placeholder={prop.description}
|
generateDefaultValue(prop)
|
||||||
value={(params[key] as string) ?? ""}
|
}
|
||||||
onChange={(e) =>
|
onChange={(newValue: JsonValue) => {
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
[key]: e.target.value,
|
[key]: newValue,
|
||||||
})
|
});
|
||||||
}
|
}}
|
||||||
className="mt-1"
|
/>
|
||||||
/>
|
</div>
|
||||||
) : prop.type === "object" || prop.type === "array" ? (
|
) : prop.type === "number" ||
|
||||||
<div className="mt-1">
|
prop.type === "integer" ? (
|
||||||
<DynamicJsonForm
|
<Input
|
||||||
schema={{
|
type="number"
|
||||||
type: prop.type,
|
id={key}
|
||||||
properties: prop.properties,
|
name={key}
|
||||||
description: prop.description,
|
placeholder={prop.description}
|
||||||
items: prop.items,
|
value={(params[key] as string) ?? ""}
|
||||||
}}
|
onChange={(e) =>
|
||||||
value={(params[key] as JsonValue) ?? {}}
|
|
||||||
onChange={(newValue: JsonValue) => {
|
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
[key]: newValue,
|
[key]: Number(e.target.value),
|
||||||
});
|
})
|
||||||
}}
|
}
|
||||||
|
className="mt-1"
|
||||||
/>
|
/>
|
||||||
</div>
|
) : (
|
||||||
) : (
|
<div className="mt-1">
|
||||||
<Input
|
<DynamicJsonForm
|
||||||
type={prop.type === "number" ? "number" : "text"}
|
schema={{
|
||||||
id={key}
|
type: prop.type,
|
||||||
name={key}
|
properties: prop.properties,
|
||||||
placeholder={prop.description}
|
description: prop.description,
|
||||||
onChange={(e) =>
|
items: prop.items,
|
||||||
setParams({
|
}}
|
||||||
...params,
|
value={params[key] as JsonValue}
|
||||||
[key]:
|
onChange={(newValue: JsonValue) => {
|
||||||
prop.type === "number"
|
setParams({
|
||||||
? Number(e.target.value)
|
...params,
|
||||||
: e.target.value,
|
[key]: newValue,
|
||||||
})
|
});
|
||||||
}
|
}}
|
||||||
className="mt-1"
|
/>
|
||||||
/>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
<Button onClick={() => callTool(selectedTool.name, params)}>
|
<Button
|
||||||
<Send className="w-4 h-4 mr-2" />
|
onClick={async () => {
|
||||||
Run Tool
|
try {
|
||||||
</Button>
|
setIsToolRunning(true);
|
||||||
{toolResult && renderToolResult()}
|
await callTool(selectedTool.name, params);
|
||||||
</div>
|
} finally {
|
||||||
) : (
|
setIsToolRunning(false);
|
||||||
<Alert>
|
}
|
||||||
<AlertDescription>
|
}}
|
||||||
Select a tool from the list to view its details and run it
|
disabled={isToolRunning}
|
||||||
</AlertDescription>
|
>
|
||||||
</Alert>
|
{isToolRunning ? (
|
||||||
)}
|
<>
|
||||||
|
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||||
|
Running...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Send className="w-4 h-4 mr-2" />
|
||||||
|
Run Tool
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
{toolResult && renderToolResult()}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>
|
||||||
|
Select a tool from the list to view its details and run it
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|||||||
382
client/src/components/__tests__/AuthDebugger.test.tsx
Normal file
382
client/src/components/__tests__/AuthDebugger.test.tsx
Normal file
@@ -0,0 +1,382 @@
|
|||||||
|
import {
|
||||||
|
render,
|
||||||
|
screen,
|
||||||
|
fireEvent,
|
||||||
|
waitFor,
|
||||||
|
act,
|
||||||
|
} from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom";
|
||||||
|
import { describe, it, beforeEach, jest } from "@jest/globals";
|
||||||
|
import AuthDebugger, { AuthDebuggerProps } from "../AuthDebugger";
|
||||||
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
|
import { SESSION_KEYS } from "@/lib/constants";
|
||||||
|
|
||||||
|
const mockOAuthTokens = {
|
||||||
|
access_token: "test_access_token",
|
||||||
|
token_type: "Bearer",
|
||||||
|
expires_in: 3600,
|
||||||
|
refresh_token: "test_refresh_token",
|
||||||
|
scope: "test_scope",
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockOAuthMetadata = {
|
||||||
|
issuer: "https://oauth.example.com",
|
||||||
|
authorization_endpoint: "https://oauth.example.com/authorize",
|
||||||
|
token_endpoint: "https://oauth.example.com/token",
|
||||||
|
response_types_supported: ["code"],
|
||||||
|
grant_types_supported: ["authorization_code"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockOAuthClientInfo = {
|
||||||
|
client_id: "test_client_id",
|
||||||
|
client_secret: "test_client_secret",
|
||||||
|
redirect_uris: ["http://localhost:3000/oauth/callback/debug"],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mock MCP SDK functions - must be before imports
|
||||||
|
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
|
||||||
|
auth: jest.fn(),
|
||||||
|
discoverOAuthMetadata: jest.fn(),
|
||||||
|
registerClient: jest.fn(),
|
||||||
|
startAuthorization: jest.fn(),
|
||||||
|
exchangeAuthorization: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Import the functions to get their types
|
||||||
|
import {
|
||||||
|
discoverOAuthMetadata,
|
||||||
|
registerClient,
|
||||||
|
startAuthorization,
|
||||||
|
exchangeAuthorization,
|
||||||
|
} from "@modelcontextprotocol/sdk/client/auth.js";
|
||||||
|
import { OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
|
|
||||||
|
// Type the mocked functions properly
|
||||||
|
const mockDiscoverOAuthMetadata = discoverOAuthMetadata as jest.MockedFunction<
|
||||||
|
typeof discoverOAuthMetadata
|
||||||
|
>;
|
||||||
|
const mockRegisterClient = registerClient as jest.MockedFunction<
|
||||||
|
typeof registerClient
|
||||||
|
>;
|
||||||
|
const mockStartAuthorization = startAuthorization as jest.MockedFunction<
|
||||||
|
typeof startAuthorization
|
||||||
|
>;
|
||||||
|
const mockExchangeAuthorization = exchangeAuthorization as jest.MockedFunction<
|
||||||
|
typeof exchangeAuthorization
|
||||||
|
>;
|
||||||
|
|
||||||
|
const sessionStorageMock = {
|
||||||
|
getItem: jest.fn(),
|
||||||
|
setItem: jest.fn(),
|
||||||
|
removeItem: jest.fn(),
|
||||||
|
clear: jest.fn(),
|
||||||
|
};
|
||||||
|
Object.defineProperty(window, "sessionStorage", {
|
||||||
|
value: sessionStorageMock,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(window, "location", {
|
||||||
|
value: {
|
||||||
|
origin: "http://localhost:3000",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("AuthDebugger", () => {
|
||||||
|
const defaultAuthState = {
|
||||||
|
isInitiatingAuth: false,
|
||||||
|
oauthTokens: null,
|
||||||
|
loading: false,
|
||||||
|
oauthStep: "metadata_discovery" as const,
|
||||||
|
oauthMetadata: null,
|
||||||
|
oauthClientInfo: null,
|
||||||
|
authorizationUrl: null,
|
||||||
|
authorizationCode: "",
|
||||||
|
latestError: null,
|
||||||
|
statusMessage: null,
|
||||||
|
validationError: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultProps = {
|
||||||
|
serverUrl: "https://example.com",
|
||||||
|
onBack: jest.fn(),
|
||||||
|
authState: defaultAuthState,
|
||||||
|
updateAuthState: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
sessionStorageMock.getItem.mockReturnValue(null);
|
||||||
|
|
||||||
|
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
|
||||||
|
mockRegisterClient.mockResolvedValue(mockOAuthClientInfo);
|
||||||
|
mockStartAuthorization.mockImplementation(async (_sseUrl, options) => {
|
||||||
|
const authUrl = new URL("https://oauth.example.com/authorize");
|
||||||
|
|
||||||
|
if (options.scope) {
|
||||||
|
authUrl.searchParams.set("scope", options.scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
authorizationUrl: authUrl,
|
||||||
|
codeVerifier: "test_verifier",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
mockExchangeAuthorization.mockResolvedValue(mockOAuthTokens);
|
||||||
|
});
|
||||||
|
|
||||||
|
const renderAuthDebugger = (props: Partial<AuthDebuggerProps> = {}) => {
|
||||||
|
const mergedProps = {
|
||||||
|
...defaultProps,
|
||||||
|
...props,
|
||||||
|
authState: { ...defaultAuthState, ...(props.authState || {}) },
|
||||||
|
};
|
||||||
|
return render(
|
||||||
|
<TooltipProvider>
|
||||||
|
<AuthDebugger {...mergedProps} />
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Initial Rendering", () => {
|
||||||
|
it("should render the component with correct title", async () => {
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger();
|
||||||
|
});
|
||||||
|
expect(screen.getByText("Authentication Settings")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onBack when Back button is clicked", async () => {
|
||||||
|
const onBack = jest.fn();
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger({ onBack });
|
||||||
|
});
|
||||||
|
fireEvent.click(screen.getByText("Back to Connect"));
|
||||||
|
expect(onBack).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("OAuth Flow", () => {
|
||||||
|
it("should start OAuth flow when 'Guided OAuth Flow' is clicked", async () => {
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger();
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(screen.getByText("Guided OAuth Flow"));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(screen.getByText("OAuth Flow Progress")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show error when OAuth flow is started without sseUrl", async () => {
|
||||||
|
const updateAuthState = jest.fn();
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger({ serverUrl: "", updateAuthState });
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(screen.getByText("Guided OAuth Flow"));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(updateAuthState).toHaveBeenCalledWith({
|
||||||
|
statusMessage: {
|
||||||
|
type: "error",
|
||||||
|
message:
|
||||||
|
"Please enter a server URL in the sidebar before authenticating",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Session Storage Integration", () => {
|
||||||
|
it("should load OAuth tokens from session storage", async () => {
|
||||||
|
// Mock the specific key for tokens with server URL
|
||||||
|
sessionStorageMock.getItem.mockImplementation((key) => {
|
||||||
|
if (key === "[https://example.com] mcp_tokens") {
|
||||||
|
return JSON.stringify(mockOAuthTokens);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger({
|
||||||
|
authState: {
|
||||||
|
...defaultAuthState,
|
||||||
|
oauthTokens: mockOAuthTokens,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText(/Access Token:/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle errors loading OAuth tokens from session storage", async () => {
|
||||||
|
// Mock console to avoid cluttering test output
|
||||||
|
const originalError = console.error;
|
||||||
|
console.error = jest.fn();
|
||||||
|
|
||||||
|
// Mock getItem to return invalid JSON for tokens
|
||||||
|
sessionStorageMock.getItem.mockImplementation((key) => {
|
||||||
|
if (key === "[https://example.com] mcp_tokens") {
|
||||||
|
return "invalid json";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Component should still render despite the error
|
||||||
|
expect(screen.getByText("Authentication Settings")).toBeInTheDocument();
|
||||||
|
|
||||||
|
// Restore console.error
|
||||||
|
console.error = originalError;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("OAuth State Management", () => {
|
||||||
|
it("should clear OAuth state when Clear button is clicked", async () => {
|
||||||
|
const updateAuthState = jest.fn();
|
||||||
|
// Mock the session storage to return tokens for the specific key
|
||||||
|
sessionStorageMock.getItem.mockImplementation((key) => {
|
||||||
|
if (key === "[https://example.com] mcp_tokens") {
|
||||||
|
return JSON.stringify(mockOAuthTokens);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger({
|
||||||
|
authState: {
|
||||||
|
...defaultAuthState,
|
||||||
|
oauthTokens: mockOAuthTokens,
|
||||||
|
},
|
||||||
|
updateAuthState,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(screen.getByText("Clear OAuth State"));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(updateAuthState).toHaveBeenCalledWith({
|
||||||
|
oauthTokens: null,
|
||||||
|
oauthStep: "metadata_discovery",
|
||||||
|
latestError: null,
|
||||||
|
oauthClientInfo: null,
|
||||||
|
oauthMetadata: null,
|
||||||
|
authorizationCode: "",
|
||||||
|
validationError: null,
|
||||||
|
statusMessage: {
|
||||||
|
type: "success",
|
||||||
|
message: "OAuth tokens cleared successfully",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify session storage was cleared
|
||||||
|
expect(sessionStorageMock.removeItem).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("OAuth Flow Steps", () => {
|
||||||
|
it("should handle OAuth flow step progression", async () => {
|
||||||
|
const updateAuthState = jest.fn();
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger({
|
||||||
|
updateAuthState,
|
||||||
|
authState: {
|
||||||
|
...defaultAuthState,
|
||||||
|
isInitiatingAuth: false, // Changed to false so button is enabled
|
||||||
|
oauthStep: "metadata_discovery",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify metadata discovery step
|
||||||
|
expect(screen.getByText("Metadata Discovery")).toBeInTheDocument();
|
||||||
|
|
||||||
|
// Click Continue - this should trigger metadata discovery
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(screen.getByText("Continue"));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockDiscoverOAuthMetadata).toHaveBeenCalledWith(
|
||||||
|
"https://example.com",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setup helper for OAuth authorization tests
|
||||||
|
const setupAuthorizationUrlTest = async (metadata: OAuthMetadata) => {
|
||||||
|
const updateAuthState = jest.fn();
|
||||||
|
|
||||||
|
// Mock the session storage to return metadata
|
||||||
|
sessionStorageMock.getItem.mockImplementation((key) => {
|
||||||
|
if (key === `[https://example.com] ${SESSION_KEYS.SERVER_METADATA}`) {
|
||||||
|
return JSON.stringify(metadata);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
key === `[https://example.com] ${SESSION_KEYS.CLIENT_INFORMATION}`
|
||||||
|
) {
|
||||||
|
return JSON.stringify(mockOAuthClientInfo);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
renderAuthDebugger({
|
||||||
|
updateAuthState,
|
||||||
|
authState: {
|
||||||
|
...defaultAuthState,
|
||||||
|
isInitiatingAuth: false,
|
||||||
|
oauthStep: "authorization_redirect",
|
||||||
|
oauthMetadata: metadata,
|
||||||
|
oauthClientInfo: mockOAuthClientInfo,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Click Continue to trigger authorization
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(screen.getByText("Continue"));
|
||||||
|
});
|
||||||
|
|
||||||
|
return updateAuthState;
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should include scope in authorization URL when scopes_supported is present", async () => {
|
||||||
|
const metadataWithScopes = {
|
||||||
|
...mockOAuthMetadata,
|
||||||
|
scopes_supported: ["read", "write", "admin"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateAuthState =
|
||||||
|
await setupAuthorizationUrlTest(metadataWithScopes);
|
||||||
|
|
||||||
|
// Wait for the updateAuthState to be called
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(updateAuthState).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
authorizationUrl: expect.stringContaining("scope="),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not include scope in authorization URL when scopes_supported is not present", async () => {
|
||||||
|
const updateAuthState =
|
||||||
|
await setupAuthorizationUrlTest(mockOAuthMetadata);
|
||||||
|
|
||||||
|
// Wait for the updateAuthState to be called
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(updateAuthState).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
authorizationUrl: expect.not.stringContaining("scope="),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
139
client/src/components/__tests__/DynamicJsonForm.test.tsx
Normal file
139
client/src/components/__tests__/DynamicJsonForm.test.tsx
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||||
|
import { describe, it, expect, jest } from "@jest/globals";
|
||||||
|
import DynamicJsonForm from "../DynamicJsonForm";
|
||||||
|
import type { JsonSchemaType } from "@/utils/jsonUtils";
|
||||||
|
|
||||||
|
describe("DynamicJsonForm String Fields", () => {
|
||||||
|
const renderForm = (props = {}) => {
|
||||||
|
const defaultProps = {
|
||||||
|
schema: {
|
||||||
|
type: "string" as const,
|
||||||
|
description: "Test string field",
|
||||||
|
} satisfies JsonSchemaType,
|
||||||
|
value: undefined,
|
||||||
|
onChange: jest.fn(),
|
||||||
|
};
|
||||||
|
return render(<DynamicJsonForm {...defaultProps} {...props} />);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Type Validation", () => {
|
||||||
|
it("should handle numeric input as string type", () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
renderForm({ onChange });
|
||||||
|
|
||||||
|
const input = screen.getByRole("textbox");
|
||||||
|
fireEvent.change(input, { target: { value: "123321" } });
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith("123321");
|
||||||
|
// Verify the value is a string, not a number
|
||||||
|
expect(typeof onChange.mock.calls[0][0]).toBe("string");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render as text input, not number input", () => {
|
||||||
|
renderForm();
|
||||||
|
const input = screen.getByRole("textbox");
|
||||||
|
expect(input).toHaveProperty("type", "text");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DynamicJsonForm Integer Fields", () => {
|
||||||
|
const renderForm = (props = {}) => {
|
||||||
|
const defaultProps = {
|
||||||
|
schema: {
|
||||||
|
type: "integer" as const,
|
||||||
|
description: "Test integer field",
|
||||||
|
} satisfies JsonSchemaType,
|
||||||
|
value: undefined,
|
||||||
|
onChange: jest.fn(),
|
||||||
|
};
|
||||||
|
return render(<DynamicJsonForm {...defaultProps} {...props} />);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Basic Operations", () => {
|
||||||
|
it("should render number input with step=1", () => {
|
||||||
|
renderForm();
|
||||||
|
const input = screen.getByRole("spinbutton");
|
||||||
|
expect(input).toHaveProperty("type", "number");
|
||||||
|
expect(input).toHaveProperty("step", "1");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should pass integer values to onChange", () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
renderForm({ onChange });
|
||||||
|
|
||||||
|
const input = screen.getByRole("spinbutton");
|
||||||
|
fireEvent.change(input, { target: { value: "42" } });
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith(42);
|
||||||
|
// Verify the value is a number, not a string
|
||||||
|
expect(typeof onChange.mock.calls[0][0]).toBe("number");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not pass string values to onChange", () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
renderForm({ onChange });
|
||||||
|
|
||||||
|
const input = screen.getByRole("spinbutton");
|
||||||
|
fireEvent.change(input, { target: { value: "abc" } });
|
||||||
|
|
||||||
|
expect(onChange).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Edge Cases", () => {
|
||||||
|
it("should handle non-numeric input by not calling onChange", () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
renderForm({ onChange });
|
||||||
|
|
||||||
|
const input = screen.getByRole("spinbutton");
|
||||||
|
fireEvent.change(input, { target: { value: "abc" } });
|
||||||
|
|
||||||
|
expect(onChange).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DynamicJsonForm Complex Fields", () => {
|
||||||
|
const renderForm = (props = {}) => {
|
||||||
|
const defaultProps = {
|
||||||
|
schema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
// The simplified JsonSchemaType does not accept oneOf fields
|
||||||
|
// But they exist in the more-complete JsonSchema7Type
|
||||||
|
nested: { oneOf: [{ type: "string" }, { type: "integer" }] },
|
||||||
|
},
|
||||||
|
} as unknown as JsonSchemaType,
|
||||||
|
value: undefined,
|
||||||
|
onChange: jest.fn(),
|
||||||
|
};
|
||||||
|
return render(<DynamicJsonForm {...defaultProps} {...props} />);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Basic Operations", () => {
|
||||||
|
it("should render textbox and autoformat button, but no switch-to-form button", () => {
|
||||||
|
renderForm();
|
||||||
|
const input = screen.getByRole("textbox");
|
||||||
|
expect(input).toHaveProperty("type", "textarea");
|
||||||
|
const buttons = screen.getAllByRole("button");
|
||||||
|
expect(buttons).toHaveLength(1);
|
||||||
|
expect(buttons[0]).toHaveProperty("textContent", "Format JSON");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should pass changed values to onChange", () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
renderForm({ onChange });
|
||||||
|
|
||||||
|
const input = screen.getByRole("textbox");
|
||||||
|
fireEvent.change(input, {
|
||||||
|
target: { value: `{ "nested": "i am string" }` },
|
||||||
|
});
|
||||||
|
|
||||||
|
// The onChange handler is debounced when using the JSON view, so we need to wait a little bit
|
||||||
|
waitFor(() => {
|
||||||
|
expect(onChange).toHaveBeenCalledWith(`{ "nested": "i am string" }`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
872
client/src/components/__tests__/Sidebar.test.tsx
Normal file
872
client/src/components/__tests__/Sidebar.test.tsx
Normal file
@@ -0,0 +1,872 @@
|
|||||||
|
import { render, screen, fireEvent, act } from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom";
|
||||||
|
import { describe, it, beforeEach, jest } from "@jest/globals";
|
||||||
|
import Sidebar from "../Sidebar";
|
||||||
|
import { DEFAULT_INSPECTOR_CONFIG } from "@/lib/constants";
|
||||||
|
import { InspectorConfig } from "@/lib/configurationTypes";
|
||||||
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
|
// Mock theme hook
|
||||||
|
jest.mock("../../lib/hooks/useTheme", () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: () => ["light", jest.fn()],
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock toast hook
|
||||||
|
const mockToast = jest.fn();
|
||||||
|
jest.mock("@/lib/hooks/useToast", () => ({
|
||||||
|
useToast: () => ({
|
||||||
|
toast: mockToast,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock navigator clipboard
|
||||||
|
const mockClipboardWrite = jest.fn(() => Promise.resolve());
|
||||||
|
Object.defineProperty(navigator, "clipboard", {
|
||||||
|
value: {
|
||||||
|
writeText: mockClipboardWrite,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setup fake timers
|
||||||
|
jest.useFakeTimers();
|
||||||
|
|
||||||
|
describe("Sidebar Environment Variables", () => {
|
||||||
|
const defaultProps = {
|
||||||
|
connectionStatus: "disconnected" as const,
|
||||||
|
transportType: "stdio" as const,
|
||||||
|
setTransportType: jest.fn(),
|
||||||
|
command: "",
|
||||||
|
setCommand: jest.fn(),
|
||||||
|
args: "",
|
||||||
|
setArgs: jest.fn(),
|
||||||
|
sseUrl: "",
|
||||||
|
setSseUrl: jest.fn(),
|
||||||
|
env: {},
|
||||||
|
setEnv: jest.fn(),
|
||||||
|
bearerToken: "",
|
||||||
|
setBearerToken: jest.fn(),
|
||||||
|
onConnect: jest.fn(),
|
||||||
|
onDisconnect: jest.fn(),
|
||||||
|
stdErrNotifications: [],
|
||||||
|
clearStdErrNotifications: jest.fn(),
|
||||||
|
logLevel: "info" as const,
|
||||||
|
sendLogLevelRequest: jest.fn(),
|
||||||
|
loggingSupported: true,
|
||||||
|
config: DEFAULT_INSPECTOR_CONFIG,
|
||||||
|
setConfig: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderSidebar = (props = {}) => {
|
||||||
|
return render(
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sidebar {...defaultProps} {...props} />
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEnvVarsSection = () => {
|
||||||
|
const button = screen.getByTestId("env-vars-button");
|
||||||
|
fireEvent.click(button);
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
jest.clearAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Basic Operations", () => {
|
||||||
|
it("should add a new environment variable", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
renderSidebar({ env: {}, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const addButton = screen.getByText("Add Environment Variable");
|
||||||
|
fireEvent.click(addButton);
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({ "": "" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should remove an environment variable", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const removeButton = screen.getByRole("button", { name: "×" });
|
||||||
|
fireEvent.click(removeButton);
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update environment variable value", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const valueInput = screen.getByDisplayValue("test_value");
|
||||||
|
fireEvent.change(valueInput, { target: { value: "new_value" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({ TEST_KEY: "new_value" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should toggle value visibility", () => {
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const valueInput = screen.getByDisplayValue("test_value");
|
||||||
|
expect(valueInput).toHaveProperty("type", "password");
|
||||||
|
|
||||||
|
const toggleButton = screen.getByRole("button", { name: /show value/i });
|
||||||
|
fireEvent.click(toggleButton);
|
||||||
|
|
||||||
|
expect(valueInput).toHaveProperty("type", "text");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Authentication", () => {
|
||||||
|
const openAuthSection = () => {
|
||||||
|
const button = screen.getByTestId("auth-button");
|
||||||
|
fireEvent.click(button);
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should update bearer token", () => {
|
||||||
|
const setBearerToken = jest.fn();
|
||||||
|
renderSidebar({
|
||||||
|
bearerToken: "",
|
||||||
|
setBearerToken,
|
||||||
|
transportType: "sse", // Set transport type to SSE
|
||||||
|
});
|
||||||
|
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
const tokenInput = screen.getByTestId("bearer-token-input");
|
||||||
|
fireEvent.change(tokenInput, { target: { value: "new_token" } });
|
||||||
|
|
||||||
|
expect(setBearerToken).toHaveBeenCalledWith("new_token");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update header name", () => {
|
||||||
|
const setHeaderName = jest.fn();
|
||||||
|
renderSidebar({
|
||||||
|
headerName: "Authorization",
|
||||||
|
setHeaderName,
|
||||||
|
transportType: "sse",
|
||||||
|
});
|
||||||
|
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
const headerInput = screen.getByTestId("header-input");
|
||||||
|
fireEvent.change(headerInput, { target: { value: "X-Custom-Auth" } });
|
||||||
|
|
||||||
|
expect(setHeaderName).toHaveBeenCalledWith("X-Custom-Auth");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should clear bearer token", () => {
|
||||||
|
const setBearerToken = jest.fn();
|
||||||
|
renderSidebar({
|
||||||
|
bearerToken: "existing_token",
|
||||||
|
setBearerToken,
|
||||||
|
transportType: "sse", // Set transport type to SSE
|
||||||
|
});
|
||||||
|
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
const tokenInput = screen.getByTestId("bearer-token-input");
|
||||||
|
fireEvent.change(tokenInput, { target: { value: "" } });
|
||||||
|
|
||||||
|
expect(setBearerToken).toHaveBeenCalledWith("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should properly render bearer token input", () => {
|
||||||
|
const { rerender } = renderSidebar({
|
||||||
|
bearerToken: "existing_token",
|
||||||
|
transportType: "sse", // Set transport type to SSE
|
||||||
|
});
|
||||||
|
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
// Token input should be a password field
|
||||||
|
const tokenInput = screen.getByTestId("bearer-token-input");
|
||||||
|
expect(tokenInput).toHaveProperty("type", "password");
|
||||||
|
|
||||||
|
// Update the token
|
||||||
|
fireEvent.change(tokenInput, { target: { value: "new_token" } });
|
||||||
|
|
||||||
|
// Rerender with updated token
|
||||||
|
rerender(
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sidebar
|
||||||
|
{...defaultProps}
|
||||||
|
bearerToken="new_token"
|
||||||
|
transportType="sse"
|
||||||
|
/>
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Token input should still exist after update
|
||||||
|
expect(screen.getByTestId("bearer-token-input")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain token visibility state after update", () => {
|
||||||
|
const { rerender } = renderSidebar({
|
||||||
|
bearerToken: "existing_token",
|
||||||
|
transportType: "sse", // Set transport type to SSE
|
||||||
|
});
|
||||||
|
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
// Token input should be a password field
|
||||||
|
const tokenInput = screen.getByTestId("bearer-token-input");
|
||||||
|
expect(tokenInput).toHaveProperty("type", "password");
|
||||||
|
|
||||||
|
// Update the token
|
||||||
|
fireEvent.change(tokenInput, { target: { value: "new_token" } });
|
||||||
|
|
||||||
|
// Rerender with updated token
|
||||||
|
rerender(
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sidebar
|
||||||
|
{...defaultProps}
|
||||||
|
bearerToken="new_token"
|
||||||
|
transportType="sse"
|
||||||
|
/>
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Token input should still exist after update
|
||||||
|
expect(screen.getByTestId("bearer-token-input")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain header name when toggling auth section", () => {
|
||||||
|
renderSidebar({
|
||||||
|
headerName: "X-API-Key",
|
||||||
|
transportType: "sse",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Open auth section
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
// Verify header name is displayed
|
||||||
|
const headerInput = screen.getByTestId("header-input");
|
||||||
|
expect(headerInput).toHaveValue("X-API-Key");
|
||||||
|
|
||||||
|
// Close auth section
|
||||||
|
const authButton = screen.getByTestId("auth-button");
|
||||||
|
fireEvent.click(authButton);
|
||||||
|
|
||||||
|
// Reopen auth section
|
||||||
|
fireEvent.click(authButton);
|
||||||
|
|
||||||
|
// Verify header name is still preserved
|
||||||
|
expect(screen.getByTestId("header-input")).toHaveValue("X-API-Key");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should display default header name when not specified", () => {
|
||||||
|
renderSidebar({
|
||||||
|
headerName: undefined,
|
||||||
|
transportType: "sse",
|
||||||
|
});
|
||||||
|
|
||||||
|
openAuthSection();
|
||||||
|
|
||||||
|
const headerInput = screen.getByTestId("header-input");
|
||||||
|
expect(headerInput).toHaveAttribute("placeholder", "Authorization");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Key Editing", () => {
|
||||||
|
it("should maintain order when editing first key", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = {
|
||||||
|
FIRST_KEY: "first_value",
|
||||||
|
SECOND_KEY: "second_value",
|
||||||
|
THIRD_KEY: "third_value",
|
||||||
|
};
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const firstKeyInput = screen.getByDisplayValue("FIRST_KEY");
|
||||||
|
fireEvent.change(firstKeyInput, { target: { value: "NEW_FIRST_KEY" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({
|
||||||
|
NEW_FIRST_KEY: "first_value",
|
||||||
|
SECOND_KEY: "second_value",
|
||||||
|
THIRD_KEY: "third_value",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain order when editing middle key", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = {
|
||||||
|
FIRST_KEY: "first_value",
|
||||||
|
SECOND_KEY: "second_value",
|
||||||
|
THIRD_KEY: "third_value",
|
||||||
|
};
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const middleKeyInput = screen.getByDisplayValue("SECOND_KEY");
|
||||||
|
fireEvent.change(middleKeyInput, { target: { value: "NEW_SECOND_KEY" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({
|
||||||
|
FIRST_KEY: "first_value",
|
||||||
|
NEW_SECOND_KEY: "second_value",
|
||||||
|
THIRD_KEY: "third_value",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain order when editing last key", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = {
|
||||||
|
FIRST_KEY: "first_value",
|
||||||
|
SECOND_KEY: "second_value",
|
||||||
|
THIRD_KEY: "third_value",
|
||||||
|
};
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const lastKeyInput = screen.getByDisplayValue("THIRD_KEY");
|
||||||
|
fireEvent.change(lastKeyInput, { target: { value: "NEW_THIRD_KEY" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({
|
||||||
|
FIRST_KEY: "first_value",
|
||||||
|
SECOND_KEY: "second_value",
|
||||||
|
NEW_THIRD_KEY: "third_value",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain order during key editing", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = {
|
||||||
|
KEY1: "value1",
|
||||||
|
KEY2: "value2",
|
||||||
|
};
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
// Type "NEW_" one character at a time
|
||||||
|
const key1Input = screen.getByDisplayValue("KEY1");
|
||||||
|
"NEW_".split("").forEach((char) => {
|
||||||
|
fireEvent.change(key1Input, {
|
||||||
|
target: { value: char + "KEY1".slice(1) },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify the last setEnv call maintains the order
|
||||||
|
const lastCall = setEnv.mock.calls[
|
||||||
|
setEnv.mock.calls.length - 1
|
||||||
|
][0] as Record<string, string>;
|
||||||
|
const entries = Object.entries(lastCall);
|
||||||
|
|
||||||
|
// The values should stay with their original keys
|
||||||
|
expect(entries[0][1]).toBe("value1"); // First entry should still have value1
|
||||||
|
expect(entries[1][1]).toBe("value2"); // Second entry should still have value2
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Multiple Operations", () => {
|
||||||
|
it("should maintain state after multiple key edits", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = {
|
||||||
|
FIRST_KEY: "first_value",
|
||||||
|
SECOND_KEY: "second_value",
|
||||||
|
};
|
||||||
|
const { rerender } = renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
// First key edit
|
||||||
|
const firstKeyInput = screen.getByDisplayValue("FIRST_KEY");
|
||||||
|
fireEvent.change(firstKeyInput, { target: { value: "NEW_FIRST_KEY" } });
|
||||||
|
|
||||||
|
// Get the updated env from the first setEnv call
|
||||||
|
const updatedEnv = setEnv.mock.calls[0][0] as Record<string, string>;
|
||||||
|
|
||||||
|
// Rerender with the updated env
|
||||||
|
rerender(
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sidebar {...defaultProps} env={updatedEnv} setEnv={setEnv} />
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Second key edit
|
||||||
|
const secondKeyInput = screen.getByDisplayValue("SECOND_KEY");
|
||||||
|
fireEvent.change(secondKeyInput, { target: { value: "NEW_SECOND_KEY" } });
|
||||||
|
|
||||||
|
// Verify the final state matches what we expect
|
||||||
|
expect(setEnv).toHaveBeenLastCalledWith({
|
||||||
|
NEW_FIRST_KEY: "first_value",
|
||||||
|
NEW_SECOND_KEY: "second_value",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain visibility state after key edit", () => {
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
const { rerender } = renderSidebar({ env: initialEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
// Show the value
|
||||||
|
const toggleButton = screen.getByRole("button", { name: /show value/i });
|
||||||
|
fireEvent.click(toggleButton);
|
||||||
|
|
||||||
|
const valueInput = screen.getByDisplayValue("test_value");
|
||||||
|
expect(valueInput).toHaveProperty("type", "text");
|
||||||
|
|
||||||
|
// Edit the key
|
||||||
|
const keyInput = screen.getByDisplayValue("TEST_KEY");
|
||||||
|
fireEvent.change(keyInput, { target: { value: "NEW_KEY" } });
|
||||||
|
|
||||||
|
// Rerender with updated env
|
||||||
|
rerender(
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sidebar {...defaultProps} env={{ NEW_KEY: "test_value" }} />
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Value should still be visible
|
||||||
|
const updatedValueInput = screen.getByDisplayValue("test_value");
|
||||||
|
expect(updatedValueInput).toHaveProperty("type", "text");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Edge Cases", () => {
|
||||||
|
it("should handle empty key", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const keyInput = screen.getByDisplayValue("TEST_KEY");
|
||||||
|
fireEvent.change(keyInput, { target: { value: "" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({ "": "test_value" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle special characters in key", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const keyInput = screen.getByDisplayValue("TEST_KEY");
|
||||||
|
fireEvent.change(keyInput, { target: { value: "TEST-KEY@123" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({ "TEST-KEY@123": "test_value" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle unicode characters", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const keyInput = screen.getByDisplayValue("TEST_KEY");
|
||||||
|
fireEvent.change(keyInput, { target: { value: "TEST_🔑" } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({ "TEST_🔑": "test_value" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle very long key names", () => {
|
||||||
|
const setEnv = jest.fn();
|
||||||
|
const initialEnv = { TEST_KEY: "test_value" };
|
||||||
|
renderSidebar({ env: initialEnv, setEnv });
|
||||||
|
|
||||||
|
openEnvVarsSection();
|
||||||
|
|
||||||
|
const keyInput = screen.getByDisplayValue("TEST_KEY");
|
||||||
|
const longKey = "A".repeat(100);
|
||||||
|
fireEvent.change(keyInput, { target: { value: longKey } });
|
||||||
|
|
||||||
|
expect(setEnv).toHaveBeenCalledWith({ [longKey]: "test_value" });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Configuration Operations", () => {
|
||||||
|
const openConfigSection = () => {
|
||||||
|
const button = screen.getByTestId("config-button");
|
||||||
|
fireEvent.click(button);
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should update MCP server request timeout", () => {
|
||||||
|
const setConfig = jest.fn();
|
||||||
|
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
|
||||||
|
|
||||||
|
openConfigSection();
|
||||||
|
|
||||||
|
const timeoutInput = screen.getByTestId(
|
||||||
|
"MCP_SERVER_REQUEST_TIMEOUT-input",
|
||||||
|
);
|
||||||
|
fireEvent.change(timeoutInput, { target: { value: "5000" } });
|
||||||
|
|
||||||
|
expect(setConfig).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
MCP_SERVER_REQUEST_TIMEOUT: {
|
||||||
|
label: "Request Timeout",
|
||||||
|
description: "Timeout for requests to the MCP server (ms)",
|
||||||
|
value: 5000,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update MCP server proxy address", () => {
|
||||||
|
const setConfig = jest.fn();
|
||||||
|
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
|
||||||
|
|
||||||
|
openConfigSection();
|
||||||
|
|
||||||
|
const proxyAddressInput = screen.getByTestId(
|
||||||
|
"MCP_PROXY_FULL_ADDRESS-input",
|
||||||
|
);
|
||||||
|
fireEvent.change(proxyAddressInput, {
|
||||||
|
target: { value: "http://localhost:8080" },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(setConfig).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
MCP_PROXY_FULL_ADDRESS: {
|
||||||
|
label: "Inspector Proxy Address",
|
||||||
|
description:
|
||||||
|
"Set this if you are running the MCP Inspector Proxy on a non-default address. Example: http://10.1.1.22:5577",
|
||||||
|
value: "http://localhost:8080",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update max total timeout", () => {
|
||||||
|
const setConfig = jest.fn();
|
||||||
|
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
|
||||||
|
|
||||||
|
openConfigSection();
|
||||||
|
|
||||||
|
const maxTotalTimeoutInput = screen.getByTestId(
|
||||||
|
"MCP_REQUEST_MAX_TOTAL_TIMEOUT-input",
|
||||||
|
);
|
||||||
|
fireEvent.change(maxTotalTimeoutInput, {
|
||||||
|
target: { value: "10000" },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(setConfig).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
MCP_REQUEST_MAX_TOTAL_TIMEOUT: {
|
||||||
|
label: "Maximum Total Timeout",
|
||||||
|
description:
|
||||||
|
"Maximum total timeout for requests sent to the MCP server (ms) (Use with progress notifications)",
|
||||||
|
value: 10000,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle invalid timeout values entered by user", () => {
|
||||||
|
const setConfig = jest.fn();
|
||||||
|
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
|
||||||
|
|
||||||
|
openConfigSection();
|
||||||
|
|
||||||
|
const timeoutInput = screen.getByTestId(
|
||||||
|
"MCP_SERVER_REQUEST_TIMEOUT-input",
|
||||||
|
);
|
||||||
|
fireEvent.change(timeoutInput, { target: { value: "abc1" } });
|
||||||
|
|
||||||
|
expect(setConfig).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
MCP_SERVER_REQUEST_TIMEOUT: {
|
||||||
|
label: "Request Timeout",
|
||||||
|
description: "Timeout for requests to the MCP server (ms)",
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain configuration state after multiple updates", () => {
|
||||||
|
const setConfig = jest.fn();
|
||||||
|
const { rerender } = renderSidebar({
|
||||||
|
config: DEFAULT_INSPECTOR_CONFIG,
|
||||||
|
setConfig,
|
||||||
|
});
|
||||||
|
|
||||||
|
openConfigSection();
|
||||||
|
// First update
|
||||||
|
const timeoutInput = screen.getByTestId(
|
||||||
|
"MCP_SERVER_REQUEST_TIMEOUT-input",
|
||||||
|
);
|
||||||
|
fireEvent.change(timeoutInput, { target: { value: "5000" } });
|
||||||
|
|
||||||
|
// Get the updated config from the first setConfig call
|
||||||
|
const updatedConfig = setConfig.mock.calls[0][0] as InspectorConfig;
|
||||||
|
|
||||||
|
// Rerender with the updated config
|
||||||
|
rerender(
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sidebar
|
||||||
|
{...defaultProps}
|
||||||
|
config={updatedConfig}
|
||||||
|
setConfig={setConfig}
|
||||||
|
/>
|
||||||
|
</TooltipProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Second update
|
||||||
|
const updatedTimeoutInput = screen.getByTestId(
|
||||||
|
"MCP_SERVER_REQUEST_TIMEOUT-input",
|
||||||
|
);
|
||||||
|
fireEvent.change(updatedTimeoutInput, { target: { value: "3000" } });
|
||||||
|
|
||||||
|
// Verify the final state matches what we expect
|
||||||
|
expect(setConfig).toHaveBeenLastCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
MCP_SERVER_REQUEST_TIMEOUT: {
|
||||||
|
label: "Request Timeout",
|
||||||
|
description: "Timeout for requests to the MCP server (ms)",
|
||||||
|
value: 3000,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Copy Configuration Features", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
jest.clearAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
const getCopyButtons = () => {
|
||||||
|
return {
|
||||||
|
serverEntry: screen.getByRole("button", { name: /server entry/i }),
|
||||||
|
serversFile: screen.getByRole("button", { name: /servers file/i }),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should render both copy buttons for all transport types", () => {
|
||||||
|
["stdio", "sse", "streamable-http"].forEach((transportType) => {
|
||||||
|
renderSidebar({ transportType });
|
||||||
|
// There should be exactly one Server Entry and one Servers File button per render
|
||||||
|
const serverEntryButtons = screen.getAllByRole("button", {
|
||||||
|
name: /server entry/i,
|
||||||
|
});
|
||||||
|
const serversFileButtons = screen.getAllByRole("button", {
|
||||||
|
name: /servers file/i,
|
||||||
|
});
|
||||||
|
expect(serverEntryButtons).toHaveLength(1);
|
||||||
|
expect(serversFileButtons).toHaveLength(1);
|
||||||
|
// Clean up DOM for next iteration
|
||||||
|
// (Testing Library's render does not auto-unmount in a loop)
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should copy server entry configuration to clipboard for STDIO transport", async () => {
|
||||||
|
const command = "node";
|
||||||
|
const args = "--inspect server.js";
|
||||||
|
const env = { API_KEY: "test-key", DEBUG: "true" };
|
||||||
|
|
||||||
|
renderSidebar({
|
||||||
|
transportType: "stdio",
|
||||||
|
command,
|
||||||
|
args,
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serverEntry } = getCopyButtons();
|
||||||
|
fireEvent.click(serverEntry);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
command,
|
||||||
|
args: ["--inspect", "server.js"],
|
||||||
|
env,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should copy servers file configuration to clipboard for STDIO transport", async () => {
|
||||||
|
const command = "node";
|
||||||
|
const args = "--inspect server.js";
|
||||||
|
const env = { API_KEY: "test-key", DEBUG: "true" };
|
||||||
|
|
||||||
|
renderSidebar({
|
||||||
|
transportType: "stdio",
|
||||||
|
command,
|
||||||
|
args,
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serversFile } = getCopyButtons();
|
||||||
|
fireEvent.click(serversFile);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
mcpServers: {
|
||||||
|
"default-server": {
|
||||||
|
command,
|
||||||
|
args: ["--inspect", "server.js"],
|
||||||
|
env,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should copy server entry configuration to clipboard for SSE transport", async () => {
|
||||||
|
const sseUrl = "http://localhost:3000/events";
|
||||||
|
renderSidebar({ transportType: "sse", sseUrl });
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serverEntry } = getCopyButtons();
|
||||||
|
fireEvent.click(serverEntry);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
type: "sse",
|
||||||
|
url: sseUrl,
|
||||||
|
note: "For SSE connections, add this URL directly in Client",
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should copy servers file configuration to clipboard for SSE transport", async () => {
|
||||||
|
const sseUrl = "http://localhost:3000/events";
|
||||||
|
renderSidebar({ transportType: "sse", sseUrl });
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serversFile } = getCopyButtons();
|
||||||
|
fireEvent.click(serversFile);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
mcpServers: {
|
||||||
|
"default-server": {
|
||||||
|
type: "sse",
|
||||||
|
url: sseUrl,
|
||||||
|
note: "For SSE connections, add this URL directly in Client",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should copy server entry configuration to clipboard for streamable-http transport", async () => {
|
||||||
|
const sseUrl = "http://localhost:3001/sse";
|
||||||
|
renderSidebar({ transportType: "streamable-http", sseUrl });
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serverEntry } = getCopyButtons();
|
||||||
|
fireEvent.click(serverEntry);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
type: "streamable-http",
|
||||||
|
url: sseUrl,
|
||||||
|
note: "For Streamable HTTP connections, add this URL directly in Client",
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should copy servers file configuration to clipboard for streamable-http transport", async () => {
|
||||||
|
const sseUrl = "http://localhost:3001/sse";
|
||||||
|
renderSidebar({ transportType: "streamable-http", sseUrl });
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serversFile } = getCopyButtons();
|
||||||
|
fireEvent.click(serversFile);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
mcpServers: {
|
||||||
|
"default-server": {
|
||||||
|
type: "streamable-http",
|
||||||
|
url: sseUrl,
|
||||||
|
note: "For Streamable HTTP connections, add this URL directly in Client",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle empty args in STDIO transport", async () => {
|
||||||
|
const command = "python";
|
||||||
|
const args = "";
|
||||||
|
|
||||||
|
renderSidebar({
|
||||||
|
transportType: "stdio",
|
||||||
|
command,
|
||||||
|
args,
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const { serverEntry } = getCopyButtons();
|
||||||
|
fireEvent.click(serverEntry);
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
const expectedConfig = JSON.stringify(
|
||||||
|
{
|
||||||
|
command,
|
||||||
|
args: [],
|
||||||
|
env: {},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
144
client/src/components/__tests__/ToolsTab.test.tsx
Normal file
144
client/src/components/__tests__/ToolsTab.test.tsx
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
import { render, screen, fireEvent, act } from "@testing-library/react";
|
||||||
|
import { describe, it, expect, jest } from "@jest/globals";
|
||||||
|
import "@testing-library/jest-dom";
|
||||||
|
import ToolsTab from "../ToolsTab";
|
||||||
|
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { Tabs } from "@/components/ui/tabs";
|
||||||
|
|
||||||
|
describe("ToolsTab", () => {
|
||||||
|
const mockTools: Tool[] = [
|
||||||
|
{
|
||||||
|
name: "tool1",
|
||||||
|
description: "First tool",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
num: { type: "number" as const },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tool3",
|
||||||
|
description: "Integer tool",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
count: { type: "integer" as const },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tool2",
|
||||||
|
description: "Second tool",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
num: { type: "number" as const },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const defaultProps = {
|
||||||
|
tools: mockTools,
|
||||||
|
listTools: jest.fn(),
|
||||||
|
clearTools: jest.fn(),
|
||||||
|
callTool: jest.fn(async () => {}),
|
||||||
|
selectedTool: null,
|
||||||
|
setSelectedTool: jest.fn(),
|
||||||
|
toolResult: null,
|
||||||
|
nextCursor: "",
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderToolsTab = (props = {}) => {
|
||||||
|
return render(
|
||||||
|
<Tabs defaultValue="tools">
|
||||||
|
<ToolsTab {...defaultProps} {...props} />
|
||||||
|
</Tabs>,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should reset input values when switching tools", async () => {
|
||||||
|
const { rerender } = renderToolsTab({
|
||||||
|
selectedTool: mockTools[0],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enter a value in the first tool's input
|
||||||
|
const input = screen.getByRole("spinbutton") as HTMLInputElement;
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.change(input, { target: { value: "42" } });
|
||||||
|
});
|
||||||
|
expect(input.value).toBe("42");
|
||||||
|
|
||||||
|
// Switch to second tool
|
||||||
|
rerender(
|
||||||
|
<Tabs defaultValue="tools">
|
||||||
|
<ToolsTab {...defaultProps} selectedTool={mockTools[2]} />
|
||||||
|
</Tabs>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify input is reset
|
||||||
|
const newInput = screen.getByRole("spinbutton") as HTMLInputElement;
|
||||||
|
expect(newInput.value).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle integer type inputs", async () => {
|
||||||
|
renderToolsTab({
|
||||||
|
selectedTool: mockTools[1], // Use the tool with integer type
|
||||||
|
});
|
||||||
|
|
||||||
|
const input = screen.getByRole("spinbutton", {
|
||||||
|
name: /count/i,
|
||||||
|
}) as HTMLInputElement;
|
||||||
|
expect(input).toHaveProperty("type", "number");
|
||||||
|
fireEvent.change(input, { target: { value: "42" } });
|
||||||
|
expect(input.value).toBe("42");
|
||||||
|
|
||||||
|
const submitButton = screen.getByRole("button", { name: /run tool/i });
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(defaultProps.callTool).toHaveBeenCalledWith(mockTools[1].name, {
|
||||||
|
count: 42,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should disable button and change text while tool is running", async () => {
|
||||||
|
// Create a promise that we can resolve later
|
||||||
|
let resolvePromise: ((value: unknown) => void) | undefined;
|
||||||
|
const mockPromise = new Promise((resolve) => {
|
||||||
|
resolvePromise = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock callTool to return our promise
|
||||||
|
const mockCallTool = jest.fn().mockReturnValue(mockPromise);
|
||||||
|
|
||||||
|
renderToolsTab({
|
||||||
|
selectedTool: mockTools[0],
|
||||||
|
callTool: mockCallTool,
|
||||||
|
});
|
||||||
|
|
||||||
|
const submitButton = screen.getByRole("button", { name: /run tool/i });
|
||||||
|
expect(submitButton.getAttribute("disabled")).toBeNull();
|
||||||
|
|
||||||
|
// Click the button and verify immediate state changes
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(submitButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify button is disabled and text changed
|
||||||
|
expect(submitButton.getAttribute("disabled")).not.toBeNull();
|
||||||
|
expect(submitButton.textContent).toBe("Running...");
|
||||||
|
|
||||||
|
// Resolve the promise to simulate tool completion
|
||||||
|
await act(async () => {
|
||||||
|
if (resolvePromise) {
|
||||||
|
await resolvePromise({});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(submitButton.getAttribute("disabled")).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
73
client/src/components/__tests__/samplingRequest.test.tsx
Normal file
73
client/src/components/__tests__/samplingRequest.test.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { render, screen, fireEvent } from "@testing-library/react";
|
||||||
|
import SamplingRequest from "../SamplingRequest";
|
||||||
|
import { PendingRequest } from "../SamplingTab";
|
||||||
|
|
||||||
|
const mockRequest: PendingRequest = {
|
||||||
|
id: 1,
|
||||||
|
request: {
|
||||||
|
method: "sampling/createMessage",
|
||||||
|
params: {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "What files are in the current directory?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
systemPrompt: "You are a helpful file system assistant.",
|
||||||
|
includeContext: "thisServer",
|
||||||
|
maxTokens: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Form to handle sampling response", () => {
|
||||||
|
const mockOnApprove = jest.fn();
|
||||||
|
const mockOnReject = jest.fn();
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onApprove with correct text content when Approve button is clicked", () => {
|
||||||
|
render(
|
||||||
|
<SamplingRequest
|
||||||
|
request={mockRequest}
|
||||||
|
onApprove={mockOnApprove}
|
||||||
|
onReject={mockOnReject}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click the Approve button
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /approve/i }));
|
||||||
|
|
||||||
|
// Assert that onApprove is called with the correct arguments
|
||||||
|
expect(mockOnApprove).toHaveBeenCalledWith(mockRequest.id, {
|
||||||
|
model: "stub-model",
|
||||||
|
stopReason: "endTurn",
|
||||||
|
role: "assistant",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onReject with correct request id when Reject button is clicked", () => {
|
||||||
|
render(
|
||||||
|
<SamplingRequest
|
||||||
|
request={mockRequest}
|
||||||
|
onApprove={mockOnApprove}
|
||||||
|
onReject={mockOnReject}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click the Approve button
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /Reject/i }));
|
||||||
|
|
||||||
|
// Assert that onApprove is called with the correct arguments
|
||||||
|
expect(mockOnReject).toHaveBeenCalledWith(mockRequest.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
55
client/src/components/__tests__/samplingTab.test.tsx
Normal file
55
client/src/components/__tests__/samplingTab.test.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import { Tabs } from "@/components/ui/tabs";
|
||||||
|
import SamplingTab, { PendingRequest } from "../SamplingTab";
|
||||||
|
|
||||||
|
describe("Sampling tab", () => {
|
||||||
|
const mockOnApprove = jest.fn();
|
||||||
|
const mockOnReject = jest.fn();
|
||||||
|
|
||||||
|
const renderSamplingTab = (pendingRequests: PendingRequest[]) =>
|
||||||
|
render(
|
||||||
|
<Tabs defaultValue="sampling">
|
||||||
|
<SamplingTab
|
||||||
|
pendingRequests={pendingRequests}
|
||||||
|
onApprove={mockOnApprove}
|
||||||
|
onReject={mockOnReject}
|
||||||
|
/>
|
||||||
|
</Tabs>,
|
||||||
|
);
|
||||||
|
|
||||||
|
it("should render 'No pending requests' when there are no pending requests", () => {
|
||||||
|
renderSamplingTab([]);
|
||||||
|
expect(
|
||||||
|
screen.getByText(
|
||||||
|
"When the server requests LLM sampling, requests will appear here for approval.",
|
||||||
|
),
|
||||||
|
).toBeTruthy();
|
||||||
|
expect(screen.findByText("No pending requests")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render the correct number of requests", () => {
|
||||||
|
renderSamplingTab(
|
||||||
|
Array.from({ length: 5 }, (_, i) => ({
|
||||||
|
id: i,
|
||||||
|
request: {
|
||||||
|
method: "sampling/createMessage",
|
||||||
|
params: {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: {
|
||||||
|
type: "text",
|
||||||
|
text: "What files are in the current directory?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
systemPrompt: "You are a helpful file system assistant.",
|
||||||
|
includeContext: "thisServer",
|
||||||
|
maxTokens: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
expect(screen.getAllByTestId("sampling-request").length).toBe(5);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -54,4 +54,4 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|||||||
);
|
);
|
||||||
Button.displayName = "Button";
|
Button.displayName = "Button";
|
||||||
|
|
||||||
export { Button, buttonVariants };
|
export { Button };
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export interface InputProps
|
export type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
|
||||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
({ className, type, ...props }, ref) => {
|
({ className, type, ...props }, ref) => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const SelectTrigger = React.forwardRef<
|
|||||||
<SelectPrimitive.Trigger
|
<SelectPrimitive.Trigger
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 hover:border-[#646cff] hover:border-1",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export interface TextareaProps
|
export type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>;
|
||||||
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
|
|
||||||
|
|
||||||
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||||
({ className, ...props }, ref) => {
|
({ className, ...props }, ref) => {
|
||||||
|
|||||||
126
client/src/components/ui/toast.tsx
Normal file
126
client/src/components/ui/toast.tsx
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as ToastPrimitives from "@radix-ui/react-toast";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Cross2Icon } from "@radix-ui/react-icons";
|
||||||
|
|
||||||
|
const ToastProvider = ToastPrimitives.Provider;
|
||||||
|
|
||||||
|
const ToastViewport = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Viewport
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
||||||
|
|
||||||
|
const toastVariants = cva(
|
||||||
|
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "border bg-background text-foreground",
|
||||||
|
destructive:
|
||||||
|
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const Toast = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||||
|
VariantProps<typeof toastVariants>
|
||||||
|
>(({ className, variant, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<ToastPrimitives.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn(toastVariants({ variant }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Toast.displayName = ToastPrimitives.Root.displayName;
|
||||||
|
|
||||||
|
const ToastAction = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ToastPrimitives.Action>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Action
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
ToastAction.displayName = ToastPrimitives.Action.displayName;
|
||||||
|
|
||||||
|
const ToastClose = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ToastPrimitives.Close>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Close
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
toast-close=""
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<Cross2Icon className="h-4 w-4" />
|
||||||
|
</ToastPrimitives.Close>
|
||||||
|
));
|
||||||
|
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
||||||
|
|
||||||
|
const ToastTitle = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Title
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
||||||
|
|
||||||
|
const ToastDescription = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Description
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm opacity-90", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
||||||
|
|
||||||
|
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
|
||||||
|
|
||||||
|
type ToastActionElement = React.ReactElement<typeof ToastAction>;
|
||||||
|
|
||||||
|
export {
|
||||||
|
type ToastProps,
|
||||||
|
type ToastActionElement,
|
||||||
|
ToastProvider,
|
||||||
|
ToastViewport,
|
||||||
|
Toast,
|
||||||
|
ToastTitle,
|
||||||
|
ToastDescription,
|
||||||
|
ToastClose,
|
||||||
|
ToastAction,
|
||||||
|
};
|
||||||
33
client/src/components/ui/toaster.tsx
Normal file
33
client/src/components/ui/toaster.tsx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
|
import {
|
||||||
|
Toast,
|
||||||
|
ToastClose,
|
||||||
|
ToastDescription,
|
||||||
|
ToastProvider,
|
||||||
|
ToastTitle,
|
||||||
|
ToastViewport,
|
||||||
|
} from "@/components/ui/toast";
|
||||||
|
|
||||||
|
export function Toaster() {
|
||||||
|
const { toasts } = useToast();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ToastProvider>
|
||||||
|
{toasts.map(function ({ id, title, description, action, ...props }) {
|
||||||
|
return (
|
||||||
|
<Toast key={id} {...props}>
|
||||||
|
<div className="grid gap-1">
|
||||||
|
{title && <ToastTitle>{title}</ToastTitle>}
|
||||||
|
{description && (
|
||||||
|
<ToastDescription>{description}</ToastDescription>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{action}
|
||||||
|
<ToastClose />
|
||||||
|
</Toast>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<ToastViewport />
|
||||||
|
</ToastProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
30
client/src/components/ui/tooltip.tsx
Normal file
30
client/src/components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const TooltipProvider = TooltipPrimitive.Provider;
|
||||||
|
|
||||||
|
const Tooltip = TooltipPrimitive.Root;
|
||||||
|
|
||||||
|
const TooltipTrigger = TooltipPrimitive.Trigger;
|
||||||
|
|
||||||
|
const TooltipContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||||
|
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||||
|
<TooltipPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
||||||
@@ -38,29 +38,6 @@ h1 {
|
|||||||
line-height: 1.1;
|
line-height: 1.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
button[role="checkbox"] {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
:root {
|
:root {
|
||||||
color: #213547;
|
color: #213547;
|
||||||
@@ -69,9 +46,6 @@ button[role="checkbox"] {
|
|||||||
a:hover {
|
a:hover {
|
||||||
color: #747bff;
|
color: #747bff;
|
||||||
}
|
}
|
||||||
button {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
|
|||||||
38
client/src/lib/auth-types.ts
Normal file
38
client/src/lib/auth-types.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import {
|
||||||
|
OAuthMetadata,
|
||||||
|
OAuthClientInformationFull,
|
||||||
|
OAuthClientInformation,
|
||||||
|
OAuthTokens,
|
||||||
|
} from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
|
|
||||||
|
// OAuth flow steps
|
||||||
|
export type OAuthStep =
|
||||||
|
| "metadata_discovery"
|
||||||
|
| "client_registration"
|
||||||
|
| "authorization_redirect"
|
||||||
|
| "authorization_code"
|
||||||
|
| "token_request"
|
||||||
|
| "complete";
|
||||||
|
|
||||||
|
// Message types for inline feedback
|
||||||
|
export type MessageType = "success" | "error" | "info";
|
||||||
|
|
||||||
|
export interface StatusMessage {
|
||||||
|
type: MessageType;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single state interface for OAuth state
|
||||||
|
export interface AuthDebuggerState {
|
||||||
|
isInitiatingAuth: boolean;
|
||||||
|
oauthTokens: OAuthTokens | null;
|
||||||
|
loading: boolean;
|
||||||
|
oauthStep: OAuthStep;
|
||||||
|
oauthMetadata: OAuthMetadata | null;
|
||||||
|
oauthClientInfo: OAuthClientInformationFull | OAuthClientInformation | null;
|
||||||
|
authorizationUrl: string | null;
|
||||||
|
authorizationCode: string;
|
||||||
|
latestError: Error | null;
|
||||||
|
statusMessage: StatusMessage | null;
|
||||||
|
validationError: string | null;
|
||||||
|
}
|
||||||
@@ -4,15 +4,22 @@ import {
|
|||||||
OAuthClientInformation,
|
OAuthClientInformation,
|
||||||
OAuthTokens,
|
OAuthTokens,
|
||||||
OAuthTokensSchema,
|
OAuthTokensSchema,
|
||||||
|
OAuthClientMetadata,
|
||||||
|
OAuthMetadata,
|
||||||
} from "@modelcontextprotocol/sdk/shared/auth.js";
|
} from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
import { SESSION_KEYS } from "./constants";
|
import { SESSION_KEYS, getServerSpecificKey } from "./constants";
|
||||||
|
|
||||||
|
export class InspectorOAuthClientProvider implements OAuthClientProvider {
|
||||||
|
constructor(public serverUrl: string) {
|
||||||
|
// Save the server URL to session storage
|
||||||
|
sessionStorage.setItem(SESSION_KEYS.SERVER_URL, serverUrl);
|
||||||
|
}
|
||||||
|
|
||||||
class InspectorOAuthClientProvider implements OAuthClientProvider {
|
|
||||||
get redirectUrl() {
|
get redirectUrl() {
|
||||||
return window.location.origin + "/oauth/callback";
|
return window.location.origin + "/oauth/callback";
|
||||||
}
|
}
|
||||||
|
|
||||||
get clientMetadata() {
|
get clientMetadata(): OAuthClientMetadata {
|
||||||
return {
|
return {
|
||||||
redirect_uris: [this.redirectUrl],
|
redirect_uris: [this.redirectUrl],
|
||||||
token_endpoint_auth_method: "none",
|
token_endpoint_auth_method: "none",
|
||||||
@@ -24,7 +31,11 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clientInformation() {
|
async clientInformation() {
|
||||||
const value = sessionStorage.getItem(SESSION_KEYS.CLIENT_INFORMATION);
|
const key = getServerSpecificKey(
|
||||||
|
SESSION_KEYS.CLIENT_INFORMATION,
|
||||||
|
this.serverUrl,
|
||||||
|
);
|
||||||
|
const value = sessionStorage.getItem(key);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -33,14 +44,16 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveClientInformation(clientInformation: OAuthClientInformation) {
|
saveClientInformation(clientInformation: OAuthClientInformation) {
|
||||||
sessionStorage.setItem(
|
const key = getServerSpecificKey(
|
||||||
SESSION_KEYS.CLIENT_INFORMATION,
|
SESSION_KEYS.CLIENT_INFORMATION,
|
||||||
JSON.stringify(clientInformation),
|
this.serverUrl,
|
||||||
);
|
);
|
||||||
|
sessionStorage.setItem(key, JSON.stringify(clientInformation));
|
||||||
}
|
}
|
||||||
|
|
||||||
async tokens() {
|
async tokens() {
|
||||||
const tokens = sessionStorage.getItem(SESSION_KEYS.TOKENS);
|
const key = getServerSpecificKey(SESSION_KEYS.TOKENS, this.serverUrl);
|
||||||
|
const tokens = sessionStorage.getItem(key);
|
||||||
if (!tokens) {
|
if (!tokens) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -49,7 +62,8 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveTokens(tokens: OAuthTokens) {
|
saveTokens(tokens: OAuthTokens) {
|
||||||
sessionStorage.setItem(SESSION_KEYS.TOKENS, JSON.stringify(tokens));
|
const key = getServerSpecificKey(SESSION_KEYS.TOKENS, this.serverUrl);
|
||||||
|
sessionStorage.setItem(key, JSON.stringify(tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectToAuthorization(authorizationUrl: URL) {
|
redirectToAuthorization(authorizationUrl: URL) {
|
||||||
@@ -57,17 +71,70 @@ class InspectorOAuthClientProvider implements OAuthClientProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveCodeVerifier(codeVerifier: string) {
|
saveCodeVerifier(codeVerifier: string) {
|
||||||
sessionStorage.setItem(SESSION_KEYS.CODE_VERIFIER, codeVerifier);
|
const key = getServerSpecificKey(
|
||||||
|
SESSION_KEYS.CODE_VERIFIER,
|
||||||
|
this.serverUrl,
|
||||||
|
);
|
||||||
|
sessionStorage.setItem(key, codeVerifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
codeVerifier() {
|
codeVerifier() {
|
||||||
const verifier = sessionStorage.getItem(SESSION_KEYS.CODE_VERIFIER);
|
const key = getServerSpecificKey(
|
||||||
|
SESSION_KEYS.CODE_VERIFIER,
|
||||||
|
this.serverUrl,
|
||||||
|
);
|
||||||
|
const verifier = sessionStorage.getItem(key);
|
||||||
if (!verifier) {
|
if (!verifier) {
|
||||||
throw new Error("No code verifier saved for session");
|
throw new Error("No code verifier saved for session");
|
||||||
}
|
}
|
||||||
|
|
||||||
return verifier;
|
return verifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
sessionStorage.removeItem(
|
||||||
|
getServerSpecificKey(SESSION_KEYS.CLIENT_INFORMATION, this.serverUrl),
|
||||||
|
);
|
||||||
|
sessionStorage.removeItem(
|
||||||
|
getServerSpecificKey(SESSION_KEYS.TOKENS, this.serverUrl),
|
||||||
|
);
|
||||||
|
sessionStorage.removeItem(
|
||||||
|
getServerSpecificKey(SESSION_KEYS.CODE_VERIFIER, this.serverUrl),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authProvider = new InspectorOAuthClientProvider();
|
// Overrides debug URL and allows saving server OAuth metadata to
|
||||||
|
// display in debug UI.
|
||||||
|
export class DebugInspectorOAuthClientProvider extends InspectorOAuthClientProvider {
|
||||||
|
get redirectUrl(): string {
|
||||||
|
return `${window.location.origin}/oauth/callback/debug`;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveServerMetadata(metadata: OAuthMetadata) {
|
||||||
|
const key = getServerSpecificKey(
|
||||||
|
SESSION_KEYS.SERVER_METADATA,
|
||||||
|
this.serverUrl,
|
||||||
|
);
|
||||||
|
sessionStorage.setItem(key, JSON.stringify(metadata));
|
||||||
|
}
|
||||||
|
|
||||||
|
getServerMetadata(): OAuthMetadata | null {
|
||||||
|
const key = getServerSpecificKey(
|
||||||
|
SESSION_KEYS.SERVER_METADATA,
|
||||||
|
this.serverUrl,
|
||||||
|
);
|
||||||
|
const metadata = sessionStorage.getItem(key);
|
||||||
|
if (!metadata) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSON.parse(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
super.clear();
|
||||||
|
sessionStorage.removeItem(
|
||||||
|
getServerSpecificKey(SESSION_KEYS.SERVER_METADATA, this.serverUrl),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
36
client/src/lib/configurationTypes.ts
Normal file
36
client/src/lib/configurationTypes.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
export type ConfigItem = {
|
||||||
|
label: string;
|
||||||
|
description: string;
|
||||||
|
value: string | number | boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration interface for the MCP Inspector, including settings for the MCP Client,
|
||||||
|
* Proxy Server, and Inspector UI/UX.
|
||||||
|
*
|
||||||
|
* Note: Configuration related to which MCP Server to use or any other MCP Server
|
||||||
|
* specific settings are outside the scope of this interface as of now.
|
||||||
|
*/
|
||||||
|
export type InspectorConfig = {
|
||||||
|
/**
|
||||||
|
* Maximum time in milliseconds to wait for a response from the MCP server before timing out.
|
||||||
|
*/
|
||||||
|
MCP_SERVER_REQUEST_TIMEOUT: ConfigItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to reset the timeout on progress notifications. Useful for long-running operations that send periodic progress updates.
|
||||||
|
* Refer: https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/utilities/progress/#progress-flow
|
||||||
|
*/
|
||||||
|
MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS: ConfigItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum total time in milliseconds to wait for a response from the MCP server before timing out. Used in conjunction with MCP_SERVER_REQUEST_TIMEOUT_RESET_ON_PROGRESS.
|
||||||
|
* Refer: https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/utilities/progress/#progress-flow
|
||||||
|
*/
|
||||||
|
MCP_REQUEST_MAX_TOTAL_TIMEOUT: ConfigItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The full address of the MCP Proxy Server, in case it is running on a non-default address. Example: http://10.1.1.22:5577
|
||||||
|
*/
|
||||||
|
MCP_PROXY_FULL_ADDRESS: ConfigItem;
|
||||||
|
};
|
||||||
@@ -1,7 +1,56 @@
|
|||||||
|
import { InspectorConfig } from "./configurationTypes";
|
||||||
|
|
||||||
// OAuth-related session storage keys
|
// OAuth-related session storage keys
|
||||||
export const SESSION_KEYS = {
|
export const SESSION_KEYS = {
|
||||||
CODE_VERIFIER: "mcp_code_verifier",
|
CODE_VERIFIER: "mcp_code_verifier",
|
||||||
SERVER_URL: "mcp_server_url",
|
SERVER_URL: "mcp_server_url",
|
||||||
TOKENS: "mcp_tokens",
|
TOKENS: "mcp_tokens",
|
||||||
CLIENT_INFORMATION: "mcp_client_information",
|
CLIENT_INFORMATION: "mcp_client_information",
|
||||||
|
SERVER_METADATA: "mcp_server_metadata",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// Generate server-specific session storage keys
|
||||||
|
export const getServerSpecificKey = (
|
||||||
|
baseKey: string,
|
||||||
|
serverUrl?: string,
|
||||||
|
): string => {
|
||||||
|
if (!serverUrl) return baseKey;
|
||||||
|
return `[${serverUrl}] ${baseKey}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ConnectionStatus =
|
||||||
|
| "disconnected"
|
||||||
|
| "connected"
|
||||||
|
| "error"
|
||||||
|
| "error-connecting-to-proxy";
|
||||||
|
|
||||||
|
export const DEFAULT_MCP_PROXY_LISTEN_PORT = "6277";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default configuration for the MCP Inspector, Currently persisted in local_storage in the Browser.
|
||||||
|
* Future plans: Provide json config file + Browser local_storage to override default values
|
||||||
|
**/
|
||||||
|
export const DEFAULT_INSPECTOR_CONFIG: InspectorConfig = {
|
||||||
|
MCP_SERVER_REQUEST_TIMEOUT: {
|
||||||
|
label: "Request Timeout",
|
||||||
|
description: "Timeout for requests to the MCP server (ms)",
|
||||||
|
value: 10000,
|
||||||
|
},
|
||||||
|
MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS: {
|
||||||
|
label: "Reset Timeout on Progress",
|
||||||
|
description: "Reset timeout on progress notifications",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
MCP_REQUEST_MAX_TOTAL_TIMEOUT: {
|
||||||
|
label: "Maximum Total Timeout",
|
||||||
|
description:
|
||||||
|
"Maximum total timeout for requests sent to the MCP server (ms) (Use with progress notifications)",
|
||||||
|
value: 60000,
|
||||||
|
},
|
||||||
|
MCP_PROXY_FULL_ADDRESS: {
|
||||||
|
label: "Inspector Proxy Address",
|
||||||
|
description:
|
||||||
|
"Set this if you are running the MCP Inspector Proxy on a non-default address. Example: http://10.1.1.22:5577",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
166
client/src/lib/hooks/__tests__/useConnection.test.tsx
Normal file
166
client/src/lib/hooks/__tests__/useConnection.test.tsx
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
import { renderHook, act } from "@testing-library/react";
|
||||||
|
import { useConnection } from "../useConnection";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { ClientRequest } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { DEFAULT_INSPECTOR_CONFIG } from "../../constants";
|
||||||
|
|
||||||
|
// Mock fetch
|
||||||
|
global.fetch = jest.fn().mockResolvedValue({
|
||||||
|
json: () => Promise.resolve({ status: "ok" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock the SDK dependencies
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ test: "response" });
|
||||||
|
const mockClient = {
|
||||||
|
request: mockRequest,
|
||||||
|
notification: jest.fn(),
|
||||||
|
connect: jest.fn().mockResolvedValue(undefined),
|
||||||
|
close: jest.fn(),
|
||||||
|
getServerCapabilities: jest.fn(),
|
||||||
|
getServerVersion: jest.fn(),
|
||||||
|
getInstructions: jest.fn(),
|
||||||
|
setNotificationHandler: jest.fn(),
|
||||||
|
setRequestHandler: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.mock("@modelcontextprotocol/sdk/client/index.js", () => ({
|
||||||
|
Client: jest.fn().mockImplementation(() => mockClient),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock("@modelcontextprotocol/sdk/client/sse.js", () => ({
|
||||||
|
SSEClientTransport: jest.fn(),
|
||||||
|
SseError: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
|
||||||
|
auth: jest.fn().mockResolvedValue("AUTHORIZED"),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock the toast hook
|
||||||
|
jest.mock("@/lib/hooks/useToast", () => ({
|
||||||
|
useToast: () => ({
|
||||||
|
toast: jest.fn(),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock the auth provider
|
||||||
|
jest.mock("../../auth", () => ({
|
||||||
|
InspectorOAuthClientProvider: jest.fn().mockImplementation(() => ({
|
||||||
|
tokens: jest.fn().mockResolvedValue({ access_token: "mock-token" }),
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("useConnection", () => {
|
||||||
|
const defaultProps = {
|
||||||
|
transportType: "sse" as const,
|
||||||
|
command: "",
|
||||||
|
args: "",
|
||||||
|
sseUrl: "http://localhost:8080",
|
||||||
|
env: {},
|
||||||
|
config: DEFAULT_INSPECTOR_CONFIG,
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Request Configuration", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses the default config values in makeRequest", async () => {
|
||||||
|
const { result } = renderHook(() => useConnection(defaultProps));
|
||||||
|
|
||||||
|
// Connect the client
|
||||||
|
await act(async () => {
|
||||||
|
await result.current.connect();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for state update
|
||||||
|
await act(async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockRequest: ClientRequest = {
|
||||||
|
method: "ping",
|
||||||
|
params: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockSchema = z.object({
|
||||||
|
test: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await result.current.makeRequest(mockRequest, mockSchema);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClient.request).toHaveBeenCalledWith(
|
||||||
|
mockRequest,
|
||||||
|
mockSchema,
|
||||||
|
expect.objectContaining({
|
||||||
|
timeout: DEFAULT_INSPECTOR_CONFIG.MCP_SERVER_REQUEST_TIMEOUT.value,
|
||||||
|
maxTotalTimeout:
|
||||||
|
DEFAULT_INSPECTOR_CONFIG.MCP_REQUEST_MAX_TOTAL_TIMEOUT.value,
|
||||||
|
resetTimeoutOnProgress:
|
||||||
|
DEFAULT_INSPECTOR_CONFIG.MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS
|
||||||
|
.value,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("overrides the default config values when passed in options in makeRequest", async () => {
|
||||||
|
const { result } = renderHook(() => useConnection(defaultProps));
|
||||||
|
|
||||||
|
// Connect the client
|
||||||
|
await act(async () => {
|
||||||
|
await result.current.connect();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for state update
|
||||||
|
await act(async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockRequest: ClientRequest = {
|
||||||
|
method: "ping",
|
||||||
|
params: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockSchema = z.object({
|
||||||
|
test: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await result.current.makeRequest(mockRequest, mockSchema, {
|
||||||
|
timeout: 1000,
|
||||||
|
maxTotalTimeout: 2000,
|
||||||
|
resetTimeoutOnProgress: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockClient.request).toHaveBeenCalledWith(
|
||||||
|
mockRequest,
|
||||||
|
mockSchema,
|
||||||
|
expect.objectContaining({
|
||||||
|
timeout: 1000,
|
||||||
|
maxTotalTimeout: 2000,
|
||||||
|
resetTimeoutOnProgress: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("throws error when mcpClient is not connected", async () => {
|
||||||
|
const { result } = renderHook(() => useConnection(defaultProps));
|
||||||
|
|
||||||
|
const mockRequest: ClientRequest = {
|
||||||
|
method: "ping",
|
||||||
|
params: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockSchema = z.object({
|
||||||
|
test: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
result.current.makeRequest(mockRequest, mockSchema),
|
||||||
|
).rejects.toThrow("MCP client not connected");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useCallback, useEffect, useRef } from "react";
|
import { useState, useCallback, useEffect, useRef, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
ResourceReference,
|
ResourceReference,
|
||||||
PromptReference,
|
PromptReference,
|
||||||
@@ -15,9 +15,11 @@ function debounce<T extends (...args: any[]) => PromiseLike<void>>(
|
|||||||
wait: number,
|
wait: number,
|
||||||
): (...args: Parameters<T>) => void {
|
): (...args: Parameters<T>) => void {
|
||||||
let timeout: ReturnType<typeof setTimeout>;
|
let timeout: ReturnType<typeof setTimeout>;
|
||||||
return function (...args: Parameters<T>) {
|
return (...args: Parameters<T>) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(() => func(...args), wait);
|
timeout = setTimeout(() => {
|
||||||
|
void func(...args);
|
||||||
|
}, wait);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +60,8 @@ export function useCompletionState(
|
|||||||
});
|
});
|
||||||
}, [cleanup]);
|
}, [cleanup]);
|
||||||
|
|
||||||
const requestCompletions = useCallback(
|
const requestCompletions = useMemo(() => {
|
||||||
debounce(
|
return debounce(
|
||||||
async (
|
async (
|
||||||
ref: ResourceReference | PromptReference,
|
ref: ResourceReference | PromptReference,
|
||||||
argName: string,
|
argName: string,
|
||||||
@@ -94,7 +96,7 @@ export function useCompletionState(
|
|||||||
loading: { ...prev.loading, [argName]: false },
|
loading: { ...prev.loading, [argName]: false },
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
if (!abortController.signal.aborted) {
|
if (!abortController.signal.aborted) {
|
||||||
setState((prev) => ({
|
setState((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@@ -108,9 +110,8 @@ export function useCompletionState(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
debounceMs,
|
debounceMs,
|
||||||
),
|
);
|
||||||
[handleCompletion, completionsSupported, cleanup, debounceMs],
|
}, [handleCompletion, completionsSupported, cleanup, debounceMs]);
|
||||||
);
|
|
||||||
|
|
||||||
// Clear completions when support status changes
|
// Clear completions when support status changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -2,14 +2,19 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|||||||
import {
|
import {
|
||||||
SSEClientTransport,
|
SSEClientTransport,
|
||||||
SseError,
|
SseError,
|
||||||
|
SSEClientTransportOptions,
|
||||||
} from "@modelcontextprotocol/sdk/client/sse.js";
|
} from "@modelcontextprotocol/sdk/client/sse.js";
|
||||||
|
import {
|
||||||
|
StreamableHTTPClientTransport,
|
||||||
|
StreamableHTTPClientTransportOptions,
|
||||||
|
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||||
import {
|
import {
|
||||||
ClientNotification,
|
ClientNotification,
|
||||||
ClientRequest,
|
ClientRequest,
|
||||||
CreateMessageRequestSchema,
|
CreateMessageRequestSchema,
|
||||||
ListRootsRequestSchema,
|
ListRootsRequestSchema,
|
||||||
ProgressNotificationSchema,
|
|
||||||
ResourceUpdatedNotificationSchema,
|
ResourceUpdatedNotificationSchema,
|
||||||
|
LoggingMessageNotificationSchema,
|
||||||
Request,
|
Request,
|
||||||
Result,
|
Result,
|
||||||
ServerCapabilities,
|
ServerCapabilities,
|
||||||
@@ -18,57 +23,63 @@ import {
|
|||||||
McpError,
|
McpError,
|
||||||
CompleteResultSchema,
|
CompleteResultSchema,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
|
CancelledNotificationSchema,
|
||||||
|
ResourceListChangedNotificationSchema,
|
||||||
|
ToolListChangedNotificationSchema,
|
||||||
|
PromptListChangedNotificationSchema,
|
||||||
|
Progress,
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "react-toastify";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { SESSION_KEYS } from "../constants";
|
import { ConnectionStatus } from "../constants";
|
||||||
import { Notification, StdErrNotificationSchema } from "../notificationTypes";
|
import { Notification, StdErrNotificationSchema } from "../notificationTypes";
|
||||||
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
||||||
import { authProvider } from "../auth";
|
import { InspectorOAuthClientProvider } from "../auth";
|
||||||
|
import packageJson from "../../../package.json";
|
||||||
const params = new URLSearchParams(window.location.search);
|
import {
|
||||||
const DEFAULT_REQUEST_TIMEOUT_MSEC =
|
getMCPProxyAddress,
|
||||||
parseInt(params.get("timeout") ?? "") || 10000;
|
getMCPServerRequestMaxTotalTimeout,
|
||||||
|
resetRequestTimeoutOnProgress,
|
||||||
|
} from "@/utils/configUtils";
|
||||||
|
import { getMCPServerRequestTimeout } from "@/utils/configUtils";
|
||||||
|
import { InspectorConfig } from "../configurationTypes";
|
||||||
|
|
||||||
interface UseConnectionOptions {
|
interface UseConnectionOptions {
|
||||||
transportType: "stdio" | "sse";
|
transportType: "stdio" | "sse" | "streamable-http";
|
||||||
command: string;
|
command: string;
|
||||||
args: string;
|
args: string;
|
||||||
sseUrl: string;
|
sseUrl: string;
|
||||||
env: Record<string, string>;
|
env: Record<string, string>;
|
||||||
proxyServerUrl: string;
|
|
||||||
bearerToken?: string;
|
bearerToken?: string;
|
||||||
requestTimeout?: number;
|
headerName?: string;
|
||||||
|
config: InspectorConfig;
|
||||||
onNotification?: (notification: Notification) => void;
|
onNotification?: (notification: Notification) => void;
|
||||||
onStdErrNotification?: (notification: Notification) => void;
|
onStdErrNotification?: (notification: Notification) => void;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
onPendingRequest?: (request: any, resolve: any, reject: any) => void;
|
onPendingRequest?: (request: any, resolve: any, reject: any) => void;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
getRoots?: () => any[];
|
getRoots?: () => any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestOptions {
|
|
||||||
signal?: AbortSignal;
|
|
||||||
timeout?: number;
|
|
||||||
suppressToast?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useConnection({
|
export function useConnection({
|
||||||
transportType,
|
transportType,
|
||||||
command,
|
command,
|
||||||
args,
|
args,
|
||||||
sseUrl,
|
sseUrl,
|
||||||
env,
|
env,
|
||||||
proxyServerUrl,
|
|
||||||
bearerToken,
|
bearerToken,
|
||||||
requestTimeout = DEFAULT_REQUEST_TIMEOUT_MSEC,
|
headerName,
|
||||||
|
config,
|
||||||
onNotification,
|
onNotification,
|
||||||
onStdErrNotification,
|
onStdErrNotification,
|
||||||
onPendingRequest,
|
onPendingRequest,
|
||||||
getRoots,
|
getRoots,
|
||||||
}: UseConnectionOptions) {
|
}: UseConnectionOptions) {
|
||||||
const [connectionStatus, setConnectionStatus] = useState<
|
const [connectionStatus, setConnectionStatus] =
|
||||||
"disconnected" | "connected" | "error"
|
useState<ConnectionStatus>("disconnected");
|
||||||
>("disconnected");
|
const { toast } = useToast();
|
||||||
const [serverCapabilities, setServerCapabilities] =
|
const [serverCapabilities, setServerCapabilities] =
|
||||||
useState<ServerCapabilities | null>(null);
|
useState<ServerCapabilities | null>(null);
|
||||||
const [mcpClient, setMcpClient] = useState<Client | null>(null);
|
const [mcpClient, setMcpClient] = useState<Client | null>(null);
|
||||||
@@ -90,38 +101,61 @@ export function useConnection({
|
|||||||
const makeRequest = async <T extends z.ZodType>(
|
const makeRequest = async <T extends z.ZodType>(
|
||||||
request: ClientRequest,
|
request: ClientRequest,
|
||||||
schema: T,
|
schema: T,
|
||||||
options?: RequestOptions,
|
options?: RequestOptions & { suppressToast?: boolean },
|
||||||
): Promise<z.output<T>> => {
|
): Promise<z.output<T>> => {
|
||||||
if (!mcpClient) {
|
if (!mcpClient) {
|
||||||
throw new Error("MCP client not connected");
|
throw new Error("MCP client not connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
const timeoutId = setTimeout(() => {
|
|
||||||
abortController.abort("Request timed out");
|
// prepare MCP Client request options
|
||||||
}, options?.timeout ?? requestTimeout);
|
const mcpRequestOptions: RequestOptions = {
|
||||||
|
signal: options?.signal ?? abortController.signal,
|
||||||
|
resetTimeoutOnProgress:
|
||||||
|
options?.resetTimeoutOnProgress ??
|
||||||
|
resetRequestTimeoutOnProgress(config),
|
||||||
|
timeout: options?.timeout ?? getMCPServerRequestTimeout(config),
|
||||||
|
maxTotalTimeout:
|
||||||
|
options?.maxTotalTimeout ??
|
||||||
|
getMCPServerRequestMaxTotalTimeout(config),
|
||||||
|
};
|
||||||
|
|
||||||
|
// If progress notifications are enabled, add an onprogress hook to the MCP Client request options
|
||||||
|
// This is required by SDK to reset the timeout on progress notifications
|
||||||
|
if (mcpRequestOptions.resetTimeoutOnProgress) {
|
||||||
|
mcpRequestOptions.onprogress = (params: Progress) => {
|
||||||
|
// Add progress notification to `Server Notification` window in the UI
|
||||||
|
if (onNotification) {
|
||||||
|
onNotification({
|
||||||
|
method: "notification/progress",
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await mcpClient.request(request, schema, {
|
response = await mcpClient.request(request, schema, mcpRequestOptions);
|
||||||
signal: options?.signal ?? abortController.signal,
|
|
||||||
});
|
|
||||||
pushHistory(request, response);
|
pushHistory(request, response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
error instanceof Error ? error.message : String(error);
|
error instanceof Error ? error.message : String(error);
|
||||||
pushHistory(request, { error: errorMessage });
|
pushHistory(request, { error: errorMessage });
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
if (!options?.suppressToast) {
|
if (!options?.suppressToast) {
|
||||||
const errorString = (e as Error).message ?? String(e);
|
const errorString = (e as Error).message ?? String(e);
|
||||||
toast.error(errorString);
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: errorString,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -163,7 +197,11 @@ export function useConnection({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unexpected errors - show toast and rethrow
|
// Unexpected errors - show toast and rethrow
|
||||||
toast.error(e instanceof Error ? e.message : String(e));
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: e instanceof Error ? e.message : String(e),
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -171,7 +209,11 @@ export function useConnection({
|
|||||||
const sendNotification = async (notification: ClientNotification) => {
|
const sendNotification = async (notification: ClientNotification) => {
|
||||||
if (!mcpClient) {
|
if (!mcpClient) {
|
||||||
const error = new Error("MCP client not connected");
|
const error = new Error("MCP client not connected");
|
||||||
toast.error(error.message);
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: error.message,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,16 +226,35 @@ export function useConnection({
|
|||||||
// Log MCP protocol errors
|
// Log MCP protocol errors
|
||||||
pushHistory(notification, { error: e.message });
|
pushHistory(notification, { error: e.message });
|
||||||
}
|
}
|
||||||
toast.error(e instanceof Error ? e.message : String(e));
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: e instanceof Error ? e.message : String(e),
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkProxyHealth = async () => {
|
||||||
|
try {
|
||||||
|
const proxyHealthUrl = new URL(`${getMCPProxyAddress(config)}/health`);
|
||||||
|
const proxyHealthResponse = await fetch(proxyHealthUrl);
|
||||||
|
const proxyHealth = await proxyHealthResponse.json();
|
||||||
|
if (proxyHealth?.status !== "ok") {
|
||||||
|
throw new Error("MCP Proxy Server is not healthy");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Couldn't connect to MCP Proxy Server", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAuthError = async (error: unknown) => {
|
const handleAuthError = async (error: unknown) => {
|
||||||
if (error instanceof SseError && error.code === 401) {
|
if (error instanceof SseError && error.code === 401) {
|
||||||
sessionStorage.setItem(SESSION_KEYS.SERVER_URL, sseUrl);
|
// Create a new auth provider with the current server URL
|
||||||
|
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
|
||||||
|
|
||||||
const result = await auth(authProvider, { serverUrl: sseUrl });
|
const result = await auth(serverAuthProvider, { serverUrl: sseUrl });
|
||||||
return result === "AUTHORIZED";
|
return result === "AUTHORIZED";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,62 +262,142 @@ export function useConnection({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const connect = async (_e?: unknown, retryCount: number = 0) => {
|
const connect = async (_e?: unknown, retryCount: number = 0) => {
|
||||||
try {
|
const client = new Client<Request, Notification, Result>(
|
||||||
const client = new Client<Request, Notification, Result>(
|
{
|
||||||
{
|
name: "mcp-inspector",
|
||||||
name: "mcp-inspector",
|
version: packageJson.version,
|
||||||
version: "0.0.1",
|
},
|
||||||
},
|
{
|
||||||
{
|
capabilities: {
|
||||||
capabilities: {
|
sampling: {},
|
||||||
sampling: {},
|
roots: {
|
||||||
roots: {
|
listChanged: true,
|
||||||
listChanged: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const backendUrl = new URL(`${proxyServerUrl}/sse`);
|
try {
|
||||||
|
await checkProxyHealth();
|
||||||
backendUrl.searchParams.append("transportType", transportType);
|
} catch {
|
||||||
if (transportType === "stdio") {
|
setConnectionStatus("error-connecting-to-proxy");
|
||||||
backendUrl.searchParams.append("command", command);
|
return;
|
||||||
backendUrl.searchParams.append("args", args);
|
}
|
||||||
backendUrl.searchParams.append("env", JSON.stringify(env));
|
|
||||||
} else {
|
|
||||||
backendUrl.searchParams.append("url", sseUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try {
|
||||||
// Inject auth manually instead of using SSEClientTransport, because we're
|
// Inject auth manually instead of using SSEClientTransport, because we're
|
||||||
// proxying through the inspector server first.
|
// proxying through the inspector server first.
|
||||||
const headers: HeadersInit = {};
|
const headers: HeadersInit = {};
|
||||||
|
|
||||||
|
// Create an auth provider with the current server URL
|
||||||
|
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
|
||||||
|
|
||||||
// Use manually provided bearer token if available, otherwise use OAuth tokens
|
// Use manually provided bearer token if available, otherwise use OAuth tokens
|
||||||
const token = bearerToken || (await authProvider.tokens())?.access_token;
|
const token =
|
||||||
|
bearerToken || (await serverAuthProvider.tokens())?.access_token;
|
||||||
if (token) {
|
if (token) {
|
||||||
headers["Authorization"] = `Bearer ${token}`;
|
const authHeaderName = headerName || "Authorization";
|
||||||
|
headers[authHeaderName] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientTransport = new SSEClientTransport(backendUrl, {
|
// Create appropriate transport
|
||||||
eventSourceInit: {
|
let transportOptions:
|
||||||
fetch: (url, init) => fetch(url, { ...init, headers }),
|
| StreamableHTTPClientTransportOptions
|
||||||
},
|
| SSEClientTransportOptions;
|
||||||
requestInit: {
|
|
||||||
headers,
|
let mcpProxyServerUrl;
|
||||||
},
|
switch (transportType) {
|
||||||
});
|
case "stdio":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("command", command);
|
||||||
|
mcpProxyServerUrl.searchParams.append("args", args);
|
||||||
|
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
|
||||||
|
transportOptions = {
|
||||||
|
authProvider: serverAuthProvider,
|
||||||
|
eventSourceInit: {
|
||||||
|
fetch: (
|
||||||
|
url: string | URL | globalThis.Request,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
) => fetch(url, { ...init, headers }),
|
||||||
|
},
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "sse":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
||||||
|
transportOptions = {
|
||||||
|
authProvider: serverAuthProvider,
|
||||||
|
eventSourceInit: {
|
||||||
|
fetch: (
|
||||||
|
url: string | URL | globalThis.Request,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
) => fetch(url, { ...init, headers }),
|
||||||
|
},
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "streamable-http":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
||||||
|
transportOptions = {
|
||||||
|
authProvider: serverAuthProvider,
|
||||||
|
eventSourceInit: {
|
||||||
|
fetch: (
|
||||||
|
url: string | URL | globalThis.Request,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
) => fetch(url, { ...init, headers }),
|
||||||
|
},
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
// TODO these should be configurable...
|
||||||
|
reconnectionOptions: {
|
||||||
|
maxReconnectionDelay: 30000,
|
||||||
|
initialReconnectionDelay: 1000,
|
||||||
|
reconnectionDelayGrowFactor: 1.5,
|
||||||
|
maxRetries: 2,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
(mcpProxyServerUrl as URL).searchParams.append(
|
||||||
|
"transportType",
|
||||||
|
transportType,
|
||||||
|
);
|
||||||
|
|
||||||
|
const clientTransport =
|
||||||
|
transportType === "streamable-http"
|
||||||
|
? new StreamableHTTPClientTransport(mcpProxyServerUrl as URL, {
|
||||||
|
sessionId: undefined,
|
||||||
|
...transportOptions,
|
||||||
|
})
|
||||||
|
: new SSEClientTransport(mcpProxyServerUrl as URL, transportOptions);
|
||||||
|
|
||||||
if (onNotification) {
|
if (onNotification) {
|
||||||
client.setNotificationHandler(
|
[
|
||||||
ProgressNotificationSchema,
|
CancelledNotificationSchema,
|
||||||
onNotification,
|
LoggingMessageNotificationSchema,
|
||||||
);
|
|
||||||
|
|
||||||
client.setNotificationHandler(
|
|
||||||
ResourceUpdatedNotificationSchema,
|
ResourceUpdatedNotificationSchema,
|
||||||
onNotification,
|
ResourceListChangedNotificationSchema,
|
||||||
);
|
ToolListChangedNotificationSchema,
|
||||||
|
PromptListChangedNotificationSchema,
|
||||||
|
].forEach((notificationSchema) => {
|
||||||
|
client.setNotificationHandler(notificationSchema, onNotification);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.fallbackNotificationHandler = (
|
||||||
|
notification: Notification,
|
||||||
|
): Promise<void> => {
|
||||||
|
onNotification(notification);
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onStdErrNotification) {
|
if (onStdErrNotification) {
|
||||||
@@ -266,10 +407,24 @@ export function useConnection({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let capabilities;
|
||||||
try {
|
try {
|
||||||
await client.connect(clientTransport);
|
await client.connect(clientTransport);
|
||||||
|
|
||||||
|
capabilities = client.getServerCapabilities();
|
||||||
|
const initializeRequest = {
|
||||||
|
method: "initialize",
|
||||||
|
};
|
||||||
|
pushHistory(initializeRequest, {
|
||||||
|
capabilities,
|
||||||
|
serverInfo: client.getServerVersion(),
|
||||||
|
instructions: client.getInstructions(),
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to connect to MCP server:", error);
|
console.error(
|
||||||
|
`Failed to connect to MCP Server via the MCP Inspector Proxy: ${mcpProxyServerUrl}:`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
const shouldRetry = await handleAuthError(error);
|
const shouldRetry = await handleAuthError(error);
|
||||||
if (shouldRetry) {
|
if (shouldRetry) {
|
||||||
return connect(undefined, retryCount + 1);
|
return connect(undefined, retryCount + 1);
|
||||||
@@ -281,8 +436,6 @@ export function useConnection({
|
|||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const capabilities = client.getServerCapabilities();
|
|
||||||
setServerCapabilities(capabilities ?? null);
|
setServerCapabilities(capabilities ?? null);
|
||||||
setCompletionsSupported(true); // Reset completions support on new connection
|
setCompletionsSupported(true); // Reset completions support on new connection
|
||||||
|
|
||||||
@@ -308,6 +461,16 @@ export function useConnection({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const disconnect = async () => {
|
||||||
|
await mcpClient?.close();
|
||||||
|
const authProvider = new InspectorOAuthClientProvider(sseUrl);
|
||||||
|
authProvider.clear();
|
||||||
|
setMcpClient(null);
|
||||||
|
setConnectionStatus("disconnected");
|
||||||
|
setCompletionsSupported(false);
|
||||||
|
setServerCapabilities(null);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connectionStatus,
|
connectionStatus,
|
||||||
serverCapabilities,
|
serverCapabilities,
|
||||||
@@ -318,5 +481,6 @@ export function useConnection({
|
|||||||
handleCompletion,
|
handleCompletion,
|
||||||
completionsSupported,
|
completionsSupported,
|
||||||
connect,
|
connect,
|
||||||
|
disconnect,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
type Theme = "light" | "dark" | "system";
|
type Theme = "light" | "dark" | "system";
|
||||||
|
|
||||||
@@ -36,16 +36,17 @@ const useTheme = (): [Theme, (mode: Theme) => void] => {
|
|||||||
};
|
};
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
return [
|
const setThemeWithSideEffect = useCallback((newTheme: Theme) => {
|
||||||
theme,
|
setTheme(newTheme);
|
||||||
useCallback((newTheme: Theme) => {
|
localStorage.setItem("theme", newTheme);
|
||||||
setTheme(newTheme);
|
if (newTheme !== "system") {
|
||||||
localStorage.setItem("theme", newTheme);
|
document.documentElement.classList.toggle("dark", newTheme === "dark");
|
||||||
if (newTheme !== "system") {
|
}
|
||||||
document.documentElement.classList.toggle("dark", newTheme === "dark");
|
}, []);
|
||||||
}
|
return useMemo(
|
||||||
}, []),
|
() => [theme, setThemeWithSideEffect],
|
||||||
];
|
[theme, setThemeWithSideEffect],
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useTheme;
|
export default useTheme;
|
||||||
191
client/src/lib/hooks/useToast.ts
Normal file
191
client/src/lib/hooks/useToast.ts
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
// Inspired by react-hot-toast library
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
import type { ToastActionElement, ToastProps } from "@/components/ui/toast";
|
||||||
|
|
||||||
|
const TOAST_LIMIT = 1;
|
||||||
|
const TOAST_REMOVE_DELAY = 1000000;
|
||||||
|
|
||||||
|
type ToasterToast = ToastProps & {
|
||||||
|
id: string;
|
||||||
|
title?: React.ReactNode;
|
||||||
|
description?: React.ReactNode;
|
||||||
|
action?: ToastActionElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
function genId() {
|
||||||
|
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
||||||
|
return count.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum ActionType {
|
||||||
|
ADD_TOAST = "ADD_TOAST",
|
||||||
|
UPDATE_TOAST = "UPDATE_TOAST",
|
||||||
|
DISMISS_TOAST = "DISMISS_TOAST",
|
||||||
|
REMOVE_TOAST = "REMOVE_TOAST",
|
||||||
|
}
|
||||||
|
|
||||||
|
type Action =
|
||||||
|
| {
|
||||||
|
type: ActionType.ADD_TOAST;
|
||||||
|
toast: ToasterToast;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: ActionType.UPDATE_TOAST;
|
||||||
|
toast: Partial<ToasterToast>;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: ActionType.DISMISS_TOAST;
|
||||||
|
toastId?: ToasterToast["id"];
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: ActionType.REMOVE_TOAST;
|
||||||
|
toastId?: ToasterToast["id"];
|
||||||
|
};
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
toasts: ToasterToast[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
||||||
|
|
||||||
|
const addToRemoveQueue = (toastId: string) => {
|
||||||
|
if (toastTimeouts.has(toastId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
toastTimeouts.delete(toastId);
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.REMOVE_TOAST,
|
||||||
|
toastId: toastId,
|
||||||
|
});
|
||||||
|
}, TOAST_REMOVE_DELAY);
|
||||||
|
|
||||||
|
toastTimeouts.set(toastId, timeout);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const reducer = (state: State, action: Action): State => {
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionType.ADD_TOAST:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
||||||
|
};
|
||||||
|
|
||||||
|
case ActionType.UPDATE_TOAST:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.map((t) =>
|
||||||
|
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
case ActionType.DISMISS_TOAST: {
|
||||||
|
const { toastId } = action;
|
||||||
|
|
||||||
|
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
||||||
|
// but I'll keep it here for simplicity
|
||||||
|
if (toastId) {
|
||||||
|
addToRemoveQueue(toastId);
|
||||||
|
} else {
|
||||||
|
state.toasts.forEach((toast) => {
|
||||||
|
addToRemoveQueue(toast.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.map((t) =>
|
||||||
|
t.id === toastId || toastId === undefined
|
||||||
|
? {
|
||||||
|
...t,
|
||||||
|
open: false,
|
||||||
|
}
|
||||||
|
: t,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case ActionType.REMOVE_TOAST:
|
||||||
|
if (action.toastId === undefined) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const listeners: Array<(state: State) => void> = [];
|
||||||
|
|
||||||
|
let memoryState: State = { toasts: [] };
|
||||||
|
|
||||||
|
function dispatch(action: Action) {
|
||||||
|
memoryState = reducer(memoryState, action);
|
||||||
|
listeners.forEach((listener) => {
|
||||||
|
listener(memoryState);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
type Toast = Omit<ToasterToast, "id">;
|
||||||
|
|
||||||
|
function toast({ ...props }: Toast) {
|
||||||
|
const id = genId();
|
||||||
|
|
||||||
|
const update = (props: ToasterToast) =>
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.UPDATE_TOAST,
|
||||||
|
toast: { ...props, id },
|
||||||
|
});
|
||||||
|
const dismiss = () =>
|
||||||
|
dispatch({ type: ActionType.DISMISS_TOAST, toastId: id });
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.ADD_TOAST,
|
||||||
|
toast: {
|
||||||
|
...props,
|
||||||
|
id,
|
||||||
|
open: true,
|
||||||
|
onOpenChange: (open) => {
|
||||||
|
if (!open) dismiss();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: id,
|
||||||
|
dismiss,
|
||||||
|
update,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function useToast() {
|
||||||
|
const [state, setState] = React.useState<State>(memoryState);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
listeners.push(setState);
|
||||||
|
return () => {
|
||||||
|
const index = listeners.indexOf(setState);
|
||||||
|
if (index > -1) {
|
||||||
|
listeners.splice(index, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toast,
|
||||||
|
dismiss: (toastId?: string) =>
|
||||||
|
dispatch({ type: ActionType.DISMISS_TOAST, toastId }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useToast, toast };
|
||||||
@@ -14,7 +14,9 @@ export const StdErrNotificationSchema = BaseNotificationSchema.extend({
|
|||||||
|
|
||||||
export const NotificationSchema = ClientNotificationSchema.or(
|
export const NotificationSchema = ClientNotificationSchema.or(
|
||||||
StdErrNotificationSchema,
|
StdErrNotificationSchema,
|
||||||
).or(ServerNotificationSchema);
|
)
|
||||||
|
.or(ServerNotificationSchema)
|
||||||
|
.or(BaseNotificationSchema);
|
||||||
|
|
||||||
export type StdErrNotification = z.infer<typeof StdErrNotificationSchema>;
|
export type StdErrNotification = z.infer<typeof StdErrNotificationSchema>;
|
||||||
export type Notification = z.infer<typeof NotificationSchema>;
|
export type Notification = z.infer<typeof NotificationSchema>;
|
||||||
|
|||||||
181
client/src/lib/oauth-state-machine.ts
Normal file
181
client/src/lib/oauth-state-machine.ts
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
import { OAuthStep, AuthDebuggerState } from "./auth-types";
|
||||||
|
import { DebugInspectorOAuthClientProvider } from "./auth";
|
||||||
|
import {
|
||||||
|
discoverOAuthMetadata,
|
||||||
|
registerClient,
|
||||||
|
startAuthorization,
|
||||||
|
exchangeAuthorization,
|
||||||
|
} from "@modelcontextprotocol/sdk/client/auth.js";
|
||||||
|
import { OAuthMetadataSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||||
|
|
||||||
|
export interface StateMachineContext {
|
||||||
|
state: AuthDebuggerState;
|
||||||
|
serverUrl: string;
|
||||||
|
provider: DebugInspectorOAuthClientProvider;
|
||||||
|
updateState: (updates: Partial<AuthDebuggerState>) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StateTransition {
|
||||||
|
canTransition: (context: StateMachineContext) => Promise<boolean>;
|
||||||
|
execute: (context: StateMachineContext) => Promise<void>;
|
||||||
|
nextStep: OAuthStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// State machine transitions
|
||||||
|
export const oauthTransitions: Record<OAuthStep, StateTransition> = {
|
||||||
|
metadata_discovery: {
|
||||||
|
canTransition: async () => true,
|
||||||
|
execute: async (context) => {
|
||||||
|
const metadata = await discoverOAuthMetadata(context.serverUrl);
|
||||||
|
if (!metadata) {
|
||||||
|
throw new Error("Failed to discover OAuth metadata");
|
||||||
|
}
|
||||||
|
const parsedMetadata = await OAuthMetadataSchema.parseAsync(metadata);
|
||||||
|
context.provider.saveServerMetadata(parsedMetadata);
|
||||||
|
context.updateState({
|
||||||
|
oauthMetadata: parsedMetadata,
|
||||||
|
oauthStep: "client_registration",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
nextStep: "client_registration",
|
||||||
|
},
|
||||||
|
|
||||||
|
client_registration: {
|
||||||
|
canTransition: async (context) => !!context.state.oauthMetadata,
|
||||||
|
execute: async (context) => {
|
||||||
|
const metadata = context.state.oauthMetadata!;
|
||||||
|
const clientMetadata = context.provider.clientMetadata;
|
||||||
|
|
||||||
|
// Add all supported scopes to client registration
|
||||||
|
if (metadata.scopes_supported) {
|
||||||
|
clientMetadata.scope = metadata.scopes_supported.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullInformation = await registerClient(context.serverUrl, {
|
||||||
|
metadata,
|
||||||
|
clientMetadata,
|
||||||
|
});
|
||||||
|
|
||||||
|
context.provider.saveClientInformation(fullInformation);
|
||||||
|
context.updateState({
|
||||||
|
oauthClientInfo: fullInformation,
|
||||||
|
oauthStep: "authorization_redirect",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
nextStep: "authorization_redirect",
|
||||||
|
},
|
||||||
|
|
||||||
|
authorization_redirect: {
|
||||||
|
canTransition: async (context) =>
|
||||||
|
!!context.state.oauthMetadata && !!context.state.oauthClientInfo,
|
||||||
|
execute: async (context) => {
|
||||||
|
const metadata = context.state.oauthMetadata!;
|
||||||
|
const clientInformation = context.state.oauthClientInfo!;
|
||||||
|
|
||||||
|
let scope: string | undefined = undefined;
|
||||||
|
if (metadata.scopes_supported) {
|
||||||
|
scope = metadata.scopes_supported.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
const { authorizationUrl, codeVerifier } = await startAuthorization(
|
||||||
|
context.serverUrl,
|
||||||
|
{
|
||||||
|
metadata,
|
||||||
|
clientInformation,
|
||||||
|
redirectUrl: context.provider.redirectUrl,
|
||||||
|
scope,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
context.provider.saveCodeVerifier(codeVerifier);
|
||||||
|
context.updateState({
|
||||||
|
authorizationUrl: authorizationUrl.toString(),
|
||||||
|
oauthStep: "authorization_code",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
nextStep: "authorization_code",
|
||||||
|
},
|
||||||
|
|
||||||
|
authorization_code: {
|
||||||
|
canTransition: async () => true,
|
||||||
|
execute: async (context) => {
|
||||||
|
if (
|
||||||
|
!context.state.authorizationCode ||
|
||||||
|
context.state.authorizationCode.trim() === ""
|
||||||
|
) {
|
||||||
|
context.updateState({
|
||||||
|
validationError: "You need to provide an authorization code",
|
||||||
|
});
|
||||||
|
// Don't advance if no code
|
||||||
|
throw new Error("Authorization code required");
|
||||||
|
}
|
||||||
|
context.updateState({
|
||||||
|
validationError: null,
|
||||||
|
oauthStep: "token_request",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
nextStep: "token_request",
|
||||||
|
},
|
||||||
|
|
||||||
|
token_request: {
|
||||||
|
canTransition: async (context) => {
|
||||||
|
return (
|
||||||
|
!!context.state.authorizationCode &&
|
||||||
|
!!context.provider.getServerMetadata() &&
|
||||||
|
!!(await context.provider.clientInformation())
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: async (context) => {
|
||||||
|
const codeVerifier = context.provider.codeVerifier();
|
||||||
|
const metadata = context.provider.getServerMetadata()!;
|
||||||
|
const clientInformation = (await context.provider.clientInformation())!;
|
||||||
|
|
||||||
|
const tokens = await exchangeAuthorization(context.serverUrl, {
|
||||||
|
metadata,
|
||||||
|
clientInformation,
|
||||||
|
authorizationCode: context.state.authorizationCode,
|
||||||
|
codeVerifier,
|
||||||
|
redirectUri: context.provider.redirectUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
context.provider.saveTokens(tokens);
|
||||||
|
context.updateState({
|
||||||
|
oauthTokens: tokens,
|
||||||
|
oauthStep: "complete",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
nextStep: "complete",
|
||||||
|
},
|
||||||
|
|
||||||
|
complete: {
|
||||||
|
canTransition: async () => false,
|
||||||
|
execute: async () => {
|
||||||
|
// No-op for complete state
|
||||||
|
},
|
||||||
|
nextStep: "complete",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export class OAuthStateMachine {
|
||||||
|
constructor(
|
||||||
|
private serverUrl: string,
|
||||||
|
private updateState: (updates: Partial<AuthDebuggerState>) => void,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async executeStep(state: AuthDebuggerState): Promise<void> {
|
||||||
|
const provider = new DebugInspectorOAuthClientProvider(this.serverUrl);
|
||||||
|
const context: StateMachineContext = {
|
||||||
|
state,
|
||||||
|
serverUrl: this.serverUrl,
|
||||||
|
provider,
|
||||||
|
updateState: this.updateState,
|
||||||
|
};
|
||||||
|
|
||||||
|
const transition = oauthTransitions[state.oauthStep];
|
||||||
|
if (!(await transition.canTransition(context))) {
|
||||||
|
throw new Error(`Cannot transition from ${state.oauthStep}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await transition.execute(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import { StrictMode } from "react";
|
import { StrictMode } from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { ToastContainer } from "react-toastify";
|
import { Toaster } from "@/components/ui/toaster.tsx";
|
||||||
import "react-toastify/dist/ReactToastify.css";
|
|
||||||
import App from "./App.tsx";
|
import App from "./App.tsx";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import { TooltipProvider } from "./components/ui/tooltip.tsx";
|
||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<App />
|
<TooltipProvider>
|
||||||
<ToastContainer />
|
<App />
|
||||||
|
</TooltipProvider>
|
||||||
|
<Toaster />
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
);
|
);
|
||||||
|
|||||||
27
client/src/utils/__tests__/escapeUnicode.test.ts
Normal file
27
client/src/utils/__tests__/escapeUnicode.test.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { escapeUnicode } from "../escapeUnicode";
|
||||||
|
|
||||||
|
describe("escapeUnicode", () => {
|
||||||
|
it("should escape Unicode characters in a string", () => {
|
||||||
|
const input = { text: "你好世界" };
|
||||||
|
const expected = '{\n "text": "\\\\u4f60\\\\u597d\\\\u4e16\\\\u754c"\n}';
|
||||||
|
expect(escapeUnicode(input)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle empty strings", () => {
|
||||||
|
const input = { text: "" };
|
||||||
|
const expected = '{\n "text": ""\n}';
|
||||||
|
expect(escapeUnicode(input)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle null and undefined values", () => {
|
||||||
|
const input = { text: null, value: undefined };
|
||||||
|
const expected = '{\n "text": null\n}';
|
||||||
|
expect(escapeUnicode(input)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle numbers and booleans", () => {
|
||||||
|
const input = { number: 123, boolean: true };
|
||||||
|
const expected = '{\n "number": 123,\n "boolean": true\n}';
|
||||||
|
expect(escapeUnicode(input)).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
319
client/src/utils/__tests__/jsonUtils.test.ts
Normal file
319
client/src/utils/__tests__/jsonUtils.test.ts
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
import {
|
||||||
|
getDataType,
|
||||||
|
tryParseJson,
|
||||||
|
updateValueAtPath,
|
||||||
|
getValueAtPath,
|
||||||
|
} from "../jsonUtils";
|
||||||
|
import type { JsonValue } from "../jsonUtils";
|
||||||
|
|
||||||
|
describe("getDataType", () => {
|
||||||
|
test("should return 'string' for string values", () => {
|
||||||
|
expect(getDataType("hello")).toBe("string");
|
||||||
|
expect(getDataType("")).toBe("string");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return 'number' for number values", () => {
|
||||||
|
expect(getDataType(123)).toBe("number");
|
||||||
|
expect(getDataType(0)).toBe("number");
|
||||||
|
expect(getDataType(-10)).toBe("number");
|
||||||
|
expect(getDataType(1.5)).toBe("number");
|
||||||
|
expect(getDataType(NaN)).toBe("number");
|
||||||
|
expect(getDataType(Infinity)).toBe("number");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return 'boolean' for boolean values", () => {
|
||||||
|
expect(getDataType(true)).toBe("boolean");
|
||||||
|
expect(getDataType(false)).toBe("boolean");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return 'undefined' for undefined value", () => {
|
||||||
|
expect(getDataType(undefined)).toBe("undefined");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return 'object' for object values", () => {
|
||||||
|
expect(getDataType({})).toBe("object");
|
||||||
|
expect(getDataType({ key: "value" })).toBe("object");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return 'array' for array values", () => {
|
||||||
|
expect(getDataType([])).toBe("array");
|
||||||
|
expect(getDataType([1, 2, 3])).toBe("array");
|
||||||
|
expect(getDataType(["a", "b", "c"])).toBe("array");
|
||||||
|
expect(getDataType([{}, { nested: true }])).toBe("array");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return 'null' for null value", () => {
|
||||||
|
expect(getDataType(null)).toBe("null");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("tryParseJson", () => {
|
||||||
|
test("should correctly parse valid JSON object", () => {
|
||||||
|
const jsonString = '{"name":"test","value":123}';
|
||||||
|
const result = tryParseJson(jsonString);
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
expect(result.data).toEqual({ name: "test", value: 123 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should correctly parse valid JSON array", () => {
|
||||||
|
const jsonString = '[1,2,3,"test"]';
|
||||||
|
const result = tryParseJson(jsonString);
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
expect(result.data).toEqual([1, 2, 3, "test"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should correctly parse JSON with whitespace", () => {
|
||||||
|
const jsonString = ' { "name" : "test" } ';
|
||||||
|
const result = tryParseJson(jsonString);
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
expect(result.data).toEqual({ name: "test" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should correctly parse nested JSON structures", () => {
|
||||||
|
const jsonString =
|
||||||
|
'{"user":{"name":"test","details":{"age":30}},"items":[1,2,3]}';
|
||||||
|
const result = tryParseJson(jsonString);
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
expect(result.data).toEqual({
|
||||||
|
user: {
|
||||||
|
name: "test",
|
||||||
|
details: {
|
||||||
|
age: 30,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
items: [1, 2, 3],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should correctly parse empty objects and arrays", () => {
|
||||||
|
expect(tryParseJson("{}").success).toBe(true);
|
||||||
|
expect(tryParseJson("{}").data).toEqual({});
|
||||||
|
|
||||||
|
expect(tryParseJson("[]").success).toBe(true);
|
||||||
|
expect(tryParseJson("[]").data).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return failure for non-JSON strings", () => {
|
||||||
|
const nonJsonString = "this is not json";
|
||||||
|
const result = tryParseJson(nonJsonString);
|
||||||
|
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
expect(result.data).toBe(nonJsonString);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return failure for malformed JSON", () => {
|
||||||
|
const malformedJson = '{"name":"test",}';
|
||||||
|
const result = tryParseJson(malformedJson);
|
||||||
|
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
expect(result.data).toBe(malformedJson);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return failure for strings with correct delimiters but invalid JSON", () => {
|
||||||
|
const invalidJson = "{name:test}";
|
||||||
|
const result = tryParseJson(invalidJson);
|
||||||
|
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
expect(result.data).toBe(invalidJson);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle edge cases", () => {
|
||||||
|
expect(tryParseJson("").success).toBe(false);
|
||||||
|
expect(tryParseJson("").data).toBe("");
|
||||||
|
|
||||||
|
expect(tryParseJson(" ").success).toBe(false);
|
||||||
|
expect(tryParseJson(" ").data).toBe(" ");
|
||||||
|
|
||||||
|
expect(tryParseJson("null").success).toBe(false);
|
||||||
|
expect(tryParseJson("null").data).toBe("null");
|
||||||
|
|
||||||
|
expect(tryParseJson('"string"').success).toBe(false);
|
||||||
|
expect(tryParseJson('"string"').data).toBe('"string"');
|
||||||
|
|
||||||
|
expect(tryParseJson("123").success).toBe(false);
|
||||||
|
expect(tryParseJson("123").data).toBe("123");
|
||||||
|
|
||||||
|
expect(tryParseJson("true").success).toBe(false);
|
||||||
|
expect(tryParseJson("true").data).toBe("true");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("updateValueAtPath", () => {
|
||||||
|
// Basic functionality tests
|
||||||
|
test("returns the new value when path is empty", () => {
|
||||||
|
expect(updateValueAtPath({ foo: "bar" }, [], "newValue")).toBe("newValue");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("initializes an empty object when input is null/undefined and path starts with a string", () => {
|
||||||
|
expect(updateValueAtPath(null, ["foo"], "bar")).toEqual({
|
||||||
|
foo: "bar",
|
||||||
|
});
|
||||||
|
expect(updateValueAtPath(undefined, ["foo"], "bar")).toEqual({
|
||||||
|
foo: "bar",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("initializes an empty array when input is null/undefined and path starts with a number", () => {
|
||||||
|
expect(updateValueAtPath(null, ["0"], "bar")).toEqual(["bar"]);
|
||||||
|
expect(updateValueAtPath(undefined, ["0"], "bar")).toEqual(["bar"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Object update tests
|
||||||
|
test("updates a simple object property", () => {
|
||||||
|
const obj = { name: "John", age: 30 };
|
||||||
|
expect(updateValueAtPath(obj, ["age"], 31)).toEqual({
|
||||||
|
name: "John",
|
||||||
|
age: 31,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates a nested object property", () => {
|
||||||
|
const obj = { user: { name: "John", address: { city: "New York" } } };
|
||||||
|
expect(
|
||||||
|
updateValueAtPath(obj, ["user", "address", "city"], "Boston"),
|
||||||
|
).toEqual({ user: { name: "John", address: { city: "Boston" } } });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("creates missing object properties", () => {
|
||||||
|
const obj = { user: { name: "John" } };
|
||||||
|
expect(
|
||||||
|
updateValueAtPath(obj, ["user", "address", "city"], "Boston"),
|
||||||
|
).toEqual({ user: { name: "John", address: { city: "Boston" } } });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Array update tests
|
||||||
|
test("updates an array item", () => {
|
||||||
|
const arr = [1, 2, 3, 4];
|
||||||
|
expect(updateValueAtPath(arr, ["2"], 5)).toEqual([1, 2, 5, 4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("extends an array when index is out of bounds", () => {
|
||||||
|
const arr = [1, 2, 3];
|
||||||
|
const result = updateValueAtPath(arr, ["5"], "new") as JsonValue[];
|
||||||
|
|
||||||
|
// Check overall array structure
|
||||||
|
expect(result).toEqual([1, 2, 3, null, null, "new"]);
|
||||||
|
|
||||||
|
// Explicitly verify that indices 3 and 4 contain null, not undefined
|
||||||
|
expect(result[3]).toBe(null);
|
||||||
|
expect(result[4]).toBe(null);
|
||||||
|
|
||||||
|
// Verify these aren't "holes" in the array (important distinction)
|
||||||
|
expect(3 in result).toBe(true);
|
||||||
|
expect(4 in result).toBe(true);
|
||||||
|
|
||||||
|
// Verify the array has the correct length
|
||||||
|
expect(result.length).toBe(6);
|
||||||
|
|
||||||
|
// Verify the array doesn't have holes by checking every index exists
|
||||||
|
expect(result.every((_, index: number) => index in result)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates a nested array item", () => {
|
||||||
|
const obj = { users: [{ name: "John" }, { name: "Jane" }] };
|
||||||
|
expect(updateValueAtPath(obj, ["users", "1", "name"], "Janet")).toEqual({
|
||||||
|
users: [{ name: "John" }, { name: "Janet" }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Error handling tests
|
||||||
|
test("returns original value when trying to update a primitive with a path", () => {
|
||||||
|
const spy = jest.spyOn(console, "error").mockImplementation();
|
||||||
|
const result = updateValueAtPath("string", ["foo"], "bar");
|
||||||
|
expect(result).toBe("string");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
spy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns original array when index is invalid", () => {
|
||||||
|
const spy = jest.spyOn(console, "error").mockImplementation();
|
||||||
|
const arr = [1, 2, 3];
|
||||||
|
expect(updateValueAtPath(arr, ["invalid"], 4)).toEqual(arr);
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
spy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns original array when index is negative", () => {
|
||||||
|
const spy = jest.spyOn(console, "error").mockImplementation();
|
||||||
|
const arr = [1, 2, 3];
|
||||||
|
expect(updateValueAtPath(arr, ["-1"], 4)).toEqual(arr);
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
spy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles sparse arrays correctly by filling holes with null", () => {
|
||||||
|
// Create a sparse array by deleting an element
|
||||||
|
const sparseArr = [1, 2, 3];
|
||||||
|
delete sparseArr[1]; // Now sparseArr is [1, <1 empty item>, 3]
|
||||||
|
|
||||||
|
// Update a value beyond the array length
|
||||||
|
const result = updateValueAtPath(sparseArr, ["5"], "new") as JsonValue[];
|
||||||
|
|
||||||
|
// Check overall array structure
|
||||||
|
expect(result).toEqual([1, null, 3, null, null, "new"]);
|
||||||
|
|
||||||
|
// Explicitly verify that index 1 (the hole) contains null, not undefined
|
||||||
|
expect(result[1]).toBe(null);
|
||||||
|
|
||||||
|
// Verify this isn't a hole in the array
|
||||||
|
expect(1 in result).toBe(true);
|
||||||
|
|
||||||
|
// Verify all indices contain null (not undefined)
|
||||||
|
expect(result[1]).not.toBe(undefined);
|
||||||
|
expect(result[3]).toBe(null);
|
||||||
|
expect(result[4]).toBe(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getValueAtPath", () => {
|
||||||
|
test("returns the original value when path is empty", () => {
|
||||||
|
const obj = { foo: "bar" };
|
||||||
|
expect(getValueAtPath(obj, [])).toBe(obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns the value at a simple path", () => {
|
||||||
|
const obj = { name: "John", age: 30 };
|
||||||
|
expect(getValueAtPath(obj, ["name"])).toBe("John");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns the value at a nested path", () => {
|
||||||
|
const obj = { user: { name: "John", address: { city: "New York" } } };
|
||||||
|
expect(getValueAtPath(obj, ["user", "address", "city"])).toBe("New York");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns default value when path does not exist", () => {
|
||||||
|
const obj = { user: { name: "John" } };
|
||||||
|
expect(getValueAtPath(obj, ["user", "address", "city"], "Unknown")).toBe(
|
||||||
|
"Unknown",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns default value when input is null/undefined", () => {
|
||||||
|
expect(getValueAtPath(null, ["foo"], "default")).toBe("default");
|
||||||
|
expect(getValueAtPath(undefined, ["foo"], "default")).toBe("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles array indices correctly", () => {
|
||||||
|
const arr = ["a", "b", "c"];
|
||||||
|
expect(getValueAtPath(arr, ["1"])).toBe("b");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns default value for out of bounds array indices", () => {
|
||||||
|
const arr = ["a", "b", "c"];
|
||||||
|
expect(getValueAtPath(arr, ["5"], "default")).toBe("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns default value for invalid array indices", () => {
|
||||||
|
const arr = ["a", "b", "c"];
|
||||||
|
expect(getValueAtPath(arr, ["invalid"], "default")).toBe("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("navigates through mixed object and array paths", () => {
|
||||||
|
const obj = { users: [{ name: "John" }, { name: "Jane" }] };
|
||||||
|
expect(getValueAtPath(obj, ["users", "1", "name"])).toBe("Jane");
|
||||||
|
});
|
||||||
|
});
|
||||||
78
client/src/utils/__tests__/oauthUtils.ts
Normal file
78
client/src/utils/__tests__/oauthUtils.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import {
|
||||||
|
generateOAuthErrorDescription,
|
||||||
|
parseOAuthCallbackParams,
|
||||||
|
} from "@/utils/oauthUtils.ts";
|
||||||
|
|
||||||
|
describe("parseOAuthCallbackParams", () => {
|
||||||
|
it("Returns successful: true and code when present", () => {
|
||||||
|
expect(parseOAuthCallbackParams("?code=fake-code")).toEqual({
|
||||||
|
successful: true,
|
||||||
|
code: "fake-code",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Returns successful: false and error when error is present", () => {
|
||||||
|
expect(parseOAuthCallbackParams("?error=access_denied")).toEqual({
|
||||||
|
successful: false,
|
||||||
|
error: "access_denied",
|
||||||
|
error_description: null,
|
||||||
|
error_uri: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Returns optional error metadata fields when present", () => {
|
||||||
|
const search =
|
||||||
|
"?error=access_denied&" +
|
||||||
|
"error_description=User%20Denied%20Request&" +
|
||||||
|
"error_uri=https%3A%2F%2Fexample.com%2Ferror-docs";
|
||||||
|
expect(parseOAuthCallbackParams(search)).toEqual({
|
||||||
|
successful: false,
|
||||||
|
error: "access_denied",
|
||||||
|
error_description: "User Denied Request",
|
||||||
|
error_uri: "https://example.com/error-docs",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Returns error when nothing present", () => {
|
||||||
|
expect(parseOAuthCallbackParams("?")).toEqual({
|
||||||
|
successful: false,
|
||||||
|
error: "invalid_request",
|
||||||
|
error_description: "Missing code or error in response",
|
||||||
|
error_uri: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("generateOAuthErrorDescription", () => {
|
||||||
|
it("When only error is present", () => {
|
||||||
|
expect(
|
||||||
|
generateOAuthErrorDescription({
|
||||||
|
successful: false,
|
||||||
|
error: "invalid_request",
|
||||||
|
error_description: null,
|
||||||
|
error_uri: null,
|
||||||
|
}),
|
||||||
|
).toBe("Error: invalid_request.");
|
||||||
|
});
|
||||||
|
it("When error description is present", () => {
|
||||||
|
expect(
|
||||||
|
generateOAuthErrorDescription({
|
||||||
|
successful: false,
|
||||||
|
error: "invalid_request",
|
||||||
|
error_description: "The request could not be completed as dialed",
|
||||||
|
error_uri: null,
|
||||||
|
}),
|
||||||
|
).toEqual(
|
||||||
|
"Error: invalid_request.\nDetails: The request could not be completed as dialed.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it("When all fields present", () => {
|
||||||
|
expect(
|
||||||
|
generateOAuthErrorDescription({
|
||||||
|
successful: false,
|
||||||
|
error: "invalid_request",
|
||||||
|
error_description: "The request could not be completed as dialed",
|
||||||
|
error_uri: "https://example.com/error-docs",
|
||||||
|
}),
|
||||||
|
).toEqual(
|
||||||
|
"Error: invalid_request.\nDetails: The request could not be completed as dialed.\nMore info: https://example.com/error-docs.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
139
client/src/utils/__tests__/schemaUtils.test.ts
Normal file
139
client/src/utils/__tests__/schemaUtils.test.ts
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import { generateDefaultValue, formatFieldLabel } from "../schemaUtils";
|
||||||
|
import type { JsonSchemaType } from "../jsonUtils";
|
||||||
|
|
||||||
|
describe("generateDefaultValue", () => {
|
||||||
|
test("generates default string", () => {
|
||||||
|
expect(generateDefaultValue({ type: "string", required: true })).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates default number", () => {
|
||||||
|
expect(generateDefaultValue({ type: "number", required: true })).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates default integer", () => {
|
||||||
|
expect(generateDefaultValue({ type: "integer", required: true })).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates default boolean", () => {
|
||||||
|
expect(generateDefaultValue({ type: "boolean", required: true })).toBe(
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates default array", () => {
|
||||||
|
expect(generateDefaultValue({ type: "array", required: true })).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates default empty object", () => {
|
||||||
|
expect(generateDefaultValue({ type: "object", required: true })).toEqual(
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates default null for unknown types", () => {
|
||||||
|
// @ts-expect-error Testing with invalid type
|
||||||
|
expect(generateDefaultValue({ type: "unknown", required: true })).toBe(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates empty array for non-required array", () => {
|
||||||
|
expect(generateDefaultValue({ type: "array", required: false })).toEqual(
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates empty object for non-required object", () => {
|
||||||
|
expect(generateDefaultValue({ type: "object", required: false })).toEqual(
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates null for non-required primitive types", () => {
|
||||||
|
expect(generateDefaultValue({ type: "string", required: false })).toBe(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
expect(generateDefaultValue({ type: "number", required: false })).toBe(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
expect(generateDefaultValue({ type: "boolean", required: false })).toBe(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generates object with properties", () => {
|
||||||
|
const schema: JsonSchemaType = {
|
||||||
|
type: "object",
|
||||||
|
required: true,
|
||||||
|
properties: {
|
||||||
|
name: { type: "string", required: true },
|
||||||
|
age: { type: "number", required: true },
|
||||||
|
isActive: { type: "boolean", required: true },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(generateDefaultValue(schema)).toEqual({
|
||||||
|
name: "",
|
||||||
|
age: 0,
|
||||||
|
isActive: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles nested objects", () => {
|
||||||
|
const schema: JsonSchemaType = {
|
||||||
|
type: "object",
|
||||||
|
required: true,
|
||||||
|
properties: {
|
||||||
|
user: {
|
||||||
|
type: "object",
|
||||||
|
required: true,
|
||||||
|
properties: {
|
||||||
|
name: { type: "string", required: true },
|
||||||
|
address: {
|
||||||
|
type: "object",
|
||||||
|
required: true,
|
||||||
|
properties: {
|
||||||
|
city: { type: "string", required: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(generateDefaultValue(schema)).toEqual({
|
||||||
|
user: {
|
||||||
|
name: "",
|
||||||
|
address: {
|
||||||
|
city: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses schema default value when provided", () => {
|
||||||
|
expect(generateDefaultValue({ type: "string", default: "test" })).toBe(
|
||||||
|
"test",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("formatFieldLabel", () => {
|
||||||
|
test("formats camelCase", () => {
|
||||||
|
expect(formatFieldLabel("firstName")).toBe("First Name");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats snake_case", () => {
|
||||||
|
expect(formatFieldLabel("first_name")).toBe("First name");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats single word", () => {
|
||||||
|
expect(formatFieldLabel("name")).toBe("Name");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats mixed case with underscores", () => {
|
||||||
|
expect(formatFieldLabel("user_firstName")).toBe("User first Name");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles empty string", () => {
|
||||||
|
expect(formatFieldLabel("")).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
126
client/src/utils/configUtils.ts
Normal file
126
client/src/utils/configUtils.ts
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
import { InspectorConfig } from "@/lib/configurationTypes";
|
||||||
|
import {
|
||||||
|
DEFAULT_MCP_PROXY_LISTEN_PORT,
|
||||||
|
DEFAULT_INSPECTOR_CONFIG,
|
||||||
|
} from "@/lib/constants";
|
||||||
|
|
||||||
|
export const getMCPProxyAddress = (config: InspectorConfig): string => {
|
||||||
|
const proxyFullAddress = config.MCP_PROXY_FULL_ADDRESS.value as string;
|
||||||
|
if (proxyFullAddress) {
|
||||||
|
return proxyFullAddress;
|
||||||
|
}
|
||||||
|
return `${window.location.protocol}//${window.location.hostname}:${DEFAULT_MCP_PROXY_LISTEN_PORT}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getMCPServerRequestTimeout = (config: InspectorConfig): number => {
|
||||||
|
return config.MCP_SERVER_REQUEST_TIMEOUT.value as number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetRequestTimeoutOnProgress = (
|
||||||
|
config: InspectorConfig,
|
||||||
|
): boolean => {
|
||||||
|
return config.MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS.value as boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getMCPServerRequestMaxTotalTimeout = (
|
||||||
|
config: InspectorConfig,
|
||||||
|
): number => {
|
||||||
|
return config.MCP_REQUEST_MAX_TOTAL_TIMEOUT.value as number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSearchParam = (key: string): string | null => {
|
||||||
|
try {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
return url.searchParams.get(key);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInitialTransportType = ():
|
||||||
|
| "stdio"
|
||||||
|
| "sse"
|
||||||
|
| "streamable-http" => {
|
||||||
|
const param = getSearchParam("transport");
|
||||||
|
if (param === "stdio" || param === "sse" || param === "streamable-http") {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
(localStorage.getItem("lastTransportType") as
|
||||||
|
| "stdio"
|
||||||
|
| "sse"
|
||||||
|
| "streamable-http") || "stdio"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInitialSseUrl = (): string => {
|
||||||
|
const param = getSearchParam("serverUrl");
|
||||||
|
if (param) return param;
|
||||||
|
return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse";
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInitialCommand = (): string => {
|
||||||
|
const param = getSearchParam("serverCommand");
|
||||||
|
if (param) return param;
|
||||||
|
return localStorage.getItem("lastCommand") || "mcp-server-everything";
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInitialArgs = (): string => {
|
||||||
|
const param = getSearchParam("serverArgs");
|
||||||
|
if (param) return param;
|
||||||
|
return localStorage.getItem("lastArgs") || "";
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns a map of config key -> value from query params if present
|
||||||
|
export const getConfigOverridesFromQueryParams = (
|
||||||
|
defaultConfig: InspectorConfig,
|
||||||
|
): Partial<InspectorConfig> => {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
const overrides: Partial<InspectorConfig> = {};
|
||||||
|
for (const key of Object.keys(defaultConfig)) {
|
||||||
|
const param = url.searchParams.get(key);
|
||||||
|
if (param !== null) {
|
||||||
|
// Try to coerce to correct type based on default value
|
||||||
|
const defaultValue = defaultConfig[key as keyof InspectorConfig].value;
|
||||||
|
let value: string | number | boolean = param;
|
||||||
|
if (typeof defaultValue === "number") {
|
||||||
|
value = Number(param);
|
||||||
|
} else if (typeof defaultValue === "boolean") {
|
||||||
|
value = param === "true";
|
||||||
|
}
|
||||||
|
overrides[key as keyof InspectorConfig] = {
|
||||||
|
...defaultConfig[key as keyof InspectorConfig],
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return overrides;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initializeInspectorConfig = (
|
||||||
|
localStorageKey: string,
|
||||||
|
): InspectorConfig => {
|
||||||
|
const savedConfig = localStorage.getItem(localStorageKey);
|
||||||
|
let baseConfig: InspectorConfig;
|
||||||
|
if (savedConfig) {
|
||||||
|
// merge default config with saved config
|
||||||
|
const mergedConfig = {
|
||||||
|
...DEFAULT_INSPECTOR_CONFIG,
|
||||||
|
...JSON.parse(savedConfig),
|
||||||
|
} as InspectorConfig;
|
||||||
|
|
||||||
|
// update description of keys to match the new description (in case of any updates to the default config description)
|
||||||
|
for (const [key, value] of Object.entries(mergedConfig)) {
|
||||||
|
mergedConfig[key as keyof InspectorConfig] = {
|
||||||
|
...value,
|
||||||
|
label: DEFAULT_INSPECTOR_CONFIG[key as keyof InspectorConfig].label,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
baseConfig = mergedConfig;
|
||||||
|
} else {
|
||||||
|
baseConfig = DEFAULT_INSPECTOR_CONFIG;
|
||||||
|
}
|
||||||
|
// Apply query param overrides
|
||||||
|
const overrides = getConfigOverridesFromQueryParams(DEFAULT_INSPECTOR_CONFIG);
|
||||||
|
return { ...baseConfig, ...overrides };
|
||||||
|
};
|
||||||
16
client/src/utils/escapeUnicode.ts
Normal file
16
client/src/utils/escapeUnicode.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Utility function to escape Unicode characters
|
||||||
|
export function escapeUnicode(obj: unknown): string {
|
||||||
|
return JSON.stringify(
|
||||||
|
obj,
|
||||||
|
(_key: string, value) => {
|
||||||
|
if (typeof value === "string") {
|
||||||
|
// Replace non-ASCII characters with their Unicode escape sequences
|
||||||
|
return value.replace(/[^\0-\x7F]/g, (char) => {
|
||||||
|
return "\\u" + ("0000" + char.charCodeAt(0).toString(16)).slice(-4);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
}
|
||||||
208
client/src/utils/jsonUtils.ts
Normal file
208
client/src/utils/jsonUtils.ts
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
export type JsonValue =
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| null
|
||||||
|
| undefined
|
||||||
|
| JsonValue[]
|
||||||
|
| { [key: string]: JsonValue };
|
||||||
|
|
||||||
|
export type JsonSchemaType = {
|
||||||
|
type:
|
||||||
|
| "string"
|
||||||
|
| "number"
|
||||||
|
| "integer"
|
||||||
|
| "boolean"
|
||||||
|
| "array"
|
||||||
|
| "object"
|
||||||
|
| "null";
|
||||||
|
description?: string;
|
||||||
|
required?: boolean;
|
||||||
|
default?: JsonValue;
|
||||||
|
properties?: Record<string, JsonSchemaType>;
|
||||||
|
items?: JsonSchemaType;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type JsonObject = { [key: string]: JsonValue };
|
||||||
|
|
||||||
|
export type DataType =
|
||||||
|
| "string"
|
||||||
|
| "number"
|
||||||
|
| "bigint"
|
||||||
|
| "boolean"
|
||||||
|
| "symbol"
|
||||||
|
| "undefined"
|
||||||
|
| "object"
|
||||||
|
| "function"
|
||||||
|
| "array"
|
||||||
|
| "null";
|
||||||
|
|
||||||
|
export function getDataType(value: JsonValue): DataType {
|
||||||
|
if (Array.isArray(value)) return "array";
|
||||||
|
if (value === null) return "null";
|
||||||
|
return typeof value;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tryParseJson(str: string): {
|
||||||
|
success: boolean;
|
||||||
|
data: JsonValue;
|
||||||
|
} {
|
||||||
|
const trimmed = str.trim();
|
||||||
|
if (
|
||||||
|
!(trimmed.startsWith("{") && trimmed.endsWith("}")) &&
|
||||||
|
!(trimmed.startsWith("[") && trimmed.endsWith("]"))
|
||||||
|
) {
|
||||||
|
return { success: false, data: str };
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return { success: true, data: JSON.parse(str) };
|
||||||
|
} catch {
|
||||||
|
return { success: false, data: str };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a value at a specific path in a nested JSON structure
|
||||||
|
* @param obj The original JSON value
|
||||||
|
* @param path Array of keys/indices representing the path to the value
|
||||||
|
* @param value The new value to set
|
||||||
|
* @returns A new JSON value with the updated path
|
||||||
|
*/
|
||||||
|
export function updateValueAtPath(
|
||||||
|
obj: JsonValue,
|
||||||
|
path: string[],
|
||||||
|
value: JsonValue,
|
||||||
|
): JsonValue {
|
||||||
|
if (path.length === 0) return value;
|
||||||
|
|
||||||
|
if (obj === null || obj === undefined) {
|
||||||
|
obj = !isNaN(Number(path[0])) ? [] : {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
return updateArray(obj, path, value);
|
||||||
|
} else if (typeof obj === "object" && obj !== null) {
|
||||||
|
return updateObject(obj as JsonObject, path, value);
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
`Cannot update path ${path.join(".")} in non-object/array value:`,
|
||||||
|
obj,
|
||||||
|
);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an array at a specific path
|
||||||
|
*/
|
||||||
|
function updateArray(
|
||||||
|
array: JsonValue[],
|
||||||
|
path: string[],
|
||||||
|
value: JsonValue,
|
||||||
|
): JsonValue[] {
|
||||||
|
const [index, ...restPath] = path;
|
||||||
|
const arrayIndex = Number(index);
|
||||||
|
|
||||||
|
if (isNaN(arrayIndex)) {
|
||||||
|
console.error(`Invalid array index: ${index}`);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arrayIndex < 0) {
|
||||||
|
console.error(`Array index out of bounds: ${arrayIndex} < 0`);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
let newArray: JsonValue[] = [];
|
||||||
|
for (let i = 0; i < array.length; i++) {
|
||||||
|
newArray[i] = i in array ? array[i] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arrayIndex >= newArray.length) {
|
||||||
|
const extendedArray: JsonValue[] = new Array(arrayIndex).fill(null);
|
||||||
|
// Copy over the existing elements (now guaranteed to be dense)
|
||||||
|
for (let i = 0; i < newArray.length; i++) {
|
||||||
|
extendedArray[i] = newArray[i];
|
||||||
|
}
|
||||||
|
newArray = extendedArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restPath.length === 0) {
|
||||||
|
newArray[arrayIndex] = value;
|
||||||
|
} else {
|
||||||
|
newArray[arrayIndex] = updateValueAtPath(
|
||||||
|
newArray[arrayIndex],
|
||||||
|
restPath,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an object at a specific path
|
||||||
|
*/
|
||||||
|
function updateObject(
|
||||||
|
obj: JsonObject,
|
||||||
|
path: string[],
|
||||||
|
value: JsonValue,
|
||||||
|
): JsonObject {
|
||||||
|
const [key, ...restPath] = path;
|
||||||
|
|
||||||
|
// Validate object key
|
||||||
|
if (typeof key !== "string") {
|
||||||
|
console.error(`Invalid object key: ${key}`);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newObj = { ...obj };
|
||||||
|
|
||||||
|
if (restPath.length === 0) {
|
||||||
|
newObj[key] = value;
|
||||||
|
} else {
|
||||||
|
// Ensure key exists
|
||||||
|
if (!(key in newObj)) {
|
||||||
|
newObj[key] = {};
|
||||||
|
}
|
||||||
|
newObj[key] = updateValueAtPath(newObj[key], restPath, value);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a value at a specific path in a nested JSON structure
|
||||||
|
* @param obj The JSON value to traverse
|
||||||
|
* @param path Array of keys/indices representing the path to the value
|
||||||
|
* @param defaultValue Value to return if path doesn't exist
|
||||||
|
* @returns The value at the path, or defaultValue if not found
|
||||||
|
*/
|
||||||
|
export function getValueAtPath(
|
||||||
|
obj: JsonValue,
|
||||||
|
path: string[],
|
||||||
|
defaultValue: JsonValue = null,
|
||||||
|
): JsonValue {
|
||||||
|
if (path.length === 0) return obj;
|
||||||
|
|
||||||
|
const [first, ...rest] = path;
|
||||||
|
|
||||||
|
if (obj === null || obj === undefined) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
const index = Number(first);
|
||||||
|
if (isNaN(index) || index < 0 || index >= obj.length) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return getValueAtPath(obj[index], rest, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof obj === "object" && obj !== null) {
|
||||||
|
if (!(first in obj)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return getValueAtPath((obj as JsonObject)[first], rest, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
65
client/src/utils/oauthUtils.ts
Normal file
65
client/src/utils/oauthUtils.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// The parsed query parameters returned by the Authorization Server
|
||||||
|
// representing either a valid authorization_code or an error
|
||||||
|
// ref: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-12#section-4.1.2
|
||||||
|
type CallbackParams =
|
||||||
|
| {
|
||||||
|
successful: true;
|
||||||
|
// The authorization code is generated by the authorization server.
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
successful: false;
|
||||||
|
// The OAuth 2.1 Error Code.
|
||||||
|
// Usually one of:
|
||||||
|
// ```
|
||||||
|
// invalid_request, unauthorized_client, access_denied, unsupported_response_type,
|
||||||
|
// invalid_scope, server_error, temporarily_unavailable
|
||||||
|
// ```
|
||||||
|
error: string;
|
||||||
|
// Human-readable ASCII text providing additional information, used to assist the
|
||||||
|
// developer in understanding the error that occurred.
|
||||||
|
error_description: string | null;
|
||||||
|
// A URI identifying a human-readable web page with information about the error,
|
||||||
|
// used to provide the client developer with additional information about the error.
|
||||||
|
error_uri: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseOAuthCallbackParams = (location: string): CallbackParams => {
|
||||||
|
const params = new URLSearchParams(location);
|
||||||
|
|
||||||
|
const code = params.get("code");
|
||||||
|
if (code) {
|
||||||
|
return { successful: true, code };
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = params.get("error");
|
||||||
|
const error_description = params.get("error_description");
|
||||||
|
const error_uri = params.get("error_uri");
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return { successful: false, error, error_description, error_uri };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
successful: false,
|
||||||
|
error: "invalid_request",
|
||||||
|
error_description: "Missing code or error in response",
|
||||||
|
error_uri: null,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const generateOAuthErrorDescription = (
|
||||||
|
params: Extract<CallbackParams, { successful: false }>,
|
||||||
|
): string => {
|
||||||
|
const error = params.error;
|
||||||
|
const errorDescription = params.error_description;
|
||||||
|
const errorUri = params.error_uri;
|
||||||
|
|
||||||
|
return [
|
||||||
|
`Error: ${error}.`,
|
||||||
|
errorDescription ? `Details: ${errorDescription}.` : "",
|
||||||
|
errorUri ? `More info: ${errorUri}.` : "",
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join("\n");
|
||||||
|
};
|
||||||
56
client/src/utils/schemaUtils.ts
Normal file
56
client/src/utils/schemaUtils.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import type { JsonValue, JsonSchemaType, JsonObject } from "./jsonUtils";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a default value based on a JSON schema type
|
||||||
|
* @param schema The JSON schema definition
|
||||||
|
* @returns A default value matching the schema type, or null for non-required fields
|
||||||
|
*/
|
||||||
|
export function generateDefaultValue(schema: JsonSchemaType): JsonValue {
|
||||||
|
if ("default" in schema) {
|
||||||
|
return schema.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!schema.required) {
|
||||||
|
if (schema.type === "array") return [];
|
||||||
|
if (schema.type === "object") return {};
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (schema.type) {
|
||||||
|
case "string":
|
||||||
|
return "";
|
||||||
|
case "number":
|
||||||
|
case "integer":
|
||||||
|
return 0;
|
||||||
|
case "boolean":
|
||||||
|
return false;
|
||||||
|
case "array":
|
||||||
|
return [];
|
||||||
|
case "object": {
|
||||||
|
if (!schema.properties) return {};
|
||||||
|
|
||||||
|
const obj: JsonObject = {};
|
||||||
|
Object.entries(schema.properties)
|
||||||
|
.filter(([, prop]) => prop.required)
|
||||||
|
.forEach(([key, prop]) => {
|
||||||
|
const value = generateDefaultValue(prop);
|
||||||
|
obj[key] = value;
|
||||||
|
});
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a field key into a human-readable label
|
||||||
|
* @param key The field key to format
|
||||||
|
* @returns A formatted label string
|
||||||
|
*/
|
||||||
|
export function formatFieldLabel(key: string): string {
|
||||||
|
return key
|
||||||
|
.replace(/([A-Z])/g, " $1") // Insert space before capital letters
|
||||||
|
.replace(/_/g, " ") // Replace underscores with spaces
|
||||||
|
.replace(/^\w/, (c) => c.toUpperCase()); // Capitalize first letter
|
||||||
|
}
|
||||||
@@ -24,7 +24,8 @@
|
|||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true,
|
||||||
|
"types": ["jest", "@testing-library/jest-dom", "node"]
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"]
|
||||||
}
|
}
|
||||||
|
|||||||
10
client/tsconfig.jest.json
Normal file
10
client/tsconfig.jest.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.app.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "node"
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
@@ -5,7 +5,9 @@ import { defineConfig } from "vite";
|
|||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
server: {},
|
server: {
|
||||||
|
host: true,
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"@": path.resolve(__dirname, "./src"),
|
"@": path.resolve(__dirname, "./src"),
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 294 KiB After Width: | Height: | Size: 418 KiB |
7968
package-lock.json
generated
7968
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@modelcontextprotocol/inspector",
|
"name": "@modelcontextprotocol/inspector",
|
||||||
"version": "0.6.0",
|
"version": "0.12.0",
|
||||||
"description": "Model Context Protocol inspector",
|
"description": "Model Context Protocol inspector",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Anthropic, PBC (https://anthropic.com)",
|
"author": "Anthropic, PBC (https://anthropic.com)",
|
||||||
@@ -8,42 +8,56 @@
|
|||||||
"bugs": "https://github.com/modelcontextprotocol/inspector/issues",
|
"bugs": "https://github.com/modelcontextprotocol/inspector/issues",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"mcp-inspector": "./bin/cli.js"
|
"mcp-inspector": "cli/build/cli.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
|
||||||
"client/bin",
|
"client/bin",
|
||||||
"client/dist",
|
"client/dist",
|
||||||
"server/build"
|
"server/build",
|
||||||
|
"cli/build"
|
||||||
],
|
],
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"client",
|
"client",
|
||||||
"server"
|
"server",
|
||||||
|
"cli"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev\"",
|
"build": "npm run build-server && npm run build-client && npm run build-cli",
|
||||||
"dev:windows": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev:windows",
|
|
||||||
"build-server": "cd server && npm run build",
|
"build-server": "cd server && npm run build",
|
||||||
"build-client": "cd client && npm run build",
|
"build-client": "cd client && npm run build",
|
||||||
"build": "npm run build-server && npm run build-client",
|
"build-cli": "cd cli && npm run build",
|
||||||
|
"clean": "rimraf ./node_modules ./client/node_modules ./cli/node_modules ./build ./client/dist ./server/build ./cli/build ./package-lock.json && npm install",
|
||||||
|
"dev": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev\"",
|
||||||
|
"dev:windows": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev:windows\"",
|
||||||
|
"start": "node client/bin/start.js",
|
||||||
"start-server": "cd server && npm run start",
|
"start-server": "cd server && npm run start",
|
||||||
"start-client": "cd client && npm run preview",
|
"start-client": "cd client && npm run preview",
|
||||||
"start": "node ./bin/cli.js",
|
"test": "npm run prettier-check && cd client && npm test",
|
||||||
"prepare": "npm run build",
|
"test-cli": "cd cli && npm run test",
|
||||||
"prettier-fix": "prettier --write .",
|
"prettier-fix": "prettier --write .",
|
||||||
|
"prettier-check": "prettier --check .",
|
||||||
|
"prepare": "npm run build",
|
||||||
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
|
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/inspector-client": "^0.6.0",
|
"@modelcontextprotocol/inspector-cli": "^0.12.0",
|
||||||
"@modelcontextprotocol/inspector-server": "^0.6.0",
|
"@modelcontextprotocol/inspector-client": "^0.12.0",
|
||||||
|
"@modelcontextprotocol/inspector-server": "^0.12.0",
|
||||||
|
"@modelcontextprotocol/sdk": "^1.11.2",
|
||||||
"concurrently": "^9.0.1",
|
"concurrently": "^9.0.1",
|
||||||
|
"open": "^10.1.0",
|
||||||
"shell-quote": "^1.8.2",
|
"shell-quote": "^1.8.2",
|
||||||
"spawn-rx": "^5.1.2",
|
"spawn-rx": "^5.1.2",
|
||||||
"ts-node": "^10.9.2"
|
"ts-node": "^10.9.2",
|
||||||
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^29.5.14",
|
||||||
"@types/node": "^22.7.5",
|
"@types/node": "^22.7.5",
|
||||||
"@types/shell-quote": "^1.7.5",
|
"@types/shell-quote": "^1.7.5",
|
||||||
"prettier": "3.3.3"
|
"jest-fixed-jsdom": "^0.0.9",
|
||||||
|
"prettier": "3.3.3",
|
||||||
|
"rimraf": "^6.0.1",
|
||||||
|
"typescript": "^5.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
sample-config.json
Normal file
19
sample-config.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"everything": {
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["@modelcontextprotocol/server-everything"],
|
||||||
|
"env": {
|
||||||
|
"HELLO": "Hello MCP!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"myserver": {
|
||||||
|
"command": "node",
|
||||||
|
"args": ["build/index.js", "arg1", "arg2"],
|
||||||
|
"env": {
|
||||||
|
"KEY": "value",
|
||||||
|
"KEY2": "value2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@modelcontextprotocol/inspector-server",
|
"name": "@modelcontextprotocol/inspector-server",
|
||||||
"version": "0.6.0",
|
"version": "0.12.0",
|
||||||
"description": "Server-side application for the Model Context Protocol inspector",
|
"description": "Server-side application for the Model Context Protocol inspector",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Anthropic, PBC (https://anthropic.com)",
|
"author": "Anthropic, PBC (https://anthropic.com)",
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
"typescript": "^5.6.2"
|
"typescript": "^5.6.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.6.1",
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.21.0",
|
"express": "^5.1.0",
|
||||||
"ws": "^8.18.0",
|
"ws": "^8.18.0",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,21 @@ import {
|
|||||||
StdioClientTransport,
|
StdioClientTransport,
|
||||||
getDefaultEnvironment,
|
getDefaultEnvironment,
|
||||||
} from "@modelcontextprotocol/sdk/client/stdio.js";
|
} from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||||
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||||
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||||
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
||||||
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { findActualExecutable } from "spawn-rx";
|
import { findActualExecutable } from "spawn-rx";
|
||||||
import mcpProxy from "./mcpProxy.js";
|
import mcpProxy from "./mcpProxy.js";
|
||||||
|
import { randomUUID } from "node:crypto";
|
||||||
|
|
||||||
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
|
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
|
||||||
|
const STREAMABLE_HTTP_HEADERS_PASSTHROUGH = [
|
||||||
|
"authorization",
|
||||||
|
"mcp-session-id",
|
||||||
|
"last-event-id",
|
||||||
|
];
|
||||||
|
|
||||||
const defaultEnvironment = {
|
const defaultEnvironment = {
|
||||||
...getDefaultEnvironment(),
|
...getDefaultEnvironment(),
|
||||||
@@ -34,10 +43,14 @@ const { values } = parseArgs({
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.header("Access-Control-Expose-Headers", "mcp-session-id");
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
let webAppTransports: SSEServerTransport[] = [];
|
const webAppTransports: Map<string, Transport> = new Map<string, Transport>(); // Transports by sessionId
|
||||||
|
|
||||||
const createTransport = async (req: express.Request) => {
|
const createTransport = async (req: express.Request): Promise<Transport> => {
|
||||||
const query = req.query;
|
const query = req.query;
|
||||||
console.log("Query parameters:", query);
|
console.log("Query parameters:", query);
|
||||||
|
|
||||||
@@ -66,7 +79,10 @@ const createTransport = async (req: express.Request) => {
|
|||||||
return transport;
|
return transport;
|
||||||
} else if (transportType === "sse") {
|
} else if (transportType === "sse") {
|
||||||
const url = query.url as string;
|
const url = query.url as string;
|
||||||
const headers: HeadersInit = {};
|
const headers: HeadersInit = {
|
||||||
|
Accept: "text/event-stream",
|
||||||
|
};
|
||||||
|
|
||||||
for (const key of SSE_HEADERS_PASSTHROUGH) {
|
for (const key of SSE_HEADERS_PASSTHROUGH) {
|
||||||
if (req.headers[key] === undefined) {
|
if (req.headers[key] === undefined) {
|
||||||
continue;
|
continue;
|
||||||
@@ -90,18 +106,132 @@ const createTransport = async (req: express.Request) => {
|
|||||||
|
|
||||||
console.log("Connected to SSE transport");
|
console.log("Connected to SSE transport");
|
||||||
return transport;
|
return transport;
|
||||||
|
} else if (transportType === "streamable-http") {
|
||||||
|
const headers: HeadersInit = {
|
||||||
|
Accept: "text/event-stream, application/json",
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const key of STREAMABLE_HTTP_HEADERS_PASSTHROUGH) {
|
||||||
|
if (req.headers[key] === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = req.headers[key];
|
||||||
|
headers[key] = Array.isArray(value) ? value[value.length - 1] : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const transport = new StreamableHTTPClientTransport(
|
||||||
|
new URL(query.url as string),
|
||||||
|
{
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await transport.start();
|
||||||
|
console.log("Connected to Streamable HTTP transport");
|
||||||
|
return transport;
|
||||||
} else {
|
} else {
|
||||||
console.error(`Invalid transport type: ${transportType}`);
|
console.error(`Invalid transport type: ${transportType}`);
|
||||||
throw new Error("Invalid transport type specified");
|
throw new Error("Invalid transport type specified");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
app.get("/sse", async (req, res) => {
|
let backingServerTransport: Transport | undefined;
|
||||||
try {
|
|
||||||
console.log("New SSE connection");
|
|
||||||
|
|
||||||
let backingServerTransport;
|
app.get("/mcp", async (req, res) => {
|
||||||
|
const sessionId = req.headers["mcp-session-id"] as string;
|
||||||
|
console.log(`Received GET message for sessionId ${sessionId}`);
|
||||||
|
try {
|
||||||
|
const transport = webAppTransports.get(
|
||||||
|
sessionId,
|
||||||
|
) as StreamableHTTPServerTransport;
|
||||||
|
if (!transport) {
|
||||||
|
res.status(404).end("Session not found");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
await transport.handleRequest(req, res);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in /mcp route:", error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post("/mcp", async (req, res) => {
|
||||||
|
const sessionId = req.headers["mcp-session-id"] as string | undefined;
|
||||||
|
console.log(`Received POST message for sessionId ${sessionId}`);
|
||||||
|
if (!sessionId) {
|
||||||
try {
|
try {
|
||||||
|
console.log("New streamable-http connection");
|
||||||
|
try {
|
||||||
|
await backingServerTransport?.close();
|
||||||
|
backingServerTransport = await createTransport(req);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof SseError && error.code === 401) {
|
||||||
|
console.error(
|
||||||
|
"Received 401 Unauthorized from MCP server:",
|
||||||
|
error.message,
|
||||||
|
);
|
||||||
|
res.status(401).json(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Connected MCP client to backing server transport");
|
||||||
|
|
||||||
|
const webAppTransport = new StreamableHTTPServerTransport({
|
||||||
|
sessionIdGenerator: randomUUID,
|
||||||
|
onsessioninitialized: (sessionId) => {
|
||||||
|
webAppTransports.set(sessionId, webAppTransport);
|
||||||
|
console.log("Created streamable web app transport " + sessionId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await webAppTransport.start();
|
||||||
|
|
||||||
|
mcpProxy({
|
||||||
|
transportToClient: webAppTransport,
|
||||||
|
transportToServer: backingServerTransport,
|
||||||
|
});
|
||||||
|
|
||||||
|
await (webAppTransport as StreamableHTTPServerTransport).handleRequest(
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
req.body,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in /mcp POST route:", error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const transport = webAppTransports.get(
|
||||||
|
sessionId,
|
||||||
|
) as StreamableHTTPServerTransport;
|
||||||
|
if (!transport) {
|
||||||
|
res.status(404).end("Transport not found for sessionId " + sessionId);
|
||||||
|
} else {
|
||||||
|
await (transport as StreamableHTTPServerTransport).handleRequest(
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in /mcp route:", error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/stdio", async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log("New connection");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await backingServerTransport?.close();
|
||||||
backingServerTransport = await createTransport(req);
|
backingServerTransport = await createTransport(req);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof SseError && error.code === 401) {
|
if (error instanceof SseError && error.code === 401) {
|
||||||
@@ -119,15 +249,14 @@ app.get("/sse", async (req, res) => {
|
|||||||
console.log("Connected MCP client to backing server transport");
|
console.log("Connected MCP client to backing server transport");
|
||||||
|
|
||||||
const webAppTransport = new SSEServerTransport("/message", res);
|
const webAppTransport = new SSEServerTransport("/message", res);
|
||||||
console.log("Created web app transport");
|
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
||||||
|
|
||||||
webAppTransports.push(webAppTransport);
|
|
||||||
console.log("Created web app transport");
|
console.log("Created web app transport");
|
||||||
|
|
||||||
await webAppTransport.start();
|
await webAppTransport.start();
|
||||||
|
(backingServerTransport as StdioClientTransport).stderr!.on(
|
||||||
if (backingServerTransport instanceof StdioClientTransport) {
|
"data",
|
||||||
backingServerTransport.stderr!.on("data", (chunk) => {
|
(chunk) => {
|
||||||
webAppTransport.send({
|
webAppTransport.send({
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
method: "notifications/stderr",
|
method: "notifications/stderr",
|
||||||
@@ -135,9 +264,51 @@ app.get("/sse", async (req, res) => {
|
|||||||
content: chunk.toString(),
|
content: chunk.toString(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
mcpProxy({
|
||||||
|
transportToClient: webAppTransport,
|
||||||
|
transportToServer: backingServerTransport,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Set up MCP proxy");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in /stdio route:", error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/sse", async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log(
|
||||||
|
"New SSE connection. NOTE: The sse transport is deprecated and has been replaced by streamable-http",
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await backingServerTransport?.close();
|
||||||
|
backingServerTransport = await createTransport(req);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof SseError && error.code === 401) {
|
||||||
|
console.error(
|
||||||
|
"Received 401 Unauthorized from MCP server:",
|
||||||
|
error.message,
|
||||||
|
);
|
||||||
|
res.status(401).json(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Connected MCP client to backing server transport");
|
||||||
|
|
||||||
|
const webAppTransport = new SSEServerTransport("/message", res);
|
||||||
|
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
||||||
|
console.log("Created web app transport");
|
||||||
|
|
||||||
|
await webAppTransport.start();
|
||||||
|
|
||||||
mcpProxy({
|
mcpProxy({
|
||||||
transportToClient: webAppTransport,
|
transportToClient: webAppTransport,
|
||||||
transportToServer: backingServerTransport,
|
transportToServer: backingServerTransport,
|
||||||
@@ -155,7 +326,9 @@ app.post("/message", async (req, res) => {
|
|||||||
const sessionId = req.query.sessionId;
|
const sessionId = req.query.sessionId;
|
||||||
console.log(`Received message for sessionId ${sessionId}`);
|
console.log(`Received message for sessionId ${sessionId}`);
|
||||||
|
|
||||||
const transport = webAppTransports.find((t) => t.sessionId === sessionId);
|
const transport = webAppTransports.get(
|
||||||
|
sessionId as string,
|
||||||
|
) as SSEServerTransport;
|
||||||
if (!transport) {
|
if (!transport) {
|
||||||
res.status(404).end("Session not found");
|
res.status(404).end("Session not found");
|
||||||
return;
|
return;
|
||||||
@@ -167,6 +340,12 @@ app.post("/message", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/health", (req, res) => {
|
||||||
|
res.json({
|
||||||
|
status: "ok",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/config", (req, res) => {
|
app.get("/config", (req, res) => {
|
||||||
try {
|
try {
|
||||||
res.json({
|
res.json({
|
||||||
@@ -180,17 +359,17 @@ app.get("/config", (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 6277;
|
||||||
|
|
||||||
try {
|
const server = app.listen(PORT);
|
||||||
const server = app.listen(PORT);
|
server.on("listening", () => {
|
||||||
|
console.log(`⚙️ Proxy server listening on port ${PORT}`);
|
||||||
server.on("listening", () => {
|
});
|
||||||
const addr = server.address();
|
server.on("error", (err) => {
|
||||||
const port = typeof addr === "string" ? addr : addr?.port;
|
if (err.message.includes(`EADDRINUSE`)) {
|
||||||
console.log(`Proxy server listening on port ${port}`);
|
console.error(`❌ Proxy Server PORT IS IN USE at port ${PORT} ❌ `);
|
||||||
});
|
} else {
|
||||||
} catch (error) {
|
console.error(err.message);
|
||||||
console.error("Failed to start server:", error);
|
}
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user