This sample demonstrates how to use the Microsoft Graph API as a Copilot plugin in a declarative agent. The agent only retrieves data from QnAs content defined in Microsoft Search using the /search/query endpoint of the Microsoft Graph API so users can ask questions based on it.
The following blog post describes the complete solution setup: https://blog.franckcornu.com/post/copilot-graph-api-qna-plugin/
- Franck Cornu- M365 Development MVP
| Version | Date | Comments |
|---|---|---|
| 1.0 | January 16, 2025 | Initial solution |
- Teams Toolkit Visual Studio Code Extension version 5.0.0 and higher or Teams Toolkit CLI
- Microsoft 365 Copilot license
- A Microsoft 365 account for development.
-
Clone this repository (or download this solution as a .ZIP file then unzip it)
-
Import QnA samples using the sample_qnas.csv file into your Microsoft Search admin center (or use your own):
-
Open the mssearchplugin-openapi.yml file, look for the
securitySchemesproperty and replacetenantidby your own ID:securitySchemes: azureaadv2: type: oauth2 flows: authorizationCode: authorizationUrl: https://login.microsoftonline.com/tenantid/oauth2/v2.0/authorize tokenUrl: https://login.microsoftonline.com/tenantid/oauth2/v2.0/token scopes: QnA.Read.All: Read QnAs from Microsoft Search
-
Register an Entra ID application in Azure and add the API permissions
QnA.Read.All(delegated). Add thehttps://teams.microsoft.com/api/platform/v1.0/oAuthRedirectas a redirect URL for web platform in the Authentication settings.
-
In the Teams developer portal, add a new OAuth client registration and register a new client with the following information (replace
tenantidby your own value):App settings
- Registration name: MicrosoftSearch
- Base URL:
https://graph.microsoft.com/beta(QnA are only usable through the beta endpoint) - Restrict usage by org: My organization only
- Restrict usage by app: Any Teams app (when agent is deployed, use the Teams app ID).
OAuth settings
- Client ID: <the entra ID application ID>
- Client secret: <the Entra ID application secret>
- Authorization endpoint: https://login.microsoftonline.com/tenantid/oauth2/v2.0/authorize
- Token endpoint: https://login.microsoftonline.com/tenantid/oauth2/v2.0/token
- Refresh endpoint: https://login.microsoftonline.com/tenantid/oauth2/v2.0/refresh
- Scope: QnA.Read.All
Save the information. A new OAuth registration key will be generated.
-
Open the ai-plugin.json file and replace the auth property by the following, using the key from the previous step. You can also use the
${{OAUTH2_REGISTRATIONKEY}}token defined the.env.devfile:"auth": { "type": "OAuthPluginVault", "reference_id": "ZTRhNDM5YjQtM2..." },
-
From Teams Toolkit, sign-in to your Microsoft 365 account.
-
From Teams Toolkit, provision the solution to create the Teams app.
-
Go to https://www.office.com/chat?auth=2 URL and enable the developer mode by using the
-developer onprompt. -
Ask a question like "Is Microsoft Search in Bing secure?". You should see the plugin triggered.
The following sample demonstrates the following concepts:
- Use Microsoft Graph API as an API plugin by using specific endpoint and instructions.
- Query the QnA content from Microsoft Search and use it for Copilot answers.
Search for: da-qna-graphapi-plugin
Search for: @FranckyC
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
You can try looking at issues related to this sample to see if anybody else is having the same issues.
If you encounter any issues using this sample, create a new issue.
Finally, if you have an idea for improvement, make a suggestion.
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.



