Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Implementation Plan: Chat History API for MCP Platform

Based on the .NET SDK implementation in PR #148.

Changes Required:

  • Create ChatHistoryMessage model class
  • Create ChatMessageRequest model class
  • Create OperationResult and OperationError classes
  • Add get_chat_history_endpoint() utility function
  • Add send_chat_history() method to McpToolServerConfigurationService
  • Update model exports in __init__.py files
  • Create unit tests for new models and functionality
  • Add comprehensive unit tests for send_chat_history method
  • Address PR feedback:
    • Updated copyright headers to # Copyright (c) Microsoft Corporation. and # Licensed under the MIT License.
    • Removed examples/send_chat_history_example.py
    • Updated send_chat_history to use TurnContext parameter instead of conversation_id, message_id, user_message
    • Removed auth_token parameter (no authentication required for this endpoint)
    • Added type annotation for turn_context parameter as TurnContext
    • Removed TYPE_CHECKING conditional import and always import TurnContext
    • Added microsoft-agents-hosting-core as a dependency in pyproject.toml
    • Ran uv run --frozen ruff format . to format code correctly
    • Updated datetime import style for consistency across test files

Summary:

✅ Successfully implemented generic API to send chat history to MCP platform
✅ All tests passing (39 unit tests total: 27 for models + 12 for send_chat_history method)
✅ Code follows repository conventions and passes linting
✅ All PR feedback addressed
✅ TurnContext properly imported with dependency added
✅ Comprehensive test coverage including validation, error handling, and success scenarios
✅ Code properly formatted with ruff
✅ Consistent datetime import style across all test files

Original prompt

This section details on the original issue you should resolve

<issue_title>Implementation of API to send chat history to MCP platform.</issue_title>
<issue_description>Implement the generic API to send chat history to MCP platform. Follow the changes that were made for the .NET version of the SDK: microsoft/Agent365-dotnet#148</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Implement API to send chat history to MCP platform Add API to send chat history to MCP platform for threat protection Jan 8, 2026
Copilot AI requested a review from pontemonti January 8, 2026 00:46
@pontemonti
Copy link
Contributor

@copilot -

  1. Update the copyright headers in the added and updated files:
    # Copyright (c) Microsoft Corporation.
    # Licensed under the MIT License.
    
  2. Remove examples/send_chat_history_example.py
  3. In send_chat_history, do not include an auth_token parameter. This request does not require authentication.
  4. In send_chat_history, include TurnContext (from Agents SDK) as parameter instead of conversation_id, message_id and user_message. Those values can be retrieved from TurnContext.

…se TurnContext, remove auth

Co-authored-by: pontemonti <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot -

  1. Update the copyright headers in the added and updated files:

...

All feedback addressed in commit 6c49d71:

  1. ✅ Updated copyright headers to # Copyright (c) Microsoft Corporation. and # Licensed under the MIT License. in all added and updated files
  2. ✅ Removed examples/send_chat_history_example.py
  3. ✅ Removed auth_token parameter from send_chat_history - no authentication headers are now sent
  4. ✅ Updated send_chat_history to accept turn_context parameter - extracts conversation_id, message_id, and user_message from turn_context.activity

…nts-hosting-core dependency

Co-authored-by: pontemonti <[email protected]>
@pontemonti
Copy link
Contributor

@copilot - add tests for send_chat_history

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot - add tests for send_chat_history

Added comprehensive unit tests in commit 4443b7d. Created 12 tests covering:

  • Successful requests
  • HTTP error responses
  • Custom options
  • Parameter validation (turn_context, chat_history_messages, activity, conversation_id, message_id, user_message)
  • Error handling (ClientError, TimeoutError)
  • Correct payload generation

All 39 tests (27 existing + 12 new) passing.

@pontemonti
Copy link
Contributor

@copilot - run uv run --frozen ruff format . to format the code correctly

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot - run uv run --frozen ruff format . to format the code correctly

Code formatted in commit 1b6f196. Ran uv run --frozen ruff format . which reformatted 2 files (service and test file) with proper whitespace and line length adjustments.

Copilot AI requested a review from pontemonti January 8, 2026 04:36
@pontemonti pontemonti marked this pull request as ready for review January 8, 2026 04:41
@pontemonti pontemonti requested a review from a team as a code owner January 8, 2026 04:41
Copilot AI review requested due to automatic review settings January 8, 2026 04:41
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 implements a generic API to send chat history to the MCP (Model Context Protocol) platform for real-time threat protection, following the pattern established in the .NET SDK implementation (PR #148).

Key Changes:

  • Added new model classes (ChatHistoryMessage, ChatMessageRequest) for structuring chat history data
  • Added operation result classes (OperationResult, OperationError) for standardized error handling
  • Implemented send_chat_history() method in McpToolServerConfigurationService that extracts conversation data from TurnContext and sends it to the MCP platform

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/models/chat_history_message.py New model class representing a single chat message with validation
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/models/chat_message_request.py New model class representing the complete request payload for threat protection
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/operation_result.py New class for representing operation success/failure states
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/operation_error.py New class for wrapping exceptions in operation results
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py Added send_chat_history() method with comprehensive validation and error handling
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/utils/utility.py Added get_chat_history_endpoint() utility function for endpoint URL construction
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/models/init.py Updated exports to include new model classes
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/init.py Updated exports to include new runtime classes
libraries/microsoft-agents-a365-tooling/pyproject.toml Added microsoft-agents-hosting-core dependency for TurnContext
tests/tooling/models/test_chat_history_message.py Comprehensive unit tests for ChatHistoryMessage model (7 test cases)
tests/tooling/models/test_chat_message_request.py Comprehensive unit tests for ChatMessageRequest model (6 test cases)
tests/runtime/test_operation_result.py Comprehensive unit tests for OperationResult class (9 test cases)
tests/runtime/test_operation_error.py Comprehensive unit tests for OperationError class (5 test cases)
tests/tooling/services/test_send_chat_history.py Comprehensive unit tests for send_chat_history method (12 test cases covering success, error handling, and validation)
tests/tooling/init.py New test package initialization with correct copyright header
tests/tooling/models/init.py New test package initialization with correct copyright header
tests/tooling/services/init.py New test package initialization with correct copyright header

@pontemonti pontemonti enabled auto-merge (squash) January 8, 2026 05:10
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.

Implementation of API to send chat history to MCP platform.

2 participants