Skip to main content
skill

m365-agents-ts — Claude Code skill for Microsoft 365 agents

Build TypeScript agents for Microsoft 365, Teams, and Copilot Studio with examples for routing, Express hosting, streaming replies, and Copilot Studio integration.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add microsoft/skills --skill m365-agents-ts -a claude-code
Open on GitHub

What m365-agents-ts does

This skill covers the Microsoft 365 Agents SDK for TypeScript and Node.js. Its examples use AgentApplication to route events and startServer to host an agent with Express. They also show invoke handling and messages sent in streaming chunks with streamingResponse.

For Azure OpenAI, the skill demonstrates streaming generated text. Copilot Studio examples start a conversation through CopilotStudioClient and connect the client to WebChat with CopilotStudioWebChat. Azure OpenAI setup uses environment values such as AZURE_API_KEY and AZURE_OPENAI_DEPLOYMENT_NAME; Copilot Studio uses environment and client identifiers, a schema name, and a bearer token. The author advises checking current API signatures in Microsoft documentation and package versions on npm, so verify those details before relying on the samples.

What it helps with

  • route agent messages with AgentApplication
  • host a Microsoft 365 agent through Express
  • send Azure OpenAI output as streaming chunks
  • connect an SDK client to Copilot Studio
  • handle invoke activities and return a response

Example prompts for the agent

  • Create a TypeScript Teams agent with AgentApplication routing and start it with startServer.
  • Add an Azure OpenAI streaming reply for user messages with streamingResponse.
  • Connect CopilotStudioClient and display its replies in WebChat.

How to install m365-agents-ts

1Skills CLI (Vercel)

npx skills add microsoft/skills --skill m365-agents-ts -a claude-code

2Manually: put the files in place

~/.claude/skills/m365-agents-ts/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/m365-agents-ts/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about m365-agents-ts

How do I install m365-agents-ts in Claude Code?

Run npx skills add microsoft/skills --skill m365-agents-ts -a claude-code. The skill file is at ~/.claude/skills/m365-agents-ts/SKILL.md.

What does m365-agents-ts do?

It provides TypeScript examples for the Microsoft 365 Agents SDK, including event routing, Express hosting, streamed replies, and Copilot Studio client integration.

Which environment values do the Azure OpenAI and Copilot Studio examples use?

The Azure OpenAI example uses AZURE_API_KEY, AZURE_RESOURCE_NAME, and AZURE_OPENAI_DEPLOYMENT_NAME. The Copilot Studio example uses environment and client IDs, a schema name, and COPILOT_BEARER_TOKEN.

Source text

SKILL.md · MIT
---
name: m365-agents-ts
description: |
  Microsoft 365 Agents SDK for TypeScript/Node.js. Build multichannel agents for Teams/M365/Copilot Studio with AgentApplication routing, Express hosting, streaming responses, and Copilot Studio client integration. Triggers: "Microsoft 365 Agents SDK", "@microsoft/agents-hosting", "AgentApplication", "startServer", "streamingResponse", "Copilot Studio client", "@microsoft/agents-copilotstudio-client".
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: "@microsoft/agents-hosting, @microsoft/agents-hosting-express, @microsoft/agents-activity, @microsoft/agents-copilotstudio-client"
---

# Microsoft 365 Agents SDK (TypeScript)

Build enterprise agents for Microsoft 365, Teams, and Copilot Studio using the Microsoft 365 Agents SDK with Express hosting, AgentApplication routing, streaming responses, and Copilot Studio client integrations.

## Before implementation

- Use the microsoft-docs MCP to verify the latest API signatures for AgentApplication, startServer, and CopilotStudioClient.
- Confirm package versions on npm before wiring up samples or templates.

## Installation

```bash
npm install @microsoft/agents-hosting @microsoft/agents-hosting-express @microsoft/agents-activity
npm install @microsoft/agents-copilotstudio-client
```

## Environment Variables

```bash
PORT=3978
AZURE_RESOURCE_NAME=<azure-openai-resource>
AZURE_API_KEY=<azure-openai-key>
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o-mini

TENANT_ID=<tenant-id>
CLIENT_ID=<client-id>
CLIENT_SECRET=<client-secret>

COPILOT_ENVIRONMENT_ID=<environment-id>
COPILOT_SCHEMA_NAME=<schema-name>
COPILOT_CLIENT_ID=<copilot-app-client-id>
COPILOT_BEARER_TOKEN=<copilot-jwt>
```

