// Read-only discovery with the application's configured MCP credential. import {createInterface} from 'node:readline'; import {createRequire} from 'node:module'; import {writeFile} from 'node:fs/promises'; if(process.stdin.isTTY){console.error('Refusing TTY credential input. Provide the token through a controlled pipe from a trusted credential source; do not type it into this terminal or put it in command arguments.');process.exit(1);} const require=createRequire(new URL('../packages/harness/package.json',import.meta.url)); const {Client}=require('@modelcontextprotocol/sdk/client/index.js'); const {StreamableHTTPClientTransport}=require('@modelcontextprotocol/sdk/client/streamableHttp.js'); const reader=createInterface({input:process.stdin}); console.log('Reading MCP token from controlled non-TTY stdin; read-only schema and identity discovery.'); const token=(await reader[Symbol.asyncIterator]().next()).value?.trim(); reader.close(); if(!token)process.exit(1); const names=new Set(['video_h3_submit','video_job_status','creative_upload_from_url','creative_import_status','swads_whoami','video_h3_workers']); const client=new Client({name:'agent-studio-i2v-contract-probe',version:'1.0.0'}); try { await client.connect(new StreamableHTTPClientTransport(new URL('https://ads.mincode.cn/mcp'),{requestInit:{redirect:'error',headers:{Authorization:`Bearer ${token}`}}}),{timeout:20000}); let cursor;const schemas=[]; do {const page=await client.listTools(cursor?{cursor}:{});schemas.push(...page.tools.filter(tool=>names.has(tool.name)));cursor=page.nextCursor;}while(cursor); const identity=await client.callTool({name:'swads_whoami',arguments:{}}); const body=identity.structuredContent??JSON.parse(identity.content.find(item=>item.type==='text').text); const account=body.access?.current_account; const report={checkedAt:new Date().toISOString(),toolSchemas:schemas,identityShape:{rootKeys:Object.keys(body),accountPath:'access.current_account',tenant_id:account?.tenant_id,platform:account?.platform,hasGeneratePermission:account?.permissions?.includes('creatives.generate'),hasUploadPermission:account?.permissions?.includes('creatives.upload')},note:'Read-only; no upload/generation or account mutation. Do not bind upload to external account. Output schemas may be absent; do not guess response fields.'}; await writeFile('.superpowers/sdd/2026-09-15-image-to-video-web/live-contracts.json',JSON.stringify(report,null,2).replaceAll(token,'[REDACTED]'),{mode:0o600}); console.log(JSON.stringify({found:schemas.map(tool=>({name:tool.name,hasOutputSchema:!!tool.outputSchema,inputRequired:tool.inputSchema.required})),identity:report.identityShape})); }catch(error){console.error(JSON.stringify({error:String(error.message).replaceAll(token,'[REDACTED]').slice(0,500)}));process.exitCode=1;}finally{await client.close();}