mcpatom 0.1.0__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,17 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ checks:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v7
12
+ - uses: astral-sh/setup-uv@v8.3.2
13
+ - run: uv sync --locked
14
+ - run: uv run ruff check .
15
+ - run: uv run ruff format --check .
16
+ - run: uv run ty check
17
+ - run: uv run pytest
@@ -0,0 +1,17 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write # PyPI trusted publishing authenticates via OIDC, no token
13
+ steps:
14
+ - uses: actions/checkout@v7
15
+ - uses: astral-sh/setup-uv@v8.3.2
16
+ - run: uv build
17
+ - run: uv publish --trusted-publishing always
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ dist/
@@ -0,0 +1 @@
1
+ 3.10
mcpatom-0.1.0/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mitch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
mcpatom-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcpatom
3
+ Version: 0.1.0
4
+ License-Expression: MIT
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+
9
+ # mcpatom
10
+
11
+ A minimal Python [MCP](https://modelcontextprotocol.io) Server SDK.
12
+
13
+ From Greek *atomos*: indivisible. The whole library is a single file,
14
+ `mcpatom.py`, consumable two ways:
15
+
16
+ - **Copy the file** into your project. No dependency, no lockfile entry.
17
+ - **Install the package**: `pip install mcpatom` - the file itself is
18
+ the installed module.
19
+
20
+ ## Scope
21
+
22
+ - Tools, resources, and prompts, over stdio or streamable HTTP.
23
+ - Protocol versions `2025-06-18` and `2025-11-25`.
24
+ - stdlib-only Python >= 3.10, no dependencies, ever.
25
+
26
+ Everything else (sampling, elicitation, subscriptions, auth, etc.) is deliberately omitted.
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from mcpatom import Server
32
+
33
+ srv = Server("my-server")
34
+
35
+
36
+ @srv.tool
37
+ def greet(name: str, excited: bool = False) -> str:
38
+ """Return a greeting for the given name."""
39
+ return f"Hello, {name}{'!' if excited else '.'}"
40
+
41
+
42
+ @srv.resource("data://motd")
43
+ def motd() -> str:
44
+ """Message of the day."""
45
+ return "Be indivisible."
46
+
47
+
48
+ @srv.prompt
49
+ def haiku(topic: str) -> str:
50
+ """Ask for a haiku."""
51
+ return f"Write a haiku about {topic}."
52
+
53
+
54
+ srv.serve_stdio()
55
+ ```
56
+
57
+ For streamable HTTP instead of stdio, end with:
58
+
59
+ ```python
60
+ srv.serve_http(8388) # http://127.0.0.1:8388/mcp
61
+ ```
62
+
63
+ `serve_http` binds to loopback and rejects DNS-rebinding requests;
64
+ `host="0.0.0.0"` widens the bind and switches those checks off.
65
+
66
+ More runnable servers in [examples/](examples/).
67
+
68
+ ## Schemas and return types
69
+
70
+ Each function's name, docstring, and annotations become the tool's name,
71
+ description, and schema; `@srv.tool(name=, description=, input_schema=,
72
+ output_schema=)` override generation, and `extra=` merges raw fields into
73
+ the listing. `Server()` also takes `version=` and `instructions=`.
74
+ Parameters may be annotated with any of these:
75
+ - `str`
76
+ - `int`
77
+ - `float`
78
+ - `bool`
79
+ - `list[X]` (or bare `list`)
80
+ - `Literal[...]`
81
+ - `TypedDict`
82
+ - `X | None` of any of the above
83
+
84
+ `Annotated[X, "text"]` adds a description the model sees.
85
+
86
+ A tool may return:
87
+
88
+ - `str` - one text block
89
+ - `dict` - JSON text plus `structuredContent`; a `TypedDict` return
90
+ annotation publishes the matching `outputSchema`
91
+ - `Image(data, mime_type)` / `Audio(data, mime_type)` - one binary
92
+ block (raw bytes in, base64 on the wire)
93
+ - a tuple - one block per item: `str` text, `Image`/`Audio` media, a
94
+ dict whose `"type"` names a spec block type verbatim (e.g.
95
+ `resource_link`)
96
+ - `None` - empty content; any other JSON value - text
97
+
98
+ Raising is the error API: any exception becomes `isError` content the
99
+ model can read and correct.
100
+
101
+ Resources return `str` (text) or `bytes` (base64 blob).
102
+
103
+ Prompts take only `str` arguments and return a `str` user message, or a
104
+ list of message dicts passed through verbatim.
105
+
106
+ ## Wiring it up
107
+
108
+ ```sh
109
+ claude mcp add my-server -- /abs/path/.venv/bin/python /abs/path/server.py
110
+ ```
111
+
112
+ or in any `mcpServers` config:
113
+
114
+ ```json
115
+ {"mcpServers": {"my-server": {"command": "/abs/path/.venv/bin/python", "args": ["/abs/path/server.py"]}}}
116
+ ```
117
+
118
+ Smoke test without a client:
119
+
120
+ ```sh
121
+ echo '{"jsonrpc":"2.0","id":1,"method":"ping"}' | python server.py
122
+ # {"jsonrpc":"2.0","id":1,"result":{}}
123
+ ```
124
+
@@ -0,0 +1,116 @@
1
+ # mcpatom
2
+
3
+ A minimal Python [MCP](https://modelcontextprotocol.io) Server SDK.
4
+
5
+ From Greek *atomos*: indivisible. The whole library is a single file,
6
+ `mcpatom.py`, consumable two ways:
7
+
8
+ - **Copy the file** into your project. No dependency, no lockfile entry.
9
+ - **Install the package**: `pip install mcpatom` - the file itself is
10
+ the installed module.
11
+
12
+ ## Scope
13
+
14
+ - Tools, resources, and prompts, over stdio or streamable HTTP.
15
+ - Protocol versions `2025-06-18` and `2025-11-25`.
16
+ - stdlib-only Python >= 3.10, no dependencies, ever.
17
+
18
+ Everything else (sampling, elicitation, subscriptions, auth, etc.) is deliberately omitted.
19
+
20
+ ## Usage
21
+
22
+ ```python
23
+ from mcpatom import Server
24
+
25
+ srv = Server("my-server")
26
+
27
+
28
+ @srv.tool
29
+ def greet(name: str, excited: bool = False) -> str:
30
+ """Return a greeting for the given name."""
31
+ return f"Hello, {name}{'!' if excited else '.'}"
32
+
33
+
34
+ @srv.resource("data://motd")
35
+ def motd() -> str:
36
+ """Message of the day."""
37
+ return "Be indivisible."
38
+
39
+
40
+ @srv.prompt
41
+ def haiku(topic: str) -> str:
42
+ """Ask for a haiku."""
43
+ return f"Write a haiku about {topic}."
44
+
45
+
46
+ srv.serve_stdio()
47
+ ```
48
+
49
+ For streamable HTTP instead of stdio, end with:
50
+
51
+ ```python
52
+ srv.serve_http(8388) # http://127.0.0.1:8388/mcp
53
+ ```
54
+
55
+ `serve_http` binds to loopback and rejects DNS-rebinding requests;
56
+ `host="0.0.0.0"` widens the bind and switches those checks off.
57
+
58
+ More runnable servers in [examples/](examples/).
59
+
60
+ ## Schemas and return types
61
+
62
+ Each function's name, docstring, and annotations become the tool's name,
63
+ description, and schema; `@srv.tool(name=, description=, input_schema=,
64
+ output_schema=)` override generation, and `extra=` merges raw fields into
65
+ the listing. `Server()` also takes `version=` and `instructions=`.
66
+ Parameters may be annotated with any of these:
67
+ - `str`
68
+ - `int`
69
+ - `float`
70
+ - `bool`
71
+ - `list[X]` (or bare `list`)
72
+ - `Literal[...]`
73
+ - `TypedDict`
74
+ - `X | None` of any of the above
75
+
76
+ `Annotated[X, "text"]` adds a description the model sees.
77
+
78
+ A tool may return:
79
+
80
+ - `str` - one text block
81
+ - `dict` - JSON text plus `structuredContent`; a `TypedDict` return
82
+ annotation publishes the matching `outputSchema`
83
+ - `Image(data, mime_type)` / `Audio(data, mime_type)` - one binary
84
+ block (raw bytes in, base64 on the wire)
85
+ - a tuple - one block per item: `str` text, `Image`/`Audio` media, a
86
+ dict whose `"type"` names a spec block type verbatim (e.g.
87
+ `resource_link`)
88
+ - `None` - empty content; any other JSON value - text
89
+
90
+ Raising is the error API: any exception becomes `isError` content the
91
+ model can read and correct.
92
+
93
+ Resources return `str` (text) or `bytes` (base64 blob).
94
+
95
+ Prompts take only `str` arguments and return a `str` user message, or a
96
+ list of message dicts passed through verbatim.
97
+
98
+ ## Wiring it up
99
+
100
+ ```sh
101
+ claude mcp add my-server -- /abs/path/.venv/bin/python /abs/path/server.py
102
+ ```
103
+
104
+ or in any `mcpServers` config:
105
+
106
+ ```json
107
+ {"mcpServers": {"my-server": {"command": "/abs/path/.venv/bin/python", "args": ["/abs/path/server.py"]}}}
108
+ ```
109
+
110
+ Smoke test without a client:
111
+
112
+ ```sh
113
+ echo '{"jsonrpc":"2.0","id":1,"method":"ping"}' | python server.py
114
+ # {"jsonrpc":"2.0","id":1,"result":{}}
115
+ ```
116
+
@@ -0,0 +1,33 @@
1
+ # Examples
2
+
3
+ Each file is a complete server. Run from the repo root:
4
+
5
+ ```sh
6
+ python -m examples.tools
7
+ ```
8
+
9
+ or copy `mcpatom.py` next to the example and run it directly.
10
+
11
+ - `tools.py` - typed parameters, a structured (dict) return, an image
12
+ return, and hand-written schema overrides
13
+ - `resources.py` - a text resource and a dict served as JSON
14
+ - `prompts.py` - a string prompt and a multi-message prompt
15
+ - `streamable_http.py` - the same idea over streamable HTTP
16
+
17
+ Smoke test a stdio example by piping a request in:
18
+
19
+ ```sh
20
+ echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | python -m examples.tools
21
+ ```
22
+
23
+ For `streamable_http.py`, start it, then:
24
+
25
+ ```sh
26
+ curl -s localhost:8388/mcp -d '{"jsonrpc":"2.0","id":1,"method":"ping"}'
27
+ ```
28
+
29
+ Or lend one to Claude Code for a single session:
30
+
31
+ ```sh
32
+ claude --mcp-config '{"mcpServers":{"ex":{"command":"python","args":["-m","examples.tools"]}}}'
33
+ ```
Binary file
@@ -0,0 +1,23 @@
1
+ """Prompts: a plain string reply and a multi-message conversation."""
2
+
3
+ from mcpatom import Server
4
+
5
+ srv = Server("prompts-example")
6
+
7
+
8
+ @srv.prompt
9
+ def haiku(topic: str) -> str:
10
+ """Ask for a haiku."""
11
+ return f"Write a haiku about {topic}."
12
+
13
+
14
+ @srv.prompt
15
+ def review(code: str) -> list:
16
+ """Review code, priming the assistant's opening."""
17
+ return [
18
+ {"role": "user", "content": {"type": "text", "text": f"Review this code:\n{code}"}},
19
+ {"role": "assistant", "content": {"type": "text", "text": "Three issues, most severe first:"}},
20
+ ]
21
+
22
+
23
+ srv.serve_stdio()
@@ -0,0 +1,20 @@
1
+ """Resources: a plain text read and a dict served as JSON."""
2
+
3
+ from mcpatom import Server
4
+
5
+ srv = Server("resources-example")
6
+
7
+
8
+ @srv.resource("data://motd")
9
+ def motd() -> str:
10
+ """Message of the day."""
11
+ return "Be indivisible."
12
+
13
+
14
+ @srv.resource("data://config", mime_type="application/json")
15
+ def config() -> dict:
16
+ """Server configuration."""
17
+ return {"theme": "dark", "retries": 3} # dicts are serialised to JSON text
18
+
19
+
20
+ srv.serve_stdio()
@@ -0,0 +1,14 @@
1
+ """A greeter served over streamable HTTP instead of stdio."""
2
+
3
+ from mcpatom import Server
4
+
5
+ srv = Server("http-example")
6
+
7
+
8
+ @srv.tool
9
+ def greet(name: str) -> str:
10
+ """Return a greeting for the given name."""
11
+ return f"Hello, {name}."
12
+
13
+
14
+ srv.serve_http(8388) # POST http://127.0.0.1:8388/mcp
@@ -0,0 +1,48 @@
1
+ """Tools: typed parameters, a structured (dict) return, an image return, and
2
+ hand-written schema overrides."""
3
+
4
+ import random
5
+ from pathlib import Path
6
+ from typing import Annotated, Literal
7
+
8
+ from mcpatom import Image, Server
9
+
10
+ srv = Server("tools-example")
11
+
12
+
13
+ @srv.tool
14
+ def add(a: float, b: float) -> str:
15
+ """Add two numbers."""
16
+ return str(a + b)
17
+
18
+
19
+ @srv.tool
20
+ def roll(sides: Annotated[Literal[6, 20], "Die size"] = 6) -> dict:
21
+ """Roll a die."""
22
+ return {"sides": sides, "value": random.randint(1, sides)}
23
+
24
+
25
+ @srv.tool(
26
+ input_schema={
27
+ "type": "object",
28
+ "properties": {"celsius": {"type": "number", "minimum": -273.15}},
29
+ "required": ["celsius"],
30
+ },
31
+ output_schema={
32
+ "type": "object",
33
+ "properties": {"fahrenheit": {"type": "number"}},
34
+ "required": ["fahrenheit"],
35
+ },
36
+ )
37
+ def convert(celsius: float) -> dict:
38
+ """Convert Celsius to Fahrenheit."""
39
+ return {"fahrenheit": celsius * 9 / 5 + 32}
40
+
41
+
42
+ @srv.tool
43
+ def image() -> Image:
44
+ """A mystery image."""
45
+ return Image(Path(__file__).with_name("cat.gif").read_bytes(), "image/gif")
46
+
47
+
48
+ srv.serve_stdio()