Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

## Unreleased

## 0.28.1

### Fixes

- **A `server/discover` refused with 401 or 403 is no longer read as a login wall.**
Dreamwork 1.10.0 answers `server/discover` with a 401 and serves a 74-tool guest menu
over the 2025 handshake; `snapshot` stopped at "wants credentials". toolmenu now tries
the 2025 `initialize` first and reports credentials only when that is refused too.
`--protocol modern` still uses the 2026-07-28 handshake alone.
- **`auth login` says so when the server never asked for a login**, and stores nothing,
instead of "Logged in" with no token behind it.

### Repository

- **The plugin runs toolmenu 0.28.0** (was 0.27.0): its tools' `apps/resource` findings
no longer call a read that failed for credentials or the network the server's.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
- uses: actions/setup-node@v7
with: { node-version: 22 }
- run: npm ci && npm run build
- uses: niksa90/toolmenu@v0.28.0
- uses: niksa90/toolmenu@v0.28.1
with:
command: node dist/server.js
baseline: menu.json # your committed snapshot
Expand Down
2 changes: 1 addition & 1 deletion docs/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ permissions:
security-events: write # to upload SARIF
steps:
# … checkout, build, as above
- uses: niksa90/toolmenu@v0.28.0
- uses: niksa90/toolmenu@v0.28.1
with:
command: node dist/server.js
sarif: toolmenu-sarif
Expand Down
10 changes: 5 additions & 5 deletions docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- run: npm ci && npm run build
- run: npm start & # the PR's version, in the background (it keeps running for later steps)
- run: npx --yes wait-on --timeout 60000 tcp:localhost:3000 # fail after 60 s instead of hanging
- uses: niksa90/toolmenu@v0.28.0
- uses: niksa90/toolmenu@v0.28.1
with:
url: http://localhost:3000/mcp
headers: "x-mcp-api-key: ${{ env.MCP_API_KEY }}"
Expand All @@ -111,7 +111,7 @@ tools behind an unlock: a renamed, removed or no-longer-read-only one never reac
the report. Let the scenario build the baseline instead:

```yaml
- uses: niksa90/toolmenu@v0.28.0
- uses: niksa90/toolmenu@v0.28.1
with:
command: node dist/server.js
scenario: scenario.yml # unlocks each toolset, lists after each
Expand Down Expand Up @@ -174,7 +174,7 @@ check even though nothing was checked. The PR comment and a notice say so, and t
`skipped` output is `'true'`. To make a skip fail instead, gate on it:

```yaml
- uses: niksa90/toolmenu@v0.28.0
- uses: niksa90/toolmenu@v0.28.1
id: toolmenu
with:
url: https://mcp.example.com/mcp # a remote server that needs a key
Expand Down Expand Up @@ -204,7 +204,7 @@ that adds findings at or above `fail-on` fails even when nothing breaks. Snapsho
session findings count either way.

