Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
php-sdk/tests/Integration/ElicitationTest.php at main · modelcontextprotocol/php-sdk · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
modelcontextprotocol
php-sdk
Repository navigation
Code
Issues
48
(48)
Pull requests
9
(9)
Actions
Projects
Security and quality
1
(1)
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
php-sdk
/
tests
/
Integration
/
ElicitationTest.php
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
129 lines (107 loc) · 4.66 KB
main
Breadcrumbs
php-sdk
/
tests
/
Integration
/
ElicitationTest.php
Copy path
Top
File metadata and controls
Code
Blame
129 lines (107 loc) · 4.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Mcp
\
Tests
\
Integration
;
use
Mcp
\
Client
\
Builder
as
ClientBuilder
;
use
Mcp
\
Client
\
Handler
\
Request
\
ElicitationCallbackInterface
;
use
Mcp
\
Client
\
Handler
\
Request
\
ElicitationRequestHandler
;
use
Mcp
\
Exception
\
RuntimeException
;
use
Mcp
\
Schema
\
ClientCapabilities
;
use
Mcp
\
Schema
\
Content
\
TextContent
;
use
Mcp
\
Schema
\
Enum
\
ElicitAction
;
use
Mcp
\
Schema
\
Enum
\
ProtocolVersion
;
use
Mcp
\
Schema
\
Request
\
ElicitRequest
;
use
Mcp
\
Schema
\
Result
\
ElicitResult
;
use
PHPUnit
\
Framework
\
Attributes
\
TestDox
;
/**
* Elicitation, driven all the way around the loop.
*
* The round-trip that suspends both sides at once: the tool's Fiber waits on
* the client while the client's request Fiber waits on the tool.
*
* @see Fixture/elicitation.php for the server under test
*/
final
class
ElicitationTest
extends
IntegrationTestCase
{
#[TestDox(
'
an accepted elicitation hands the content back to the tool
'
)]
public
function
testAcceptedElicitation
():
void
{
$
client
=
$
this
->
connect
(
'
elicitation
'
,
$
this
->
clientAnswering
(
new
ElicitResult
(ElicitAction::Accept, [
'
name
'
=>
'
Ada
'
]),
));
$
result
=
$
client
->
callTool
(
'
ask_name
'
);
$
this
->
assertFalse
(
$
result
->
isError
);
$
this
->
assertInstanceOf
(TextContent::class,
$
result
->
content
[
0
]);
$
this
->
assertSame
(
'
accept:Ada
'
,
$
result
->
content
[
0
]->
text
);
}
#[TestDox(
'
a declined elicitation reaches the tool as a decline, not an error
'
)]
public
function
testDeclinedElicitation
():
void
{
$
client
=
$
this
->
connect
(
'
elicitation
'
,
$
this
->
clientAnswering
(
new
ElicitResult
(ElicitAction::Decline),
));
$
result
=
$
client
->
callTool
(
'
ask_name
'
);
$
this
->
assertInstanceOf
(TextContent::class,
$
result
->
content
[
0
]);
$
this
->
assertSame
(
'
decline:
'
,
$
result
->
content
[
0
]->
text
);
}
#[TestDox(
'
a client that does not advertise elicitation is not asked
'
)]
public
function
testCapabilityIsVisibleToTheServer
():
void
{
// The tool consults supportsElicitation(), which answers from the
// capabilities this client declared.
$
client
=
$
this
->
connect
(
'
elicitation
'
);
$
result
=
$
client
->
callTool
(
'
ask_name
'
);
$
this
->
assertInstanceOf
(TextContent::class,
$
result
->
content
[
0
]);
$
this
->
assertSame
(
'
unsupported
'
,
$
result
->
content
[
0
]->
text
);
}
#[TestDox(
'
a client advertising elicitation without a handler fails the tool call
'
)]
public
function
testAdvertisedCapabilityWithoutHandler
():
void
{
// The client answers "method not found", which the gateway raises inside
// the tool as a ClientException rather than leaving it waiting.
$
client
=
$
this
->
connect
(
'
elicitation
'
,
$
this
->
clientBuilder
()
->
setProtocolVersion
(ProtocolVersion::
V2025_11_25
)
->
setCapabilities
(
new
ClientCapabilities
(elicitation:
true
)),
);
$
result
=
$
client
->
callTool
(
'
ask_name
'
);
$
this
->
assertInstanceOf
(TextContent::class,
$
result
->
content
[
0
]);
$
this
->
assertSame
(
'
Client does not handle "elicitation/create" requests.
'
,
$
result
->
content
[
0
]->
text
);
}
#[TestDox(
'
on the modern era, an ask the client advertised but cannot answer fails the call on the client
'
)]
public
function
testAdvertisedCapabilityWithoutHandlerOnTheModernEra
():
void
{
$
client
=
$
this
->
connect
(
'
elicitation
'
,
$
this
->
clientBuilder
()
->
setProtocolVersion
(ProtocolVersion::
V2026_07_28
)
->
setCapabilities
(
new
ClientCapabilities
(elicitation:
true
)),
);
$
this
->
assertSame
(ProtocolVersion::
V2026_07_28
,
$
client
->
getProtocolVersion
());
$
this
->
expectException
(RuntimeException::class);
$
this
->
expectExceptionMessage
(
'
Client does not handle "elicitation/create" requests.
'
);
$
client
->
callTool
(
'
ask_name
'
);
}
private
function
clientAnswering
(
ElicitResult
$
answer
):
ClientBuilder
{
$
callback
=
new
class
(
$
answer
)
implements
ElicitationCallbackInterface {
public
function
__construct
(
private
readonly
ElicitResult
$
answer
)
{
}
public
function
__invoke
(
ElicitRequest
$
request
):
ElicitResult
{
return
$
this
->
answer
;
}
};
return
$
this
->
clientBuilder
()
->
setCapabilities
(
new
ClientCapabilities
(elicitation:
true
))
->
addRequestHandler
(
new
ElicitationRequestHandler
(
$
callback
));
}
}
You can’t perform that action at this time.