使用 @youdotcom-oss/teams-anthropic 将 Anthropic Claude 模型(Opus、Sonnet、Haiku)添加到 Microsoft Teams.ai 应用程序中。可选集成 You.com MCP 服务器以进行网页搜索和内容提取。
与 Anthropic Claude 一起建立 Teams.ai Apps. 使用@yodotcom-oss/teams-harmanic 将 Claude 模是一项面向实际任务的技能,主要用于optionally election You.com MCP ser。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;
涉及批量任务时,还应保存进度,避免中断后重复操作。该技能适合用于一次性任务,也可以接入自动化工作流,与其他技能或上层代理配合完成更完整的业务链路;在组合使用时,应明确每一步的输入输出关系,并避免不同步骤之间出现参数冲突。
使用 @youdotcom-oss/teams-anthropic 将 Claude 模型(Opus、Sonnet、Haiku)集成到 Microsoft Teams.ai 应用中。可选集成 You.com MCP 服务以实现网页搜索与内容提取功能。
路径 A:基础配置(推荐用于快速上手)
路径 B:集成 You.com MCP(适用于需要网页搜索能力的场景)
请确认:您的 Teams 应用是否需要网页搜索与内容提取功能?
在 Teams.ai 应用中使用 Anthropic Claude 模型,无需引入额外依赖。
npm install @youdotcom-oss/teams-anthropic @anthropic-ai/sdk @microsoft/teams.ai
从 console.anthropic.com 获取您的 API 密钥
# 添加至 .env 文件
ANTHROPIC_API_KEY=your-anthropic-api-key
适用于 NEW 应用:
import { App } from '@microsoft/teams.apps';
import { AnthropicChatModel, AnthropicModel } from '@youdotcom-oss/teams-anthropic';
if (!process.env.ANTHROPIC_API_KEY) {
throw new Error('ANTHROPIC_API_KEY environment variable is required');
}
const model = new AnthropicChatModel({
model: AnthropicModel.CLAUDE_SONNET_4_5,
apiKey: process.env.ANTHROPIC_API_KEY,
requestOptions: {
max_tokens: 2048,
temperature: 0.7,
},
});
const app = new App();
app.on('message', async ({ send, activity }) => {
await send({ type: 'typing' });
const response = await model.send(
{ role: 'user', content: activity.text }
);
if (response.content) {
await send(response.content);
}
});
app.start().catch(console.error);
适用于 EXISTING 应用:
在您已有的 import 语句中添加:
import { AnthropicChatModel, AnthropicModel } from '@youdotcom-oss/teams-anthropic';
替换您当前使用的模型实例:
const model = new AnthropicChatModel({
model: AnthropicModel.CLAUDE_SONNET_4_5,
apiKey: process.env.ANTHROPIC_API_KEY,
});
// 最强能力 —— 推荐用于复杂任务
AnthropicModel.CLAUDE_OPUS_4_5
// 智能性与响应速度均衡(推荐)
AnthropicModel.CLAUDE_SONNET_4_5
// 快速高效
AnthropicModel.CLAUDE_HAIKU_3_5
npm start
在 Teams 中发送一条消息,验证 Claude 是否正常响应。
为基于 Claude 的 Teams 应用添加网页搜索与内容提取能力。
npm install @youdotcom-oss/teams-anthropic @anthropic-ai/sdk @microsoft/teams.ai @microsoft/teams.mcpclient
# 添加至 .env 文件
ANTHROPIC_API_KEY=your-anthropic-api-key
YDC_API_KEY=your-you-com-api-key
适用于 NEW 应用:
import { App } from '@microsoft/teams.apps';
import { ChatPrompt } from '@microsoft/teams.ai';
import { ConsoleLogger } from '@microsoft/teams.common';
import { McpClientPlugin } from '@microsoft/teams.mcpclient';
import {
AnthropicChatModel,
AnthropicModel,
getYouMcpConfig,
} from '@youdotcom-oss/teams-anthropic';
// 校验环境变量
if (!process.env.ANTHROPIC_API_KEY) {
throw new Error('ANTHROPIC_API_KEY environment variable is required');
}
if (!process.env.YDC_API_KEY) {
throw new Error('YDC_API_KEY environment variable is required');
}
// 配置日志记录器
const logger = new ConsoleLogger('mcp-client', { level: 'info' });
// 创建集成 MCP 的 prompt
const prompt = new ChatPrompt(
{
instructions: 'You are a helpful assistant with access to web search and content extraction. Use these tools to provide accurate, up-to-date information.',
model: new AnthropicChatModel({
model: AnthropicModel.CLAUDE_SONNET_4_5,
apiKey: process.env.ANTHROPIC_API_KEY,
requestOptions: {
max_tokens: 2048,
},
}),
},
[new McpClientPlugin({ logger })],
).usePlugin('mcpClient', getYouMcpConfig());
const app = new App();
app.on('message', async ({ send, activity }) => {
await send({ type: 'typing' });
const result = await prompt.send(activity.text);
if (result.content) {
await send(result.content);
}
});
app.start().catch(console.error);
适用于已集成 Claude 的 EXISTING 应用:
若您已完成路径 A 的配置,请按以下步骤添加 MCP 集成:
安装 MCP 依赖:
npm install @microsoft/teams.mcpclient
添加导入语句:
import { ChatPrompt } from '@microsoft/teams.ai';
import { ConsoleLogger } from '@microsoft/teams.common';
import { McpClientPlugin } from '@microsoft/teams.mcpclient';
import { getYouMcpConfig } from '@youdotcom-oss/teams-anthropic';
校验 You.com API 密钥:
if (!process.env.YDC_API_KEY) {
throw new Error('YDC_API_KEY environment variable is required');
}
用 ChatPrompt 替换原有模型配置:
const logger = new ConsoleLogger('mcp-client', { level: 'info' });
const prompt = new ChatPrompt(
{
instructions: 'Your instructions here',
model: new AnthropicChatModel({
model: AnthropicModel.CLAUDE_SONNET_4_5,
apiKey: process.env.ANTHROPIC_API_KEY,
}),
},
[new McpClientPlugin({ logger })],
).usePlugin('mcpClient', getYouMcpConfig());
使用 prompt.send() 替代 model.send():
const result = await prompt.send(activity.text);
npm start
向 Claude 提出一个需借助网页搜索才能回答的问题,例如:
| 模型 | 枚举值 | 适用场景 |
|---|---|---|
| Claude Opus 4.5 | AnthropicModel.CLAUDE_OPUS_4_5 |
复杂任务,最高能力 |
| Claude Sonnet 4.5 | AnthropicModel.CLAUDE_SONNET_4_5 |
智能性与响应速度均衡(推荐) |
| Claude Haiku 3.5 | AnthropicModel.CLAUDE_HAIKU_3_5 |
快速响应,高效率 |
| Claude Sonnet 3.5 | AnthropicModel.CLAUDE_SONNET_3_5 |
上一代模型,稳定性高 |
const response = await model.send(
{ role: 'user', content: 'Write a short story' },
{
onChunk: async (delta) => {
// 每个 token 到达时立即流式输出
process.stdout.write(delta);
},
}
);
const response = await model.send(
{ role: 'user', content: 'What is the weather in San Francisco?' },
{
functions: {
get_weather: {
description: 'Get the current weather for a location',
parameters: {
location: { type: 'string', description: 'City name' },
},
handler: async (args: { location: string }) => {
// 此处填入您的 API 调用逻辑
return { temperature: 72, conditions: 'Sunny' };
},
},
},
}
);
import { LocalMemory } from '@microsoft/teams.ai';
const memory = new LocalMemory();
// 首条消息
await model.send(
{ role: 'user', content: 'My name is Alice' },
{ messages: memory }
);
// 第二条消息 —— Claude 将记住上下文
const response = await model.send(
{ role: 'user', content: 'What is my name?' },
{ messages: memory }
);
// 返回结果:"Your name is Alice."
@youdotcom-oss/teams-anthropicANTHROPIC_API_KEYAnthropicChatModel 配置模型@microsoft/teams.mcpclientYDC_API_KEYgetYouMcpConfig() 配置 ChatPrompt“Cannot find module @youdotcom-oss/teams-anthropic”
npm install @youdotcom-oss/teams-anthropic @anthropic-ai/sdk
“ANTHROPIC_API_KEY environment variable is required”
ANTHROPIC_API_KEY=your-key-here“Invalid model identifier”
AnthropicModel.CLAUDE_SONNET_4_5'claude-sonnet-4-5-20250929'“YDC_API_KEY environment variable is required”
YDC_API_KEY=your-key-here“MCP connection fails”
“Cannot find module @microsoft/teams.mcpclient”
npm install @microsoft/teams.mcpclient
自动配置 You.com MCP 连接:
https://api.you.com/mcpYDC_API_KEY 生成的 Bearer Token// 方式一:使用环境变量(推荐)
getYouMcpConfig()
// 方式二:自定义 API 密钥
getYouMcpConfig({ apiKey: 'your-custom-key' })