model-context-api 0.1.1__tar.gz → 0.1.4__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.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.3
2
+ Name: model-context-api
3
+ Version: 0.1.4
4
+ Summary: Model Context API for AI Agents
5
+ Requires-Dist: jsonschema>=4.26.0
6
+ Requires-Dist: pydantic>=2.13.5
7
+ Requires-Dist: mcp>=2.2,<3 ; extra == 'mcp'
8
+ Requires-Dist: django>=6.1.1 ; extra == 'ninja'
9
+ Requires-Dist: django-ninja>=1.7.0 ; extra == 'ninja'
10
+ Requires-Python: >=3.12
11
+ Provides-Extra: mcp
12
+ Provides-Extra: ninja
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Model Context API
16
+
17
+ model-context-api is a reusable registry and discovery layer for APIs that
18
+ need to be usable by both HTTP clients and AI agents.
19
+
20
+ The distribution name is `model-context-api`. The Python import package is
21
+ `mca`:
22
+
23
+ ~~~python
24
+ from mca.ninja import NinjaMCARouter
25
+ ~~~
26
+
27
+ MCA provides:
28
+
29
+ - one operation registry shared by discovery, HTTP, and MCP;
30
+ - Markdown guides that can be discovered and read on demand;
31
+ - Pydantic dispatch for framework-independent engines;
32
+ - Django Ninja registration with generated request and response schemas;
33
+ - one MCP host and `mc_api` tool for registered Django applications.
34
+
35
+ ## Why MCA exists
36
+
37
+ An ordinary API can be perfectly usable by a human developer and still be
38
+ difficult for an AI agent to use. MCA publishes both a machine-readable
39
+ contract—routes, parameters, request bodies, and responses—and human-readable
40
+ context about concepts, policies, and workflows.
41
+
42
+ An agent can progressively discover an API, read only the relevant guide,
43
+ inspect one operation's schema, and then invoke the selected route:
44
+
45
+ ~~~text
46
+ agent
47
+ │
48
+ ├─ GET / discover the API and list capabilities
49
+ ├─ GET /?guide=... read relevant domain instructions
50
+ ├─ GET /?operation=... read one operation's schema
51
+ └─ POST /items call the selected operation
52
+ ~~~
53
+
54
+ MCA does not replace the application that owns the data or business logic. It
55
+ gives that application a consistent way to publish its capabilities through
56
+ HTTP, in-process dispatch, or MCP.
57
+
58
+ ## Terminology
59
+
60
+ | Term | Meaning |
61
+ | --- | --- |
62
+ | Registry | The object that owns operations, routes, discovery, and guides for one API. |
63
+ | Operation | One callable capability, such as `get_item` or `make_board`. |
64
+ | Route | The HTTP method and path used to invoke an operation. |
65
+ | Schema | Machine-readable information describing valid inputs and outputs. |
66
+ | Guide | Markdown written by the API owner to explain concepts, rules, and workflows. |
67
+ | Discovery | The entry point that lists capabilities and tells clients how to request more context. |
68
+ | Adapter | The layer that connects the shared MCA registry to Pydantic or Django Ninja. |
69
+ | Transport | The way a client reaches the registry, such as direct HTTP or MCP. |
70
+ | MCP host | The ASGI bridge that exposes registered Django registries as one MCP tool. |
71
+
72
+ Every registry includes a discovery operation named `get_context`. With the
73
+ default `mca_path="/"`, it is exposed as `GET /` relative to the API mount.
74
+ When guides are enabled, the root discovery response returns the contents of
75
+ `index.md` as `help`; the router's instructions are returned as `usage`.
76
+
77
+ ## Installation
78
+
79
+ The base package includes Pydantic support:
80
+
81
+ ~~~bash
82
+ python -m pip install model-context-api
83
+ ~~~
84
+
85
+ Install the adapters that your application uses:
86
+
87
+ ~~~bash
88
+ python -m pip install "model-context-api[ninja]"
89
+ python -m pip install "model-context-api[mcp]"
90
+ python -m pip install "model-context-api[ninja,mcp]"
91
+ ~~~
92
+
93
+ The `ninja` extra installs Django and Django Ninja. The `mcp` extra installs
94
+ the MCP Python SDK. Applications using MCP normally install both extras. The
95
+ package requires Python 3.12 or newer.
96
+
97
+ ## The MCA model
98
+
99
+ A registry is the API's published catalog. It connects each named operation to
100
+ its route, validation rules, response shape, description, and relevant guides.
101
+ The registry does not store application data and does not decide whether a
102
+ user is authenticated; the endpoint implementation and host application own
103
+ those responsibilities.
104
+
105
+ Operation names determine their HTTP methods:
106
+
107
+ | Function prefix | HTTP method | Example operation |
108
+ | --- | --- | --- |
109
+ | `get_` | GET | `get_item` |
110
+ | `make_` | POST | `make_item` |
111
+ | `set_` | PUT | `set_item` |
112
+ | `update_` | PATCH | `update_item` |
113
+ | `remove_` | DELETE | `remove_item` |
114
+
115
+ Choose the smallest adapter that matches where the operation lives:
116
+
117
+ | Adapter | Use it when |
118
+ | --- | --- |
119
+ | `PydanticMCARouter` | The operation is a typed Python function or engine. |
120
+ | `NinjaMCARouter` | The operation is part of a Django Ninja REST API. |
121
+ | `MCPHost` | MCP clients need access to registered Django registries. |
122
+ | `BaseMCARouter` | You are implementing another transport. |
123
+
124
+ ## Documentation
125
+
126
+ The detailed guides are organized by topic:
127
+
128
+ - [Documentation index](docs/index.md)
129
+ - [Guides and discovery](docs/discovery.md)
130
+ - [Pydantic APIs](docs/pydantic.md)
131
+ - [Django Ninja APIs](docs/ninja.md)
132
+ - [MCP hosting](docs/mcp.md)
133
+ - [Errors and authentication](docs/errors-and-authentication.md)
134
+ - [API reference](docs/api-reference.md)
135
+
136
+ The [Ninja composition example](examples/ninja/README.md) demonstrates a
137
+ public Django Ninja router, a private Pydantic service, and the shared MCP
138
+ endpoint.
@@ -0,0 +1,124 @@
1
+ # Model Context API
2
+
3
+ model-context-api is a reusable registry and discovery layer for APIs that
4
+ need to be usable by both HTTP clients and AI agents.
5
+
6
+ The distribution name is `model-context-api`. The Python import package is
7
+ `mca`:
8
+
9
+ ~~~python
10
+ from mca.ninja import NinjaMCARouter
11
+ ~~~
12
+
13
+ MCA provides:
14
+
15
+ - one operation registry shared by discovery, HTTP, and MCP;
16
+ - Markdown guides that can be discovered and read on demand;
17
+ - Pydantic dispatch for framework-independent engines;
18
+ - Django Ninja registration with generated request and response schemas;
19
+ - one MCP host and `mc_api` tool for registered Django applications.
20
+
21
+ ## Why MCA exists
22
+
23
+ An ordinary API can be perfectly usable by a human developer and still be
24
+ difficult for an AI agent to use. MCA publishes both a machine-readable
25
+ contract—routes, parameters, request bodies, and responses—and human-readable
26
+ context about concepts, policies, and workflows.
27
+
28
+ An agent can progressively discover an API, read only the relevant guide,
29
+ inspect one operation's schema, and then invoke the selected route:
30
+
31
+ ~~~text
32
+ agent
33
+ │
34
+ ├─ GET / discover the API and list capabilities
35
+ ├─ GET /?guide=... read relevant domain instructions
36
+ ├─ GET /?operation=... read one operation's schema
37
+ └─ POST /items call the selected operation
38
+ ~~~
39
+
40
+ MCA does not replace the application that owns the data or business logic. It
41
+ gives that application a consistent way to publish its capabilities through
42
+ HTTP, in-process dispatch, or MCP.
43
+
44
+ ## Terminology
45
+
46
+ | Term | Meaning |
47
+ | --- | --- |
48
+ | Registry | The object that owns operations, routes, discovery, and guides for one API. |
49
+ | Operation | One callable capability, such as `get_item` or `make_board`. |
50
+ | Route | The HTTP method and path used to invoke an operation. |
51
+ | Schema | Machine-readable information describing valid inputs and outputs. |
52
+ | Guide | Markdown written by the API owner to explain concepts, rules, and workflows. |
53
+ | Discovery | The entry point that lists capabilities and tells clients how to request more context. |
54
+ | Adapter | The layer that connects the shared MCA registry to Pydantic or Django Ninja. |
55
+ | Transport | The way a client reaches the registry, such as direct HTTP or MCP. |
56
+ | MCP host | The ASGI bridge that exposes registered Django registries as one MCP tool. |
57
+
58
+ Every registry includes a discovery operation named `get_context`. With the
59
+ default `mca_path="/"`, it is exposed as `GET /` relative to the API mount.
60
+ When guides are enabled, the root discovery response returns the contents of
61
+ `index.md` as `help`; the router's instructions are returned as `usage`.
62
+
63
+ ## Installation
64
+
65
+ The base package includes Pydantic support:
66
+
67
+ ~~~bash
68
+ python -m pip install model-context-api
69
+ ~~~
70
+
71
+ Install the adapters that your application uses:
72
+
73
+ ~~~bash
74
+ python -m pip install "model-context-api[ninja]"
75
+ python -m pip install "model-context-api[mcp]"
76
+ python -m pip install "model-context-api[ninja,mcp]"
77
+ ~~~
78
+
79
+ The `ninja` extra installs Django and Django Ninja. The `mcp` extra installs
80
+ the MCP Python SDK. Applications using MCP normally install both extras. The
81
+ package requires Python 3.12 or newer.
82
+
83
+ ## The MCA model
84
+
85
+ A registry is the API's published catalog. It connects each named operation to
86
+ its route, validation rules, response shape, description, and relevant guides.
87
+ The registry does not store application data and does not decide whether a
88
+ user is authenticated; the endpoint implementation and host application own
89
+ those responsibilities.
90
+
91
+ Operation names determine their HTTP methods:
92
+
93
+ | Function prefix | HTTP method | Example operation |
94
+ | --- | --- | --- |
95
+ | `get_` | GET | `get_item` |
96
+ | `make_` | POST | `make_item` |
97
+ | `set_` | PUT | `set_item` |
98
+ | `update_` | PATCH | `update_item` |
99
+ | `remove_` | DELETE | `remove_item` |
100
+
101
+ Choose the smallest adapter that matches where the operation lives:
102
+
103
+ | Adapter | Use it when |
104
+ | --- | --- |
105
+ | `PydanticMCARouter` | The operation is a typed Python function or engine. |
106
+ | `NinjaMCARouter` | The operation is part of a Django Ninja REST API. |
107
+ | `MCPHost` | MCP clients need access to registered Django registries. |
108
+ | `BaseMCARouter` | You are implementing another transport. |
109
+
110
+ ## Documentation
111
+
112
+ The detailed guides are organized by topic:
113
+
114
+ - [Documentation index](docs/index.md)
115
+ - [Guides and discovery](docs/discovery.md)
116
+ - [Pydantic APIs](docs/pydantic.md)
117
+ - [Django Ninja APIs](docs/ninja.md)
118
+ - [MCP hosting](docs/mcp.md)
119
+ - [Errors and authentication](docs/errors-and-authentication.md)
120
+ - [API reference](docs/api-reference.md)
121
+
122
+ The [Ninja composition example](examples/ninja/README.md) demonstrates a
123
+ public Django Ninja router, a private Pydantic service, and the shared MCP
124
+ endpoint.
@@ -0,0 +1,8 @@
1
+ """Reusable Model Context API routers and MCP hosting utilities."""
2
+
3
+ from .base import BaseMCARouter, GuideCatalog, MCAError
4
+ from .composition import MCAClient
5
+
6
+ __version__ = "0.1.4"
7
+
8
+ __all__ = ["BaseMCARouter", "GuideCatalog", "MCAClient", "MCAError", "__version__"]