TypeScript (MCP SDK)
公式 TypeScript MCP SDK (2.3.0 以降) と StreamableHTTPClientTransport。
- API キー (Bearer)
パッケージをインストール
npm install @modelcontextprotocol/client@^2.3.0
2.3.0 以降を使用してください (リダイレクト時に headers が再送される問題のセキュリティ修正)。
クライアントのコード
推奨import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
const client = new Client({ name: 'my-app', version: '1.0.0' });
await client.connect(new StreamableHTTPClientTransport(new URL('https://aicharged.io/api/v1/mcp'), {
requestInit: { headers: { Authorization: `Bearer ${process.env.AICHARGED_API_KEY}` } },
}));
const { tools } = await client.listTools();
console.log(tools.map((tool) => tool.name));
console.log(await client.callTool({ name: 'list_runs', arguments: {} }));