Sponsored by Deepsite.site

Mcp Server For Microsoft Copilot Studio (mcs)

Created By
Prasanna Nagarajan6 months ago
An MCP (Model Context Protocol) server implementation that connects to Microsoft Copilot Studio agents, allowing seamless integration of Copilot Studio agents with any MCP-compatible client.
Content

🤖 MCP Server for Copilot Studio Agents

An MCP (Model Context Protocol) server implementation that connects to Microsoft Copilot Studio agents, allowing seamless integration of Copilot Studio agents with any MCP-compatible client.

https://github.com/user-attachments/assets/19fdd17b-2837-4797-8653-fe9439de355f

✨ Features

  • 🔌 Connect to Copilot Studio agents through DirectLine API
  • 🧠 Maintain conversation context across multiple queries
  • 🔄 Easy integration with any MCP-compatible client
  • 💬 Stateful conversations with conversation ID and watermark tracking
  • ⚙️ Configurable agent definitions

🛠️ Tools

This MCP server exposes the following tools:

  • 📮 query_agent: Send queries to a Copilot Studio agent and receive responses
    • 🔄 Maintains conversation context across multiple queries using conversation IDs and watermarks
    • 📊 Returns structured responses with success/error status

🔧 Configuration

Pre-requisites

  • 🔐 Ensure you have a Copilot Studio agent set up and configure direct line channel security.
  • 📝 Update the agent_definitions in the src/main.py file to include your agent's details.
  • The agent_definitions should include the following fields:
    • 📛 name: The name of the agent
    • 📄 description: A brief description of the agent for the MCP client to identify the responsibility of the agent.

Environment Variables

The server requires the following environment variables:

  • 🔗 DIRECTLINE_ENDPOINT: The DirectLine API endpoint for your Copilot Studio agent
  • 🔑 COPILOT_AGENT_SECRET: Bot key for authenticating with the Copilot Studio agent via the DirectLine API

You can set these variables in a .env file in the project root directory or configure them through your system's environment variables.

📦 Installation

Prerequisites

  • 🐍 Python 3.12 or higher
  • 🚀 uv package manager (recommended) or pip

Python Setup

# Setup environment with uv
uv venv
.venv\Scripts\activate  # On Windows
source .venv/bin/activate  # On macOS/Linux

# Install dependencies
uv sync

If you prefer using pip:

# Create a virtual environment
python -m venv .venv
.venv\Scripts\activate  # On Windows
source .venv/bin/activate  # On macOS/Linux

# Install dependencies
pip install -e .

Testing with MCP Inspector

Once you activate your environment, you can run the MCP server locally using MCP Inspector.

  1. Run the MCP server using the following command:
mcp dev src/main.py
  1. You will be prompted to install the @modelcontextprotocol/inspector package. Choose y to install it.
    Install MCP Inspector

  2. Launch the MCP Inspector and connect to the MCP server.

  3. Navigate to Tools and click List Tools to view all the available tools in the MCP server.

  4. Select the query_agent tool to send queries to your Copilot Studio agent.
    MCP Inspector Result

Usage with Claude Desktop

To use with Claude Desktop, add the following to your configuration file:

  1. Download Claude Desktop and install it, if you haven't already.
  2. Navigate to File > Settings > Developer > Edit Config.
  3. Open the claude_desktop_config.json file and add the following configurations to the mcpServers section. You can use either uv, python, or docker to run the server.
    Claude Desktop Config
  4. Save the configuration file and restart Claude Desktop.
  5. Once the MCP server is added to Claude Desktop, you can view it under the tools section. Claude Desktop Tools

MCP Server Configurations for Claude Desktop

Run via uv

{
  "mcpServers": {
    "agent-name": {
      "command": "uv", // you might need to use the full path to uv if it's not in your PATH. use `which uv` to find the path.
      "args": [
        "--directory",
        "<PATH_TO_THE_PARENT_FOLDER>",
        "run",
        "mcp",
        "run",
        "<PATH_TO_THE_PARENT_FOLDER>/src/main.py"
      ],
      "env": {
        "DIRECTLINE_ENDPOINT": "endpoint-url",
        "COPILOT_AGENT_SECRET": "secret-key"
      }
    }
  }
}

Run via python

Post setup of virtual environment and installing the necessary packages, you can run the server using the following command:

{
  "mcpServers": {
    "agent-name": {
      "command": "<PATH_TO_VENV>/bin/python",
      "args": [
        "<PATH_TO_THE_PARENT_FOLDER>/src/main.py"
      ],
      "env": {
        "DIRECTLINE_ENDPOINT": "endpoint-url",
        "COPILOT_AGENT_SECRET": "secret-key"
      }
    }
  }
}

Alternatively you can install the server to Claude Desktop by running the following command (inside the virtual environment):

mcp install src/main.py -f .env

Run via docker

You can run the MCP server as a container using Docker. Ensure you have Docker installed and running on your machine.

Build the Docker image:

docker build -t mcp-server-copilot-agent .

Add the following to your Claude Desktop configuration file:

{
  "mcpServers": {
    "agent-name": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-p", "8000:8000",
        "--env-file", "<PATH_TO_THE_PARENT_FOLDER>/.env",
        "mcp-server-copilot-agent"
      ]
    }
  }
}

Once you have configured Claude Desktop with the

🌐 Usage with Other MCP Clients

This server follows the MCP protocol specification and can be used with any MCP-compatible client. Refer to your client's documentation for specific instructions on how to connect to external MCP servers.

👩‍💻 Development

To contribute to this project, set up a development environment:

# Install development dependencies
uv sync -e dev

The project uses Ruff for linting:

# Run linter
ruff check .

Server Config

{
  "mcpServers": {
    "agent-name": {
      "command": "uv",
      "args": [
        "--directory",
        "<PATH_TO_THE_PARENT_FOLDER>",
        "run",
        "mcp",
        "run",
        "<PATH_TO_THE_PARENT_FOLDER>/src/main.py"
      ],
      "env": {
        "DIRECTLINE_ENDPOINT": "endpoint-url",
        "COPILOT_AGENT_SECRET": "secret-key"
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
WindsurfThe new purpose-built IDE to harness magic
DeepChatYour AI Partner on Desktop
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Serper MCP ServerA Serper MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Playwright McpPlaywright MCP server
Amap Maps高德地图官方 MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
ChatWiseThe second fastest AI chatbot™
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Tavily Mcp
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
CursorThe AI Code Editor