FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sdk/tests/client/test_stdio.py at main · pqbas/python-sdk · GitHub
pqbas
/
python-sdk
Public
forked from
modelcontextprotocol/python-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-sdk
/
tests
/
client
/
test_stdio.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (33 loc) · 1.41 KB
Breadcrumbs
python-sdk
/
tests
/
client
/
test_stdio.py
Copy path
File metadata and controls
43 lines (33 loc) · 1.41 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
import
shutil
import
pytest
from
mcp
.
client
.
stdio
import
StdioServerParameters
,
stdio_client
from
mcp
.
types
import
JSONRPCMessage
,
JSONRPCRequest
,
JSONRPCResponse
tee
:
str
=
shutil
.
which
(
"tee"
)
# type: ignore
@
pytest
.
mark
.
anyio
@
pytest
.
mark
.
skipif
(
tee
is
None
,
reason
=
"could not find tee command"
)
async
def
test_stdio_client
():
server_parameters
=
StdioServerParameters
(
command
=
tee
)
async
with
stdio_client
(
server_parameters
)
as
(
read_stream
,
write_stream
):
# Test sending and receiving messages
messages
=
[
JSONRPCMessage
(
root
=
JSONRPCRequest
(
jsonrpc
=
"2.0"
,
id
=
1
,
method
=
"ping"
)),
JSONRPCMessage
(
root
=
JSONRPCResponse
(
jsonrpc
=
"2.0"
,
id
=
2
,
result
=
{})),
]
async
with
write_stream
:
for
message
in
messages
:
await
write_stream
.
send
(
message
)
read_messages
=
[]
async
with
read_stream
:
async
for
message
in
read_stream
:
if
isinstance
(
message
,
Exception
):
raise
message
read_messages
.
append
(
message
)
if
len
(
read_messages
)
==
2
:
break
assert
len
(
read_messages
)
==
2
assert
read_messages
[
0
]
==
JSONRPCMessage
(
root
=
JSONRPCRequest
(
jsonrpc
=
"2.0"
,
id
=
1
,
method
=
"ping"
)
)
assert
read_messages
[
1
]
==
JSONRPCMessage
(
root
=
JSONRPCResponse
(
jsonrpc
=
"2.0"
,
id
=
2
,
result
=
{})
)
Back
|
FazBrowse Home
|
New Git URL