## Core Workflow: Express-hosted AgentApplication

```typescript
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";
import { startServer } from "@microsoft/agents-hosting-express";

const agent = new AgentApplication<TurnState>();

agent.onConversationUpdate("membersAdded", async (context: TurnContext) => {
  await context.sendActivity("Welcome to the agent.");
});

agent.onMessage("hello", async (context: TurnContext) => {
  await context.sendActivity(`Echo: ${context.activity.text}`);
});

startServer(agent);
```

## Streaming responses with Azure OpenAI

```typescript
import { azure } from "@ai-sdk/azure";
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";
import { startServer } from "@microsoft/agents-hosting-express";
import { streamText } from "ai";

const agent = new AgentApplication<TurnState>();

agent.onMessage("poem", async (context: TurnContext) => {
  context.streamingResponse.setFeedbackLoop(true);
  context.streamingResponse.setGeneratedByAILabel(true);
  context.streamingResponse.setSensitivityLabel({
    type: "https://schema.org/Message",
    "@type": "CreativeWork",
    name: "Internal",
  });

  await context.streamingResponse.queueInformativeUpdate("starting a poem...");

  const { fullStream } = streamText({
    model: azure(process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "gpt-4o-mini"),
    system: "You are a creative assistant.",
    prompt: "Write a poem about Apollo.",
  });

  try {
    for await (const part of fullStream) {
      if (part.type === "text-delta" && part.text.length > 0) {
        await context.streamingResponse.queueTextChunk(part.text);
      }
      if (part.type === "error") {
        throw new Error(`Streaming error: ${part.error}`);
      }
    }
  } finally {
    await context.streamingResponse.endStream();
  }
});

startServer(agent);
```

## Invoke activity handling

```typescript
import { Activity, ActivityTypes } from "@microsoft/agents-activity";
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";

const agent = new AgentApplication<TurnState>();

agent.onActivity("invoke", async (context: TurnContext) => {
  const invokeResponse = Activity.fromObject({
    type: ActivityTypes.InvokeResponse,
    value: { status: 200 },
  });

  await context.sendActivity(invokeResponse);
  await context.sendActivity("Thanks for submitting your feedback.");
});
```

## Copilot Studio client (Direct to Engine)

```typescript
import { CopilotStudioClient } from "@microsoft/agents-copilotstudio-client";

const settings = {
  environmentId: process.env.COPILOT_ENVIRONMENT_ID!,
  schemaName: process.env.COPILOT_SCHEMA_NAME!,
  clientId: process.env.COPILOT_CLIENT_ID!,
};

const tokenProvider = async (): Promise<string> => {
  return process.env.COPILOT_BEARER_TOKEN!;
};

const client = new CopilotStudioClient(settings, tokenProvider);

const conversation = await client.startConversationAsync();
const reply = await client.askQuestionAsync("Hello!", conversation.id);
console.log(reply);
```

## Copilot Studio WebChat integration

```typescript
import { CopilotStudioWebChat } from "@microsoft/agents-copilotstudio-client";

const directLine = CopilotStudioWebChat.createConnection(client, {
  showTyping: true,
});

window.WebChat.renderWebChat(
  {
    directLine,
  },
  document.getElementById("webchat")!,
);
```

## Best Practices

1. Use AgentApplication for routing and keep handlers focused on one responsibility.
2. Prefer streamingResponse for long-running completions and call endStream in finally blocks.
3. Keep secrets out of source code; load tokens from environment variables or secure stores.
4. Reuse CopilotStudioClient instances and cache tokens in your token provider.
5. Validate invoke payloads before logging or persisting feedback.

## Reference Links

| Resource                               | URL                                                                                                                 |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| Microsoft 365 Agents SDK               | https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/                                                         |
| JavaScript SDK overview                | https://learn.microsoft.com/en-us/javascript/api/overview/agents-overview?view=agents-sdk-js-latest                 |
| @microsoft/agents-hosting-express      | https://learn.microsoft.com/en-us/javascript/api/%40microsoft/agents-hosting-express?view=agents-sdk-js-latest      |
| @microsoft/agents-copilotstudio-client | https://learn.microsoft.com/en-us/javascript/api/%40microsoft/agents-copilotstudio-client?view=agents-sdk-js-latest |
| Integrate with Copilot Studio          | https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/integrate-with-mcs                                       |
| GitHub samples                         | https://github.com/microsoft/Agents/tree/main/samples/nodejs                                                        |

© Microsoft · MIT · microsoft/skills

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set143

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor