Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 28, 2025

This PR makes the .well-known/agent-card.json URL optional when hosting an A2A agent by separating it from the core JSON-RPC functionality.

Problem

Previously, the MapA2A method automatically mapped both the JSON-RPC endpoint and the well-known agent discovery endpoint:

app.MapA2A(taskManager, "/agent");
// This mapped BOTH:
// - POST /agent (JSON-RPC endpoint) 
// - GET /.well-known/agent.json (agent discovery)

This forced all A2A agents to expose discovery information, even when it wasn't desired for security or architectural reasons.

Solution

Split the functionality into two separate extension methods:

// Option 1: JSON-RPC only (no agent discovery)
app.MapA2A(taskManager, "/agent");

// Option 2: Agent discovery only
app.MapWellKnownAgentCard(taskManager, "/agent");

// Option 3: Both (maintains previous behavior)
app.MapA2A(taskManager, "/agent");
app.MapWellKnownAgentCard(taskManager, "/agent");

Changes Made

  • Modified MapA2A: Removed the well-known endpoint mapping, now only handles JSON-RPC
  • Added MapWellKnownAgentCard: New extension method that maps only the /.well-known/agent.json endpoint
  • Updated samples: All sample applications now explicitly call both methods to preserve existing functionality
  • Added comprehensive tests: New test suite validates independent operation of both methods

Benefits

  • Flexibility: Developers can choose whether to expose agent discovery
  • Security: Agents can be hosted without exposing discovery information
  • Backward compatibility: Existing behavior is preserved by calling both methods
  • Separation of concerns: JSON-RPC handling and agent discovery are now logically separate

This approach follows the pattern used by other A2A implementations and provides the granular control requested in the issue.

Fixes #105.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] It should be possible to host an A2A agent without the .well-known/agent-card.json URL Separate well-known agent card endpoint from MapA2A method Jul 28, 2025
Copilot AI requested a review from brandonh-msft July 28, 2025 21:56
Copilot finished work on behalf of brandonh-msft July 28, 2025 21:56
@brandonh-msft brandonh-msft marked this pull request as ready for review July 28, 2025 22:05
@brandonh-msft brandonh-msft changed the title Separate well-known agent card endpoint from MapA2A method feat: Separate well-known agent card endpoint from MapA2A method Jul 28, 2025
@brandonh-msft
Copy link
Collaborator

@copilot don't use aspnet testhost; it's not net8 compatible

Copy link
Contributor Author

Copilot AI commented Jul 28, 2025

@copilot don't use aspnet testhost; it's not net8 compatible

Fixed in commit 19c718b. Removed all usage of Microsoft.AspNetCore.TestHost and UseTestServer(). The tests now use unit testing approach that verifies endpoint registration without requiring a test server, following the same pattern as other tests in the project.

Copilot finished work on behalf of brandonh-msft July 28, 2025 22:26
@brandonh-msft brandonh-msft enabled auto-merge July 28, 2025 22:31
Copy link
Collaborator

@brandonh-msft brandonh-msft left a comment

Choose a reason for hiding this comment

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

solved roslyn analyzer issues & tested locally w/ the Echo sample. the /echo/v1/card still gives back the card, but /.well-known/agent.json does not.

Do we want the /v1/card to be dead unless we map well-known as well, @darrelmiller ?

Copy link
Collaborator

@darrelmiller darrelmiller left a comment

Choose a reason for hiding this comment

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

Love it! Thanks.

@brandonh-msft brandonh-msft added this pull request to the merge queue Jul 31, 2025
Merged via the queue into main with commit 1d82cb4 Jul 31, 2025
4 checks passed
@brandonh-msft brandonh-msft deleted the copilot/fix-105 branch July 31, 2025 16:27
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.

It should be possible to host an A2A agent without the .well-known/agent-card.json URL

3 participants