Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { v4 as uuidv4 } from 'uuid';
import { McpToolServerConfigurationService, Utility, ToolOptions, ChatHistoryMessage } from '@microsoft/agents-a365-tooling';
import { AgenticAuthenticationService, Utility as RuntimeUtility, OperationResult } from '@microsoft/agents-a365-runtime';
import { AgenticAuthenticationService, Utility as RuntimeUtility, OperationResult, OperationError } from '@microsoft/agents-a365-runtime';

// Agents SDK
import { TurnContext, Authorization } from '@microsoft/agents-hosting';
Expand Down Expand Up @@ -117,10 +117,18 @@ export class McpToolRegistrationService {
throw new Error('session is required');
}

// Extract messages from session
const items = await session.getItems(limit);
let items: AgentInputItem[];
try {
// Extract messages from session
items = await session.getItems(limit);
} catch (err: unknown) {
// Convert errors from session.getItems() into a failed OperationResult
const error = err as Error;
return OperationResult.failed(new OperationError(error));
}

// Delegate to the list-based method
// Validation errors from this method will propagate
return await this.sendChatHistoryMessagesAsync(
turnContext,
items,
Expand Down
9 changes: 8 additions & 1 deletion tests/tooling-extensions-openai/sendChatHistoryAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ describe('McpToolRegistrationService - sendChatHistoryAsync', () => {
const result = await service.sendChatHistoryAsync(mockTurnContext, mockSession as unknown as OpenAIConversationsSession);

expect(result.succeeded).toBe(true);
// Even with an empty array, sendChatHistoryAsync should invoke the underlying HTTP call
// Even with empty array, API call should be made to MCP platform
expect(mockedAxios.post).toHaveBeenCalledTimes(1);
const callArgs = mockedAxios.post.mock.calls[0];
expect(callArgs[1]).toEqual({
conversationId: 'conv-123',
messageId: 'msg-456',
userMessage: 'Current user message',
chatHistory: []
});
});

it('should pass toolOptions to the underlying service', async () => {
Expand Down