> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-tool-agent/javascript-typescript.md).

# JavaScript / TypeScript

```js
import { DNotifier } from "@dnotifier-realtime/dnotifier";

async function main() {
  const notifier = new DNotifier({
    appId: process.env.DNOTIFIER_APP_ID,
    secret: process.env.DNOTIFIER_SECRET,
    transport: "http",
    userId: "demo-user",
    permissionEnforcement: "disabled", // use "backend" in production
    onAgentEvent: (event) => console.log("[agent]", event.type, event.toolId),
  });

  await notifier.connect();

  const add = notifier.tools.register({
    name: "math.add",
    description: "Add two numbers and return { sum }",
    inputSchema: {
      type: "object",
      properties: {
        a: { type: "number" },
        b: { type: "number" },
      },
      required: ["a", "b"],
    },
    async execute(input) {
      return { sum: Number(input.a) + Number(input.b) };
    },
  });

  const agent = DNotifier.defineAgent({
    name: "math-assistant",
    instructions:
      "You are a calculator assistant. Use math.add for addition. Reply briefly.",
    provider: "open_ai",
    model: "gpt-4o",
    observability: true,
    tools: [add],
    permissions: { "math.add": ["execute"] },
  });

  const result = await notifier.runAgent(agent, {
    input: "What is 21 + 21?",
    maxToolRounds: 4,
  });

  console.log("output:", result.output);
  console.log("finishReason:", result.finishReason);
  console.log("executionId:", result.executionId);
}

main().catch((err) => {
  console.error(err);
  process.exitCode = 1;
});
```

## Learn more

* [**Tools & MCP — JavaScript**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp/javascript-typescript.md)
* [**MCP Mermaid example**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-mcp-agent/javascript-typescript.md)
