Skip to content

MCP servers in CustomAgentConfig are not exposed to the agent during execution #553

@galiacheng

Description

@galiacheng

Description

When creating a custom agent with MCP servers using the Copilot SDK, the MCP server tools are not available to the agent during execution, even though the CustomAgentConfig.McpServers property is properly populated and passed to the session.

Environment

  • Copilot SDK Version: 0.1.25
  • .NET Version: 10.0
  • OS: Linux
  • Copilot CLI: Installed and working

Expected Behavior

When a custom agent is created with MCP servers specified in CustomAgentConfig.McpServers:

var agentConfig = new CustomAgentConfig
{
    Name = "test-agent",
    Description = "A test agent that uses an MCP server",
    Prompt = "...",
    McpServers = mcpServers  // Dictionary<string, object> with MCP config
};

var session = await client.CreateSessionAsync(new SessionConfig
{
    CustomAgents = [agentConfig],
    ConfigDir = configPath
});

The agent should have access to tools from the MCP servers when invoked with @test-agent.

Actual Behavior

The custom agent can only access standard Copilot CLI tools (view, create, edit, grep, bash, etc.) but NOT the tools from the MCP servers specified in CustomAgentConfig.McpServers.

Test Output

✅ Loaded MCP server configurations: 1 server(s)
   - AppModJavaUpgrade

✅ Created custom agent: test-agent
   MCP Servers: 1

--- Invoking Custom Agent ---
Prompt: @test-agent Please scan TestApp.java and suggest how to upgrade it

✅ Received 2 message(s)
   Tool executions: 5
   Tools used: report_intent, task, view, show_file

❌ MCP tools NOT USED by the agent!
   Expected tools like: appmod-get-plan, appmod-scan-project, etc.

The agent successfully responds but only uses standard CLI tools, never the MCP tools.

Steps to Reproduce

I've created a minimal test project that reproduces this issue:

1. Test Project Structure

McpTest/
├── Program.cs                  # Creates custom agent with MCP servers
├── McpTest.csproj             
└── config/
    └── mcp-configs/
        └── test-mcp.json      # MCP server configuration

2. MCP Configuration (config/mcp-configs/test-mcp.json)

{
  "mcpServers": {
    "AppModJavaUpgrade": {
      "type": "local",
      "command": "npx",
      "args": [
        "-y",
        "-p",
        "@microsoft/github-copilot-app-modernization-mcp-server",
        "github-copilot-app-modernization-mcp-server",
        "--loglevel",
        "verbose",
        "--callerType",
        "copilot-cli",
        "--serverType",
        "javaUpgrade"
      ],
      "tools": ["*"]
    }
  }
}

3. Test Code (Program.cs)

// Load MCP server configuration
var configPath = Path.Combine(Directory.GetCurrentDirectory(), "config");
var mcpServers = LoadMcpServers(configPath, "AppModJavaUpgrade");

// Create custom agent with MCP servers
var agentConfig = new CustomAgentConfig
{
    Name = "test-agent",
    Description = "A test agent that uses an MCP server",
    Prompt = "You are a test agent with access to MCP server tools...",
    McpServers = mcpServers  // ✅ This is populated correctly
};

// Create Copilot client and session
var client = new CopilotClient(new CopilotClientOptions
{
    CliPath = "copilot",
    Cwd = Directory.GetCurrentDirectory(),
    UseStdio = true
});

await client.StartAsync();

var session = await client.CreateSessionAsync(new SessionConfig
{
    CustomAgents = [agentConfig],
    ConfigDir = configPath
});

// Invoke the custom agent
await session.SendAsync(new MessageOptions
{
    Prompt = "@test-agent Please scan TestApp.java and suggest upgrades"
});

4. Run Test

dotnet build
dotnet run

5. Observe Results

  • ✅ Session creates successfully
  • ✅ Custom agent is loaded
  • ✅ Agent responds to messages
  • Agent never uses MCP tools (only standard CLI tools)

Analysis

The issue appears to be that while CustomAgentConfig.McpServers is accepted by the SDK and passed to CreateSessionAsync, those MCP servers are not being:

  1. Started/initialized for the custom agent
  2. Registered as available tools for the custom agent
  3. Exposed to the agent when it's invoked with @agent-name

Comparison with Working Scenario

When MCP servers are passed directly to SessionConfig.McpServers (not inside a custom agent), they work correctly. The issue is specific to MCP servers defined within a CustomAgentConfig.

Workaround

None found. The feature appears to be partially implemented (the property exists and is accepted) but non-functional.

Impact

This prevents custom agents from using MCP tools, which is a key use case for building domain-specific agents with custom tooling.

Full Reproduction Project

The complete test project is available at:

McpTest-repro.zip

It includes:

  • Full working code demonstrating the issue
  • MCP server configuration
  • Documentation
  • Build/run instructions

Additional Notes

  • The LoadMcpServers function successfully loads MCP configurations from JSON
  • The CustomAgentConfig.McpServers property is properly populated (verified with logging)
  • Session creation succeeds without errors
  • The agent can be invoked and responds correctly
  • Only the MCP tools exposure is failing

Questions

  1. Is the CustomAgentConfig.McpServers property fully implemented, or is this a known limitation?
  2. Should MCP servers for custom agents be configured differently?
  3. Is there additional setup required beyond setting the McpServers property?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions