|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { Client } from '@modelcontextprotocol/sdk/client/index.js'; |
| 4 | +import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; |
| 5 | +import { withOAuthRetry } from './helpers/withOAuthRetry'; |
| 6 | +import { runAsCli } from './helpers/cliRunner'; |
| 7 | +import { logger } from './helpers/logger'; |
| 8 | + |
| 9 | +/** |
| 10 | + * Non-compliant client that doesn't use CIMD (Client ID Metadata Document). |
| 11 | + * |
| 12 | + * This client intentionally omits the clientMetadataUrl parameter when the server |
| 13 | + * advertises client_id_metadata_document_supported=true. A compliant client should |
| 14 | + * use CIMD when the server supports it, but this client falls back to DCR (Dynamic |
| 15 | + * Client Registration) instead. |
| 16 | + * |
| 17 | + * Used to test that conformance checks detect clients that don't properly |
| 18 | + * implement CIMD support. |
| 19 | + */ |
| 20 | +export async function runClient(serverUrl: string): Promise<void> { |
| 21 | + const client = new Client( |
| 22 | + { name: 'test-auth-client-no-cimd', version: '1.0.0' }, |
| 23 | + { capabilities: {} } |
| 24 | + ); |
| 25 | + |
| 26 | + // Non-compliant: omitting clientMetadataUrl causes fallback to DCR |
| 27 | + // A compliant client would pass a clientMetadataUrl here when the server |
| 28 | + // advertises client_id_metadata_document_supported=true |
| 29 | + const oauthFetch = withOAuthRetry( |
| 30 | + 'test-auth-client-no-cimd', |
| 31 | + new URL(serverUrl) |
| 32 | + )(fetch); |
| 33 | + |
| 34 | + const transport = new StreamableHTTPClientTransport(new URL(serverUrl), { |
| 35 | + fetch: oauthFetch |
| 36 | + }); |
| 37 | + |
| 38 | + await client.connect(transport); |
| 39 | + logger.debug('Connected to MCP server (without CIMD)'); |
| 40 | + |
| 41 | + await client.listTools(); |
| 42 | + logger.debug('Successfully listed tools'); |
| 43 | + |
| 44 | + await client.callTool({ name: 'test-tool', arguments: {} }); |
| 45 | + logger.debug('Successfully called tool'); |
| 46 | + |
| 47 | + await transport.close(); |
| 48 | + logger.debug('Connection closed successfully'); |
| 49 | +} |
| 50 | + |
| 51 | +runAsCli(runClient, import.meta.url, 'auth-test-no-cimd <server-url>'); |
0 commit comments