FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sdk/docs_src/lowlevel/tutorial007.py at main · modelcontextprotocol/python-sdk · GitHub
modelcontextprotocol
python-sdk
Repository navigation
Code
Issues
250
(250)
Pull requests
106
(106)
Actions
Projects
Security and quality
12
(12)
Insights
Expand file tree
Breadcrumbs
python-sdk
/
docs_src
/
lowlevel
/
tutorial007.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (23 loc) · 1.17 KB
Breadcrumbs
python-sdk
/
docs_src
/
lowlevel
/
tutorial007.py
Copy path
File metadata and controls
30 lines (23 loc) · 1.17 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
from
mcp
.
server
import
Server
,
ServerRequestContext
from
mcp
.
types
import
CallToolRequestParams
,
CallToolResult
,
ListToolsResult
,
PaginatedRequestParams
,
TextContent
,
Tool
FIND_BOOK
=
Tool
(
name
=
"find_book"
,
description
=
"Find one book by ISBN, or by title and author."
,
input_schema
=
{
"type"
:
"object"
,
"properties"
: {
"isbn"
: {
"type"
:
"string"
,
"pattern"
:
"^[0-9]{13}$"
},
"title"
: {
"type"
:
"string"
},
"author"
: {
"type"
:
"string"
},
},
"oneOf"
: [{
"required"
: [
"isbn"
]}, {
"required"
: [
"title"
,
"author"
]}],
"additionalProperties"
:
False
,
},
)
async
def
list_tools
(
ctx
:
ServerRequestContext
,
params
:
PaginatedRequestParams
|
None
)
->
ListToolsResult
:
return
ListToolsResult
(
tools
=
[
FIND_BOOK
])
async
def
call_tool
(
ctx
:
ServerRequestContext
,
params
:
CallToolRequestParams
)
->
CallToolResult
:
args
=
params
.
arguments
or
{}
found
=
f"ISBN
{
args
[
'isbn'
]
}
"
if
"isbn"
in
args
else
f"
{
args
[
'title'
]!r
}
by
{
args
[
'author'
]
}
"
return
CallToolResult
(
content
=
[
TextContent
(
type
=
"text"
,
text
=
f"Found
{
found
}
on shelf C-3."
)])
server
=
Server
(
"Bookshop"
,
on_list_tools
=
list_tools
,
on_call_tool
=
call_tool
)
Back
|
FazBrowse Home
|
New Git URL