Skip to content

Conversation

@pratapladhani
Copy link

Add gateway endpoint to mock tooling server for local agent testing

Problem

  • .NET agents expect a platform gateway endpoint at /agents/{agentInstanceId}/mcpServers to discover available MCP servers
  • The mock server only provided direct MCP endpoints (/mcp/sse, /agents/servers/{name})
  • This caused MCP tool loading failures during local testing, resulting in 404 errors when agents tried to discover MCP servers

Solution

  • Added /agents/{agentInstanceId}/mcpServers gateway endpoint to Server.cs
  • The endpoint returns an MCP server discovery list matching the ToolingManifest.json structure expected by the platform
  • Added startup logging to indicate the gateway endpoint is available
  • Response includes mcpServerName, mcpServerUniqueName, url, scope, and audience for each configured MCP server

Changes

File Change
src/Microsoft.Agents.A365.DevTools.MockToolingServer/Server.cs Added gateway endpoint implementation (+36 lines)

Testing

  • Verified with local agent + Agent Playground
  • Successfully loaded 32 MCP tools (12 Calendar + 20 Mail)
  • Agent correctly executes operations using mock calendar/mail tools
  • No regressions to existing endpoints (/mcp/sse, /mcp/schema.json, /health)

Related

Enables Phase 6 local testing workflow for agent development

Problem:
- .NET agents expect a platform gateway endpoint at /agents/{agentInstanceId}/mcpServers
- Mock server only provided direct MCP endpoints (/mcp/sse, /agents/servers/{name})
- This caused MCP tool loading failures during local testing with 404 errors

Solution:
- Added /agents/{agentInstanceId}/mcpServers endpoint (lines 208-241)
- Endpoint returns MCP server discovery list matching ToolingManifest.json structure
- Added logging statement for gateway endpoint at startup (line 81)

Testing:
- Verified with local agent + Agent Playground
- Successfully loaded 32 MCP tools (12 Calendar + 20 Mail)
- Agent now correctly schedules meetings using mock calendar tools

Related: Enables Phase 6 local testing workflow
@pratapladhani pratapladhani requested review from a team as code owners January 27, 2026 00:00
Copilot AI review requested due to automatic review settings January 27, 2026 00:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a platform gateway endpoint to the mock tooling server to enable local agent testing with MCP server discovery. Previously, .NET agents received 404 errors when trying to discover MCP servers through the expected /agents/{agentInstanceId}/mcpServers endpoint, as the mock server only provided direct MCP endpoints.

Changes:

  • Added /agents/{agentInstanceId}/mcpServers gateway endpoint that returns MCP server discovery information
  • Included startup logging to indicate gateway endpoint availability
  • Response structure matches the platform's ToolingManifest.json format with proper fields (mcpServerName, mcpServerUniqueName, url, scope, audience)

Comment on lines +212 to +242
app.MapGet("/agents/{agentInstanceId}/mcpServers", (string agentInstanceId, ILogger<Program> log) =>
{
try
{
log.LogInformation("Gateway endpoint called for agent instance: {AgentInstanceId}", agentInstanceId);

// Get the configured server port from the URLs
var serverUrl = app.Urls.FirstOrDefault() ?? "http://localhost:5309";

// Build the MCP server list matching ToolingManifest.json structure
var mcpServers = mcpServerNames.Select(serverName => new
{
mcpServerName = serverName,
mcpServerUniqueName = serverName,
url = $"{serverUrl}/agents/servers/{serverName}",
scope = "offline_access",
audience = serverUrl
}).ToArray();

log.LogInformation("Returning {Count} MCP servers: {Servers}",
mcpServers.Length,
string.Join(", ", mcpServerNames));

return Results.Json(new { mcpServers });
}
catch (Exception ex)
{
log.LogError(ex, "Failed to process gateway endpoint request");
return Results.Problem(ex.Message, statusCode: 500);
}
});
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new gateway endpoint lacks test coverage. While this is a development/mock server and other endpoints in this file also lack direct tests, consider adding an integration test to verify the endpoint returns the expected JSON structure with the correct MCP server list. This would help prevent regressions if the endpoint behavior needs to change in the future.

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +228
scope = "offline_access",
audience = serverUrl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are not used by the SDK and can be safely removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants