postara-mcp 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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.4
2
+ Name: postara-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that exposes Postara mailboxes to Claude Desktop, Cursor, and Cline
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: httpx>=0.27.0
10
+ Requires-Dist: mcp>=1.2.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest>=8.2.0; extra == "dev"
13
+ Dynamic: license-file
14
+
15
+ # postara-mcp
16
+
17
+ An [MCP](https://modelcontextprotocol.io) server that exposes [Postara](https://postara.dev)
18
+ mailboxes to MCP clients like Claude Desktop, Cursor, and Cline.
19
+
20
+ It is a thin client: it holds a base URL and an API key and calls a running
21
+ Postara instance over HTTP. The same command works against a self-hosted
22
+ deployment or the hosted service. Its only dependencies are `httpx` and `mcp`.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install 'git+https://github.com/jmluang/postara-mcp.git'
28
+ ```
29
+
30
+ Or run it without installing, using [uv](https://docs.astral.sh/uv/):
31
+
32
+ ```bash
33
+ uvx --from 'git+https://github.com/jmluang/postara-mcp.git' postara-mcp
34
+ ```
35
+
36
+ ## Configure
37
+
38
+ The server reads two environment variables:
39
+
40
+ | Variable | Required | Default | Notes |
41
+ |---|---|---|---|
42
+ | `POSTARA_API_KEY` | yes | — | A scoped API key created in the Postara app. |
43
+ | `POSTARA_BASE_URL` | no | `http://127.0.0.1:18080` | URL of the running Postara instance. |
44
+
45
+ Create the API key in Postara (Workspace -> API keys). Give it only the scopes
46
+ the client needs:
47
+
48
+ - `read` — discover mailboxes, list folders and messages, fetch messages.
49
+ - `mark_seen` — change read/unread state. Add this only if the client should
50
+ mark messages seen.
51
+
52
+ One `postara-mcp` process uses one API key, so it sees exactly the mailboxes
53
+ that key can access.
54
+
55
+ ## Connect Claude Desktop
56
+
57
+ Add the server to `claude_desktop_config.json`:
58
+
59
+ ```json
60
+ {
61
+ "mcpServers": {
62
+ "postara": {
63
+ "command": "uvx",
64
+ "args": ["--from", "git+https://github.com/jmluang/postara-mcp.git", "postara-mcp"],
65
+ "env": {
66
+ "POSTARA_BASE_URL": "http://127.0.0.1:18080",
67
+ "POSTARA_API_KEY": "pst_live_your_key_here"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ If you installed the package with `pip`, set `"command": "postara-mcp"` and drop
75
+ `args` instead. Restart Claude Desktop; the Postara tools then appear.
76
+
77
+ Cursor and Cline use the same MCP server config shape.
78
+
79
+ ## Tools
80
+
81
+ | Tool | Purpose |
82
+ |---|---|
83
+ | `list_mailboxes` | Discover mailboxes the key can access. Includes connection `health`. |
84
+ | `list_folders` | List folders in a mailbox. |
85
+ | `list_messages` | List message summaries, with folder/date/sender/read filters. |
86
+ | `get_message` | Fetch one message body by uid. |
87
+ | `mark_message_seen` | Mark a message read or unread (needs the `mark_seen` scope). |
88
+
89
+ `list_mailboxes` returns a `health` block per mailbox. A client should skip a
90
+ mailbox whose `health.status` is `reconnect_required` and ask the user to
91
+ reconnect it in Postara.
92
+
93
+ ## Transport
94
+
95
+ `postara-mcp` runs over stdio, the transport Claude Desktop, Cursor, and Cline
96
+ use for local MCP servers.
97
+
98
+ ## Develop
99
+
100
+ ```bash
101
+ pip install -e '.[dev]'
102
+ pytest
103
+ ```
104
+
105
+ ## License
106
+
107
+ Apache-2.0.
@@ -0,0 +1,93 @@
1
+ # postara-mcp
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server that exposes [Postara](https://postara.dev)
4
+ mailboxes to MCP clients like Claude Desktop, Cursor, and Cline.
5
+
6
+ It is a thin client: it holds a base URL and an API key and calls a running
7
+ Postara instance over HTTP. The same command works against a self-hosted
8
+ deployment or the hosted service. Its only dependencies are `httpx` and `mcp`.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install 'git+https://github.com/jmluang/postara-mcp.git'
14
+ ```
15
+
16
+ Or run it without installing, using [uv](https://docs.astral.sh/uv/):
17
+
18
+ ```bash
19
+ uvx --from 'git+https://github.com/jmluang/postara-mcp.git' postara-mcp
20
+ ```
21
+
22
+ ## Configure
23
+
24
+ The server reads two environment variables:
25
+
26
+ | Variable | Required | Default | Notes |
27
+ |---|---|---|---|
28
+ | `POSTARA_API_KEY` | yes | — | A scoped API key created in the Postara app. |
29
+ | `POSTARA_BASE_URL` | no | `http://127.0.0.1:18080` | URL of the running Postara instance. |
30
+
31
+ Create the API key in Postara (Workspace -> API keys). Give it only the scopes
32
+ the client needs:
33
+
34
+ - `read` — discover mailboxes, list folders and messages, fetch messages.
35
+ - `mark_seen` — change read/unread state. Add this only if the client should
36
+ mark messages seen.
37
+
38
+ One `postara-mcp` process uses one API key, so it sees exactly the mailboxes
39
+ that key can access.
40
+
41
+ ## Connect Claude Desktop
42
+
43
+ Add the server to `claude_desktop_config.json`:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "postara": {
49
+ "command": "uvx",
50
+ "args": ["--from", "git+https://github.com/jmluang/postara-mcp.git", "postara-mcp"],
51
+ "env": {
52
+ "POSTARA_BASE_URL": "http://127.0.0.1:18080",
53
+ "POSTARA_API_KEY": "pst_live_your_key_here"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ If you installed the package with `pip`, set `"command": "postara-mcp"` and drop
61
+ `args` instead. Restart Claude Desktop; the Postara tools then appear.
62
+
63
+ Cursor and Cline use the same MCP server config shape.
64
+
65
+ ## Tools
66
+
67
+ | Tool | Purpose |
68
+ |---|---|
69
+ | `list_mailboxes` | Discover mailboxes the key can access. Includes connection `health`. |
70
+ | `list_folders` | List folders in a mailbox. |
71
+ | `list_messages` | List message summaries, with folder/date/sender/read filters. |
72
+ | `get_message` | Fetch one message body by uid. |
73
+ | `mark_message_seen` | Mark a message read or unread (needs the `mark_seen` scope). |
74
+
75
+ `list_mailboxes` returns a `health` block per mailbox. A client should skip a
76
+ mailbox whose `health.status` is `reconnect_required` and ask the user to
77
+ reconnect it in Postara.
78
+
79
+ ## Transport
80
+
81
+ `postara-mcp` runs over stdio, the transport Claude Desktop, Cursor, and Cline
82
+ use for local MCP servers.
83
+
84
+ ## Develop
85
+
86
+ ```bash
87
+ pip install -e '.[dev]'
88
+ pytest
89
+ ```
90
+
91
+ ## License
92
+
93
+ Apache-2.0.
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "postara-mcp"
7
+ version = "0.1.0"
8
+ description = "MCP server that exposes Postara mailboxes to Claude Desktop, Cursor, and Cline"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ dependencies = [
13
+ "httpx>=0.27.0",
14
+ "mcp>=1.2.0",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ dev = ["pytest>=8.2.0"]
19
+
20
+ [project.scripts]
21
+ postara-mcp = "postara_mcp.server:main"
22
+
23
+ [tool.setuptools.packages.find]
24
+ where = ["src"]
25
+
26
+ [tool.pytest.ini_options]
27
+ testpaths = ["tests"]
28
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """Postara MCP server.
2
+
3
+ Exposes user-connected Postara mailboxes as Model Context Protocol tools by
4
+ wrapping the Postara REST API. Run with the ``postara-mcp`` console script.
5
+ """
@@ -0,0 +1,113 @@
1
+ """HTTP client that wraps the Postara REST API for the MCP server.
2
+
3
+ The MCP server is a thin client: it holds a base URL and an API key, and calls
4
+ a running Postara instance over HTTP. The same client works against a
5
+ self-hosted deployment or the hosted service.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import os
11
+
12
+ import httpx
13
+
14
+ DEFAULT_BASE_URL = "http://127.0.0.1:18080"
15
+
16
+
17
+ class PostaraConfigError(RuntimeError):
18
+ """Raised when required MCP server configuration is missing."""
19
+
20
+
21
+ class PostaraMCPError(RuntimeError):
22
+ """A Postara request failed. Carries a human-readable, agent-safe message."""
23
+
24
+
25
+ def _error_message(response: httpx.Response) -> str:
26
+ """Turn a Postara error response into one readable line, no secrets."""
27
+ try:
28
+ body = response.json()
29
+ except ValueError:
30
+ return f"Postara request failed (HTTP {response.status_code})."
31
+ error = body.get("error") if isinstance(body, dict) else None
32
+ if isinstance(error, dict):
33
+ code = error.get("code", "error")
34
+ message = error.get("message", "").strip()
35
+ return f"{message} [{code}]".strip() if message else f"Postara error: {code}."
36
+ return f"Postara request failed (HTTP {response.status_code})."
37
+
38
+
39
+ class PostaraClient:
40
+ """Async client over the Postara mailbox REST API."""
41
+
42
+ def __init__(
43
+ self,
44
+ base_url: str,
45
+ api_key: str,
46
+ *,
47
+ transport: httpx.BaseTransport | httpx.AsyncBaseTransport | None = None,
48
+ ) -> None:
49
+ self.base_url = base_url.rstrip("/")
50
+ self._client = httpx.AsyncClient(
51
+ base_url=self.base_url,
52
+ headers={"X-Api-Key": api_key},
53
+ transport=transport,
54
+ timeout=30.0,
55
+ )
56
+
57
+ @classmethod
58
+ def from_env(cls) -> "PostaraClient":
59
+ """Build a client from POSTARA_BASE_URL / POSTARA_API_KEY."""
60
+ api_key = os.environ.get("POSTARA_API_KEY")
61
+ if not api_key:
62
+ raise PostaraConfigError(
63
+ "POSTARA_API_KEY is required. Create a scoped API key in Postara "
64
+ "and set it in the environment."
65
+ )
66
+ base_url = os.environ.get("POSTARA_BASE_URL", DEFAULT_BASE_URL)
67
+ return cls(base_url, api_key)
68
+
69
+ async def aclose(self) -> None:
70
+ await self._client.aclose()
71
+
72
+ async def _request(
73
+ self,
74
+ method: str,
75
+ path: str,
76
+ *,
77
+ params: dict | None = None,
78
+ json: dict | None = None,
79
+ ) -> dict:
80
+ try:
81
+ response = await self._client.request(method, path, params=params, json=json)
82
+ except httpx.HTTPError as exc:
83
+ raise PostaraMCPError(
84
+ f"Could not reach Postara at {self.base_url}: {exc}"
85
+ ) from exc
86
+ if response.status_code >= 400:
87
+ raise PostaraMCPError(_error_message(response))
88
+ return response.json()
89
+
90
+ async def list_mailboxes(self) -> dict:
91
+ return await self._request("GET", "/mailboxes")
92
+
93
+ async def list_folders(self, mailbox: str) -> dict:
94
+ return await self._request("GET", f"/mailboxes/{mailbox}/folders")
95
+
96
+ async def list_messages(self, mailbox: str, **filters: object) -> dict:
97
+ params = {key: value for key, value in filters.items() if value is not None}
98
+ return await self._request("GET", f"/mailboxes/{mailbox}/messages", params=params)
99
+
100
+ async def get_message(self, mailbox: str, uid: str, folder: str = "INBOX") -> dict:
101
+ return await self._request(
102
+ "GET", f"/mailboxes/{mailbox}/messages/{uid}", params={"folder": folder}
103
+ )
104
+
105
+ async def mark_message_seen(
106
+ self, mailbox: str, uid: str, seen: bool = True, folder: str = "INBOX"
107
+ ) -> dict:
108
+ return await self._request(
109
+ "POST",
110
+ f"/mailboxes/{mailbox}/messages/{uid}/seen",
111
+ params={"folder": folder},
112
+ json={"seen": seen},
113
+ )
@@ -0,0 +1,27 @@
1
+ """Entry point for the ``postara-mcp`` console script.
2
+
3
+ Runs a stdio MCP server that exposes Postara mailbox tools. Configure it with
4
+ the POSTARA_BASE_URL and POSTARA_API_KEY environment variables.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import sys
10
+
11
+ from postara_mcp.client import PostaraClient, PostaraConfigError
12
+ from postara_mcp.tools import build_mcp, set_client
13
+
14
+
15
+ def main() -> None:
16
+ try:
17
+ client = PostaraClient.from_env()
18
+ except PostaraConfigError as exc:
19
+ print(f"postara-mcp: {exc}", file=sys.stderr)
20
+ sys.exit(1)
21
+
22
+ set_client(client)
23
+ build_mcp().run() # stdio transport
24
+
25
+
26
+ if __name__ == "__main__":
27
+ main()
@@ -0,0 +1,114 @@
1
+ """MCP tools that wrap the Postara mailbox API.
2
+
3
+ Each tool is a plain async function (directly callable in tests) and is also
4
+ registered onto a FastMCP server by ``build_mcp``. Tool docstrings mirror the
5
+ agent guidance in the Postara agent API guide.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from mcp.server.fastmcp import FastMCP
11
+
12
+ from postara_mcp.client import PostaraClient
13
+
14
+ _client: PostaraClient | None = None
15
+
16
+
17
+ def set_client(client: PostaraClient) -> None:
18
+ """Install the PostaraClient the tools call. Set this before serving."""
19
+ global _client
20
+ _client = client
21
+
22
+
23
+ def get_client() -> PostaraClient:
24
+ if _client is None:
25
+ raise RuntimeError("PostaraClient is not configured; call set_client first.")
26
+ return _client
27
+
28
+
29
+ async def list_mailboxes() -> dict:
30
+ """List mailboxes this API key can access.
31
+
32
+ Use a mailbox's ``name`` or ``api_path`` for later calls, never the numeric
33
+ ``mailbox_id``. Skip any mailbox whose ``health.status`` is
34
+ ``reconnect_required`` and tell the user to reconnect it in Postara.
35
+ """
36
+ return await get_client().list_mailboxes()
37
+
38
+
39
+ async def list_folders(mailbox: str) -> dict:
40
+ """List folders in a mailbox.
41
+
42
+ ``mailbox`` is the mailbox ``name`` from list_mailboxes. Use a folder's
43
+ ``native_name`` as the ``folder`` argument of the other tools.
44
+ """
45
+ return await get_client().list_folders(mailbox)
46
+
47
+
48
+ async def list_messages(
49
+ mailbox: str,
50
+ folder: str = "INBOX",
51
+ limit: int = 20,
52
+ cursor: str | None = None,
53
+ unread_only: bool = False,
54
+ since: str | None = None,
55
+ before: str | None = None,
56
+ from_address: str | None = None,
57
+ subject_contains: str | None = None,
58
+ text_contains: str | None = None,
59
+ has_attachment: bool | None = None,
60
+ ) -> dict:
61
+ """List message summaries in a folder.
62
+
63
+ ``since`` and ``before`` are ISO 8601 datetime strings. Paginate with the
64
+ ``next_cursor`` value from the previous response. Some providers reject
65
+ ``subject_contains`` / ``text_contains`` / ``has_attachment`` with an
66
+ ``unsupported_provider_feature`` error; retry without those filters.
67
+ """
68
+ return await get_client().list_messages(
69
+ mailbox,
70
+ folder=folder,
71
+ limit=limit,
72
+ cursor=cursor,
73
+ unread_only=unread_only,
74
+ since=since,
75
+ before=before,
76
+ from_address=from_address,
77
+ subject_contains=subject_contains,
78
+ text_contains=text_contains,
79
+ has_attachment=has_attachment,
80
+ )
81
+
82
+
83
+ async def get_message(mailbox: str, uid: str, folder: str = "INBOX") -> dict:
84
+ """Fetch one message by uid. Prefer the ``text`` body for summarizing."""
85
+ return await get_client().get_message(mailbox, uid, folder=folder)
86
+
87
+
88
+ async def mark_message_seen(
89
+ mailbox: str, uid: str, seen: bool = True, folder: str = "INBOX"
90
+ ) -> dict:
91
+ """Mark a message read or unread.
92
+
93
+ Only call this when the user explicitly asks to change read state. The API
94
+ key must include the ``mark_seen`` scope; on a ``scope_forbidden`` error,
95
+ stop and tell the user the key lacks that scope.
96
+ """
97
+ return await get_client().mark_message_seen(mailbox, uid, seen=seen, folder=folder)
98
+
99
+
100
+ ALL_TOOLS = (
101
+ list_mailboxes,
102
+ list_folders,
103
+ list_messages,
104
+ get_message,
105
+ mark_message_seen,
106
+ )
107
+
108
+
109
+ def build_mcp() -> FastMCP:
110
+ """Build the Postara FastMCP server with all tools registered."""
111
+ mcp = FastMCP("postara")
112
+ for tool in ALL_TOOLS:
113
+ mcp.tool()(tool)
114
+ return mcp
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.4
2
+ Name: postara-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that exposes Postara mailboxes to Claude Desktop, Cursor, and Cline
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: httpx>=0.27.0
10
+ Requires-Dist: mcp>=1.2.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest>=8.2.0; extra == "dev"
13
+ Dynamic: license-file
14
+
15
+ # postara-mcp
16
+
17
+ An [MCP](https://modelcontextprotocol.io) server that exposes [Postara](https://postara.dev)
18
+ mailboxes to MCP clients like Claude Desktop, Cursor, and Cline.
19
+
20
+ It is a thin client: it holds a base URL and an API key and calls a running
21
+ Postara instance over HTTP. The same command works against a self-hosted
22
+ deployment or the hosted service. Its only dependencies are `httpx` and `mcp`.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install 'git+https://github.com/jmluang/postara-mcp.git'
28
+ ```
29
+
30
+ Or run it without installing, using [uv](https://docs.astral.sh/uv/):
31
+
32
+ ```bash
33
+ uvx --from 'git+https://github.com/jmluang/postara-mcp.git' postara-mcp
34
+ ```
35
+
36
+ ## Configure
37
+
38
+ The server reads two environment variables:
39
+
40
+ | Variable | Required | Default | Notes |
41
+ |---|---|---|---|
42
+ | `POSTARA_API_KEY` | yes | — | A scoped API key created in the Postara app. |
43
+ | `POSTARA_BASE_URL` | no | `http://127.0.0.1:18080` | URL of the running Postara instance. |
44
+
45
+ Create the API key in Postara (Workspace -> API keys). Give it only the scopes
46
+ the client needs:
47
+
48
+ - `read` — discover mailboxes, list folders and messages, fetch messages.
49
+ - `mark_seen` — change read/unread state. Add this only if the client should
50
+ mark messages seen.
51
+
52
+ One `postara-mcp` process uses one API key, so it sees exactly the mailboxes
53
+ that key can access.
54
+
55
+ ## Connect Claude Desktop
56
+
57
+ Add the server to `claude_desktop_config.json`:
58
+
59
+ ```json
60
+ {
61
+ "mcpServers": {
62
+ "postara": {
63
+ "command": "uvx",
64
+ "args": ["--from", "git+https://github.com/jmluang/postara-mcp.git", "postara-mcp"],
65
+ "env": {
66
+ "POSTARA_BASE_URL": "http://127.0.0.1:18080",
67
+ "POSTARA_API_KEY": "pst_live_your_key_here"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ If you installed the package with `pip`, set `"command": "postara-mcp"` and drop
75
+ `args` instead. Restart Claude Desktop; the Postara tools then appear.
76
+
77
+ Cursor and Cline use the same MCP server config shape.
78
+
79
+ ## Tools
80
+
81
+ | Tool | Purpose |
82
+ |---|---|
83
+ | `list_mailboxes` | Discover mailboxes the key can access. Includes connection `health`. |
84
+ | `list_folders` | List folders in a mailbox. |
85
+ | `list_messages` | List message summaries, with folder/date/sender/read filters. |
86
+ | `get_message` | Fetch one message body by uid. |
87
+ | `mark_message_seen` | Mark a message read or unread (needs the `mark_seen` scope). |
88
+
89
+ `list_mailboxes` returns a `health` block per mailbox. A client should skip a
90
+ mailbox whose `health.status` is `reconnect_required` and ask the user to
91
+ reconnect it in Postara.
92
+
93
+ ## Transport
94
+
95
+ `postara-mcp` runs over stdio, the transport Claude Desktop, Cursor, and Cline
96
+ use for local MCP servers.
97
+
98
+ ## Develop
99
+
100
+ ```bash
101
+ pip install -e '.[dev]'
102
+ pytest
103
+ ```
104
+
105
+ ## License
106
+
107
+ Apache-2.0.
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/postara_mcp/__init__.py
5
+ src/postara_mcp/client.py
6
+ src/postara_mcp/server.py
7
+ src/postara_mcp/tools.py
8
+ src/postara_mcp.egg-info/PKG-INFO
9
+ src/postara_mcp.egg-info/SOURCES.txt
10
+ src/postara_mcp.egg-info/dependency_links.txt
11
+ src/postara_mcp.egg-info/entry_points.txt
12
+ src/postara_mcp.egg-info/requires.txt
13
+ src/postara_mcp.egg-info/top_level.txt
14
+ tests/test_client.py
15
+ tests/test_tools.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ postara-mcp = postara_mcp.server:main
@@ -0,0 +1,5 @@
1
+ httpx>=0.27.0
2
+ mcp>=1.2.0
3
+
4
+ [dev]
5
+ pytest>=8.2.0
@@ -0,0 +1 @@
1
+ postara_mcp
@@ -0,0 +1,118 @@
1
+ import asyncio
2
+ import json
3
+
4
+ import httpx
5
+ import pytest
6
+
7
+ from postara_mcp.client import PostaraClient, PostaraMCPError
8
+
9
+ API_KEY = "pst_live_test"
10
+
11
+
12
+ def client_with(handler) -> PostaraClient:
13
+ return PostaraClient("http://postara.test", API_KEY, transport=httpx.MockTransport(handler))
14
+
15
+
16
+ def run(client: PostaraClient, coro_factory):
17
+ async def body():
18
+ try:
19
+ return await coro_factory(client)
20
+ finally:
21
+ await client.aclose()
22
+
23
+ return asyncio.run(body())
24
+
25
+
26
+ def ok(payload: dict) -> httpx.Response:
27
+ return httpx.Response(200, json=payload)
28
+
29
+
30
+ def err(status: int, code: str, message: str) -> httpx.Response:
31
+ return httpx.Response(status, json={"error": {"code": code, "message": message}})
32
+
33
+
34
+ def test_list_mailboxes_sends_key_and_returns_payload():
35
+ captured = {}
36
+
37
+ def handler(request: httpx.Request) -> httpx.Response:
38
+ captured["path"] = request.url.path
39
+ captured["key"] = request.headers.get("X-Api-Key")
40
+ return ok({"mailboxes": [{"name": "work", "health": {"status": "ok"}}]})
41
+
42
+ data = run(client_with(handler), lambda c: c.list_mailboxes())
43
+
44
+ assert captured["path"] == "/mailboxes"
45
+ assert captured["key"] == API_KEY
46
+ assert data["mailboxes"][0]["name"] == "work"
47
+
48
+
49
+ def test_list_folders_targets_the_mailbox():
50
+ def handler(request: httpx.Request) -> httpx.Response:
51
+ assert request.url.path == "/mailboxes/work/folders"
52
+ return ok({"folders": [{"native_name": "INBOX"}]})
53
+
54
+ data = run(client_with(handler), lambda c: c.list_folders("work"))
55
+
56
+ assert data["folders"][0]["native_name"] == "INBOX"
57
+
58
+
59
+ def test_list_messages_passes_filters_and_drops_none():
60
+ captured = {}
61
+
62
+ def handler(request: httpx.Request) -> httpx.Response:
63
+ captured["params"] = dict(request.url.params)
64
+ return ok({"messages": [], "next_cursor": None})
65
+
66
+ run(client_with(handler), lambda c: c.list_messages("work", limit=5, unread_only=True, since=None))
67
+
68
+ assert captured["params"]["limit"] == "5"
69
+ assert captured["params"]["unread_only"] == "true"
70
+ assert "since" not in captured["params"]
71
+
72
+
73
+ def test_get_message_includes_folder_query():
74
+ def handler(request: httpx.Request) -> httpx.Response:
75
+ assert request.url.path == "/mailboxes/work/messages/123"
76
+ assert request.url.params["folder"] == "INBOX"
77
+ return ok({"message": {"uid": "123", "text": "hi"}})
78
+
79
+ data = run(client_with(handler), lambda c: c.get_message("work", "123"))
80
+
81
+ assert data["message"]["text"] == "hi"
82
+
83
+
84
+ def test_mark_message_seen_posts_seen_body():
85
+ captured = {}
86
+
87
+ def handler(request: httpx.Request) -> httpx.Response:
88
+ captured["method"] = request.method
89
+ captured["body"] = json.loads(request.content)
90
+ return ok({"uid": "123", "seen": True})
91
+
92
+ data = run(client_with(handler), lambda c: c.mark_message_seen("work", "123", seen=True))
93
+
94
+ assert captured["method"] == "POST"
95
+ assert captured["body"] == {"seen": True}
96
+ assert data["seen"] is True
97
+
98
+
99
+ def test_error_response_becomes_readable_postara_error():
100
+ def handler(request: httpx.Request) -> httpx.Response:
101
+ return err(404, "message_not_found", "Message not found.")
102
+
103
+ with pytest.raises(PostaraMCPError) as exc:
104
+ run(client_with(handler), lambda c: c.get_message("work", "999"))
105
+
106
+ message = str(exc.value)
107
+ assert "message_not_found" in message
108
+ assert "Message not found." in message
109
+
110
+
111
+ def test_network_failure_becomes_readable_error():
112
+ def handler(request: httpx.Request) -> httpx.Response:
113
+ raise httpx.ConnectError("connection refused")
114
+
115
+ with pytest.raises(PostaraMCPError) as exc:
116
+ run(client_with(handler), lambda c: c.list_mailboxes())
117
+
118
+ assert "Could not reach Postara" in str(exc.value)
@@ -0,0 +1,64 @@
1
+ import asyncio
2
+
3
+ import httpx
4
+ import pytest
5
+
6
+ from postara_mcp.client import PostaraClient, PostaraMCPError
7
+ from postara_mcp.tools import build_mcp, get_message, list_mailboxes, set_client
8
+
9
+ EXPECTED_TOOLS = {
10
+ "list_mailboxes",
11
+ "list_folders",
12
+ "list_messages",
13
+ "get_message",
14
+ "mark_message_seen",
15
+ }
16
+
17
+
18
+ def client_with(handler) -> PostaraClient:
19
+ return PostaraClient("http://postara.test", "pst_live_test", transport=httpx.MockTransport(handler))
20
+
21
+
22
+ def test_build_mcp_registers_all_tools():
23
+ mcp = build_mcp()
24
+
25
+ tools = asyncio.run(mcp.list_tools())
26
+
27
+ assert {tool.name for tool in tools} == EXPECTED_TOOLS
28
+
29
+
30
+ def test_tool_calls_through_to_postara():
31
+ def handler(request: httpx.Request) -> httpx.Response:
32
+ return httpx.Response(200, json={"mailboxes": [{"name": "work"}]})
33
+
34
+ client = client_with(handler)
35
+ set_client(client)
36
+
37
+ async def body():
38
+ try:
39
+ return await list_mailboxes()
40
+ finally:
41
+ await client.aclose()
42
+
43
+ data = asyncio.run(body())
44
+
45
+ assert data["mailboxes"][0]["name"] == "work"
46
+
47
+
48
+ def test_tool_propagates_readable_error():
49
+ def handler(request: httpx.Request) -> httpx.Response:
50
+ return httpx.Response(
51
+ 404, json={"error": {"code": "message_not_found", "message": "Message not found."}}
52
+ )
53
+
54
+ client = client_with(handler)
55
+ set_client(client)
56
+
57
+ async def body():
58
+ try:
59
+ return await get_message("work", "999")
60
+ finally:
61
+ await client.aclose()
62
+
63
+ with pytest.raises(PostaraMCPError):
64
+ asyncio.run(body())