-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
1416d6c
0a71a30
9e9693e
d4cea64
bb22ba7
1294ca5
dfb2c27
5087505
4f1af20
f6ca999
a7bc91a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ | |||||
TextContent, | ||||||
TextResourceContents, | ||||||
) | ||||||
from pydantic import AnyUrl | ||||||
from pydantic import AnyUrl, BaseModel | ||||||
|
||||||
mcp = FastMCP('Pydantic AI MCP Server') | ||||||
log_level = 'unset' | ||||||
|
@@ -186,7 +186,7 @@ async def echo_deps(ctx: Context[ServerSessionT, LifespanContextT, RequestT]) -> | |||||
|
||||||
|
||||||
@mcp.tool() | ||||||
async def use_sampling(ctx: Context, foo: str) -> str: # type: ignore | ||||||
async def use_sampling(ctx: Context[ServerSessionT, LifespanContextT, RequestT], foo: str) -> str: | ||||||
"""Use sampling callback.""" | ||||||
|
||||||
result = await ctx.session.create_message( | ||||||
|
@@ -202,6 +202,22 @@ async def use_sampling(ctx: Context, foo: str) -> str: # type: ignore | |||||
return result.model_dump_json(indent=2) | ||||||
|
||||||
|
||||||
class UserResponse(BaseModel): | ||||||
response: str | ||||||
|
||||||
|
||||||
@mcp.tool() | ||||||
async def use_elicitation(ctx: Context[ServerSessionT, LifespanContextT, RequestT], question: str) -> str: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the correct type. It's probably this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i noticed the other mcp test functions ( |
||||||
"""Use elicitation callback to ask the user a question.""" | ||||||
|
||||||
result = await ctx.elicit(message=question, schema=UserResponse) | ||||||
|
||||||
if result.action == 'accept' and result.data: | ||||||
return f'User responded: {result.data.response}' | ||||||
else: | ||||||
return f'User {result.action}ed the elicitation' | ||||||
|
||||||
|
||||||
@mcp._mcp_server.set_logging_level() # pyright: ignore[reportPrivateUsage] | ||||||
async def set_logging_level(level: str) -> None: | ||||||
global log_level | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.