Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nodejs/claude/sample-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "claude-agents-sdk",
"version": "1.0.0",
"main": "index.js",
"type": "commonjs",
"scripts": {
"start": "node dist/index.js",
"dev": "nodemon --watch src/*.ts --exec ts-node src/index.ts",
Expand Down
3 changes: 2 additions & 1 deletion nodejs/claude/sample-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AgentNotificationActivity } from '@microsoft/agents-a365-notifications'
import { Client, getClient } from './client';

export class MyAgent extends AgentApplication<TurnState> {
static authHandlerName: string = 'agentic';

constructor() {
super({
Expand Down Expand Up @@ -45,7 +46,7 @@ export class MyAgent extends AgentApplication<TurnState> {
}

try {
const client: Client = await getClient(this.authorization, turnContext);
const client: Client = await getClient(this.authorization, MyAgent.authHandlerName, turnContext);
const response = await client.invokeAgentWithScope(userMessage);
await turnContext.sendActivity(response);
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions nodejs/claude/sample-agent/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ const agentConfig = {
};


export async function getClient(authorization: Authorization, turnContext: TurnContext): Promise<Client> {
export async function getClient(authorization: Authorization, authHandlerName: string, turnContext: TurnContext): Promise<Client> {
try {
await toolService.addToolServersToAgent(
agentConfig,
process.env.AGENTIC_USER_ID || '',
authorization,
authHandlerName,
turnContext,
process.env.MCP_AUTH_TOKEN || "",
);
Expand Down
4 changes: 2 additions & 2 deletions nodejs/claude/sample-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { configDotenv } from 'dotenv';

configDotenv();

import { AuthConfiguration, authorizeJWT, CloudAdapter, Request } from '@microsoft/agents-hosting';
import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting';
import express, { Response } from 'express'
import { agentApplication } from './agent';

const authConfig: AuthConfiguration = {};
const authConfig: AuthConfiguration = loadAuthConfigFromEnv();

const server = express()
server.use(express.json())
Expand Down
1 change: 1 addition & 0 deletions nodejs/langchain/sample-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2025.11.6",
"description": "Sample agent integrating LangChain Agents with Microsoft 365 Agents SDK and Microsoft Agent 365 SDK",
"main": "src/index.ts",
"type": "commonjs",
"scripts": {
"preinstall": "node preinstall-local-packages.js",
"start": "node dist/index.js",
Expand Down
4 changes: 3 additions & 1 deletion nodejs/langchain/sample-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { AgentNotificationActivity } from '@microsoft/agents-a365-notifications'
import { Client, getClient } from './client';

export class A365Agent extends AgentApplication<TurnState> {
static authHandlerName: string = 'agentic';

constructor() {
super({
startTypingTimer: true,
Expand Down Expand Up @@ -41,7 +43,7 @@ export class A365Agent extends AgentApplication<TurnState> {
}

try {
const client: Client = await getClient(this.authorization, turnContext);
const client: Client = await getClient(this.authorization, A365Agent.authHandlerName, turnContext);
const response = await client.invokeAgentWithScope(userMessage);
await turnContext.sendActivity(response);
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions nodejs/langchain/sample-agent/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ const agent = createAgent({
* const response = await client.invokeAgent("Send an email to john@example.com");
* ```
*/
export async function getClient(authorization: Authorization, turnContext: TurnContext): Promise<Client> {
export async function getClient(authorization: Authorization, authHandlerName: string, turnContext: TurnContext): Promise<Client> {
// Get Mcp Tools
let agentWithMcpTools = undefined;
try {
agentWithMcpTools = await toolService.addToolServersToAgent(
agent,
'',
authorization,
authHandlerName,
turnContext,
process.env.BEARER_TOKEN || "",
);
Expand Down
4 changes: 2 additions & 2 deletions nodejs/langchain/sample-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { configDotenv } from 'dotenv';

configDotenv();

import { AuthConfiguration, authorizeJWT, CloudAdapter, Request } from '@microsoft/agents-hosting';
import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting';
import express, { Response } from 'express'
import { agentApplication } from './agent';

const authConfig: AuthConfiguration = {};
const authConfig: AuthConfiguration = loadAuthConfigFromEnv();

const server = express()
server.use(express.json())
Expand Down
1 change: 1 addition & 0 deletions nodejs/n8n/sample-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "sample agent to integrate with n8n",
"main": "src/index.ts",
"type": "commonjs",
"scripts": {
"start": "node ./dist/index.js",
"dev": "tsx watch ./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion nodejs/n8n/sample-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const agentApplication = new AgentApplication<ApplicationTurnState>({
fileDownloaders: [downloader]
});

const n8nAgent = new N8nAgent(undefined);
const n8nAgent = new N8nAgent();

agentApplication.onActivity(ActivityTypes.Message, async (context: TurnContext, state: ApplicationTurnState) => {
// Increment count state
Expand Down
11 changes: 7 additions & 4 deletions nodejs/n8n/sample-agent/src/mcpToolRegistrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ export class McpToolRegistrationService {
private configService: McpToolServerConfigurationService = new McpToolServerConfigurationService();

async getMcpServers(
agentUserId: string,
authorization: Authorization,
authHandlerName: string,
turnContext: TurnContext,
authToken: string
): Promise<McpServer[]> {
const authorization = turnContext.turnState.get('authorization');
if (!authToken) {
Comment thread
abdulanu0 marked this conversation as resolved.
authToken = await AgenticAuthenticationService.GetAgenticUserToken(authorization, turnContext);
authToken = await AgenticAuthenticationService.GetAgenticUserToken(authorization, authHandlerName, turnContext);
}

// Get the agentic user ID from the authorization configuration
const agenticUserId = authorization?.[authHandlerName]?.agenticUserId || authHandlerName;
Comment thread
abdulanu0 marked this conversation as resolved.
Outdated

const mcpServers: McpServer[] = [];
const servers = await this.configService.listToolServers(agentUserId, authToken);
const servers = await this.configService.listToolServers(agenticUserId, authToken);

for (const server of servers) {
// Compose headers if values are available
Expand Down
8 changes: 3 additions & 5 deletions nodejs/n8n/sample-agent/src/n8nAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { N8nClient } from './n8nClient';
import { McpToolRegistrationService, McpServer } from './mcpToolRegistrationService';

export class N8nAgent {
static authHandlerName: string = 'agentic';
isApplicationInstalled: boolean = false;
termsAndConditionsAccepted: boolean = false;
toolService: McpToolRegistrationService = new McpToolRegistrationService();
authorization: any;

constructor(authorization: any) {
this.authorization = authorization;
constructor() {
}

/**
Expand Down Expand Up @@ -181,8 +180,7 @@ export class N8nAgent {
const mcpServers: McpServer[] = [];
try {
mcpServers.push(...await this.toolService.getMcpServers(
process.env.AGENTIC_USER_ID || '',
this.authorization,
N8nAgent.authHandlerName,
turnContext,
process.env.MCP_AUTH_TOKEN || ""
));
Expand Down
Loading