MCP 应用(OAuth)
适用于 Claude、ChatGPT 及其他支持 MCP 的应用。填写服务器地址——应用会自动打开 Mytrade 登录页,您在那里授权访问。无需保存密钥。
- MCP 服务器地址
https://mytrade.kz/api/demand-network/v1/mcp
- Claude
- 在 Claude 设置中添加自定义连接器,地址为 https://mytrade.kz/api/demand-network/v1/mcp,然后登录 Mytrade 并授权访问。
- ChatGPT
- 在 ChatGPT 设置中创建连接器,地址为 https://mytrade.kz/api/demand-network/v1/mcp,认证方式选择 OAuth,然后登录 Mytrade 并授权访问。
- MCP SDK
- 将 Streamable HTTP 传输连接到 https://mytrade.kz/api/demand-network/v1/mcp:客户端会自动发现 OAuth 地址、完成注册并打开登录窗口。
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
// authProvider: your OAuthClientProvider (redirect URL, PKCE verifier and token storage).
const transport = new StreamableHTTPClientTransport(new URL('https://mytrade.kz/api/demand-network/v1/mcp'), { authProvider });
const client = new Client({ name: 'my-agent', version: '1.0.0' });
await client.connect(transport); // 401 -> discovery -> registration -> browser consent
console.log(await client.listTools());
自有服务器(密钥)
如果助手运行在您的服务器上,请用工作密钥(DN-HMAC-SHA256)为每个请求签名。TypeScript 示例可直接运行:它会验证密钥,并演示如何在买家同意后准备需求。
密钥的机密值只显示一次。请将其保存在密钥存储或环境变量中,切勿写入代码或网址。
// Mytrade BIT Agent Network: signed calls from your own server (Node.js 18+).
// BIT_KEY_ID and BIT_KEY_SECRET come from your secret store, never from the code.
import { createHash, createHmac, randomBytes } from 'node:crypto';
const API = 'https://mytrade.kz/api/demand-network/v1';
const KEY_ID = process.env.BIT_KEY_ID!;
const SECRET = process.env.BIT_KEY_SECRET!;
async function signed(method: string, path: string, payload?: unknown) {
const body = payload === undefined ? '' : JSON.stringify(payload);
const ts = String(Math.floor(Date.now() / 1000));
const nonce = randomBytes(16).toString('hex');
const bodyHash = createHash('sha256').update(body).digest('hex');
const signature = createHmac('sha256', SECRET)
.update([method, path, ts, nonce, bodyHash].join('\n')).digest('hex');
const response = await fetch(new URL(path, API).href, {
method,
body: body || undefined,
headers: {
Authorization: `DN-HMAC-SHA256 ${KEY_ID}`,
'X-DN-Timestamp': ts, 'X-DN-Nonce': nonce, 'X-DN-Signature': signature,
'Content-Type': 'application/json', 'Idempotency-Key': randomBytes(16).toString('hex'),
},
});
return response.json();
}
// 1. Check the key. The first successful call marks the platform as Connected.
console.log(await signed('GET', '/api/demand-network/v1/me'));
// 2. Only after the user agreed: prepare a Want request. The user reviews and sends it on Mytrade.
// prepareWant({ query: 'chairs', quantity: '20', quantity_unit: 'pcs', country_code: 'KZ', language: 'en' })
export const prepareWant = (want: Record<string, string>) => signed('POST', '/api/demand-network/v1/want-invites', want);
下载 example.ts