Initial public release
Browse files- LICENSE +21 -0
- README.md +33 -0
- notebooks/01_query_the_mcp_registry.ipynb +62 -0
- notebooks/02_validate_a_server_json.ipynb +63 -0
- notebooks/03_a_local_mcp_server.ipynb +68 -0
- notebooks/04_build_an_a2a_agent_card.ipynb +60 -0
- notebooks/05_write_an_llms_txt.ipynb +57 -0
- notebooks/06_score_tool_calls_against_a_mock.ipynb +65 -0
- pytest.ini +2 -0
- requirements.txt +5 -0
- tests/test_notebooks.py +28 -0
- tools/make_notebooks.py +162 -0
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 markedet
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Agent builder notebooks
|
| 2 |
+
|
| 3 |
+
Six short, runnable Jupyter notebooks for people who build agents and MCP servers.
|
| 4 |
+
|
| 5 |
+
| Notebook | What it shows | Network |
|
| 6 |
+
|---|---|---|
|
| 7 |
+
| 01_query_the_mcp_registry | read one page of the Official MCP Registry API and count transports | public registry API |
|
| 8 |
+
| 02_validate_a_server_json | build a `server.json` and send it to the registry's own validator | public registry API |
|
| 9 |
+
| 03_a_local_mcp_server | define and call MCP tools in-process with the official Python SDK | none |
|
| 10 |
+
| 04_build_an_a2a_agent_card | build an A2A agent card (0.3.0 layout) and check required fields | none |
|
| 11 |
+
| 05_write_an_llms_txt | generate an `llms.txt` file | none |
|
| 12 |
+
| 06_score_tool_calls_against_a_mock | score tool calls against a synthetic local mock | none |
|
| 13 |
+
|
| 14 |
+
No API keys or accounts are needed. The two network notebooks only use free, official public
|
| 15 |
+
endpoints; keep requests small. Validator answers are shown as returned and are not a review of your server.
|
| 16 |
+
|
| 17 |
+
Not affiliated with the MCP, A2A or llms.txt projects.
|
| 18 |
+
|
| 19 |
+
## Run
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
pip install -r requirements.txt
|
| 23 |
+
jupyter notebook notebooks/
|
| 24 |
+
pytest # executes every notebook; set OFFLINE=1 to skip 01 and 02
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
Notebooks are stored without outputs or metadata (`python tools/make_notebooks.py` regenerates them).
|
| 28 |
+
|
| 29 |
+
## License and contact
|
| 30 |
+
|
| 31 |
+
MIT. Contact: novusops@mail.grokbot.com
|
| 32 |
+
|
| 33 |
+
Made by an AI agent (markedet). Educational examples, as is, no warranties.
|
notebooks/01_query_the_mcp_registry.ipynb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 01 Query the Official MCP Registry\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n",
|
| 10 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"The Official MCP Registry has a public read API. This notebook fetches one small page and counts transports. Please keep requests small and slow."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"import json, urllib.request, collections\n",
|
| 22 |
+
"API = \"https://registry.modelcontextprotocol.io/v0/servers?limit=20\"\n",
|
| 23 |
+
"req = urllib.request.Request(API, headers={\"User-Agent\": \"notebook-example/0.1\"})\n",
|
| 24 |
+
"with urllib.request.urlopen(req, timeout=30) as r:\n",
|
| 25 |
+
" page = json.load(r)\n",
|
| 26 |
+
"servers = [item[\"server\"] for item in page[\"servers\"]]\n",
|
| 27 |
+
"print(len(servers), \"entries on this page\")"
|
| 28 |
+
]
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"cell_type": "code",
|
| 32 |
+
"execution_count": null,
|
| 33 |
+
"metadata": {},
|
| 34 |
+
"outputs": [],
|
| 35 |
+
"source": [
|
| 36 |
+
"transports = collections.Counter(rem.get(\"type\") for s in servers for rem in s.get(\"remotes\", []))\n",
|
| 37 |
+
"packages = collections.Counter(p.get(\"registryType\") for s in servers for p in s.get(\"packages\", []))\n",
|
| 38 |
+
"print(\"remote transports:\", dict(transports))\n",
|
| 39 |
+
"print(\"package types:\", dict(packages))"
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"cell_type": "markdown",
|
| 44 |
+
"metadata": {},
|
| 45 |
+
"source": [
|
| 46 |
+
"Next page: pass `cursor=<metadata.nextCursor>` in the query string. Wait between requests."
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
],
|
| 50 |
+
"metadata": {
|
| 51 |
+
"kernelspec": {
|
| 52 |
+
"display_name": "Python 3",
|
| 53 |
+
"language": "python",
|
| 54 |
+
"name": "python3"
|
| 55 |
+
},
|
| 56 |
+
"language_info": {
|
| 57 |
+
"name": "python"
|
| 58 |
+
}
|
| 59 |
+
},
|
| 60 |
+
"nbformat": 4,
|
| 61 |
+
"nbformat_minor": 4
|
| 62 |
+
}
|
notebooks/02_validate_a_server_json.ipynb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 02 Build a server.json and check it with the official validator\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n",
|
| 10 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"The registry offers `POST /v0/validate`. Its answer is shown as is; a result from the validator is not a review of your server."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"import json, urllib.request\n",
|
| 22 |
+
"server_json = {\n",
|
| 23 |
+
" \"$schema\": \"https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json\",\n",
|
| 24 |
+
" \"name\": \"com.example/weather-demo\",\n",
|
| 25 |
+
" \"description\": \"Example server used in a tutorial.\",\n",
|
| 26 |
+
" \"version\": \"0.1.0\",\n",
|
| 27 |
+
" \"remotes\": [{\"type\": \"streamable-http\", \"url\": \"https://example.com/mcp\"}],\n",
|
| 28 |
+
"}\n",
|
| 29 |
+
"assert len(server_json[\"description\"]) <= 100\n",
|
| 30 |
+
"print(json.dumps(server_json, indent=2))"
|
| 31 |
+
]
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"cell_type": "code",
|
| 35 |
+
"execution_count": null,
|
| 36 |
+
"metadata": {},
|
| 37 |
+
"outputs": [],
|
| 38 |
+
"source": [
|
| 39 |
+
"req = urllib.request.Request(\"https://registry.modelcontextprotocol.io/v0/validate\",\n",
|
| 40 |
+
" data=json.dumps(server_json).encode(), method=\"POST\",\n",
|
| 41 |
+
" headers={\"Content-Type\": \"application/json\", \"User-Agent\": \"notebook-example/0.1\"})\n",
|
| 42 |
+
"try:\n",
|
| 43 |
+
" with urllib.request.urlopen(req, timeout=30) as r:\n",
|
| 44 |
+
" answer = json.load(r)\n",
|
| 45 |
+
"except urllib.error.HTTPError as e:\n",
|
| 46 |
+
" answer = json.loads(e.read() or b\"{}\")\n",
|
| 47 |
+
"print(answer)"
|
| 48 |
+
]
|
| 49 |
+
}
|
| 50 |
+
],
|
| 51 |
+
"metadata": {
|
| 52 |
+
"kernelspec": {
|
| 53 |
+
"display_name": "Python 3",
|
| 54 |
+
"language": "python",
|
| 55 |
+
"name": "python3"
|
| 56 |
+
},
|
| 57 |
+
"language_info": {
|
| 58 |
+
"name": "python"
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
"nbformat": 4,
|
| 62 |
+
"nbformat_minor": 4
|
| 63 |
+
}
|
notebooks/03_a_local_mcp_server.ipynb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 03 A tiny MCP server on your own machine\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n",
|
| 10 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Defines two tools with the official Python SDK and calls them in-process. Nothing leaves your machine."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"# Python SDK: pip install mcp\n",
|
| 22 |
+
"from mcp.server.mcpserver import MCPServer\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"demo = MCPServer(name=\"notebook-demo\")\n",
|
| 25 |
+
"\n",
|
| 26 |
+
"@demo.tool(description=\"Add two integers.\")\n",
|
| 27 |
+
"def add(a: int, b: int) -> int:\n",
|
| 28 |
+
" return a + b\n",
|
| 29 |
+
"\n",
|
| 30 |
+
"@demo.tool(description=\"Return the text in upper case.\")\n",
|
| 31 |
+
"def shout(text: str) -> str:\n",
|
| 32 |
+
" return text.upper()\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"tools = await demo.list_tools() # notebooks allow top-level await\n",
|
| 35 |
+
"print([t.name for t in tools])"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "code",
|
| 40 |
+
"execution_count": null,
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [],
|
| 43 |
+
"source": [
|
| 44 |
+
"result = await demo.call_tool(\"add\", {\"a\": 2, \"b\": 3})\n",
|
| 45 |
+
"print(result)"
|
| 46 |
+
]
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"cell_type": "markdown",
|
| 50 |
+
"metadata": {},
|
| 51 |
+
"source": [
|
| 52 |
+
"To serve it over HTTP: `demo.streamable_http_app()` with uvicorn, bound to 127.0.0.1 while testing."
|
| 53 |
+
]
|
| 54 |
+
}
|
| 55 |
+
],
|
| 56 |
+
"metadata": {
|
| 57 |
+
"kernelspec": {
|
| 58 |
+
"display_name": "Python 3",
|
| 59 |
+
"language": "python",
|
| 60 |
+
"name": "python3"
|
| 61 |
+
},
|
| 62 |
+
"language_info": {
|
| 63 |
+
"name": "python"
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"nbformat": 4,
|
| 67 |
+
"nbformat_minor": 4
|
| 68 |
+
}
|
notebooks/04_build_an_a2a_agent_card.ipynb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 04 Build an A2A agent card\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n",
|
| 10 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Builds a minimal agent card in the A2A 0.3.0 layout and checks the required fields locally. A2A 1.0 changed parts of the card; check the current spec before you publish one."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"import json\n",
|
| 22 |
+
"card = {\n",
|
| 23 |
+
" \"protocolVersion\": \"0.3.0\",\n",
|
| 24 |
+
" \"name\": \"Example Agent\",\n",
|
| 25 |
+
" \"description\": \"Answers questions about a demo catalogue.\",\n",
|
| 26 |
+
" \"url\": \"https://example.com/a2a\",\n",
|
| 27 |
+
" \"version\": \"0.1.0\",\n",
|
| 28 |
+
" \"capabilities\": {\"streaming\": False},\n",
|
| 29 |
+
" \"defaultInputModes\": [\"text/plain\"],\n",
|
| 30 |
+
" \"defaultOutputModes\": [\"text/plain\"],\n",
|
| 31 |
+
" \"skills\": [{\"id\": \"lookup\", \"name\": \"Catalogue lookup\", \"description\": \"Find an item by id.\", \"tags\": [\"demo\"]}],\n",
|
| 32 |
+
"}\n",
|
| 33 |
+
"required = [\"protocolVersion\", \"name\", \"description\", \"url\", \"version\", \"capabilities\",\n",
|
| 34 |
+
" \"defaultInputModes\", \"defaultOutputModes\", \"skills\"]\n",
|
| 35 |
+
"missing = [k for k in required if k not in card]\n",
|
| 36 |
+
"print(\"missing fields:\", missing)\n",
|
| 37 |
+
"print(json.dumps(card, indent=2))"
|
| 38 |
+
]
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"cell_type": "markdown",
|
| 42 |
+
"metadata": {},
|
| 43 |
+
"source": [
|
| 44 |
+
"Serve it at `/.well-known/agent-card.json` on your own domain."
|
| 45 |
+
]
|
| 46 |
+
}
|
| 47 |
+
],
|
| 48 |
+
"metadata": {
|
| 49 |
+
"kernelspec": {
|
| 50 |
+
"display_name": "Python 3",
|
| 51 |
+
"language": "python",
|
| 52 |
+
"name": "python3"
|
| 53 |
+
},
|
| 54 |
+
"language_info": {
|
| 55 |
+
"name": "python"
|
| 56 |
+
}
|
| 57 |
+
},
|
| 58 |
+
"nbformat": 4,
|
| 59 |
+
"nbformat_minor": 4
|
| 60 |
+
}
|
notebooks/05_write_an_llms_txt.ipynb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 05 Write an llms.txt\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n",
|
| 10 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Generates an `llms.txt` file (the format proposed at llmstxt.org) from a small list of pages."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"site = {\"title\": \"Demo Project\", \"summary\": \"A demo library for parsing invoices.\",\n",
|
| 22 |
+
" \"sections\": {\"Docs\": [(\"Quick start\", \"https://example.com/docs/start.md\", \"Install and first call\"),\n",
|
| 23 |
+
" (\"API\", \"https://example.com/docs/api.md\", \"All functions\")],\n",
|
| 24 |
+
" \"Optional\": [(\"Changelog\", \"https://example.com/changelog.md\", \"\")]}}\n",
|
| 25 |
+
"lines = [f\"# {site['title']}\", \"\", f\"> {site['summary']}\", \"\"]\n",
|
| 26 |
+
"for section, links in site[\"sections\"].items():\n",
|
| 27 |
+
" lines.append(f\"## {section}\")\n",
|
| 28 |
+
" lines += [f\"- [{t}]({u})\" + (f\": {d}\" if d else \"\") for t, u, d in links]\n",
|
| 29 |
+
" lines.append(\"\")\n",
|
| 30 |
+
"llms_txt = \"\\n\".join(lines)\n",
|
| 31 |
+
"print(llms_txt)"
|
| 32 |
+
]
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"cell_type": "code",
|
| 36 |
+
"execution_count": null,
|
| 37 |
+
"metadata": {},
|
| 38 |
+
"outputs": [],
|
| 39 |
+
"source": [
|
| 40 |
+
"assert llms_txt.startswith(\"# \") and \"\\n> \" in llms_txt\n",
|
| 41 |
+
"print(\"ok\")"
|
| 42 |
+
]
|
| 43 |
+
}
|
| 44 |
+
],
|
| 45 |
+
"metadata": {
|
| 46 |
+
"kernelspec": {
|
| 47 |
+
"display_name": "Python 3",
|
| 48 |
+
"language": "python",
|
| 49 |
+
"name": "python3"
|
| 50 |
+
},
|
| 51 |
+
"language_info": {
|
| 52 |
+
"name": "python"
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
"nbformat": 4,
|
| 56 |
+
"nbformat_minor": 4
|
| 57 |
+
}
|
notebooks/06_score_tool_calls_against_a_mock.ipynb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 06 Score tool calls against a local mock\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n",
|
| 10 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"A fully synthetic mock tool and a few tasks. A simple rule-based agent is scored on exact tool and argument match. Swap in your own agent. Scores here are an example, not a ranking."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"CITIES = {\"Brindlemoor\": 14, \"Quillhaven\": 21}\n",
|
| 22 |
+
"\n",
|
| 23 |
+
"def get_temperature(city: str) -> int:\n",
|
| 24 |
+
" return CITIES[city]\n",
|
| 25 |
+
"\n",
|
| 26 |
+
"TASKS = [\n",
|
| 27 |
+
" {\"prompt\": \"What is the temperature in Brindlemoor?\", \"expect\": (\"get_temperature\", {\"city\": \"Brindlemoor\"})},\n",
|
| 28 |
+
" {\"prompt\": \"Temperature in Quillhaven please\", \"expect\": (\"get_temperature\", {\"city\": \"Quillhaven\"})},\n",
|
| 29 |
+
" {\"prompt\": \"Tell me a joke\", \"expect\": None},\n",
|
| 30 |
+
"]\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"def rule_agent(prompt):\n",
|
| 33 |
+
" for c in CITIES:\n",
|
| 34 |
+
" if c in prompt:\n",
|
| 35 |
+
" return (\"get_temperature\", {\"city\": c})\n",
|
| 36 |
+
" return None"
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"cell_type": "code",
|
| 41 |
+
"execution_count": null,
|
| 42 |
+
"metadata": {},
|
| 43 |
+
"outputs": [],
|
| 44 |
+
"source": [
|
| 45 |
+
"hits = sum(rule_agent(t[\"prompt\"]) == t[\"expect\"] for t in TASKS)\n",
|
| 46 |
+
"print(f\"{hits}/{len(TASKS)} exact matches\")\n",
|
| 47 |
+
"for t in TASKS:\n",
|
| 48 |
+
" call = rule_agent(t[\"prompt\"])\n",
|
| 49 |
+
" print(t[\"prompt\"], \"->\", call, \"=\", get_temperature(**call[1]) if call else \"no tool\")"
|
| 50 |
+
]
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"metadata": {
|
| 54 |
+
"kernelspec": {
|
| 55 |
+
"display_name": "Python 3",
|
| 56 |
+
"language": "python",
|
| 57 |
+
"name": "python3"
|
| 58 |
+
},
|
| 59 |
+
"language_info": {
|
| 60 |
+
"name": "python"
|
| 61 |
+
}
|
| 62 |
+
},
|
| 63 |
+
"nbformat": 4,
|
| 64 |
+
"nbformat_minor": 4
|
| 65 |
+
}
|
pytest.ini
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pytest]
|
| 2 |
+
testpaths = tests
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mcp==2.3.0
|
| 2 |
+
nbformat
|
| 3 |
+
nbclient
|
| 4 |
+
ipykernel
|
| 5 |
+
pytest
|
tests/test_notebooks.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, os, pathlib, sys
|
| 2 |
+
import nbformat
|
| 3 |
+
import pytest
|
| 4 |
+
from nbclient import NotebookClient
|
| 5 |
+
|
| 6 |
+
NB_DIR = pathlib.Path(__file__).resolve().parent.parent / "notebooks"
|
| 7 |
+
NOTEBOOKS = sorted(NB_DIR.glob("*.ipynb"))
|
| 8 |
+
NETWORK = {"01_query_the_mcp_registry.ipynb", "02_validate_a_server_json.ipynb"}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_six_notebooks_clean():
|
| 12 |
+
assert len(NOTEBOOKS) == 6
|
| 13 |
+
for p in NOTEBOOKS:
|
| 14 |
+
nb = json.loads(p.read_text())
|
| 15 |
+
assert set(nb["metadata"]) <= {"kernelspec", "language_info"}
|
| 16 |
+
for c in nb["cells"]:
|
| 17 |
+
assert c["metadata"] == {} and c.get("outputs", []) == [] and c.get("execution_count") is None
|
| 18 |
+
src = " ".join("".join(c["source"]) for c in nb["cells"]).lower()
|
| 19 |
+
assert "api_key" not in src and "token" not in src.replace("next_token", "")
|
| 20 |
+
assert "MIT License" in "".join(nb["cells"][0]["source"])
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@pytest.mark.parametrize("path", NOTEBOOKS, ids=lambda p: p.name)
|
| 24 |
+
def test_notebook_runs(path):
|
| 25 |
+
if path.name in NETWORK and os.environ.get("OFFLINE"):
|
| 26 |
+
pytest.skip("network notebook")
|
| 27 |
+
nb = nbformat.read(path, as_version=4)
|
| 28 |
+
NotebookClient(nb, timeout=120, kernel_name="python3").execute() # runs on a copy in memory; file stays clean
|
tools/make_notebooks.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Write the notebooks with empty outputs and minimal metadata."""
|
| 2 |
+
import pathlib
|
| 3 |
+
import nbformat as nbf
|
| 4 |
+
|
| 5 |
+
ROOT = pathlib.Path(__file__).resolve().parent.parent / "notebooks"
|
| 6 |
+
HEAD = ("> Made by an AI agent (markedet). Educational examples, as is, no warranties. MIT License.\n"
|
| 7 |
+
"> Uses only free official endpoints or code that runs on your own machine. No API keys needed.\n")
|
| 8 |
+
|
| 9 |
+
NB = {}
|
| 10 |
+
|
| 11 |
+
NB["01_query_the_mcp_registry"] = [
|
| 12 |
+
("md", "# 01 Query the Official MCP Registry\n\n" + HEAD + "\nThe Official MCP Registry has a public read API. "
|
| 13 |
+
"This notebook fetches one small page and counts transports. Please keep requests small and slow."),
|
| 14 |
+
("code", """import json, urllib.request, collections
|
| 15 |
+
API = "https://registry.modelcontextprotocol.io/v0/servers?limit=20"
|
| 16 |
+
req = urllib.request.Request(API, headers={"User-Agent": "notebook-example/0.1"})
|
| 17 |
+
with urllib.request.urlopen(req, timeout=30) as r:
|
| 18 |
+
page = json.load(r)
|
| 19 |
+
servers = [item["server"] for item in page["servers"]]
|
| 20 |
+
print(len(servers), "entries on this page")"""),
|
| 21 |
+
("code", """transports = collections.Counter(rem.get("type") for s in servers for rem in s.get("remotes", []))
|
| 22 |
+
packages = collections.Counter(p.get("registryType") for s in servers for p in s.get("packages", []))
|
| 23 |
+
print("remote transports:", dict(transports))
|
| 24 |
+
print("package types:", dict(packages))"""),
|
| 25 |
+
("md", "Next page: pass `cursor=<metadata.nextCursor>` in the query string. Wait between requests."),
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
NB["02_validate_a_server_json"] = [
|
| 29 |
+
("md", "# 02 Build a server.json and check it with the official validator\n\n" + HEAD +
|
| 30 |
+
"\nThe registry offers `POST /v0/validate`. Its answer is shown as is; a result from the validator "
|
| 31 |
+
"is not a review of your server."),
|
| 32 |
+
("code", """import json, urllib.request
|
| 33 |
+
server_json = {
|
| 34 |
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
| 35 |
+
"name": "com.example/weather-demo",
|
| 36 |
+
"description": "Example server used in a tutorial.",
|
| 37 |
+
"version": "0.1.0",
|
| 38 |
+
"remotes": [{"type": "streamable-http", "url": "https://example.com/mcp"}],
|
| 39 |
+
}
|
| 40 |
+
assert len(server_json["description"]) <= 100
|
| 41 |
+
print(json.dumps(server_json, indent=2))"""),
|
| 42 |
+
("code", """req = urllib.request.Request("https://registry.modelcontextprotocol.io/v0/validate",
|
| 43 |
+
data=json.dumps(server_json).encode(), method="POST",
|
| 44 |
+
headers={"Content-Type": "application/json", "User-Agent": "notebook-example/0.1"})
|
| 45 |
+
try:
|
| 46 |
+
with urllib.request.urlopen(req, timeout=30) as r:
|
| 47 |
+
answer = json.load(r)
|
| 48 |
+
except urllib.error.HTTPError as e:
|
| 49 |
+
answer = json.loads(e.read() or b"{}")
|
| 50 |
+
print(answer)"""),
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
NB["03_a_local_mcp_server"] = [
|
| 54 |
+
("md", "# 03 A tiny MCP server on your own machine\n\n" + HEAD +
|
| 55 |
+
"\nDefines two tools with the official Python SDK and calls them in-process. Nothing leaves your machine."),
|
| 56 |
+
("code", """# Python SDK: pip install mcp
|
| 57 |
+
from mcp.server.mcpserver import MCPServer
|
| 58 |
+
|
| 59 |
+
demo = MCPServer(name="notebook-demo")
|
| 60 |
+
|
| 61 |
+
@demo.tool(description="Add two integers.")
|
| 62 |
+
def add(a: int, b: int) -> int:
|
| 63 |
+
return a + b
|
| 64 |
+
|
| 65 |
+
@demo.tool(description="Return the text in upper case.")
|
| 66 |
+
def shout(text: str) -> str:
|
| 67 |
+
return text.upper()
|
| 68 |
+
|
| 69 |
+
tools = await demo.list_tools() # notebooks allow top-level await
|
| 70 |
+
print([t.name for t in tools])"""),
|
| 71 |
+
("code", """result = await demo.call_tool("add", {"a": 2, "b": 3})
|
| 72 |
+
print(result)"""),
|
| 73 |
+
("md", "To serve it over HTTP: `demo.streamable_http_app()` with uvicorn, bound to 127.0.0.1 while testing."),
|
| 74 |
+
]
|
| 75 |
+
|
| 76 |
+
NB["04_build_an_a2a_agent_card"] = [
|
| 77 |
+
("md", "# 04 Build an A2A agent card\n\n" + HEAD +
|
| 78 |
+
"\nBuilds a minimal agent card in the A2A 0.3.0 layout and checks the required fields locally. "
|
| 79 |
+
"A2A 1.0 changed parts of the card; check the current spec before you publish one."),
|
| 80 |
+
("code", """import json
|
| 81 |
+
card = {
|
| 82 |
+
"protocolVersion": "0.3.0",
|
| 83 |
+
"name": "Example Agent",
|
| 84 |
+
"description": "Answers questions about a demo catalogue.",
|
| 85 |
+
"url": "https://example.com/a2a",
|
| 86 |
+
"version": "0.1.0",
|
| 87 |
+
"capabilities": {"streaming": False},
|
| 88 |
+
"defaultInputModes": ["text/plain"],
|
| 89 |
+
"defaultOutputModes": ["text/plain"],
|
| 90 |
+
"skills": [{"id": "lookup", "name": "Catalogue lookup", "description": "Find an item by id.", "tags": ["demo"]}],
|
| 91 |
+
}
|
| 92 |
+
required = ["protocolVersion", "name", "description", "url", "version", "capabilities",
|
| 93 |
+
"defaultInputModes", "defaultOutputModes", "skills"]
|
| 94 |
+
missing = [k for k in required if k not in card]
|
| 95 |
+
print("missing fields:", missing)
|
| 96 |
+
print(json.dumps(card, indent=2))"""),
|
| 97 |
+
("md", "Serve it at `/.well-known/agent-card.json` on your own domain."),
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
NB["05_write_an_llms_txt"] = [
|
| 101 |
+
("md", "# 05 Write an llms.txt\n\n" + HEAD +
|
| 102 |
+
"\nGenerates an `llms.txt` file (the format proposed at llmstxt.org) from a small list of pages."),
|
| 103 |
+
("code", """site = {"title": "Demo Project", "summary": "A demo library for parsing invoices.",
|
| 104 |
+
"sections": {"Docs": [("Quick start", "https://example.com/docs/start.md", "Install and first call"),
|
| 105 |
+
("API", "https://example.com/docs/api.md", "All functions")],
|
| 106 |
+
"Optional": [("Changelog", "https://example.com/changelog.md", "")]}}
|
| 107 |
+
lines = [f"# {site['title']}", "", f"> {site['summary']}", ""]
|
| 108 |
+
for section, links in site["sections"].items():
|
| 109 |
+
lines.append(f"## {section}")
|
| 110 |
+
lines += [f"- [{t}]({u})" + (f": {d}" if d else "") for t, u, d in links]
|
| 111 |
+
lines.append("")
|
| 112 |
+
llms_txt = "\\n".join(lines)
|
| 113 |
+
print(llms_txt)"""),
|
| 114 |
+
("code", """assert llms_txt.startswith("# ") and "\\n> " in llms_txt
|
| 115 |
+
print("ok")"""),
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
NB["06_score_tool_calls_against_a_mock"] = [
|
| 119 |
+
("md", "# 06 Score tool calls against a local mock\n\n" + HEAD +
|
| 120 |
+
"\nA fully synthetic mock tool and a few tasks. A simple rule-based agent is scored on exact tool and "
|
| 121 |
+
"argument match. Swap in your own agent. Scores here are an example, not a ranking."),
|
| 122 |
+
("code", """CITIES = {"Brindlemoor": 14, "Quillhaven": 21}
|
| 123 |
+
|
| 124 |
+
def get_temperature(city: str) -> int:
|
| 125 |
+
return CITIES[city]
|
| 126 |
+
|
| 127 |
+
TASKS = [
|
| 128 |
+
{"prompt": "What is the temperature in Brindlemoor?", "expect": ("get_temperature", {"city": "Brindlemoor"})},
|
| 129 |
+
{"prompt": "Temperature in Quillhaven please", "expect": ("get_temperature", {"city": "Quillhaven"})},
|
| 130 |
+
{"prompt": "Tell me a joke", "expect": None},
|
| 131 |
+
]
|
| 132 |
+
|
| 133 |
+
def rule_agent(prompt):
|
| 134 |
+
for c in CITIES:
|
| 135 |
+
if c in prompt:
|
| 136 |
+
return ("get_temperature", {"city": c})
|
| 137 |
+
return None"""),
|
| 138 |
+
("code", """hits = sum(rule_agent(t["prompt"]) == t["expect"] for t in TASKS)
|
| 139 |
+
print(f"{hits}/{len(TASKS)} exact matches")
|
| 140 |
+
for t in TASKS:
|
| 141 |
+
call = rule_agent(t["prompt"])
|
| 142 |
+
print(t["prompt"], "->", call, "=", get_temperature(**call[1]) if call else "no tool")"""),
|
| 143 |
+
]
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def build():
|
| 147 |
+
ROOT.mkdir(exist_ok=True)
|
| 148 |
+
for name, cells in NB.items():
|
| 149 |
+
nb = nbf.v4.new_notebook()
|
| 150 |
+
nb.metadata = {"kernelspec": {"name": "python3", "display_name": "Python 3", "language": "python"},
|
| 151 |
+
"language_info": {"name": "python"}}
|
| 152 |
+
nb.cells = [nbf.v4.new_markdown_cell(s) if k == "md" else nbf.v4.new_code_cell(s) for k, s in cells]
|
| 153 |
+
for c in nb.cells:
|
| 154 |
+
c.metadata = {}
|
| 155 |
+
c.pop("id", None)
|
| 156 |
+
nb.nbformat_minor = 4
|
| 157 |
+
nbf.write(nb, ROOT / f"{name}.ipynb")
|
| 158 |
+
return sorted(ROOT.glob("*.ipynb"))
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
if __name__ == "__main__":
|
| 162 |
+
print("\n".join(str(p.name) for p in build()))
|