@@ -213,8 +213,15 @@ async function credentialRejectionStatus(err: unknown): Promise<number | undefin
213213 * tool names, with the `openapi` provider's meaning. An `include` that is not
214214 * an array of non-empty strings is refused before connecting, and an entry
215215 * naming a tool the server's `tools/list` does not carry is refused after
216- * listing (the connection is closed first); both are configuration faults,
217- * thrown plain. The instance never falls back to exposing every tool.
216+ * listing (the connection is closed first); both are configuration faults.
217+ * The instance never falls back to exposing every tool. The second refusal is
218+ * thrown plain when the handshake carried no instance credential, and as
219+ * {@link ConnectorCredentialRejectedError} when it did: a server may list only
220+ * the tools a credential is allowed to use (GitHub's hides a tool a classic
221+ * token's scopes do not cover), and nothing in a `tools/list` answer tells a
222+ * tool hidden from this credential apart from one the server never had, so the
223+ * refusal names both and takes the credential's path — the instance degraded,
224+ * a stored credential marked `rejected`, the boot not failed.
218225 */
219226export function createMcpProviderFactory ( deps : McpProviderDeps = { } ) : ConnectorProviderFactory {
220227 return async ( ctx ) => {
@@ -300,33 +307,64 @@ export function createMcpProviderFactory(deps: McpProviderDeps = {}): ConnectorP
300307 { cause : err } ,
301308 ) ;
302309 }
310+ // [#27237] The handshake carried the instance's credential only over
311+ // http, and only as a header (an api-key `paramName` is not sent): then
312+ // the server's answer was given to that credential.
313+ const credentialSent = transport . kind === 'http' && sendsInstanceAuth ( ctx . auth ) ;
303314 if ( includeList ) {
304- // An entry naming a tool the server does not list is a configuration
305- // fault, thrown plain — fatal at boot, a skipped entry on reload — after
306- // the connection is released. Ignoring it would bring the instance up
307- // without the tool the author listed (a typo, or a tool the server
308- // renamed or dropped), and the first sign would be a flow failing at
309- // run time.
315+ // An entry naming a tool the server does not list is refused after the
316+ // connection is released. Ignoring it would bring the instance up
317+ // without the tool the author listed (a typo, a tool the server renamed
318+ // or dropped, or one hidden from this credential), and the first sign
319+ // would be a flow failing at run time.
310320 const offered = new Set ( listedTools ) ;
311321 const unknown = [ ...new Set ( includeList ) ] . filter ( ( entry ) => ! offered . has ( entry ) ) ;
312322 if ( unknown . length > 0 ) {
313323 await bundle . close ( ) . catch ( ( ) => { } ) ;
324+ const named = unknown . map ( ( entry ) => `'${ entry } '` ) . join ( ', ' ) ;
314325 // At most 20 of the server's tool names, as the openapi refusal lists.
315326 const sample = [ ...offered ] . slice ( 0 , 20 ) ;
316327 const more = offered . size > sample . length ? `, … ${ offered . size - sample . length } more` : '' ;
328+ const listed =
329+ `the server lists ${ offered . size } tool(s): ` + `${ sample . map ( ( name ) => `'${ name } '` ) . join ( ', ' ) } ${ more } .` ;
330+ if ( credentialSent ) {
331+ // A server may list only the tools the credential it was sent is
332+ // allowed to use: GitHub's hides each tool a classic token's scopes
333+ // do not cover, and its answer carries nothing about what it hid —
334+ // no field in the tools/list result, no response header. So a
335+ // missing tool is the credential's fault or the declaration's, and
336+ // which one cannot be read off the answer. It takes the credential's
337+ // path, like a 401 / 403 above: the instance degraded naming both
338+ // causes, a stored credential marked `rejected` (cleared by setting
339+ // it again, or by a handshake that lists every entry), and never a
340+ // failed boot for a value the administrator supplies and can fix.
341+ // Status 403: the server answered 200 and refused nothing in so many
342+ // words, and 403 is the status a credential short of the scopes a
343+ // resource needs is answered with (RFC 6750 §3.1, insufficient_scope;
344+ // GitHub's server answers a tools/call outside its token's scopes
345+ // that way). The message quotes no HTTP status for that reason.
346+ throw new ConnectorCredentialRejectedError (
347+ `connector-mcp provider: connector '${ ctx . name } ' providerConfig.include names ${ named } , which the MCP ` +
348+ `server does not list for the credential this instance sent. A server may list only the tools a ` +
349+ `credential is allowed to use, and its tools/list answer cannot tell the two causes apart: either the ` +
350+ `credential lacks the scopes or permissions these tools need — fix the credential, then set it ` +
351+ `again — or the declaration names a tool this server does not have — fix providerConfig.include. ` +
352+ `For this credential, ${ listed } ` ,
353+ 403 ,
354+ ) ;
355+ }
356+ // No instance credential reached the server, so its list is not one
357+ // filtered for a credential: a configuration fault, thrown plain —
358+ // fatal at boot, a skipped entry on reload.
317359 throw new Error (
318360 `connector-mcp provider: connector '${ ctx . name } ' providerConfig.include names ` +
319- `${ unknown . map ( ( entry ) => `'${ entry } '` ) . join ( ', ' ) } , which the MCP server does not list. ` +
320- `Each entry must be the name of a tool from the server's tools/list; ` +
321- `the server lists ${ offered . size } tool(s): ` +
322- `${ sample . map ( ( name ) => `'${ name } '` ) . join ( ', ' ) } ${ more } .` ,
361+ `${ named } , which the MCP server does not list. ` +
362+ `Each entry must be the name of a tool from the server's tools/list; ${ listed } ` ,
323363 ) ;
324364 }
325365 }
326- // [#27237] The handshake carried the instance's credential only over
327- // http, and only as a header (an api-key `paramName` is not sent): then
328- // the server's answer proved it.
329- const credentialVerified = transport . kind === 'http' && sendsInstanceAuth ( ctx . auth ) ;
366+ // [#27237] Then the server's answer proved the credential.
367+ const credentialVerified = credentialSent ;
330368 return {
331369 def : bundle . def ,
332370 handlers : bundle . handlers ,
0 commit comments