Skip to content

Python: Skip MCP prompt loading when unsupported#5370

Open
karimbaidar wants to merge 1 commit intomicrosoft:mainfrom
karimbaidar:karimbaidar/issue-5360-mcp-prompts
Open

Python: Skip MCP prompt loading when unsupported#5370
karimbaidar wants to merge 1 commit intomicrosoft:mainfrom
karimbaidar:karimbaidar/issue-5360-mcp-prompts

Conversation

@karimbaidar
Copy link
Copy Markdown

Motivation and Context

Fixes #5360.

MCP servers can advertise tools without supporting prompts. The client was still calling prompts/list whenever prompt loading was enabled, so tool-only servers could fail during connect.

Description

Stores the server capabilities returned by MCP initialization and skips prompt discovery when the server does not advertise the prompts capability. If capabilities are unavailable, the existing behavior is preserved.

Adds a focused core MCP regression test for a tool-only server that would otherwise raise Method 'prompts/list' is not available.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? No

@karimbaidar
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@moonbox3
Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py6253294%153, 295, 355–356, 485, 547, 560, 562–565, 584–585, 598–601, 603–604, 608, 672–674, 722–723, 1047, 1160, 1212–1213, 1216, 1234, 1687
TOTAL28386330088% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5666 30 💤 0 ❌ 0 🔥 1m 36s ⏱️

Copy link
Copy Markdown
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 fixes MCP client connections to tool-only servers by honoring negotiated server capabilities from MCP initialization, avoiding prompt discovery calls when the server does not support prompts.

Changes:

  • Cache MCP initialize() capabilities on MCPTool and use them to detect prompt support.
  • Skip prompts/list discovery when the server does not advertise the prompts capability (preserving existing behavior when capabilities are unavailable).
  • Add a regression test ensuring prompt discovery is skipped for tool-only servers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/core/agent_framework/_mcp.py Store negotiated server capabilities and gate prompt loading on prompts capability support.
python/packages/core/tests/core/test_mcp.py Add regression coverage for connecting to a server that supports tools but not prompts.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Found capabilities during initialize are not respected and is throwing exception

3 participants