Skip to content

Conversation

@rbrighenti
Copy link
Contributor

This PR fixes the Agentic User Token retrieval in mcpToolRegistrationService.ts by getting the Authorization entity from the Agent Application instead of the TurnContext.

Beyond that I've taken the opportunity to simplify the sample agent, update dependencies and tidy up the environment template file

@rbrighenti rbrighenti requested a review from a team as a code owner November 20, 2025 15:57
Copilot AI review requested due to automatic review settings November 20, 2025 15:57
Copilot finished reviewing on behalf of rbrighenti November 20, 2025 16:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug in the agentic user token retrieval mechanism for the n8n sample agent. The main issue was that the authorization object was incorrectly being retrieved from TurnContext.turnState instead of from the AgentApplication instance. The PR also modernizes the sample by removing unnecessary state management, updating dependencies, and refactoring to use the AgentApplicationBuilder pattern.

Key changes:

  • Fixed authorization retrieval to use agentApplication.authorization instead of turnContext.turnState.get('authorization')
  • Removed application installation and terms acceptance state management logic
  • Refactored agent initialization to use AgentApplicationBuilder with fluent configuration pattern

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
nodejs/n8n/sample-agent/src/mcpToolRegistrationService.ts Fixed agentic user token retrieval by getting authorization from AgentApplication; removed unused Authorization import
nodejs/n8n/sample-agent/src/n8nAgent.ts Removed installation and terms acceptance state management; added AgentApplication parameter to constructor
nodejs/n8n/sample-agent/src/agent.ts Refactored to use AgentApplicationBuilder pattern; removed custom ConversationState interface and message counter logic
nodejs/n8n/sample-agent/src/index.ts Moved adapter retrieval to request handler; improved debug logging output
nodejs/n8n/sample-agent/package.json Updated dependencies to latest versions (@modelcontextprotocol/sdk, dotenv, tsx, etc.)
nodejs/n8n/sample-agent/.env.template Reorganized and added observability configuration; updated auth scope from Agentic to Microsoft Graph
nodejs/n8n/sample-agent/Agent-Code-Walkthrough.MD Updated documentation to reflect removal of state management features

@rbrighenti rbrighenti force-pushed the users/rbrighenti/n8n-fix-agentic-token branch from b9b7b21 to 18977ac Compare November 20, 2025 16:02
@rbrighenti rbrighenti force-pushed the users/rbrighenti/n8n-fix-agentic-token branch from 18977ac to c3291f3 Compare November 20, 2025 16:08
@rbrighenti rbrighenti enabled auto-merge (squash) November 20, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants