$npx -y skills add microsoft/power-platform-skills --skill add-mcscopilotAdds Microsoft Copilot Studio connector to a Power Apps code app. Use when invoking Copilot Studio agents, sending prompts to agents, or integrating agent responses.
| 1 | **📋 Shared Instructions: [shared-instructions.md](${PLUGIN_ROOT}/shared/shared-instructions.md)** - Cross-cutting concerns. |
| 2 | |
| 3 | # Add Microsoft Copilot Studio |
| 4 | |
| 5 | ## Workflow |
| 6 | |
| 7 | 1. Check Memory Bank → 2. Add Connector → 3. Configure → 4. Build → 5. Update Memory Bank |
| 8 | |
| 9 | --- |
| 10 | |
| 11 | ### Step 1: Check Memory Bank |
| 12 | |
| 13 | Check for `memory-bank.md` per [shared-instructions.md](${PLUGIN_ROOT}/shared/shared-instructions.md). |
| 14 | |
| 15 | ### Step 2: Add Connector |
| 16 | |
| 17 | **First, find the connection ID** (see [connector-reference.md](${PLUGIN_ROOT}/shared/connector-reference.md)): |
| 18 | |
| 19 | Run the `/list-connections` skill. Find the Microsoft Copilot Studio connection in the output. If none exists, direct the user to create one using the environment-specific Connections URL — construct it from the active environment ID in context (from `power.config.json` or a prior step): `https://make.powerapps.com/environments/<environment-id>/connections` → **+ New connection** → search for the connector → Create. |
| 20 | |
| 21 | ```bash |
| 22 | npx power-apps add-data-source -a microsoftcopilotstudio -c <connection-id> |
| 23 | ``` |
| 24 | |
| 25 | ### Step 3: Configure |
| 26 | |
| 27 | Ask the user which Copilot Studio agent they want to invoke and what operations they need. |
| 28 | |
| 29 | **Agent Setup Prerequisites** (manual steps the user must complete in Copilot Studio): |
| 30 | |
| 31 | 1. **Publish the agent**: In Copilot Studio, click Channels → select Teams → add to Teams → click Publish. |
| 32 | 2. **Get the agent name**: Under Channels, click "Web app". The connection string URL contains the agent name. Example: `https://...api.powerplatform.com/copilotstudio/dataverse-backed/authenticated/bots/cr3e1_myAgent/conversations?...` — the agent name is `cr3e1_myAgent`. |
| 33 | |
| 34 | **ExecuteCopilotAsyncV2** -- execute an agent and wait for the response: |
| 35 | |
| 36 | Use the `ExecuteCopilotAsyncV2` operation (path: `/proactivecopilot/executeAsyncV2`). This is the **only** endpoint that reliably returns agent responses synchronously. It is the same endpoint used by Power Automate's "Execute Agent and wait" action. |
| 37 | |
| 38 | ```typescript |
| 39 | const result = await MicrosoftCopilotStudioService.ExecuteCopilotAsyncV2({ |
| 40 | message: "Your prompt or data here", // Can be a JSON string |
| 41 | notificationUrl: "https://notificationurlplaceholder" // Required by API but unused; any URL works |
| 42 | }); |
| 43 | |
| 44 | // Response structure: |
| 45 | // result.responses — Array of response strings from the agent |
| 46 | // result.conversationId — The conversation ID |
| 47 | // result.lastResponse — The last response from the agent |
| 48 | // result.completed — Boolean indicating if the agent finished |
| 49 | ``` |
| 50 | |
| 51 | **Important:** Agents often return responses as JSON strings. Parse the `responses` array to extract meaningful data: |
| 52 | |
| 53 | ```typescript |
| 54 | const agentResponse = result.responses?.[0]; |
| 55 | if (agentResponse) { |
| 56 | const parsed = JSON.parse(agentResponse); |
| 57 | // Extract specific fields, e.g., parsed.trend_summary |
| 58 | } |
| 59 | ``` |
| 60 | |
| 61 | Use `Grep` to find specific methods in the generated service file (generated files can be very large — see [connector-reference.md](${PLUGIN_ROOT}/shared/connector-reference.md#inspecting-large-generated-files)). |
| 62 | |
| 63 | #### Known Issues |
| 64 | |
| 65 | - **ExecuteCopilot** (`/execute`) -- fire-and-forget, only returns `ConversationId`, not the actual response. Do NOT use this. |
| 66 | - **ExecuteCopilotAsync** (`/executeAsync`) -- returns 502 "Cannot read server response" errors. Do NOT use this. |
| 67 | - **Conversation turn model** (`/conversations/{ConversationId}`) -- only works after `/execute`, which doesn't provide responses. Do NOT use this. |
| 68 | - **Response casing varies** -- check all variations: `conversationId`, `ConversationId`, `conversationID`. |
| 69 | |
| 70 | ### Step 4: Build |
| 71 | |
| 72 | ```bash |
| 73 | npm run build |
| 74 | ``` |
| 75 | |
| 76 | Fix TypeScript errors before proceeding. Do NOT deploy yet. |
| 77 | |
| 78 | ### Step 5: Update Memory Bank |
| 79 | |
| 80 | Update `memory-bank.md` with: connector added, agent name configured, configured operations, build status. |