1. Basic information
The server function “COPILOTCHAT(secret)” inserts a chat with an agent built in Microsoft Copilot Studio into a view page or an edit form, in the colors of the NET Genium layout. The “secret” parameter is the secret of the web channel of the agent. The server uses it to start a new conversation with every rendering of the page and passes only the token of this conversation to the browser, so the secret never reaches the browser. The function is described in the guide Server functions.
The setup of the agent depends on what the agent is to work with:
- Variant 1 – agent with knowledge (chapter 3)
- answers from documents that anyone who sees the page may see – typically from an Azure AI Search index,
- authentication of the agent “No authentication” – the user does not sign in and the agent does not know who is asking.
- Variant 2 – agent with an MCP tool (chapter 4)
- answers from NET Genium data on behalf of the signed-in user – through the integrated MCP server of the instance or a custom API,
- authentication of the agent “Authenticate manually” through Microsoft Entra ID – the user signs in every time the page is opened with a validation code typed into the chat (chapter 2).
Both variants end the same way – with a secured web channel and the function inserted into the page (chapter 5).
In variant 2, the sign-in is the main drawback of the web chat. For an agent with an MCP tool it is therefore usually better to put on the page just a link to an agent published to Microsoft Teams (chapter 2) – this option is worth considering before setting up the agent.
2. Signing the user in to the chat
The sign-in concerns only an agent with an MCP tool (variant 2). The user signs in to the web chat on their own, and every time the page is opened – even after reloading it. The “COPILOTCHAT” function starts a new conversation with every rendering of the page and the sign-in applies only within it. This is inconvenient for the user, but Copilot Studio does not offer another solution for the web chat yet.
A link to the agent in Teams instead of the chat in the page – instead of the “COPILOTCHAT” function, the page can contain a link to an agent published to Microsoft Teams, which opens in a new browser tab. The user signs in to this agent automatically with their Microsoft 365 account and connects to the MCP tool only on first use. The user must have an account in the Microsoft 365 tenant the agent is published in, and the agent must be shared with them. A detailed description of the setup of such an agent is provided in the separate guide Microsoft Copilot Studio.
For the user to sign in to the web chat and for the agent to work with their data, the following must hold:
- the agent is shared with the user (chapter 4, step 6),
- the connector of the MCP tool is shared with the organization (chapter 4, step 4) – otherwise only the owner of the connector can create a connection to the tool,
- the user has the e-mail address of their Microsoft work account filled in in NET Genium – the MCP server finds the user in NET Genium by it, the same as for the agent in Teams,
- the browser allows pop-up windows for the page – the sign-in opens in a new window.
The course of the sign-in:
- The agent answers the first question with a card asking the user to sign in before continuing, with a sign-in button.
- The button opens a new window with the Microsoft sign-in. The user signs in with their work account.
- The window shows a six-digit validation code (“Please enter this validation code into the chat window to complete the sign-in”). The user types the code into the chat and sends it as a message, then the window can be closed.
- The agent confirms the sign-in and answers the original question. Without the sentence about the validation code in the instructions of the agent (sample in chapter 6), the agent answers the code as if it were a new question – the sign-in has nevertheless succeeded and further questions already work.
When the agent is used for the very first time, the user additionally connects to the MCP tool once. The agent answers with a card asking to connect first, with an “Open connection manager” link, in which the user creates a connection for the tool in the same way as in Teams (the guide Microsoft Copilot Studio, chapter 3). After returning to the chat, it is better to type the question again – the “Retry” button on the card resends the last message of the user, and that is the validation code. The connection to the tool applies to further conversations as well.
Details
- The validation code confirms that the sign-in in the new window belongs to whoever is writing in the chat. The web chat cannot tell this without the code.
- The sign-in of the agent (the scopes “profile openid”) only finds out who the user is. The access token for the MCP server is obtained separately by the connector of the tool, which is why on first use the user signs in twice – to the agent and to the tool.
3. Variant 1 – agent with knowledge
An agent without authentication does not know who is asking. Access to the knowledge is therefore controlled only by the permissions of the view page or form the function is inserted into – the knowledge should contain only documents that anyone who opens the page may see.
- Agent – an agent is created in Copilot Studio and “No authentication” is chosen in the authentication settings (Settings / Security / Authentication).
- Knowledge – the source the agent is to answer from is added on the “Knowledge” tab, for example an Azure AI Search index (an “Azure AI Search” connection with the address of the search service and its admin key). The connection belongs to the account that created it – the other owners of the agent do not see it in the editor and the knowledge is shown to them as failed, although the published agent answers correctly.
- Instructions – the instructions of the agent state which documents it answers from (a sample is in chapter 6), and “Web search” is turned off as needed so that the agent answers only from the knowledge.
- Web channel and page – according to chapter 5.
4. Variant 2 – agent with an MCP tool
The agent works with NET Genium data in the same way as the agent in Teams from the guide Microsoft Copilot Studio – with an MCP tool whose connector obtains a Microsoft Entra ID access token on behalf of the user. The web chat, however, has no Teams sign-in. The agent therefore signs the user in itself, with manually configured authentication through the same app registration, and without a client secret – using federated credentials. The “Authenticate with Microsoft” option is not suitable for the web chat – it works only in Teams, SharePoint, Power Apps and Microsoft 365 Copilot, and the web channel is not available with it.
- Agent – a new agent of the “Standard” type is created in Copilot Studio. Only this type of agent offers manual authentication. “Web search” is turned off in the overview of the agent.
- Authentication of the agent – in the settings of the agent (Settings / Security / Authentication), “Authenticate manually” is chosen and the following is filled in:
- Require users to sign in – checked,
- Service provider – “Microsoft Entra ID V2 with federated credentials”,
- Client ID – the client ID of the app registration from the guide Microsoft Copilot Studio (step 2), the same as in the MCP tool,
- Scopes – “profile openid”,
- Token exchange URL and Login URL – left empty.
- After saving, the page shows the values “Redirect URL”, “Federated credential issuer” and “Federated credential value”, which are written to the app registration in the next step.
- App registration – in the app registration in Microsoft Entra ID (portal.azure.com / App registrations):
- under “Authentication”, the redirect URL from Copilot Studio, for example “https://europe.token.botframework.com/.auth/web/redirect”, is added to the “Web” platform,
- under “Certificates & secrets”, on the “Federated credentials” tab, credentials are added with the “Add credential” button: scenario “Other issuer”, “Issuer” = the federated credential issuer from Copilot Studio, “Type” = “Explicit subject identifier”, “Value” = the federated credential value from Copilot Studio, “Name” of any choice (for example after the name of the agent) and “Audience” left at “api://AzureADTokenExchange”.
- The federated credential value contains the ID of the agent, so every agent needs its own entry. The options for public clients and for the implicit flow stay turned off.
- MCP tool – on the “Tools” tab of the agent, a tool of the “Model Context Protocol” type is added with the “Add a tool” button, with the name, description and URL of the server and with OAuth 2.0 authentication (the values are in chapter 6). Then:
- the redirect URL of the tool (“https://global.consent.azure-apim.net/redirect/...”), which Copilot Studio shows once the tool is created, is added to the “Web” platform of the app registration – every tool has its own address,
- the connector of the tool is switched in Power Apps to the “Azure Active Directory” identity provider and shared with the organization – without the switch the agent gets the status code 401 after an hour, without sharing only the owner of the connector can create a connection to the tool. The procedure and the values are in the guide Microsoft Copilot Studio, step 5,
- the tenant ID and the client ID are written to the “Config\CopilotOAuth.json” file of the NET Genium instance. A custom API needs on top the changes described in the guide API,
- a connection is created for the tool (sign-in with a Microsoft account) and in the details of the tool, “Credentials to use” stays at “End user credentials”.
- Instructions – the instructions of the agent state that it answers questions about the data only from the results of the tool and asks the user for consent before every write, and a sentence about the sign-in validation code (chapter 2) is added. Sample instructions are in chapter 6.
- Sharing – the agent is shared with all users of the page. An agent with manual authentication can be used only by the users it is shared with – Copilot Studio warns about this already when the authentication is saved.
- Web channel and page – according to chapter 5. The agent is published in Copilot Studio without the “Microsoft 365 and Microsoft Teams” channel.
5. Secured web channel and the COPILOTCHAT function
- Publishing – the agent is published in Copilot Studio with the “Publish” button. The chat in the page always uses the published version of the agent, changes of the agent reach the chat only with the next publishing.
- Secure access – in the settings of the agent (Settings / Security / Web channel security), the “Require secured access” option is turned on. The agent then answers through the web channel only to someone who knows the secret or a token, and the demo website of Copilot Studio stops working.
- Secret – on the same page, “Secret 1” is copied with the “Copy” button.
- Page – an HTML control with the text “COPILOTCHAT(<secret>)” is added to a view page or an edit form. The chat is rendered from the place of the control down to the bottom edge of the window.
The secret always belongs to one agent – every agent has its own two secrets in the settings of its web channel, and there is no common secret for all agents of a Copilot Studio environment or of a Microsoft 365 tenant. When NET Genium shows a chat with one agent on several pages, all the pages use the same secret. A chat with another agent needs the secret of that agent.
Details
- The secret is stored in the implementation model and every administrator who opens the settings of the HTML control can see it. The “Regenerate” button creates a new secret and the old one stops being valid – the chat then shows an error message instead of the conversation until the new secret is written to the control. Secret 2 serves for a replacement without an outage: the control is switched to secret 2, secret 1 is regenerated and the control returns to the new secret 1.
- Anyone who knows the secret can talk to the agent even outside NET Genium. In variant 2 they have to sign in and get only their own data, in variant 1 they get answers from all the knowledge of the agent.
6. Sample agent setup
Sample values of an agent with an MCP tool (variant 2):
- Agent
- Agent type – “Standard”,
- Web search – turned off,
- Authentication of the agent – “Authenticate manually”, provider “Microsoft Entra ID V2 with federated credentials”, the client ID of the app registration, scopes “profile openid”.
- MCP tool
- Server name – “netgenium-data”,
- Server description – “NET Genium data the signed-in user has access to”,
- Server URL – “https://<instance address>/mcp” (integrated MCP server), or “https://<api address>/mcp” (custom API),
- Authentication of the tool – “OAuth 2.0”, type “Manual”, the client ID and the client secret of the app registration,
- Authorization URL – “https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/authorize”,
- Token URL template and refresh URL – “https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/token”,
- Scopes of the tool – “api://<client ID>/mcp.access offline_access”,
- Credentials to use – “End user credentials”.
Sample instructions of an agent with an MCP tool:
You are an assistant over the NET Genium of <company name>. Answer questions about data
(for example about contracts, orders or documents) only from the results of the netgenium-data
tool. The tool works on behalf of the signed-in user and returns only what they may see.
When the tool returns nothing or fails, tell the user and do not make up any data. Before every
write (creating a record, a comment, a change), summarize for the user exactly what you will
write and wait for their explicit consent. Answer in English, briefly and to the point.
A message that contains only a six-digit number and arrives right after the sign-in prompt
is the sign-in validation code. Do not treat it as a record number (for example a contract
or order number). Confirm that the user is signed in and answer their previous question.
Details
- The last three sentences of the instructions deal with the sign-in validation code (chapter 2). The user types it into the chat as an ordinary message and once the sign-in is completed, the agent answers it like any other question. Without these sentences, the agent takes the six-digit number for a record number and answers, for example, that the record with that number could not be found, or asks what the number means. The sign-in has nevertheless succeeded and further questions already work.
- It is advisable to list in the brackets of the “Do not treat it as a record number...” sentence the kinds of records the tool works with whose numbers can have six digits.
Sample instructions of an agent with knowledge (variant 1):
Answer only from the knowledge of the agent. With every answer, state the name of the document
it is based on. When the answer is not in the knowledge, say so and do not make anything up.
Answer in English, briefly and to the point.
7. Troubleshooting
| Symptom | Cause and remedy |
| The authentication of the agent does not offer “Authenticate manually” | The agent is not of the “Standard” type – create a new agent of this type (chapter 4). |
| The chat is not rendered and the function returns an error message | The secret in the HTML control is not valid (it was regenerated), or the server has no outbound access to europe.directline.botframework.com. |
| A change of the agent does not show in the chat | The agent was not published after the change (chapter 5, step 1). |
| The agent asks for sign-in every time the page is opened | Expected behaviour – the sign-in applies only to one conversation (chapter 2). |
| The sign-in window ends with an error instead of the validation code | The app registration lacks the redirect URL or the federated credentials of the agent, or the client ID in the authentication of the agent belongs to a different registration (chapter 4, steps 2 and 3). |
| The agent answers the validation code as a record number or asks what the number means | The sentence about the validation code is missing in the instructions of the agent (sample in chapter 6). The sign-in has succeeded, it is enough to type the question again. |
| The connection manager reports that the connector information could not be loaded | The connector of the tool is not shared with the organization (the guide Microsoft Copilot Studio, troubleshooting). |
| The agent answers from the web and does not call the tool | Web search is turned on – turn it off in the overview of the agent. |
Other problems with the MCP tool and the token validation are described in the “Troubleshooting” chapter of the guide Microsoft Copilot Studio.