From 7130a5ad162213cf98663f0b7be8c0580b531ede Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Mon, 17 Nov 2025 17:40:39 -0800 Subject: [PATCH 1/7] adding authorization back to add tool servers call --- nodejs/claude/sample-agent/src/client.ts | 3 ++- nodejs/langchain/quickstart-before/src/client.ts | 2 +- nodejs/langchain/sample-agent/src/client.ts | 3 ++- nodejs/openai/sample-agent/src/client.ts | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/nodejs/claude/sample-agent/src/client.ts b/nodejs/claude/sample-agent/src/client.ts index 466486ea..bf90a38d 100644 --- a/nodejs/claude/sample-agent/src/client.ts +++ b/nodejs/claude/sample-agent/src/client.ts @@ -42,9 +42,10 @@ export async function getClient(authorization: Authorization, authHandlerName: s try { await toolService.addToolServersToAgent( agentConfig, + authorization, authHandlerName, turnContext, - process.env.MCP_AUTH_TOKEN || "", + process.env.BEARER_TOKEN || "", ); } catch (error) { console.warn('Failed to register MCP tool servers:', error); diff --git a/nodejs/langchain/quickstart-before/src/client.ts b/nodejs/langchain/quickstart-before/src/client.ts index 0655014d..146390c9 100644 --- a/nodejs/langchain/quickstart-before/src/client.ts +++ b/nodejs/langchain/quickstart-before/src/client.ts @@ -33,7 +33,7 @@ export async function getClient(): Promise { const agent = createAgent({ model: model, tools: [], - name: 'My Custom Agent', + name: 'MyCustomAgent', }); return new LangChainClient(agent); diff --git a/nodejs/langchain/sample-agent/src/client.ts b/nodejs/langchain/sample-agent/src/client.ts index fb15d058..6e153e36 100644 --- a/nodejs/langchain/sample-agent/src/client.ts +++ b/nodejs/langchain/sample-agent/src/client.ts @@ -30,7 +30,7 @@ sdk.start(); const toolService = new McpToolRegistrationService(); -const agentName = "LangChain A365 Agent"; +const agentName = "LangChainA365Agent"; const agent = createAgent({ model: new ChatOpenAI({ temperature: 0 }), name: agentName, @@ -59,6 +59,7 @@ export async function getClient(authorization: Authorization, authHandlerName: s try { agentWithMcpTools = await toolService.addToolServersToAgent( agent, + authorization, authHandlerName, turnContext, process.env.BEARER_TOKEN || "", diff --git a/nodejs/openai/sample-agent/src/client.ts b/nodejs/openai/sample-agent/src/client.ts index 470f5dfe..261c6d5f 100644 --- a/nodejs/openai/sample-agent/src/client.ts +++ b/nodejs/openai/sample-agent/src/client.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { Agent, run } from '@openai/agents'; -import { TurnContext } from '@microsoft/agents-hosting'; +import { Authorization, TurnContext } from '@microsoft/agents-hosting'; import { McpToolRegistrationService } from '@microsoft/agents-a365-tooling-extensions-openai'; @@ -31,7 +31,7 @@ sdk.start(); const toolService = new McpToolRegistrationService(); -export async function getClient(authorization: any, authHandlerName: string, turnContext: TurnContext): Promise { +export async function getClient(authorization: Authorization, authHandlerName: string, turnContext: TurnContext): Promise { const agent = new Agent({ // You can customize the agent configuration here if needed name: 'OpenAI Agent', @@ -42,7 +42,7 @@ export async function getClient(authorization: any, authHandlerName: string, tur authorization, authHandlerName, turnContext, - process.env.MCP_AUTH_TOKEN || "", + process.env.BEARER_TOKEN || "", ); } catch (error) { console.warn('Failed to register MCP tool servers:', error); From 6525101c371238555f995f14e103cb36787bb2e0 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Mon, 17 Nov 2025 17:44:41 -0800 Subject: [PATCH 2/7] remove auth config for agentsplayground connection --- nodejs/claude/sample-agent/src/index.ts | 4 ++-- nodejs/langchain/sample-agent/src/index.ts | 4 ++-- nodejs/openai/sample-agent/src/index.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nodejs/claude/sample-agent/src/index.ts b/nodejs/claude/sample-agent/src/index.ts index 2b362914..de76eed5 100644 --- a/nodejs/claude/sample-agent/src/index.ts +++ b/nodejs/claude/sample-agent/src/index.ts @@ -6,11 +6,11 @@ import { configDotenv } from 'dotenv'; configDotenv(); -import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting'; +import { AuthConfiguration, authorizeJWT, CloudAdapter, Request } from '@microsoft/agents-hosting'; import express, { Response } from 'express' import { agentApplication } from './agent'; -const authConfig: AuthConfiguration = loadAuthConfigFromEnv(); +const authConfig: AuthConfiguration = {}; const server = express() server.use(express.json()) diff --git a/nodejs/langchain/sample-agent/src/index.ts b/nodejs/langchain/sample-agent/src/index.ts index e3db4218..85bd9eff 100644 --- a/nodejs/langchain/sample-agent/src/index.ts +++ b/nodejs/langchain/sample-agent/src/index.ts @@ -3,11 +3,11 @@ import { configDotenv } from 'dotenv'; configDotenv(); -import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting'; +import { AuthConfiguration, authorizeJWT, CloudAdapter, Request } from '@microsoft/agents-hosting'; import express, { Response } from 'express' import { agentApplication } from './agent'; -const authConfig: AuthConfiguration = loadAuthConfigFromEnv(); +const authConfig: AuthConfiguration = {}; const server = express() server.use(express.json()) diff --git a/nodejs/openai/sample-agent/src/index.ts b/nodejs/openai/sample-agent/src/index.ts index c67ac375..f00da9f7 100644 --- a/nodejs/openai/sample-agent/src/index.ts +++ b/nodejs/openai/sample-agent/src/index.ts @@ -6,11 +6,11 @@ import { configDotenv } from 'dotenv'; configDotenv(); -import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting'; +import { AuthConfiguration, authorizeJWT, CloudAdapter, Request } from '@microsoft/agents-hosting'; import express, { Response } from 'express' import { agentApplication } from './agent'; -const authConfig: AuthConfiguration = loadAuthConfigFromEnv(); +const authConfig: AuthConfiguration = {}; const server = express() server.use(express.json()) From 87b195e478fa7512f362060645ef1791bad60719 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Mon, 17 Nov 2025 18:27:26 -0800 Subject: [PATCH 3/7] fixing claude sample --- nodejs/claude/sample-agent/src/client.ts | 37 +++++++----------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/nodejs/claude/sample-agent/src/client.ts b/nodejs/claude/sample-agent/src/client.ts index bf90a38d..31b285da 100644 --- a/nodejs/claude/sample-agent/src/client.ts +++ b/nodejs/claude/sample-agent/src/client.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { query } from '@anthropic-ai/claude-agent-sdk'; +import { Options, query } from '@anthropic-ai/claude-agent-sdk'; import { TurnContext, Authorization } from '@microsoft/agents-hosting'; import { McpToolRegistrationService } from '@microsoft/agents-a365-tooling-extensions-claude'; @@ -32,11 +32,13 @@ sdk.start(); const toolService = new McpToolRegistrationService(); // Claude agent configuration -const agentConfig = { +const agentConfig: Options = { maxTurns: 10, - mcpServers: {} as Record + env: { ...process.env} }; +delete agentConfig.env!.NODE_OPTIONS; // Remove NODE_OPTIONS to prevent issues +delete agentConfig.env!.VSCODE_INSPECTOR_OPTIONS; // Remove VSCODE_INSPECTOR_OPTIONS to prevent issues export async function getClient(authorization: Authorization, authHandlerName: string, turnContext: TurnContext): Promise { try { @@ -59,9 +61,9 @@ export async function getClient(authorization: Authorization, authHandlerName: s * It maintains agentConfig as an instance field and exposes an invokeAgent method. */ class ClaudeClient implements Client { - config: typeof agentConfig; + config: Options; - constructor(config: typeof agentConfig) { + constructor(config: Options) { this.config = config; } @@ -76,10 +78,7 @@ class ClaudeClient implements Client { try { const result = query({ prompt, - options: { - maxTurns: this.config.maxTurns, - mcpServers: this.config.mcpServers - } + options: this.config, }); let finalResponse = ''; @@ -88,24 +87,10 @@ class ClaudeClient implements Client { for await (const message of result) { if (message.type === 'result') { // Get the final output from the result message - const resultContent = message.content; + const resultContent = (message as any).result; if (resultContent && resultContent.length > 0) { - for (const content of resultContent) { - if (content.type === 'text') { - finalResponse += content.text; - } - } - } - } else if (message.type === 'assistant') { - // Get assistant message content - const assistantContent = message.content; - if (assistantContent && assistantContent.length > 0) { - for (const content of assistantContent) { - if (content.type === 'text') { - finalResponse += content.text; - } + finalResponse += resultContent; } - } } } @@ -120,7 +105,7 @@ class ClaudeClient implements Client { async invokeAgentWithScope(prompt: string) { const inferenceDetails: InferenceDetails = { operationName: InferenceOperationType.CHAT, - model: this.config.model, + model: this.config.model || "", }; const agentDetails: AgentDetails = { From 9d40ca65e49815667d84cab61f2daf02de069723 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Mon, 17 Nov 2025 18:46:06 -0800 Subject: [PATCH 4/7] fix indentation --- nodejs/claude/sample-agent/src/client.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nodejs/claude/sample-agent/src/client.ts b/nodejs/claude/sample-agent/src/client.ts index 31b285da..5ccb9905 100644 --- a/nodejs/claude/sample-agent/src/client.ts +++ b/nodejs/claude/sample-agent/src/client.ts @@ -88,9 +88,9 @@ class ClaudeClient implements Client { if (message.type === 'result') { // Get the final output from the result message const resultContent = (message as any).result; - if (resultContent && resultContent.length > 0) { - finalResponse += resultContent; - } + if (resultContent) { + finalResponse += resultContent; + } } } From c8fe9ff3ebd837129fc865fad7ad209a86d3cba9 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Tue, 18 Nov 2025 14:40:23 -0800 Subject: [PATCH 5/7] Add useJwtMiddleware if agent is hosted publicly --- nodejs/claude/sample-agent/src/index.ts | 15 +++++++++------ nodejs/langchain/sample-agent/src/index.ts | 13 ++++++++----- nodejs/openai/sample-agent/src/index.ts | 13 ++++++++----- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/nodejs/claude/sample-agent/src/index.ts b/nodejs/claude/sample-agent/src/index.ts index de76eed5..24523ffe 100644 --- a/nodejs/claude/sample-agent/src/index.ts +++ b/nodejs/claude/sample-agent/src/index.ts @@ -6,11 +6,13 @@ 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 = {}; +// Use request validation middleware only if hosting publicly +const useJwtMiddleware = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; +const authConfig: AuthConfiguration = useJwtMiddleware ? loadAuthConfigFromEnv() : {}; const server = express() server.use(express.json()) @@ -23,13 +25,14 @@ server.post('/api/messages', (req: Request, res: Response) => { }) }) -const port = process.env.PORT || 3978 -server.listen(port, async () => { - console.log(`\nServer listening to port ${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) +const port = Number(process.env.PORT) || 3978 +const host = useJwtMiddleware ? '0.0.0.0' : '127.0.0.1'; +server.listen(port, host, async () => { + console.log(`\nServer listening on ${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) }).on('error', async (err) => { console.error(err); process.exit(1); }).on('close', async () => { console.log('Server closed'); process.exit(0); -}); +}); \ No newline at end of file diff --git a/nodejs/langchain/sample-agent/src/index.ts b/nodejs/langchain/sample-agent/src/index.ts index 85bd9eff..e4e9ea3a 100644 --- a/nodejs/langchain/sample-agent/src/index.ts +++ b/nodejs/langchain/sample-agent/src/index.ts @@ -3,11 +3,13 @@ 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 = {}; +// Use request validation middleware only if hosting publicly +const useJwtMiddleware = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; +const authConfig: AuthConfiguration = useJwtMiddleware ? loadAuthConfigFromEnv() : {}; const server = express() server.use(express.json()) @@ -20,9 +22,10 @@ server.post('/api/messages', (req: Request, res: Response) => { }) }) -const port = process.env.PORT || 3978 -server.listen(port, async () => { - console.log(`\nServer listening to port ${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) +const port = Number(process.env.PORT) || 3978 +const host = useJwtMiddleware ? '0.0.0.0' : '127.0.0.1'; +server.listen(port, host, async () => { + console.log(`\nServer listening on ${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) }).on('error', async (err) => { console.error(err); process.exit(1); diff --git a/nodejs/openai/sample-agent/src/index.ts b/nodejs/openai/sample-agent/src/index.ts index f00da9f7..24523ffe 100644 --- a/nodejs/openai/sample-agent/src/index.ts +++ b/nodejs/openai/sample-agent/src/index.ts @@ -6,11 +6,13 @@ 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 = {}; +// Use request validation middleware only if hosting publicly +const useJwtMiddleware = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; +const authConfig: AuthConfiguration = useJwtMiddleware ? loadAuthConfigFromEnv() : {}; const server = express() server.use(express.json()) @@ -23,9 +25,10 @@ server.post('/api/messages', (req: Request, res: Response) => { }) }) -const port = process.env.PORT || 3978 -server.listen(port, async () => { - console.log(`\nServer listening to port ${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) +const port = Number(process.env.PORT) || 3978 +const host = useJwtMiddleware ? '0.0.0.0' : '127.0.0.1'; +server.listen(port, host, async () => { + console.log(`\nServer listening on ${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) }).on('error', async (err) => { console.error(err); process.exit(1); From 63638c33c7f21f6188617959992ddf892f0ff2bd Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Fri, 21 Nov 2025 15:51:31 -0800 Subject: [PATCH 6/7] change useJwt to isProd --- nodejs/langchain/sample-agent/ToolingManifest.json | 3 --- nodejs/langchain/sample-agent/src/index.ts | 14 +++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/nodejs/langchain/sample-agent/ToolingManifest.json b/nodejs/langchain/sample-agent/ToolingManifest.json index 72f11922..d0e627f0 100644 --- a/nodejs/langchain/sample-agent/ToolingManifest.json +++ b/nodejs/langchain/sample-agent/ToolingManifest.json @@ -2,9 +2,6 @@ "mcpServers": [ { "mcpServerName": "mcp_MailTools" - }, - { - "mcpServerName": "mcp_NLWeb" } ] } \ No newline at end of file diff --git a/nodejs/langchain/sample-agent/src/index.ts b/nodejs/langchain/sample-agent/src/index.ts index e4e9ea3a..c7a968ab 100644 --- a/nodejs/langchain/sample-agent/src/index.ts +++ b/nodejs/langchain/sample-agent/src/index.ts @@ -4,14 +4,14 @@ import { configDotenv } from 'dotenv'; configDotenv(); import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting'; -import express, { Response } from 'express' +import express, { Response, Express } from 'express' import { agentApplication } from './agent'; // Use request validation middleware only if hosting publicly -const useJwtMiddleware = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; -const authConfig: AuthConfiguration = useJwtMiddleware ? loadAuthConfigFromEnv() : {}; +const isProduction = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; +const authConfig: AuthConfiguration = isProduction ? loadAuthConfigFromEnv() : {}; -const server = express() +const server: Express = express() server.use(express.json()) server.use(authorizeJWT(authConfig)) @@ -22,10 +22,10 @@ server.post('/api/messages', (req: Request, res: Response) => { }) }) -const port = Number(process.env.PORT) || 3978 -const host = useJwtMiddleware ? '0.0.0.0' : '127.0.0.1'; +const port = 3978 +const host = isProduction ? '0.0.0.0' : '127.0.0.1'; server.listen(port, host, async () => { - console.log(`\nServer listening on ${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) + console.log(`\nServer listening on http://${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) }).on('error', async (err) => { console.error(err); process.exit(1); From a12057e8b117b715626c58fca633ca5700dccbbc Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Wed, 26 Nov 2025 11:23:53 -0800 Subject: [PATCH 7/7] Namechange isProduction boolean --- nodejs/claude/sample-agent/src/index.ts | 6 +++--- nodejs/openai/sample-agent/src/index.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nodejs/claude/sample-agent/src/index.ts b/nodejs/claude/sample-agent/src/index.ts index 24523ffe..3af228d7 100644 --- a/nodejs/claude/sample-agent/src/index.ts +++ b/nodejs/claude/sample-agent/src/index.ts @@ -11,8 +11,8 @@ import express, { Response } from 'express' import { agentApplication } from './agent'; // Use request validation middleware only if hosting publicly -const useJwtMiddleware = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; -const authConfig: AuthConfiguration = useJwtMiddleware ? loadAuthConfigFromEnv() : {}; +const isProduction = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; +const authConfig: AuthConfiguration = isProduction ? loadAuthConfigFromEnv() : {}; const server = express() server.use(express.json()) @@ -26,7 +26,7 @@ server.post('/api/messages', (req: Request, res: Response) => { }) const port = Number(process.env.PORT) || 3978 -const host = useJwtMiddleware ? '0.0.0.0' : '127.0.0.1'; +const host = isProduction ? '0.0.0.0' : '127.0.0.1'; server.listen(port, host, async () => { console.log(`\nServer listening on ${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) }).on('error', async (err) => { diff --git a/nodejs/openai/sample-agent/src/index.ts b/nodejs/openai/sample-agent/src/index.ts index 24523ffe..3af228d7 100644 --- a/nodejs/openai/sample-agent/src/index.ts +++ b/nodejs/openai/sample-agent/src/index.ts @@ -11,8 +11,8 @@ import express, { Response } from 'express' import { agentApplication } from './agent'; // Use request validation middleware only if hosting publicly -const useJwtMiddleware = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; -const authConfig: AuthConfiguration = useJwtMiddleware ? loadAuthConfigFromEnv() : {}; +const isProduction = Boolean(process.env.WEBSITE_SITE_NAME) || process.env.NODE_ENV === 'production'; +const authConfig: AuthConfiguration = isProduction ? loadAuthConfigFromEnv() : {}; const server = express() server.use(express.json()) @@ -26,7 +26,7 @@ server.post('/api/messages', (req: Request, res: Response) => { }) const port = Number(process.env.PORT) || 3978 -const host = useJwtMiddleware ? '0.0.0.0' : '127.0.0.1'; +const host = isProduction ? '0.0.0.0' : '127.0.0.1'; server.listen(port, host, async () => { console.log(`\nServer listening on ${host}:${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`) }).on('error', async (err) => {