ai-oriented-a2a-mcp 0.4.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_oriented_a2a_mcp-0.4.5/.gitignore +11 -0
- ai_oriented_a2a_mcp-0.4.5/LICENSE +21 -0
- ai_oriented_a2a_mcp-0.4.5/PKG-INFO +125 -0
- ai_oriented_a2a_mcp-0.4.5/README.md +100 -0
- ai_oriented_a2a_mcp-0.4.5/hatch_build.py +96 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/__init__.py +70 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/_second_impl/__init__.py +5 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/_second_impl/a2a_core.py +735 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/_second_impl/minimal_client.py +401 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/LICENSE +18 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-001.json +26 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-002.json +29 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-003.json +28 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-004.json +26 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-005.json +28 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-006.json +29 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-007.json +33 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/corpus/pkt-synth-timeout-008.json +35 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/lookup.py +259 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/schema/absorption-result.schema.json +59 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/schema/agent-profile.schema.json +49 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/schema/experience-packet.schema.json +104 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/schema/negotiation.schema.json +123 -0
- ai_oriented_a2a_mcp-0.4.5/mcp_a2a/server.py +332 -0
- ai_oriented_a2a_mcp-0.4.5/pyproject.toml +56 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 robotmarvin0706
|
|
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.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ai-oriented-a2a-mcp
|
|
3
|
+
Version: 0.4.5
|
|
4
|
+
Summary: MCP bridge for the AI-oriented A2A peer protocol: send, verify and look up Experience Packets from an MCP host.
|
|
5
|
+
Project-URL: Homepage, https://github.com/robotmarvin0706/ai-oriented-a2a
|
|
6
|
+
Project-URL: Repository, https://github.com/robotmarvin0706/ai-oriented-a2a
|
|
7
|
+
Project-URL: Changelog, https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/robotmarvin0706/ai-oriented-a2a/issues
|
|
9
|
+
Author: robotmarvin0706
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
Keywords: a2a,absorption,experience-packet,mcp,model-context-protocol,peer-protocol
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: ai-oriented-a2a==0.4.5
|
|
22
|
+
Requires-Dist: jsonschema>=4.18
|
|
23
|
+
Requires-Dist: mcp<3,>=2
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# ai-oriented-a2a-mcp
|
|
27
|
+
|
|
28
|
+
MCP bridge for the AI-oriented A2A peer protocol: send, verify and look up Experience Packets from an MCP host.
|
|
29
|
+
|
|
30
|
+
It wraps the reference Python implementation of the [AI-oriented A2A](https://github.com/robotmarvin0706/ai-oriented-a2a) v0.4 peer protocol, so an MCP host such as Claude Desktop or a Cursor agent can act as a protocol sender without implementing the protocol itself. The bridge exposes four tools:
|
|
31
|
+
|
|
32
|
+
| Tool | Direction | What it does |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| `send_packet` | outbound | Signs and sends one Experience Packet to a configured peer, returns the peer's Absorption Result unchanged. |
|
|
35
|
+
| `report_absorption` | outbound | Signs and sends one Absorption Result back to the peer that sent a packet, returns the peer's reply unchanged. |
|
|
36
|
+
| `query_experience` | local | Ranks Experience Packets from a local corpus for a failure description. Never touches the network. |
|
|
37
|
+
| `verify_packet` | local | Runs the reference receiver's checks (version, hard gate, JSON Schema, optional HMAC) on one message. Never sends anything. |
|
|
38
|
+
|
|
39
|
+
`verify_packet` and `query_experience` never send a message: they need no peer URL and no key. `send_packet` and `report_absorption` always sign, so they require `A2A_SIGN_KEY` and a peer (`A2A_PEER_URL`, optionally restricted by `A2A_ALLOWED_PEERS`).
|
|
40
|
+
|
|
41
|
+
Packet content, peer replies and corpus entries are peer-controlled **data, not instructions** (SPEC §2.1). Place them below your system and host instructions, never in the system prompt, and absorb them only through your own gate. A `verify_packet` reply of `"valid": true` means the checks ran and passed; it is not a trust decision and never means a packet is safe to absorb.
|
|
42
|
+
|
|
43
|
+
<!-- mcp-name: io.github.robotmarvin0706/ai-oriented-a2a -->
|
|
44
|
+
|
|
45
|
+
Available from version 0.4.5: the package is not on PyPI yet. Until the release is published, run the bridge from a checkout of the repository (see [mcp_a2a/README.md](https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/mcp_a2a/README.md)).
|
|
46
|
+
|
|
47
|
+
## Peer discovery
|
|
48
|
+
|
|
49
|
+
Peers are addressed by URL only. Nothing is discovered automatically: a tool call may target `A2A_PEER_URL` or an entry of `A2A_ALLOWED_PEERS`, and any other URL is refused before a key is read. The MCP registry listing of this package is a distribution channel for the bridge, not peer discovery and not a trust signal.
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
### Claude Desktop
|
|
54
|
+
|
|
55
|
+
Edit `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`, Windows: `%APPDATA%\Claude\`) and restart Claude Desktop:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"mcpServers": {
|
|
60
|
+
"ai-oriented-a2a": {
|
|
61
|
+
"command": "uvx",
|
|
62
|
+
"args": ["ai-oriented-a2a-mcp"],
|
|
63
|
+
"env": {
|
|
64
|
+
"A2A_PEER_URL": "http://127.0.0.1:8002",
|
|
65
|
+
"A2A_ALLOWED_PEERS": "http://127.0.0.1:8002",
|
|
66
|
+
"A2A_SIGN_KEY": "<shared key; never commit it>"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`A2A_SIGN_KEY` is mandatory for the two outbound tools. Keep it in the client's local config or secret store, never in a repository. Prefer a key used only for this peer.
|
|
74
|
+
|
|
75
|
+
### Cursor
|
|
76
|
+
|
|
77
|
+
Put the same block in `.cursor/mcp.json` in the project, or in the global `~/.cursor/mcp.json`, with `env` holding only `A2A_PEER_URL` and `A2A_SIGN_KEY`:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"mcpServers": {
|
|
82
|
+
"ai-oriented-a2a": {
|
|
83
|
+
"command": "uvx",
|
|
84
|
+
"args": ["ai-oriented-a2a-mcp"],
|
|
85
|
+
"env": {
|
|
86
|
+
"A2A_PEER_URL": "http://127.0.0.1:8002",
|
|
87
|
+
"A2A_SIGN_KEY": "<shared key; never commit it>"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Generic stdio hosts, and without uv
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
uvx ai-oriented-a2a-mcp # one line, needs uv
|
|
98
|
+
uvx --python 3.12 ai-oriented-a2a-mcp # fallback when the default Python is older than 3.10
|
|
99
|
+
pipx run ai-oriented-a2a-mcp # one line, needs pipx
|
|
100
|
+
pip install ai-oriented-a2a-mcp && ai-oriented-a2a-mcp # plain pip, Python >= 3.10
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The same fallback as a JSON argument list: `"args": ["--python", "3.12", "ai-oriented-a2a-mcp"]`.
|
|
104
|
+
|
|
105
|
+
The server speaks MCP over stdio: logs go to stderr, stdout is the MCP wire. `ai-oriented-a2a-mcp --version` prints the bridge version and exits.
|
|
106
|
+
|
|
107
|
+
### Environment variables
|
|
108
|
+
|
|
109
|
+
All settings are read from the environment on every call.
|
|
110
|
+
|
|
111
|
+
| Variable | Meaning |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| `A2A_PEER_URL` | Default peer base URL (`/a2a/message` is appended). Always allowed. |
|
|
114
|
+
| `A2A_ALLOWED_PEERS` | Comma-separated base URLs a tool call may target with `peer_url`. Anything else is refused. If neither this nor `A2A_PEER_URL` is set, every outbound call is refused. |
|
|
115
|
+
| `A2A_SIGN_KEY` | HMAC-SHA256 key for signing outbound messages and checking signed replies. Required by `send_packet` and `report_absorption`; environment only, never a tool argument, so the model never sees it. |
|
|
116
|
+
| `A2A_EXPERIENCE_DIR` | Directory of Experience Packet JSON files used by `query_experience`. Default: the bundled corpus. |
|
|
117
|
+
| `A2A_NO_SCHEMA` | `1` to skip JSON Schema checks. |
|
|
118
|
+
|
|
119
|
+
## Bundled corpus
|
|
120
|
+
|
|
121
|
+
`query_experience` ships with the eight synthetic timeout-recovery Experience Packets of the public corpus ([datasets/timeout_recovery](https://github.com/robotmarvin0706/ai-oriented-a2a/tree/main/datasets/timeout_recovery)), dedicated to the public domain under CC0 1.0 (`mcp_a2a/corpus/LICENSE`). Point `A2A_EXPERIENCE_DIR` at your own directory to use another corpus.
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
The package is MIT licensed ([LICENSE](https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/LICENSE)). The bundled corpus is CC0 1.0. The protocol specification and the schema files are in the repository: [SPEC.md](https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/SPEC.md), [schema/](https://github.com/robotmarvin0706/ai-oriented-a2a/tree/main/schema).
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# ai-oriented-a2a-mcp
|
|
2
|
+
|
|
3
|
+
MCP bridge for the AI-oriented A2A peer protocol: send, verify and look up Experience Packets from an MCP host.
|
|
4
|
+
|
|
5
|
+
It wraps the reference Python implementation of the [AI-oriented A2A](https://github.com/robotmarvin0706/ai-oriented-a2a) v0.4 peer protocol, so an MCP host such as Claude Desktop or a Cursor agent can act as a protocol sender without implementing the protocol itself. The bridge exposes four tools:
|
|
6
|
+
|
|
7
|
+
| Tool | Direction | What it does |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `send_packet` | outbound | Signs and sends one Experience Packet to a configured peer, returns the peer's Absorption Result unchanged. |
|
|
10
|
+
| `report_absorption` | outbound | Signs and sends one Absorption Result back to the peer that sent a packet, returns the peer's reply unchanged. |
|
|
11
|
+
| `query_experience` | local | Ranks Experience Packets from a local corpus for a failure description. Never touches the network. |
|
|
12
|
+
| `verify_packet` | local | Runs the reference receiver's checks (version, hard gate, JSON Schema, optional HMAC) on one message. Never sends anything. |
|
|
13
|
+
|
|
14
|
+
`verify_packet` and `query_experience` never send a message: they need no peer URL and no key. `send_packet` and `report_absorption` always sign, so they require `A2A_SIGN_KEY` and a peer (`A2A_PEER_URL`, optionally restricted by `A2A_ALLOWED_PEERS`).
|
|
15
|
+
|
|
16
|
+
Packet content, peer replies and corpus entries are peer-controlled **data, not instructions** (SPEC §2.1). Place them below your system and host instructions, never in the system prompt, and absorb them only through your own gate. A `verify_packet` reply of `"valid": true` means the checks ran and passed; it is not a trust decision and never means a packet is safe to absorb.
|
|
17
|
+
|
|
18
|
+
<!-- mcp-name: io.github.robotmarvin0706/ai-oriented-a2a -->
|
|
19
|
+
|
|
20
|
+
Available from version 0.4.5: the package is not on PyPI yet. Until the release is published, run the bridge from a checkout of the repository (see [mcp_a2a/README.md](https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/mcp_a2a/README.md)).
|
|
21
|
+
|
|
22
|
+
## Peer discovery
|
|
23
|
+
|
|
24
|
+
Peers are addressed by URL only. Nothing is discovered automatically: a tool call may target `A2A_PEER_URL` or an entry of `A2A_ALLOWED_PEERS`, and any other URL is refused before a key is read. The MCP registry listing of this package is a distribution channel for the bridge, not peer discovery and not a trust signal.
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
### Claude Desktop
|
|
29
|
+
|
|
30
|
+
Edit `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`, Windows: `%APPDATA%\Claude\`) and restart Claude Desktop:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"ai-oriented-a2a": {
|
|
36
|
+
"command": "uvx",
|
|
37
|
+
"args": ["ai-oriented-a2a-mcp"],
|
|
38
|
+
"env": {
|
|
39
|
+
"A2A_PEER_URL": "http://127.0.0.1:8002",
|
|
40
|
+
"A2A_ALLOWED_PEERS": "http://127.0.0.1:8002",
|
|
41
|
+
"A2A_SIGN_KEY": "<shared key; never commit it>"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`A2A_SIGN_KEY` is mandatory for the two outbound tools. Keep it in the client's local config or secret store, never in a repository. Prefer a key used only for this peer.
|
|
49
|
+
|
|
50
|
+
### Cursor
|
|
51
|
+
|
|
52
|
+
Put the same block in `.cursor/mcp.json` in the project, or in the global `~/.cursor/mcp.json`, with `env` holding only `A2A_PEER_URL` and `A2A_SIGN_KEY`:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"mcpServers": {
|
|
57
|
+
"ai-oriented-a2a": {
|
|
58
|
+
"command": "uvx",
|
|
59
|
+
"args": ["ai-oriented-a2a-mcp"],
|
|
60
|
+
"env": {
|
|
61
|
+
"A2A_PEER_URL": "http://127.0.0.1:8002",
|
|
62
|
+
"A2A_SIGN_KEY": "<shared key; never commit it>"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Generic stdio hosts, and without uv
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
uvx ai-oriented-a2a-mcp # one line, needs uv
|
|
73
|
+
uvx --python 3.12 ai-oriented-a2a-mcp # fallback when the default Python is older than 3.10
|
|
74
|
+
pipx run ai-oriented-a2a-mcp # one line, needs pipx
|
|
75
|
+
pip install ai-oriented-a2a-mcp && ai-oriented-a2a-mcp # plain pip, Python >= 3.10
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The same fallback as a JSON argument list: `"args": ["--python", "3.12", "ai-oriented-a2a-mcp"]`.
|
|
79
|
+
|
|
80
|
+
The server speaks MCP over stdio: logs go to stderr, stdout is the MCP wire. `ai-oriented-a2a-mcp --version` prints the bridge version and exits.
|
|
81
|
+
|
|
82
|
+
### Environment variables
|
|
83
|
+
|
|
84
|
+
All settings are read from the environment on every call.
|
|
85
|
+
|
|
86
|
+
| Variable | Meaning |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `A2A_PEER_URL` | Default peer base URL (`/a2a/message` is appended). Always allowed. |
|
|
89
|
+
| `A2A_ALLOWED_PEERS` | Comma-separated base URLs a tool call may target with `peer_url`. Anything else is refused. If neither this nor `A2A_PEER_URL` is set, every outbound call is refused. |
|
|
90
|
+
| `A2A_SIGN_KEY` | HMAC-SHA256 key for signing outbound messages and checking signed replies. Required by `send_packet` and `report_absorption`; environment only, never a tool argument, so the model never sees it. |
|
|
91
|
+
| `A2A_EXPERIENCE_DIR` | Directory of Experience Packet JSON files used by `query_experience`. Default: the bundled corpus. |
|
|
92
|
+
| `A2A_NO_SCHEMA` | `1` to skip JSON Schema checks. |
|
|
93
|
+
|
|
94
|
+
## Bundled corpus
|
|
95
|
+
|
|
96
|
+
`query_experience` ships with the eight synthetic timeout-recovery Experience Packets of the public corpus ([datasets/timeout_recovery](https://github.com/robotmarvin0706/ai-oriented-a2a/tree/main/datasets/timeout_recovery)), dedicated to the public domain under CC0 1.0 (`mcp_a2a/corpus/LICENSE`). Point `A2A_EXPERIENCE_DIR` at your own directory to use another corpus.
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
The package is MIT licensed ([LICENSE](https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/LICENSE)). The bundled corpus is CC0 1.0. The protocol specification and the schema files are in the repository: [SPEC.md](https://github.com/robotmarvin0706/ai-oriented-a2a/blob/main/SPEC.md), [schema/](https://github.com/robotmarvin0706/ai-oriented-a2a/tree/main/schema).
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Hatch build hook: assemble ``ai-oriented-a2a-mcp`` from files kept at the repo root.
|
|
2
|
+
|
|
3
|
+
No shipped file is duplicated in git. ``packaging/mcp`` holds only this package
|
|
4
|
+
metadata; every source is copied (never edited) at build time, and the same
|
|
5
|
+
wheel layout is produced for both build paths:
|
|
6
|
+
|
|
7
|
+
- from the repository checkout, the sources sit two levels up
|
|
8
|
+
(``../../mcp_a2a/server.py``, ``../../second_impl/``, ``../../schema/``, ...);
|
|
9
|
+
- from the sdist that ``python -m build packaging/mcp`` unpacks before building
|
|
10
|
+
the wheel, the sources are already at the sdist root in the wheel layout
|
|
11
|
+
(``mcp_a2a/server.py``, ``mcp_a2a/_second_impl/``, ...), because the sdist
|
|
12
|
+
pass of this hook copied them there.
|
|
13
|
+
|
|
14
|
+
``second_impl/`` is mapped to ``mcp_a2a/_second_impl/`` so that
|
|
15
|
+
``a2a_core.schema_dir()`` (``Path(__file__).parent.parent / "schema"``) points
|
|
16
|
+
at ``mcp_a2a/schema/`` in the installed package.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
22
|
+
|
|
23
|
+
#: Copied from ``mcp_a2a/`` itself; ``mcp_a2a/README.md`` and caches stay out.
|
|
24
|
+
BRIDGE_FILES = ("__init__.py", "lookup.py", "server.py")
|
|
25
|
+
#: Vendored copy of ``second_impl/`` (unmodified).
|
|
26
|
+
CORE_FILES = ("__init__.py", "a2a_core.py", "minimal_client.py")
|
|
27
|
+
#: JSON Schemas from ``schema/``.
|
|
28
|
+
SCHEMA_GLOB = "*.schema.json"
|
|
29
|
+
#: The CC0 timeout-recovery corpus; ``lookup`` only globs ``*.json``.
|
|
30
|
+
CORPUS_GLOB = "*.json"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CustomBuildHook(BuildHookInterface):
|
|
34
|
+
PLUGIN_NAME = "custom"
|
|
35
|
+
|
|
36
|
+
def initialize(self, version, build_data):
|
|
37
|
+
root = Path(self.root).resolve()
|
|
38
|
+
sdist_layout = root / "mcp_a2a" / "server.py"
|
|
39
|
+
repo_layout = root.parent.parent / "mcp_a2a" / "server.py"
|
|
40
|
+
if sdist_layout.is_file():
|
|
41
|
+
source, groups = root, self._sdist_groups(root)
|
|
42
|
+
elif repo_layout.is_file():
|
|
43
|
+
source = root.parent.parent
|
|
44
|
+
groups = self._repo_groups(source)
|
|
45
|
+
else:
|
|
46
|
+
message = (
|
|
47
|
+
f"{self.PLUGIN_NAME} build hook: neither {sdist_layout} nor "
|
|
48
|
+
f"{repo_layout} exists; build inside the repository or from the "
|
|
49
|
+
"unpacked sdist"
|
|
50
|
+
)
|
|
51
|
+
raise FileNotFoundError(message)
|
|
52
|
+
|
|
53
|
+
files = {}
|
|
54
|
+
for source_dir, target_dir, names, pattern in groups:
|
|
55
|
+
directory = source / source_dir
|
|
56
|
+
listed = list(names) if names else []
|
|
57
|
+
listed += [path.name for path in sorted(directory.glob(pattern))] if pattern else []
|
|
58
|
+
for name in listed:
|
|
59
|
+
files[str(directory / name)] = f"{target_dir}/{name}"
|
|
60
|
+
|
|
61
|
+
# The sdist carries the MIT license at its root, so the wheel built from
|
|
62
|
+
# it picks the file up through ``license-files``. A direct wheel build
|
|
63
|
+
# from the repository has no such file next to this pyproject, so the
|
|
64
|
+
# license goes straight into ``dist-info/licenses/`` where a wheel keeps
|
|
65
|
+
# it (``License-File`` still comes from the repository metadata).
|
|
66
|
+
license_file = source / "LICENSE"
|
|
67
|
+
if self.target_name == "sdist":
|
|
68
|
+
files[str(license_file)] = "LICENSE"
|
|
69
|
+
elif not (root / "LICENSE").is_file():
|
|
70
|
+
files[str(license_file)] = f"{self._dist_info()}/licenses/LICENSE"
|
|
71
|
+
|
|
72
|
+
build_data["force_include"].update(files)
|
|
73
|
+
|
|
74
|
+
def _dist_info(self) -> str:
|
|
75
|
+
"""Return the ``*.dist-info`` directory name hatchling will use."""
|
|
76
|
+
name = self.metadata.name.replace("-", "_").replace(".", "_").lower()
|
|
77
|
+
return f"{name}-{self.metadata.version}.dist-info"
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def _repo_groups(source: Path) -> list:
|
|
81
|
+
return [
|
|
82
|
+
("mcp_a2a", "mcp_a2a", BRIDGE_FILES, None),
|
|
83
|
+
("second_impl", "mcp_a2a/_second_impl", CORE_FILES, None),
|
|
84
|
+
("schema", "mcp_a2a/schema", (), SCHEMA_GLOB),
|
|
85
|
+
("datasets/timeout_recovery/packets", "mcp_a2a/corpus", (), CORPUS_GLOB),
|
|
86
|
+
("datasets", "mcp_a2a/corpus", ("LICENSE",), None),
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def _sdist_groups(source: Path) -> list:
|
|
91
|
+
return [
|
|
92
|
+
("mcp_a2a", "mcp_a2a", BRIDGE_FILES, None),
|
|
93
|
+
("mcp_a2a/_second_impl", "mcp_a2a/_second_impl", CORE_FILES, None),
|
|
94
|
+
("mcp_a2a/schema", "mcp_a2a/schema", (), SCHEMA_GLOB),
|
|
95
|
+
("mcp_a2a/corpus", "mcp_a2a/corpus", ("LICENSE",), CORPUS_GLOB),
|
|
96
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""MCP bridge to AI-oriented A2A v0.4 peers (outbound messages and a local lookup). See README.md.
|
|
2
|
+
|
|
3
|
+
Importing the package does not import the MCP SDK; ``mcp_a2a.server`` does.
|
|
4
|
+
``mcp_unavailable_reason()`` tells callers (and the tests) whether the
|
|
5
|
+
installed SDK satisfies ``MCP_REQUIREMENT`` without importing it.
|
|
6
|
+
|
|
7
|
+
Outbound signing is mandatory: ``require_sign_key()`` raises ``MissingSignKey``
|
|
8
|
+
when ``A2A_SIGN_KEY`` is unset or blank, so the bridge never sends an unsigned
|
|
9
|
+
message. The key is read from the environment only, never from a tool argument.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import sys
|
|
17
|
+
from typing import Dict, Optional
|
|
18
|
+
|
|
19
|
+
#: Environment variable holding the HMAC-SHA256 key for outbound messages.
|
|
20
|
+
SIGN_KEY_ENV = "A2A_SIGN_KEY"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class MissingSignKey(ValueError):
|
|
24
|
+
"""``A2A_SIGN_KEY`` is unset or blank; the bridge refuses to send unsigned."""
|
|
25
|
+
|
|
26
|
+
# Same bound as the ``mcp`` extra in pyproject.toml.
|
|
27
|
+
MCP_REQUIREMENT = "mcp>=2,<3"
|
|
28
|
+
MCP_MIN_MAJOR = 2
|
|
29
|
+
MCP_MAX_MAJOR_EXCLUSIVE = 3
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def mcp_unavailable_reason() -> Optional[str]:
|
|
33
|
+
"""None when an ``mcp`` SDK in ``MCP_REQUIREMENT`` is installed, else why not."""
|
|
34
|
+
if sys.version_info < (3, 10):
|
|
35
|
+
return f"the MCP bridge needs Python >= 3.10 (running {sys.version_info[0]}.{sys.version_info[1]})"
|
|
36
|
+
try:
|
|
37
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
38
|
+
except ImportError: # pragma: no cover - Python < 3.8
|
|
39
|
+
return "importlib.metadata unavailable"
|
|
40
|
+
try:
|
|
41
|
+
installed = version("mcp")
|
|
42
|
+
except PackageNotFoundError:
|
|
43
|
+
return f"mcp is not installed (needs {MCP_REQUIREMENT})"
|
|
44
|
+
m = re.match(r"\s*(\d+)", installed)
|
|
45
|
+
if m is None:
|
|
46
|
+
return f"mcp {installed} has an unreadable version (needs {MCP_REQUIREMENT})"
|
|
47
|
+
major = int(m.group(1))
|
|
48
|
+
if not MCP_MIN_MAJOR <= major < MCP_MAX_MAJOR_EXCLUSIVE:
|
|
49
|
+
return f"mcp {installed} is installed but the bridge needs {MCP_REQUIREMENT}"
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def require_sign_key(environ: Optional[Dict[str, str]] = None) -> str:
|
|
54
|
+
"""The HMAC-SHA256 key for outbound messages, or ``MissingSignKey``.
|
|
55
|
+
|
|
56
|
+
There is no unsigned fallback: a bridge that silently drops the signature
|
|
57
|
+
would let a misconfigured host send unauthenticated Experience Packets,
|
|
58
|
+
which is exactly what SPEC §2.1 and docs/SECURITY.md warn about.
|
|
59
|
+
"""
|
|
60
|
+
env = os.environ if environ is None else environ
|
|
61
|
+
key = (env.get(SIGN_KEY_ENV) or "").strip()
|
|
62
|
+
if not key:
|
|
63
|
+
raise MissingSignKey(
|
|
64
|
+
f"{SIGN_KEY_ENV} is not set: the MCP bridge signs every outbound message and "
|
|
65
|
+
"refuses to send unsigned ones"
|
|
66
|
+
)
|
|
67
|
+
return key
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
__all__ = ["MCP_REQUIREMENT", "MissingSignKey", "SIGN_KEY_ENV", "mcp_unavailable_reason", "require_sign_key"]
|