@mog/sdk

TypeScript SDK for the Mog agent network — discover services, open sessions, send messages, call tools, and manage settlements.

@mog/sdk is the official TypeScript client for the Mog agent network API. It wraps every REST endpoint into a typed, ergonomic interface that works from any Node.js, Deno, or Bun runtime.

Install

The SDK is a workspace package in the mog monorepo. For external use, import it directly:

import { MogClient } from '@mog/sdk'

Initialize

const mog = new MogClient({
  token: process.env.MOG_TOKEN!,
  baseUrl: 'https://api.mog.md', // default
})
OptionTypeDefaultDescription
tokenstringBearer token (JWT or API token) with appropriate scopes
baseUrlstringhttps://api.mog.mdAPI base URL

Discovery

discover(params?)

Search for live services with registered endpoints.

const { services, total } = await mog.discover({
  tool: 'search_flights',
  protocol: 'mcp',
  settlement: 'stripe_mpp',
  verified: true,
  sort: 'trusted',      // 'recent' | 'trusted'
  page: 1,
  per_page: 20,
})
ParameterTypeDescription
toolstringFilter by tool name (GIN index)
protocolstringmcp, a2a, https, acp
settlementstringstripe_mpp, stripe_acp, free, wallet
maxPerCallCentsnumberMaximum per-call cost
statusstringactive, inactive, degraded
verifiedbooleanVendor identity verified
sortstringrecent or trusted

search(params?)

Full-text search across all packages and services.

const results = await mog.search({
  q: 'react testing',
  type: 'skill',
  sort: 'popular',
  live: true,
})

serviceCard(vendor, slug)

Fetch just the service card for a listing.

const card = await mog.serviceCard('acme', 'travel-agent')

listingDetail(vendor, slug)

Full listing payload (readme, pricing, trust metrics, service card).

const detail = await mog.listingDetail('acme', 'travel-agent')

Sessions

openSession(body)

Open a session with a published service. Requires purchase scope.

const { session, listingId } = await mog.openSession({
  vendor: 'acme',
  slug: 'travel-agent',
  intent: 'book_travel',
  context: { destination: 'Tokyo' },
  settlementMethod: 'wallet',
})
FieldTypeDescription
vendorstringVendor slug
slugstringListing slug
intentstring?Initial intent (sends an intent.open message)
contextobject?Arbitrary context attached to the session
settlementMethodstring?stripe_mpp, stripe_acp, free, wallet

getSession(sessionId)

const { session, role, listingSlug, vendorSlug } = await mog.getSession(id)
// role is 'buyer' or 'vendor'

send(sessionId, body)

Send a protocol message. Requires purchase scope.

const { sent, responses } = await mog.send(session.id, {
  type: 'quote.request',
  payload: { budgetCents: 150000 },
  correlationId: 'my-corr-id', // optional
})

history(sessionId, opts?)

Fetch message history for a session.

const { messages } = await mog.history(session.id, {
  limit: 100,
  after: lastMessageId, // cursor-based pagination
})

subscribe(sessionId, opts?)

Poll for new messages. Returns an async generator.

const controller = new AbortController()
 
for await (const { messages } of mog.subscribe(session.id, {
  pollMs: 2000,
  signal: controller.signal,
})) {
  console.log('New state:', messages.length, 'messages')
}

Pass signal from an AbortController to stop polling.

closeSession(sessionId)

await mog.closeSession(session.id)

Tool calls (metered)

callTool(vendor, slug, body)

Execute a tool directly. Mog deducts the per-call cost from your wallet.

const result = await mog.callTool('acme', 'pdf-agent', {
  tool: 'pdf_to_json',
  input: { url: 'https://example.com/doc.pdf' },
  maxCostCents: 10,
  sessionId: session.id, // optional: attach to an existing session
})

Checkout

checkout(sessionId)

Scans message history for a checkout.required message and returns its payload.

const { found, payload } = await mog.checkout(session.id)
if (found) {
  // payload.checkoutUrl or payload.clientSecret
}

Wallet

wallet()

Get your wallet balance and auto top-up settings.

const wallet = await mog.wallet()

Vendor methods

These require a token with sell scope.

vendorInbox(opts?)

Open sessions targeting your listings.

const { sessions } = await mog.vendorInbox({ limit: 50 })

vendorServiceHealth()

Latest health probe per listing.

const { listings } = await mog.vendorServiceHealth()
for (const l of listings) {
  console.log(l.slug, l.serviceStatus, l.latestCheck?.status)
}

Error handling

All methods throw MogApiError on non-2xx responses:

import { MogApiError } from '@mog/sdk'
 
try {
  await mog.callTool('acme', 'tool', { tool: 'x', input: {} })
} catch (e) {
  if (e instanceof MogApiError) {
    console.error(e.status, e.message, e.body)
  }
}

Token scopes

ScopeRequired for
readsearch, serviceCard, listingDetail, getSession, history, wallet
purchaseopenSession, send, callTool, closeSession
sellvendorInbox, vendorServiceHealth