```yaml
- uses: niksa90/toolmenu@v0.28.0
- uses: niksa90/toolmenu@v0.28.1
with:
command: node dist/server.js
gate: review
Expand Down Expand Up @@ -247,7 +247,7 @@ version in a comment, and let Dependabot's `github-actions` updates keep the pin
current:

```yaml
- uses: niksa90/toolmenu@<commit SHA of the release> # v0.28.0
- uses: niksa90/toolmenu@<commit SHA of the release> # v0.28.1
```

`toolmenu init` writes the actions it sets up (checkout, setup-node, …) pinned this
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toolmenu",
"version": "0.28.0",
"version": "0.28.1",
"mcpName": "io.github.niksa90/toolmenu",
"description": "Test your MCP server the way agents and clients meet it: the menu, the calls, the results, the sign-in, and every release after. No LLM involved.",
"author": "Nikša Perović (https://niksa.me)",
Expand Down
4 changes: 2 additions & 2 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"mimeType": "image/svg+xml"
}
],
"version": "0.28.0",
"version": "0.28.1",
"packages": [
{
"registryType": "npm",
"registryBaseUrl": "https://registry.npmjs.org",
"identifier": "toolmenu",
"version": "0.28.0",
"version": "0.28.1",
"runtimeHint": "npx",
"transport": {
"type": "stdio"
Expand Down
11 changes: 9 additions & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ function printForPaste(port: number): (url: URL) => void {
* exchange the code (PKCE, issuer check: the SDK's), then connect once with the new
* token to confirm it works. Returns the server's name and tool count.
*/
export async function login(serverUrl: string, options: LoginOptions = {}): Promise<{ name?: string; tools: number }> {
export async function login(serverUrl: string, options: LoginOptions = {}): Promise<{ name?: string; tools: number; authenticated: boolean }> {
const port = options.port ?? DEFAULT_PORT;
// What was stored before this login (a registered client, a rejected token) is kept.
const stored = hasLogin(serverUrl);
const callback = await listenForCallback(port, options.timeoutMs ?? 300_000);
try {
const provider = new StoredOAuthProvider(serverUrl, {
Expand Down Expand Up @@ -398,7 +400,12 @@ export async function login(serverUrl: string, options: LoginOptions = {}): Prom
await transport.finishAuth(params);
await endSession(client, transport);
}
return await check(serverUrl);
// A server that never asked for credentials leaves nothing to log in with: the
// file the discovery step wrote holds no token, so drop it rather than list a login.
// A file from before this login stays: it may hold a registered client.
const authenticated = Boolean(await provider.tokens());
if (!authenticated && !stored) await logout(serverUrl);
return { ...(await check(serverUrl)), authenticated };
} catch (error) {
// GitHub's hosted server, for one: no dynamic registration, so toolmenu can't
// register itself. Say what works instead.
Expand Down
8 changes: 7 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,13 @@ async function authCommand(args: string[], values: { port?: string; scope?: stri
if (port !== undefined && !(Number.isInteger(port) && port > 0 && port < 65536)) throw new UsageError('--port must be a port number');
if (values['client-secret'] && !values['client-id']) throw new UsageError('--client-secret goes with --client-id');
const result = await login(url, { port, scope: values.scope, clientId: values['client-id'], clientSecret: values['client-secret'], noBrowser: values['no-browser'] });
process.stdout.write(`Logged in to ${plain(result.name ?? url)} (${url}): it lists ${result.tools} tool${result.tools === 1 ? '' : 's'} with this login.\nsnapshot and session use it from now on (--no-auth to skip it); stored in ${authDir()}.\n`);
const count = `${result.tools} tool${result.tools === 1 ? '' : 's'}`;
process.stdout.write(
result.authenticated
? `Logged in to ${plain(result.name ?? url)} (${url}): it lists ${count} with this login.\nsnapshot and session use it from now on (--no-auth to skip it); stored in ${authDir()}.\n`
: `No login made for ${plain(result.name ?? url)} (${url}): it listed ${count} without asking for credentials, so nothing was stored.\n` +
`→ Next: A server like this usually asks for a login only when a tool is called. If session reports session/untested, pass a token with --header "Authorization: Bearer <token>".\n`,
);
return 0;
}

Expand Down
22 changes: 22 additions & 0 deletions src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,28 @@ export async function connect(target: Target, options: ConnectOptions = {}): Pro
await stderrEnded(stdioStderr, trace.exit ? STDERR_AFTER_EXIT_MS : 1000);
}
await endSession(client, transport);
// A 401 or 403 to server/discover alone isn't the server's last word: Dreamwork
// 1.10.0 answers it with a 401 while its 2025 handshake serves a guest menu. With
// the handshake left to toolmenu, and no stored login (a refused one is reported as
// such), try the 2025 one before calling it a login wall. A server that wants
// credentials refuses that too; one that fails it any other way (a 2026-only
// server) is reported with the first refusal, which is the one that explains it.
const discover = trace.http.get('server/discover')?.status;
if (
target.kind === 'http' &&
!oauth &&
(!target.protocol || target.protocol === 'auto') &&
(discover === 401 || discover === 403) &&
!trace.sent.some((s) => s.method === 'initialize')
) {
const refused = explain(error, trace, context);
try {
return await connect({ ...target, protocol: 'legacy' }, options);
} catch (retry) {
const status = (retry as { status?: unknown }).status;
throw status === 401 || status === 403 ? retry : refused;
}
}
throw explain(error, trace, context);
}
const wire = new WireLog();
Expand Down
21 changes: 21 additions & 0 deletions test/auth.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,24 @@ test('auth login: a login address that is not https is never opened or printed',
}
}
});

test('auth login: a server that never asks for credentials is not a login, and nothing is stored', async () => {
const dir = isolated();
const { start: open } = await import('./fixtures/http-server.mjs');
const server = await open();
try {
const result = await login(server.url, { port: port() });
assert.equal(result.authenticated, false);
assert.equal(result.tools > 0, true);
assert.equal(hasLogin(server.url), false);
assert.deepEqual(readdirSync(dir).filter((f) => f.endsWith('.json')), []);
const cli = await run(['auth', 'login', server.url, '--port', String(port())]);
assert.equal(cli.code, 0);
assert.match(cli.stdout, /^No login made for .*without asking for credentials, so nothing was stored\./);
assert.doesNotMatch(cli.stdout, /Logged in/);
assert.match(cli.stdout, /→ Next: .*--header "Authorization: Bearer <token>"\.\n$/);
assert.match((await run(['auth', 'list'])).stdout, /No logins stored/);
} finally {
await server.close();
}
});
50 changes: 50 additions & 0 deletions test/cli.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,53 @@ test('a toolmenu.config.json that isn\'t JSON: where it broke, never what it hol
assert.match(r.stderr, /toolmenu\.config\.json isn't valid JSON/);
assert.doesNotMatch(r.stderr, /S3CRET|registry/);
});

test('cli: a server/discover refused with 401 falls back to the 2025 handshake, and a server that refuses both wants credentials', async () => {
// Dreamwork 1.10.0: server/discover gets a 401, initialize serves a guest menu.
const guest = await startRaw({ discoverStatus: 401 });
try {
const r = await run(['snapshot', guest.url, '--processes', '1']);
assert.equal(r.code, 0, r.stderr);
assert.match(r.stdout, /protocol 2025-11-25 · 3 tools/);
assert.doesNotMatch(r.stderr, /wants credentials/);
assert.equal(guest.discovers(), 1);
} finally {
await guest.close();
}
const forbidden = await startRaw({ discoverStatus: 403 });
try {
const r = await run(['snapshot', forbidden.url, '--processes', '1']);
assert.equal(r.code, 0, r.stderr);
assert.match(r.stdout, /protocol 2025-11-25 · 3 tools/);
} finally {
await forbidden.close();
}
// Asked for its own handshake, toolmenu doesn't swap it.
const pinned = await startRaw({ discoverStatus: 401 });
try {
const r = await run(['snapshot', pinned.url, '--processes', '1', '--protocol', 'modern']);
assert.notEqual(r.code, 0);
} finally {
await pinned.close();
}
// A 2026-only server behind a login: the 2025 retry fails for another reason, so the
// 401 that explains it is what's reported.
const modernOnly = await startRaw({ discoverStatus: 401, initializeStatus: 400 });
try {
const r = await run(['snapshot', modernOnly.url, '--processes', '1']);
assert.equal(r.code, 2, r.stdout);
assert.match(r.stderr, /wants credentials: server\/discover got HTTP 401 Unauthorized\./);
} finally {
await modernOnly.close();
}
const walled = await startRaw({ requireAuth: true });
try {
const r = await run(['snapshot', walled.url, '--processes', '1']);
assert.equal(r.code, 2, r.stdout);
assert.match(r.stderr, /wants credentials: initialize got HTTP 401 Unauthorized\./);
assert.match(r.stderr, /→ Next: If the server uses OAuth, log in once with: toolmenu auth login /);
assert.equal(walled.discovers(), 1);
} finally {
await walled.close();
}
});
19 changes: 18 additions & 1 deletion test/fixtures/raw-http-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { createServer } from 'node:http';
import { randomUUID } from 'node:crypto';

// card: a Server Card served at /mcp/server-card (with cardType as its Content-Type).
export async function start({ scope = 'local', vary = false, onePerClient = false, card, cardType = 'application/mcp-server-card+json' } = {}) {
// discoverStatus: answer server/discover with this HTTP status (401: like Dreamwork, whose
// 2025 handshake serves a guest menu while server/discover asks for credentials).
// requireAuth: every POST without an Authorization header gets a 401.
// initializeStatus: answer initialize with this HTTP status (400: a server on 2026-07-28 only).
export async function start({ scope = 'local', vary = false, onePerClient = false, card, cardType = 'application/mcp-server-card+json', discoverStatus, requireAuth = false, initializeStatus } = {}) {
const sessions = new Map();
const byClient = new Map();
const global = { unlocked: false };
Expand Down Expand Up @@ -45,6 +49,19 @@ export async function start({ scope = 'local', vary = false, onePerClient = fals
for await (const c of req) chunks.push(c);
const msg = JSON.parse(Buffer.concat(chunks).toString());
if (msg.method === 'server/discover') discovers++;
const unauthorized = { 'content-type': 'application/json', 'www-authenticate': 'Bearer realm="fixture"' };
if (requireAuth && !req.headers.authorization) {
res.writeHead(401, unauthorized).end(JSON.stringify({ error: 'unauthorized' }));
return;
}
if (msg.method === 'initialize' && initializeStatus) {
res.writeHead(initializeStatus, { 'content-type': 'application/json' }).end(JSON.stringify({ error: 'unsupported protocol version' }));
return;
}
if (msg.method === 'server/discover' && discoverStatus) {
res.writeHead(discoverStatus, unauthorized).end(JSON.stringify({ error: 'unauthorized' }));
return;
}
const headers = { 'content-type': 'application/json' };
let session = sessions.get(req.headers['mcp-session-id']);
if (msg.method === 'initialize') {
Expand Down
Loading