copilot-studio-agent-direct-line-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@copilot-studio-agent-direct-line-mcpAsk my agent about product availability"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
β Copilot Studio Agent Direct Line MCP Server
Easily install the Copilot Studio Agent Direct Line MCP Server for VS Code or VS Code Insiders:
This TypeScript project provides a local MCP server for Microsoft Copilot Studio Agents, enabling you to interact with your Copilot Studio Agents directly from your code editor via the Direct Line 3.0 API.
π Table of Contents
Related MCP server: Azure DevOps MCP Server
πΊ Overview
The Copilot Studio Agent Direct Line MCP Server brings Microsoft Copilot Studio Agent context to your development environment. Try prompts like:
"Start a conversation with my Copilot Studio Agent"
"Ask my agent about product sizing"
"Send a message to the agent: What are your capabilities?"
"Get the conversation history"
"End the current conversation"
π Expectations
The Copilot Studio Agent Direct Line MCP Server is built with tools that are concise, simple, focused, and easy to useβeach designed for a specific scenario. We intentionally avoid complex tools that try to do too much. The goal is to provide a thin abstraction layer over the Direct Line 3.0 API, making agent interaction straightforward and letting the language model handle complex reasoning.
βοΈ Features
β Direct Line 3.0 Integration - Full support for Microsoft Bot Framework Direct Line API
β Token Management - Automatic token caching and proactive refresh
β Conversation State - Manages conversation lifecycle with 30-minute idle timeout
β MCP Tools - Four tools for agent interaction: send_message, start_conversation, end_conversation, get_conversation_history
β Error Handling - Retry logic with exponential backoff, circuit breaker pattern
β Input Validation - Zod schemas for type-safe validation
β Security - Secret masking in logs, secure environment configuration
π Authentication Requirements
Important: This MCP server currently supports Copilot Studio Agents configured with "No authentication" only.
In Copilot Studio, ensure your agent's Security > Authentication setting is set to "No authentication" for this MCP server to work properly.
π§ Coming Soon: Entra ID (Azure AD) authentication support is under development and will be available in a future release.
βοΈ Supported Tools
Interact with your Copilot Studio Agent using these tools:
send_message: Send a message to the Copilot Studio Agent and receive a response.
start_conversation: Start a new conversation with the Agent, optionally with an initial message.
end_conversation: End a conversation and clean up resources.
get_conversation_history: Retrieve message history for a conversation.
π Installation & Getting Started
For the best experience, use Visual Studio Code and GitHub Copilot.
Prerequisites
Install VS Code or VS Code Insiders
Install Node.js 18+
Microsoft Copilot Studio Agent with Direct Line 3.0 enabled
Direct Line secret key from your Copilot Studio Agent
Installation
β¨ One-Click Install (Recommended)
Click one of the badges below to automatically configure the MCP server in VS Code:
After clicking, VS Code will:
Prompt you for your Direct Line secret key
Automatically configure the MCP server
Start the server using
npx(no manual installation needed!)
Then:
Select GitHub Copilot Agent Mode
Click "Select Tools" and choose the available Copilot Studio tools
Try a prompt like:
Start a conversation with my Copilot Studio Agent
Learn more about Agent Mode in the VS Code Documentation.
𧨠Manual Install with NPX
If you prefer manual configuration, add this to your .vscode/mcp.json file:
{
"inputs": [
{
"id": "direct_line_secret",
"type": "promptString",
"description": "Direct Line secret key from your Copilot Studio Agent"
}
],
"servers": {
"copilot-studio-agent-direct-line-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "copilot-studio-agent-direct-line-mcp"],
"env": {
"DIRECT_LINE_SECRET": "${input:direct_line_secret}"
}
}
}
}Save the file and click 'Start' in the MCP Server panel. VS Code will prompt you for your Direct Line secret.
π οΈ Install from Source (For Development)
For contributing or local development:
# Clone and build
git clone https://github.com/bradcstevens/copilot-studio-agent-direct-line-mcp.git
cd copilot-studio-agent-direct-line-mcp
npm install
npm run build
# Add to .vscode/mcp.json
{
"inputs": [
{
"id": "direct_line_secret",
"type": "promptString",
"description": "Direct Line secret key from your Copilot Studio Agent"
}
],
"servers": {
"copilot-studio-agent-direct-line-mcp": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/copilot-studio-agent-direct-line-mcp/dist/index.js"],
"env": {
"DIRECT_LINE_SECRET": "${input:direct_line_secret}"
}
}
}
}Important: Replace /absolute/path/to/ with the actual path to the cloned repository.
π₯ Pro Tip: Create a
.github/copilot-instructions.mdfile in your project with:This project uses Microsoft Copilot Studio Agents. Always check to see if the Copilot Studio MCP server has a tool relevant to the user's request.This will enhance your experience with GitHub Copilot Chat!
π§ Configuration
Using NPX (Recommended)
When using npx, configuration is handled through VS Code's MCP input prompts or environment variables:
DIRECT_LINE_SECRET (required): Your Direct Line secret key from Copilot Studio
LOG_LEVEL (optional): Logging level (default:
info)TOKEN_REFRESH_INTERVAL (optional): Token refresh interval in milliseconds (default:
1800000= 30 minutes)
The one-click install will automatically prompt you for the Direct Line secret. For manual configuration, you can add these to the env section of your mcp.json file.
Using Source Installation
Create a .env file based on .env.example:
# Required
DIRECT_LINE_SECRET=your_direct_line_secret_here
# Optional
LOG_LEVEL=info
TOKEN_REFRESH_INTERVAL=1800000 # 30 minutes in msπ Development
# Build
npm run build
# Development mode with watch
npm run dev
# Lint
npm run lint
# Format
npm run formatπ Usage
Using with VS Code
After installation, the MCP server runs automatically when you use GitHub Copilot. The server is invoked via npx, which automatically downloads and runs the latest version from NPM.
Standalone Server Usage
You can run the server standalone for testing or integration with other MCP clients:
# Using npx (recommended)
DIRECT_LINE_SECRET=your_secret npx -y copilot-studio-agent-direct-line-mcp
# Or from source after building
node dist/index.jsThe server uses stdio transport and will wait for MCP client connections.
Using the Tools
You can now interact with your Copilot Studio Agent directly from GitHub Copilot:
Start a conversation with my bot and ask about product sizingGitHub Copilot will use the start_conversation and send_message tools to communicate with your Copilot Studio Agent.
MCP Tools Reference
send_message
Send a message to the Copilot Studio Agent.
Parameters:
message(string, required): The message textconversationId(string, optional): Conversation ID to continue existing conversation
Returns: JSON with conversationId, response, and activityId
start_conversation
Start a new conversation with the Agent.
Parameters:
initialMessage(string, optional): First message to send
Returns: JSON with conversationId, status, and optional response
end_conversation
End a conversation and clean up resources.
Parameters:
conversationId(string, required): Conversation ID to terminate
Returns: JSON with conversationId, status, and messageCount
get_conversation_history
Retrieve message history for a conversation.
Parameters:
conversationId(string, required): Conversation IDlimit(number, optional): Maximum number of messages to return
Returns: JSON with conversationId, messageCount, totalMessages, and messages array
ποΈ Architecture
src/
βββ config/ # Environment configuration with Zod validation
βββ server/ # MCP server implementation
β βββ mcp-server.ts # Main MCP server class
β βββ tool-schemas.ts # Zod validation schemas
β βββ mcp-response.ts # Response formatting & error handling
βββ services/ # Core business logic
β βββ directline-client.ts # Direct Line API client with circuit breaker
β βββ token-manager.ts # Token caching & refresh
β βββ conversation-manager.ts # Conversation lifecycle management
β βββ http-client.ts # Axios HTTP client
βββ types/ # TypeScript type definitions
βββ utils/ # Utility functions
βββ retry.ts # Retry logic with exponential backoff
βββ circuit-breaker.ts # Circuit breaker pattern
βββ secret-masking.ts # Security utilitiesπ Key Components
DirectLineClient
Handles all Direct Line API interactions with circuit breaker protection:
Token generation
Conversation creation
Message sending
Activity retrieval
TokenManager
Manages Direct Line tokens with:
In-memory caching (no disk persistence for security)
Automatic refresh 5 minutes before expiry
Metrics tracking
ConversationManager
Tracks conversation state with:
30-minute idle timeout
Watermark-based message tracking
Message history buffering
Automatic cleanup
CircuitBreaker
Prevents cascading failures with:
3 states: CLOSED, OPEN, HALF_OPEN
Configurable failure threshold (5 failures in 30s)
Recovery timeout (60s)
Success threshold for recovery (3 consecutive successes)
π‘οΈ Error Handling
The server implements comprehensive error handling:
Retry Logic: Exponential backoff (1s, 2s, 4s delays, max 3 retries)
Circuit Breaker: Automatic fail-fast when service is degraded
Error Classification: Categorizes errors (network, auth, rate limit, etc.)
MCP Error Transformation: Converts internal errors to MCP-compliant responses
π Security
No Secret Logging: Direct Line secret and tokens are never logged
Secret Masking: Shows only first 4 and last 4 characters in logs
Environment Validation: Zod schema validation for configuration
In-Memory Only: No disk persistence of sensitive data
π Troubleshooting
MCP Server Not Connecting in VS Code
Check the configuration path - Ensure the absolute path to
dist/index.jsis correctVerify the build - Run
npm run buildto ensure TypeScript compiled successfullyCheck logs - Look at VS Code logs for error messages
Test standalone - Run
node dist/index.jsto verify the server starts without errorsRestart VS Code - After making config changes, fully quit and restart
Direct Line Connection Issues
Verify Secret - Check that
DIRECT_LINE_SECRETis correct in your configurationCheck Bot Status - Ensure your Copilot Studio Agent is published and Direct Line channel is enabled
Review Logs - Server logs will show connection attempts and errors
Common Errors
Failed to generate Direct Line token
Verify your
DIRECT_LINE_SECRETis correctCheck that the Direct Line channel is enabled in Azure Bot Service
Conversation not found or expired
Conversations expire after 30 minutes of inactivity
Start a new conversation with
start_conversationtool
Circuit breaker is OPEN
The server detected multiple failures and is protecting against cascading failures
Wait 60 seconds for the circuit breaker to attempt recovery
Check Direct Line API connectivity
Example VS Code mcp.json Configuration
Here's a complete example configuration using npx (works on all platforms):
{
"inputs": [
{
"id": "direct_line_secret",
"type": "promptString",
"description": "Direct Line secret key from your Copilot Studio Agent"
}
],
"servers": {
"copilot-studio-agent-direct-line-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "copilot-studio-agent-direct-line-mcp"],
"env": {
"DIRECT_LINE_SECRET": "${input:direct_line_secret}",
"LOG_LEVEL": "info",
"TOKEN_REFRESH_INTERVAL": "1800000"
}
}
}
}Alternative: Hardcoded secret (not recommended for shared projects):
{
"servers": {
"copilot-studio-agent-direct-line-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "copilot-studio-agent-direct-line-mcp"],
"env": {
"DIRECT_LINE_SECRET": "your_secret_here"
}
}
}
}π§ͺ Testing
Testing the MCP Server
The easiest way to test is through VS Code after installation:
Install using the one-click badge or manual npx configuration
Open GitHub Copilot Chat in Agent Mode
Try prompts like:
"Start a conversation with my Copilot Studio Agent"
"Send a message: Hello, what can you help me with?"
"Get the conversation history"
Running Test Client (For Development)
If you've cloned the repository, you can run the included test client:
# Set your Direct Line secret
export DIRECT_LINE_SECRET=your_secret_here
# Run tests
npx tsx tests/test-mcp-client.tsThis will test all 4 MCP tools and verify integration with your Copilot Studio Agent.
π Contributing
We welcome contributions! Please file issues for bugs, enhancements, or documentation improvements.
For development setup:
Fork the repository
Create a feature branch:
git checkout -b feature/my-featureMake your changes
Run tests:
npm testCommit your changes:
git commit -am 'Add new feature'Push to the branch:
git push origin feature/my-featureSubmit a pull request
License
Licensed under the MIT License.
π¬ Support
For issues or questions, please open an issue on GitHub.
This project is not affiliated with or endorsed by Microsoft Corporation.
Available Tools
4 toolsend_conversationB
End an existing conversation and clean up resources
| Name | Required | Description | Default |
|---|---|---|---|
| conversationId | Yes | Conversation ID to terminate |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden. 'End an existing conversation' implies mutation, and 'clean up resources' hints at side effects, but it does not disclose irreversibility, impact on history, or any other behavioral nuances. The description is vague about what cleanup entails.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single concise sentence, front-loaded with the action verb 'End'. Every word earns its place, including the useful addition of 'clean up resources' which hints at side effects without unnecessary elaboration.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool is simple with one parameter, 100% schema coverage, and no output schema. The description is minimally viable, but it lacks usage guidance and behavioral details about consequences, making it less complete than ideal for a terminating action.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%: the parameter 'conversationId' is described as 'Conversation ID to terminate'. The description adds no additional semantic meaning beyond the schema, so baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses the specific verb 'End' with the resource 'conversation', clearly indicating the action. It distinguishes from siblings like 'send_message' and 'start_conversation' by being the terminating action, though it does not explicitly contrast with them.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus alternatives. It does not mention conditions for ending a conversation or exclusions, relying on the agent to infer usage from the verb 'End' and sibling context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_conversation_historyB
Retrieve message history for a conversation
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of messages to return | |
| conversationId | Yes | Conversation ID |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It only says 'Retrieve message history' and does not explicitly confirm read-only behavior, mention pagination, ordering, error handling, or authentication requirements. The verb 'retrieve' implies a read operation, but this is not stated.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, well-formed sentence that conveys the core purpose without any superfluous words. It is front-loaded and every word contributes meaning.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool is simple (two parameters, no output schema, no annotations), and the schema covers parameters adequately. However, the description lacks context about response format, message ordering, or usage scenarios, making it minimally viable but not comprehensive.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already documents both parameters with clear descriptions ('Conversation ID' and 'Maximum number of messages to return'), achieving 100% schema coverage. The tool description adds no further parameter semantics, so a baseline score of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb 'Retrieve' and clearly identifies the resource as 'message history for a conversation.' This distinguishes it from sibling tools like send_message, start_conversation, and end_conversation, which perform different actions on conversations.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description offers no guidance on when to use this tool versus alternatives. It simply states the action without mentioning context or exclusions, and sibling tools are not referenced, leaving the agent to infer usage solely from the name.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
send_messageC
Send a message to the Copilot Studio Agent
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | The message text to send | |
| conversationId | No | Optional conversation ID to continue existing conversation |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden of behavioral disclosure. It only states the basic action and omits important behaviors such as whether the tool can start a conversation without a conversationId, how it handles invalid conversation IDs, or any side effects. This is a significant gap for a messaging tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence that directly states the tool's purpose with no superfluous words. It is compact and front-loaded, making the core function immediately clear.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Despite the tool's technical simplicity, the description lacks critical context about the conversation lifecycle. The existence of sibling tools (start_conversation, end_conversation) implies a workflow, but the description does not clarify whether send_message requires an existing conversation or can initiate one. This ambiguity affects correct usage.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already provides full descriptions for both parameters (message and conversationId). The tool description adds no additional semantics beyond the schema, so the baseline score of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Send') and the object/resource ('a message to the Copilot Studio Agent'). It is distinguishable from siblings like start_conversation and get_conversation_history, though it could be more explicit about whether it sends within an existing conversation or starts a new one.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus the siblings. There is no mention of prerequisites (e.g., needing an active conversation) or alternatives, leaving the agent to infer the intended workflow.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
start_conversationB
Start a new conversation with the Copilot Studio Agent
| Name | Required | Description | Default |
|---|---|---|---|
| initialMessage | No | Optional first message to send |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden for transparency. It fails to disclose behavioral traits such as whether it resets prior context, returns a conversation ID, affects an existing conversation, or requires any prerequisites. The state-changing nature is implied but not explained.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, front-loaded sentence with no redundancy or filler. It fully serves its immediate purpose in minimal words, earning a high score for conciseness.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Despite the simple one-parameter schema, the description omits critical context such as the return value, how it interacts with sibling tools, or whether it terminates an existing conversation. With no output schema or annotations, this lack of information leaves the agent uncertain about the tool's full behavior.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema already provides full coverage for the single optional parameter 'initialMessage' with a clear description. The tool description adds no additional semantic context about the parameter, so the baseline of 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly specifies the action 'Start' and the resource 'a new conversation' with the target 'Copilot Studio Agent.' It distinguishes itself from sibling tools like send_message and end_conversation by explicitly indicating a new conversational session.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description only implies usage through the verb 'Start,' giving no explicit guidance on when to use this tool versus siblings, nor any exclusions or prerequisites. The context of the sibling names suggests lifecycle phases but is not articulated.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
Each tool targets a distinct action in the conversation lifecycle: starting, sending, ending, and retrieving history. There is no overlap or ambiguity between tool purposes.
All tool names follow a consistent verb_noun pattern (send_message, start_conversation, end_conversation, get_conversation_history), making the API predictable and easy to navigate.
Four tools is perfectly scoped for a conversation management server, covering the essential operations without unnecessary bloat. Each tool earns its place.
The set provides full lifecycle coverage for a conversation: start, send, get history, and end. No obvious gaps exist for the stated purpose of interacting with a Copilot Studio agent.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Create and manage AI agents that collaborate and solve problems through natural language interactiβ¦
Debug, build, and manage Power Automate cloud flows with AI agents
Build, deploy, and sell AI agents for local-service businesses - from your IDE.
Chat with your Zihin.ai agents, list them and load platform skills from any MCP client.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables interaction with Microsoft Copilot Studio Agents directly from VS Code through the Direct Line 3.0 API. Supports starting conversations, sending messages, retrieving history, and managing conversation lifecycle with your custom agents.421MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Azure DevOps services including work items, builds, releases, test plans, repositories, and search via natural language commands from a code editor.16MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to debug code inside VS Code by setting breakpoints, stepping through execution, inspecting variables, and evaluating expressions across multiple languages.482MIT
- AlicenseNot gradedqualityFmaintenanceEnables AI assistants to interact with VS Code for language intelligence, debugging, and code execution.17MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/swigerb/copilot-studio-agent-direct-line-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server