dns_discovery
Check if a domain has an AgentStamp DNS TXT record to verify agent discovery. Verifies _agentstamp.domain.com TXT records and cross-checks with the registry.
Instructions
Check if a domain has an AgentStamp DNS TXT record for agent discovery. Verifies _agentstamp.domain.com TXT record and cross-checks with the registry. Free.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | Domain to check (e.g., shippingrates.org) |
Implementation Reference
- src/mcp-server.js:611-669 (handler)The `dns_discovery` tool handler is defined and implemented directly in `src/mcp-server.js`. It performs DNS TXT record lookups for agent discovery and validates against the local database.
server.tool( 'dns_discovery', 'Check if a domain has an AgentStamp DNS TXT record for agent discovery. Verifies _agentstamp.domain.com TXT record and cross-checks with the registry. Free.', { domain: z.string().describe('Domain to check (e.g., shippingrates.org)'), }, async ({ domain }) => { try { const dns = require('dns'); const cleanDomain = domain.toLowerCase().replace(/[^a-z0-9.\-]/g, ''); if (!cleanDomain || cleanDomain.length > 253) { return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'Invalid domain' }, null, 2) }] }; } const txtHost = `_agentstamp.${cleanDomain}`; const records = await new Promise((resolve, reject) => { dns.resolveTxt(txtHost, (err, recs) => { if (err) reject(err); else resolve(recs); }); }).catch(() => null); if (!records) { return { content: [{ type: 'text', text: JSON.stringify({ found: false, domain: cleanDomain, txt_host: txtHost, message: 'No _agentstamp TXT record found', setup: `Add TXT record: ${txtHost} "v=as1; wallet=YOUR_WALLET; stamp=TIER"`, }, null, 2) }] }; } const flat = records.map(r => r.join('')).filter(r => r.startsWith('v=as1')); if (flat.length === 0) { return { content: [{ type: 'text', text: JSON.stringify({ found: true, valid: false, message: 'TXT exists but not AgentStamp format' }, null, 2) }] }; } const fields = Object.fromEntries( flat[0].split(';').map(s => s.trim().split('=', 2)).filter(([k]) => k) ); const { getDb } = require('./database'); const db = getDb(); // Validate wallet from untrusted DNS source const { validateWalletAddress } = require('./utils/validators'); const walletCheck = validateWalletAddress(fields.wallet || ''); if (!walletCheck.valid) { return { content: [{ type: 'text', text: JSON.stringify({ found: true, valid: false, error: 'TXT record contains invalid wallet address' }, null, 2) }] }; } const agent = db.prepare("SELECT id, name FROM agents WHERE wallet_address = ? AND status = 'active' LIMIT 1").get(fields.wallet); return { content: [{ type: 'text', text: JSON.stringify({ found: true, valid: !!agent, domain: cleanDomain, wallet: fields.wallet, claimed_stamp: fields.stamp, agent: agent ? { id: agent.id, name: agent.name } : null, trust_check_url: `https://agentstamp.org/api/v1/trust/check/${fields.wallet}`, }, null, 2) }] }; } catch (err) { return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'DNS lookup failed' }, null, 2) }] }; }