Skip to content

feat: add elicitation callback support to MCP servers #2373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

yamanahlawat
Copy link
Contributor

@yamanahlawat yamanahlawat commented Jul 30, 2025

Copy link
Contributor

hyperlint-ai bot commented Jul 31, 2025

PR Change Summary

Added support for elicitation callbacks in MCP servers, allowing user interaction during tool execution.

  • Introduced elicitation callback functionality for user input during tool execution.
  • Provided examples for setting up elicitation in MCP server and client.
  • Included practical use case for file deletion confirmation.

Modified Files

  • docs/mcp/client.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

@yamanahlawat yamanahlawat requested a review from DouweM July 31, 2025 18:28
Copy link
Collaborator

@DouweM DouweM left a comment

Choose a reason for hiding this comment

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

@yamanahlawat The code and test looks good but the examples are wrong 😅

@yamanahlawat yamanahlawat requested a review from DouweM August 1, 2025 17:21
Copy link
Collaborator

@DouweM DouweM left a comment

Choose a reason for hiding this comment

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

@yamanahlawat Still some issues with the examples, did you verify they actually work? They smell a bit AI generated to me with too little human oversight 😅 I realize this isn't the feature you were initially trying to implement, but unfortunately we can't get to that one until this feature it builds on is solid so I'd appreciate a bit more love for the examples here

@yamanahlawat
Copy link
Contributor Author

@yamanahlawat Still some issues with the examples, did you verify they actually work? They smell a bit AI generated to me with too little human oversight 😅 I realize this isn't the feature you were initially trying to implement, but unfortunately we can't get to that one until this feature it builds on is solid so I'd appreciate a bit more love for the examples here

Guilty as charged. Thanks for the feedback. Here is my updated love for the docs, let me know if any other changes are required.

@yamanahlawat
Copy link
Contributor Author

image

@yamanahlawat yamanahlawat requested a review from DouweM August 2, 2025 09:52
@DouweM
Copy link
Collaborator

DouweM commented Aug 6, 2025

@Kludex Can you please review this as our resident MCP expert? I'm thinking it would be more proper to add our own types instead of directly using those from mcp.

@Kludex
Copy link
Member

Kludex commented Aug 8, 2025

@Kludex Can you please review this as our resident MCP expert? I'm thinking it would be more proper to add our own types instead of directly using those from mcp.

I think it would be easier if we use their types.

@yamanahlawat
Copy link
Contributor Author

yamanahlawat commented Aug 11, 2025

@DouweM Can we merge this? or i'll add the server logic in this PR?

@@ -100,7 +100,7 @@ Will display as follows:
[`MCPServerSSE`][pydantic_ai.mcp.MCPServerSSE] connects over HTTP using the [HTTP + Server Sent Events transport](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#http-with-sse) to a server.

!!! note
[`MCPServerSSE`][pydantic_ai.mcp.MCPServerSSE] requires an MCP server to be running and accepting HTTP connections before running the agent. Running the server is not managed by Pydantic AI.
Copy link
Member

Choose a reason for hiding this comment

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

You need to revert those changes.



@mcp.tool()
async def use_elicitation(ctx: Context[ServerSessionT, LifespanContextT, RequestT], question: str) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

This is not the correct type.

It's probably this:

Suggested change
async def use_elicitation(ctx: Context[ServerSessionT, LifespanContextT, RequestT], question: str) -> str:
async def use_elicitation(ctx: Context[ServerSession, None], question: str) -> str:

Comment on lines +43 to +49
__all__ = (
'MCPServer',
'MCPServerStdio',
'MCPServerHTTP',
'MCPServerSSE',
'MCPServerStreamableHTTP',
)
Copy link
Member

Choose a reason for hiding this comment

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

Revert please.

if __name__ == '__main__':
mcp.run(transport='stdio')
```

Copy link
Member

Choose a reason for hiding this comment

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

We need something written here.

Comment on lines +525 to +527
### Supported Schema Types

MCP elicitation supports string, number, boolean, and enum types with flat object structures only. These limitations ensure reliable cross-client compatibility. See [supported schema types](https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation#supported-schema-types) for details.
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

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

Successfully merging this pull request may close these issues.

3 participants