An agent built in Microsoft Copilot Studio and published to Microsoft Teams and Microsoft 365 Copilot connects to NET Genium by signing in through Microsoft Entra ID. The agent cannot send each user their own personal MCP token. It can, however, obtain a Microsoft Entra ID access token on behalf of the signed-in user and send it in the “Authorization” header. The server validates the token and finds the user in NET Genium by the e-mail address. Everyone thus works with the agent under their own identity and with their own permissions, without generating or copying anything.
Copilot can be connected to two servers:
| Server | For whom | Tools |
| Integrated MCP server of the instance (“<instance address>/mcp”) | administrators of the instance | reading and writing data and the model according to the checkboxes on the personal MCP token of the user, without a token only the framework documentation |
| Custom API of a customer solution (“https://<api address>/mcp”) | any NET Genium user | the tools the custom API offers – typically a few tools tailored to the business |
Both servers take the Microsoft Entra ID settings from the “Config\CopilotOAuth.json” file of the NET Genium instance. The procedure is the same for both. It differs only in the server address in the tool (step 3) and in the code changes that a custom API needs on top (step 6).
For agentic development, work with the implementation model and analyses of the data of the instance, Claude and ChatGPT and their developer variants Claude Code and Codex are recommended – Copilot is less reliable in them.
1. Before you start
- The setup has a fixed order – first the agent and its tool in Copilot Studio, then the app registration in Microsoft Entra ID and finally the connector of the tool in Power Apps. Copilot Studio shows the redirect URL only for a finished tool and the connector is created only together with the tool. The wizards in Copilot Studio and Power Apps change with the product, but the values below are what they ask for.
- The setup requires an account with access to Copilot Studio and Power Apps, an owner of the app registration and, once, an administrator of the Microsoft 365 tenant to grant consent to the permission (step 2).
- NET Genium users must have the e-mail address of their Microsoft work account filled in.
2. Procedure
- Agent – a new agent of the “Standard” type is created in Copilot Studio. The authentication of the agent stays at the default “Authenticate with Microsoft”, so that the agent knows the user from the Teams sign-in. Web search is turned off in the overview of the agent and the instructions state that the agent answers questions about the data only from the results of the tool and asks the user for consent before every write. With web search turned on, the agent answers questions such as “my tasks” from the web and does not call the tool.
- App registration – an app registration is created in Microsoft Entra ID. One registration is enough for the integrated MCP server of the instance, for the custom API and for all agents connecting to them. Under “Expose an API”, the identifier is set to “api://<client ID>” and a delegated scope is added, for example “mcp.access”. In the manifest, “requestedAccessTokenVersion” is set to 2. Under “Certificates & secrets”, a client secret is created. Under “API permissions”, the delegated permission “mcp.access” is added (the “My APIs” tab, the registration itself) and a tenant administrator approves it with the “Grant admin consent for ...” button – the button is disabled for a user without the administrator role. The options for public clients and for issuing access tokens by the implicit flow must stay turned off (the default).
- MCP tool – a new tool of the “Model Context Protocol” type is added on the “Tools” tab of the agent:
- Server name – only letters, digits, “-” and “_”, for example “erp-api”,
- Server description – which data the server works with, the agent decides by the description when to use the server,
- Server URL – “<instance address>/mcp” for the integrated MCP server, “https://<api address>/mcp” for a custom API,
- Authentication – “OAuth 2.0”, type “Manual”, the client ID and the client secret from the app registration, the authorization URL “https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/authorize”, the token URL template and the refresh URL “https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/token”, and the scopes “api://<client ID>/mcp.access offline_access”.
- Redirect URL – once the tool is created, Copilot Studio shows its redirect URL (“https://global.consent.azure-apim.net/redirect/...”). The address is added to the app registration under “Authentication” as a “Web” platform. Every tool has its own address.
- Connector – the tool creates a custom connector in Power Apps with the same name as the server. A connector with the generic OAuth 2.0 provider obtains a valid token but does not renew it after an hour, and the agent then gets the status code 401. That is why the connector is edited in Power Apps (make.powerapps.com, the environment of the agent) under “Custom connectors” and the following is set in step “2. Security”:
- Identity provider – “Azure Active Directory”,
- Client ID and Client secret – the client ID and the client secret from the app registration. The form does not show them after saving, so both have to be entered again with every later edit of the connector,
- Authorization URL – “https://login.microsoftonline.com”, Tenant ID – the tenant ID,
- Resource URL – the client ID alone (a GUID), not “api://<client ID>”,
- Scope – “api://<client ID>/mcp.access offline_access”.
- Saving – with the “Update connector” button. The redirect URL stays the same and does not change in the app registration. Connections created before editing the connector have to be created again and the agent has to be published again (step 8), forcing the newest version in ongoing conversations.
- Sharing – in the “Custom connectors” list, “...” and “Invite another user” are chosen next to the connector, the connector is shared with the whole organization on the “Share” tab and the change is saved. Without sharing, only the owner of the connector can create a connection to the tool, and the connection manager tells other users that the connector information could not be loaded.
- The “CopilotOAuth.json” file – the tenant ID and the client ID are written to the “Config\CopilotOAuth.json” file of the NET Genium instance (see the example below). This is enough for the integrated MCP server. A custom API needs on top the path to this file in its “Web.config” file and the authentication of the caller in the “Global.asax.cs” file – a detailed description is provided in the separate guide API. The modified API has to be deployed.
- Connection – a connection for the tool is created in Copilot Studio (sign-in with a Microsoft account) and the tool is added to the agent. In the details of the tool, “Credentials to use” stays at “End user credentials”. The agent is then tried in the test pane.
- Publishing – the agent is published and the “Microsoft 365 and Microsoft Teams” channel is added on the “Channels” tab.
- Sharing – in the “Microsoft 365 and Microsoft Teams” channel, “Availability options” and “Manage sharing” are opened. The users who are to use the agent get “End user access” – individually, as a security group, or through the “Everyone in the organization” entry. Without sharing, only the owner of the agent can open it.
- Link – in “Availability options”, the link to the agent is copied with the “Copy link” button and sent to the users, for example in a Teams message. The user opens the link and adds the agent in Teams. The link opens the agent only for the users it is shared with.
The “Config\CopilotOAuth.json” file in the root directory of the NET Genium instance:
{
"tenant_id": "<tenant ID>",
"client_id": "<client ID>"
}
3. First use in Teams
The connection created in Copilot Studio applies only to the test pane, in Teams every user connects to the tool on their own. The agent answers the first question with a card asking to connect first, with an “Open connection manager” link. In the connection manager, the user clicks “Connect” next to the tool and chooses to create a new connection in the “Connection” list. Nothing has to be filled in the dialog – the display name is optional and the authentication type stays at OAuth. After clicking “Create”, the user signs in with their work account in a new window (when the browser blocks the pop-up window, it has to be allowed for the page) and then clicks “Retry” on the card in the chat. Further questions come without the prompt.
Teams for desktop may offer a card with an “Allow” button instead of the link, and clicking it ends with a message that the bot is disabled. The agent then answers only “One moment please, I'm still signing you in...” and the message box says that messages cannot be sent to the bot. The agent is not disabled, it is a fault of the card in Teams. The “Allow” button is not used – the user waits for the card saying the connection could not be made, opens the connection manager in the browser with the “Open connection manager” link, clicks “Manage” next to the tool, selects or creates a connection and confirms it with “Submit”. Then “Retry” is clicked on the card in Teams.
4. Token validation
The Microsoft Entra ID token must be issued by the tenant “tenant_id” for the app registration “client_id”, must be valid and must carry the scope “mcp.access” (a different scope can be written to the file with the “scope” key). The scope is not required for a token that the app registration requested for itself – the connector from step 5 obtains such a token, and only someone who knows the client secret can obtain it. The server finds the user by the e-mail address from the token, case-insensitively. Exactly one NET Genium user who is not the anonymous user must match it – accounts are not created automatically. An invalid token as well as a user not found end with the status code 401. No client secret is needed for the validation.
The integrated MCP server admits only users with administrator rights and gives them tools according to the checkboxes on their personal MCP token – the validity of the token does not matter and the token itself is not sent. A custom API does not require the “Access via a custom API” permission for a Microsoft Entra ID token.
Details
- The server takes the e-mail address from the “preferred_username” claim of the token and, when it is missing, from the “email” claim.
- Version 1.0 tokens (issuer “https://sts.windows.net/...”) are rejected by the server, which is why the manifest of the app registration needs “requestedAccessTokenVersion” set to 2.
- The validity of the token is assessed with a tolerance of 5 minutes. The server downloads the signing keys of the tenant from Microsoft and keeps them for 24 hours. It tries to download a key it does not know again at most once a minute. When Microsoft does not provide the keys, the last downloaded ones remain valid. When the token cannot be validated at all (no downloaded keys or a faulty “CopilotOAuth.json” file), the integrated MCP server answers with the status code 503, not 401.
- The “CopilotOAuth.json” file is read with every request, so a change applies immediately. When the “scope” key is missing in it, the scope “mcp.access” applies. The server reads neither the client secret nor other keys.
- A token from a connector with the “Azure Active Directory” provider carries only “User.Read” in the “scp” claim, the scope “mcp.access” is missing even after admin consent. The server accepts it because the “azp” claim of the token is the client ID of the app registration. Only someone who knows the client secret can obtain this token, which is why the registration must not allow public clients nor issuing access tokens by the implicit flow.
5. Troubleshooting
The reason for rejecting a token is written to the log in a line “Microsoft Entra ID token rejected (...)” – to the “api.aspx” log for the integrated MCP server, to its own log for a custom API – and it is not returned to the client. The “missing scope” reason also states the actual values of the “scp”, “roles” and “azp” claims of the token.
| Symptom | Cause and remedy |
| Copilot Studio refuses to create the tool | The server name contains a dot, a slash or a space – only letters, digits, “-” and “_” are allowed. |
| 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 (step 1). |
| The sign-in window closes and no connection is created | The “Resource URL” in the connector has the form “api://<client ID>” and the sign-in ends with the error AADSTS90009 – enter the client ID alone. |
| After editing the connector the sign-in does not work at all | The connector was saved without the Client ID or the Client secret – enter both again and update the connector. |
| The agent works for an hour, then gets 401 and the log shows “expired” | The connector has the generic OAuth 2.0 provider and reports “Failed to refresh access token for service: oauth2pkce” – switch it to “Azure Active Directory” (step 5). |
| 401 and the log shows “missing scope ... azp” with a different ID | The token was issued by a different app registration – check the Client ID in the connector. |
| 401 and the log shows “token v1.0” | “requestedAccessTokenVersion” 2 is missing in the manifest of the registration. |
| 401 and the log shows “no user found by e-mail ...” | The e-mail of the user does not belong to any NET Genium user, or belongs to several users – fix the e-mail in NET Genium. |
| The integrated MCP server returns 401 and the line “Microsoft Entra ID token rejected” is missing in the “api.aspx” log | The instance does not have the “Config\CopilotOAuth.json” file, so it does not validate a Microsoft Entra ID token. |
| The integrated MCP server returns 403 | The user does not have administrator rights, is not in the list of administrators with access to the MCP server, the licence key does not allow AI, the IP address is not among the allowed ones, or the licences are exhausted. The reason is in the “Auth” log. |
| Teams shows “One moment please, I'm still signing you in...” and the “Allow” button ends with a message that the bot is disabled | A fault of the sign-in card in Teams – connect through the “Open connection manager” link and click “Retry” (chapter 3). After editing the connector, publish the agent again (step 5). |
| The connection manager offers no connection for the tool and then reports that the connector information could not be loaded, with the text “does not have ReadAccess right(s)” | The connector is not shared with the user – share it with the organization (step 5). For the owner of the connector, the connection works even without sharing. |
| A user cannot open the agent from the link | The agent is not shared with them – give them “End user access” (step 9). |
| The connection manager shows “Something went wrong” after clicking “Connect” | The connection was usually created – after reloading the page and clicking “Refresh”, the tool has the status “Connected”. |
The other ways to connect are listed in the overview MCP server setup.