taskmaster-api 0.2.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taskmaster-api
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Client for the Taskmaster Computer agent
5
5
  Author: Naren Sengodan
6
6
  License-Expression: MIT
@@ -40,6 +40,16 @@ acted = tm.computer_act("open_url", url="https://example.com", capture_after=Tru
40
40
  print(acted["result"])
41
41
  ```
42
42
 
43
+ Connect a provider, save an MCP server, or start a deck. `builtin_mcp_url()` is the daemon's own `/mcp`, which already has Computer and the document tools.
44
+
45
+ ```python
46
+ tm.connect_provider("grok")
47
+ tm.connect_provider("openrouter", api_key="sk-...")
48
+ tm.connect_mcp("linear", "npx", args=["-y", "mcp-remote"], secret_env={"LINEAR_API_KEY": "..."})
49
+ session = tm.make_pptx("Q4 plan", "Three slides: goal, plan, ask")
50
+ print(tm.docs())
51
+ ```
52
+
43
53
  The standard library is the only dependency. Coding-run methods (`start`, `approve`, `events`) remain. `call(method, path, body)` sends any other route.
44
54
 
45
55
  The same client is published for Rust (`cargo add taskmaster-api`) and JavaScript (`npm install taskmaster-api`).
@@ -23,6 +23,16 @@ acted = tm.computer_act("open_url", url="https://example.com", capture_after=Tru
23
23
  print(acted["result"])
24
24
  ```
25
25
 
26
+ Connect a provider, save an MCP server, or start a deck. `builtin_mcp_url()` is the daemon's own `/mcp`, which already has Computer and the document tools.
27
+
28
+ ```python
29
+ tm.connect_provider("grok")
30
+ tm.connect_provider("openrouter", api_key="sk-...")
31
+ tm.connect_mcp("linear", "npx", args=["-y", "mcp-remote"], secret_env={"LINEAR_API_KEY": "..."})
32
+ session = tm.make_pptx("Q4 plan", "Three slides: goal, plan, ask")
33
+ print(tm.docs())
34
+ ```
35
+
26
36
  The standard library is the only dependency. Coding-run methods (`start`, `approve`, `events`) remain. `call(method, path, body)` sends any other route.
27
37
 
28
38
  The same client is published for Rust (`cargo add taskmaster-api`) and JavaScript (`npm install taskmaster-api`).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "taskmaster-api"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Client for the Taskmaster Computer agent"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -12,7 +12,7 @@ import urllib.request
12
12
  from typing import Any, Mapping, Optional
13
13
 
14
14
  DEFAULT_BASE_URL = "http://127.0.0.1:8737"
15
- VERSION = "0.2.0"
15
+ VERSION = "0.3.0"
16
16
 
17
17
 
18
18
  class TaskmasterError(Exception):
@@ -143,6 +143,119 @@ class Taskmaster:
143
143
  """``POST /api/computer/routines/{id}/run``."""
144
144
  return self.call("POST", f"/api/computer/routines/{_segment(routine_id)}/run", {})
145
145
 
146
+ def builtin_mcp_url(self) -> str:
147
+ """URL of the daemon's own MCP endpoint.
148
+
149
+ Agents already get this server. It carries the dictionary, Computer,
150
+ and the document tools. ``connect_mcp`` adds another server.
151
+ """
152
+ return f"{self.base_url}/mcp"
153
+
154
+ def mcp_servers(self) -> list[Any]:
155
+ """``GET /api/mcp``. User MCP servers saved for this project."""
156
+ listed = self._object(self.call("GET", "/api/mcp"))
157
+ servers = listed.get("servers")
158
+ if not isinstance(servers, list):
159
+ raise TaskmasterError(0, "mcp response had no list")
160
+ return servers
161
+
162
+ def connect_mcp(
163
+ self,
164
+ name: str,
165
+ command: str,
166
+ *,
167
+ args: Optional[list[str]] = None,
168
+ env: Optional[Mapping[str, str]] = None,
169
+ secret_env: Optional[Mapping[str, str]] = None,
170
+ roles: Optional[list[str]] = None,
171
+ enabled: Optional[bool] = None,
172
+ require_approval: Optional[bool] = None,
173
+ ) -> dict[str, Any]:
174
+ """``POST /api/mcp``. Adds or replaces a user MCP server.
175
+
176
+ ``secret_env`` values go to the OS keychain. The daemon does not echo them.
177
+ """
178
+ body: dict[str, Any] = {"name": name, "command": command}
179
+ if args:
180
+ body["args"] = args
181
+ if env:
182
+ body["env"] = dict(env)
183
+ if secret_env:
184
+ body["secret_env"] = dict(secret_env)
185
+ if roles:
186
+ body["roles"] = roles
187
+ if enabled is not None:
188
+ body["enabled"] = enabled
189
+ if require_approval is not None:
190
+ body["require_approval"] = require_approval
191
+ saved = self._object(self.call("POST", "/api/mcp", body))
192
+ server = saved.get("server")
193
+ if not isinstance(server, dict):
194
+ raise TaskmasterError(0, "mcp response had no server")
195
+ return server
196
+
197
+ def disconnect_mcp(self, name: str) -> Any:
198
+ """``POST /api/mcp/{name}/remove``."""
199
+ return self.call("POST", f"/api/mcp/{_segment(name)}/remove", {})
200
+
201
+ def docs(self) -> list[Any]:
202
+ """``GET /api/computer/docs``."""
203
+ listed = self._object(self.call("GET", "/api/computer/docs"))
204
+ docs = listed.get("docs")
205
+ if not isinstance(docs, list):
206
+ raise TaskmasterError(0, "docs response had no list")
207
+ return docs
208
+
209
+ def doc(self, doc_id: str) -> dict[str, Any]:
210
+ """``GET /api/computer/docs/{id}``."""
211
+ return self._object(self.call("GET", f"/api/computer/docs/{_segment(doc_id)}"))
212
+
213
+ def upload_doc(self, name: str, data_base64: str) -> dict[str, Any]:
214
+ """``POST /api/computer/files``. ``data_base64`` is the file bytes."""
215
+ return self._object(self.call("POST", "/api/computer/files", {"name": name, "data_base64": data_base64}))
216
+
217
+ def open_doc(self, doc_id: str) -> Any:
218
+ """``POST /api/computer/docs/{id}/open``. Opens the file in the host's default app."""
219
+ return self.call("POST", f"/api/computer/docs/{_segment(doc_id)}/open", {})
220
+
221
+ def make_pptx(self, title: str, brief: Optional[str] = None) -> dict[str, Any]:
222
+ """Start a Computer session that builds a PowerPoint with ``doc_create_pptx``."""
223
+ return self.computer_start(_document_task("PowerPoint", "doc_create_pptx", title, brief))
224
+
225
+ def make_docx(self, title: str, brief: Optional[str] = None) -> dict[str, Any]:
226
+ """Start a Computer session that builds a Word document with ``doc_create_docx``."""
227
+ return self.computer_start(_document_task("Word document", "doc_create_docx", title, brief))
228
+
229
+ def setup(self) -> dict[str, Any]:
230
+ """``GET /api/setup``. Each provider's install and sign-in state, plus runtimes and jobs."""
231
+ return self._object(self.call("GET", "/api/setup"))
232
+
233
+ def connect_provider(self, provider_id: str, api_key: Optional[str] = None) -> Any:
234
+ """Connect a provider in one call.
235
+
236
+ An ``api_key`` is saved for a provider that uses one (``openrouter``).
237
+ Otherwise this installs the CLI when it is missing, or starts its sign-in
238
+ when it is already installed. A provider that is installed and signed in
239
+ returns ``{"ok": true, "connected": true}``.
240
+ """
241
+ segment = _segment(provider_id)
242
+ if api_key is not None:
243
+ return self.call("POST", f"/api/setup/providers/{segment}/key", {"api_key": api_key})
244
+ setup = self.setup()
245
+ providers = setup.get("providers")
246
+ match = None
247
+ if isinstance(providers, list):
248
+ for item in providers:
249
+ if isinstance(item, dict) and item.get("id") == provider_id:
250
+ match = item
251
+ break
252
+ installed = bool(match and match.get("installed") is True)
253
+ signed_in = bool(match and match.get("signed_in") is True)
254
+ if installed and signed_in:
255
+ return {"ok": True, "connected": True, "id": provider_id}
256
+ action = "login" if installed else "install"
257
+ return self.call("POST", f"/api/setup/providers/{segment}/{action}", {})
258
+
146
259
  def runs(self) -> dict[str, Any]:
147
260
  """``GET /api/runs``. The body is ``{"runs": [...], "seq": n}``."""
148
261
  return self._object(self.call("GET", "/api/runs"))
@@ -287,6 +400,13 @@ class Taskmaster:
287
400
  return value
288
401
 
289
402
 
403
+ def _document_task(kind: str, tool: str, title: str, brief: Optional[str]) -> str:
404
+ task = f"Make a {kind} with {tool}. Title: {title}. Use one cohesive theme on every page."
405
+ if brief:
406
+ task = f"{task} {brief}"
407
+ return task
408
+
409
+
290
410
  def _segment(run_id: str) -> str:
291
411
  from urllib.parse import quote
292
412
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taskmaster-api
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Client for the Taskmaster Computer agent
5
5
  Author: Naren Sengodan
6
6
  License-Expression: MIT
@@ -40,6 +40,16 @@ acted = tm.computer_act("open_url", url="https://example.com", capture_after=Tru
40
40
  print(acted["result"])
41
41
  ```
42
42
 
43
+ Connect a provider, save an MCP server, or start a deck. `builtin_mcp_url()` is the daemon's own `/mcp`, which already has Computer and the document tools.
44
+
45
+ ```python
46
+ tm.connect_provider("grok")
47
+ tm.connect_provider("openrouter", api_key="sk-...")
48
+ tm.connect_mcp("linear", "npx", args=["-y", "mcp-remote"], secret_env={"LINEAR_API_KEY": "..."})
49
+ session = tm.make_pptx("Q4 plan", "Three slides: goal, plan, ask")
50
+ print(tm.docs())
51
+ ```
52
+
43
53
  The standard library is the only dependency. Coding-run methods (`start`, `approve`, `events`) remain. `call(method, path, body)` sends any other route.
44
54
 
45
55
  The same client is published for Rust (`cargo add taskmaster-api`) and JavaScript (`npm install taskmaster-api`).
@@ -32,7 +32,13 @@ class Handler(BaseHTTPRequestHandler):
32
32
  else:
33
33
  self._send(401, {"error": "that code was refused"})
34
34
  return
35
- if not authed and (path.startswith("/api/runs") or path == "/api/doctor" or path.startswith("/api/computer")):
35
+ if not authed and (
36
+ path.startswith("/api/runs")
37
+ or path == "/api/doctor"
38
+ or path.startswith("/api/computer")
39
+ or path.startswith("/api/mcp")
40
+ or path.startswith("/api/setup")
41
+ ):
36
42
  self._send(401, {"error": "a token is required"})
37
43
  return
38
44
  if method == "GET" and path == "/api/runs":
@@ -62,6 +68,12 @@ class Handler(BaseHTTPRequestHandler):
62
68
  if method == "POST" and path == "/api/computer/sessions" and "weather" in body:
63
69
  self._send(200, {"id": "cs-1", "task": "Open Chrome and search for the weather", "status": "running", "harness": "grok", "final_reply": ""})
64
70
  return
71
+ if method == "POST" and path == "/api/computer/sessions" and "doc_create_pptx" in body:
72
+ self._send(200, {"id": "cs-doc", "task": "Make a PowerPoint with doc_create_pptx. Title: Q4 plan.", "status": "running", "final_reply": ""})
73
+ return
74
+ if method == "POST" and path == "/api/computer/sessions" and "doc_create_docx" in body:
75
+ self._send(200, {"id": "cs-docx", "task": "Make a Word document with doc_create_docx. Title: Notes.", "status": "running", "final_reply": ""})
76
+ return
65
77
  if method == "GET" and path == "/api/computer/sessions":
66
78
  self._send(200, {"sessions": [{"id": "cs-1", "task": "Open Chrome and search for the weather", "status": "running", "step_count": 1, "agent_count": 1}]})
67
79
  return
@@ -77,6 +89,36 @@ class Handler(BaseHTTPRequestHandler):
77
89
  if method == "POST" and path == "/api/computer/act" and "click_text" in body and "Search" in body:
78
90
  self._send(200, {"ok": True, "result": "clicked Search"})
79
91
  return
92
+ if method == "GET" and path == "/api/mcp":
93
+ self._send(200, {"servers": [{"name": "linear", "command": "npx", "enabled": True}]})
94
+ return
95
+ if method == "POST" and path == "/api/mcp" and "linear" in body and "npx" in body:
96
+ self._send(200, {"server": {"name": "linear", "command": "npx", "enabled": True}})
97
+ return
98
+ if method == "POST" and path == "/api/mcp/linear/remove":
99
+ self._send(200, {"removed": True})
100
+ return
101
+ if method == "GET" and path == "/api/computer/docs":
102
+ self._send(200, {"docs": [{"id": "doc-1", "filename": "Deck.pptx", "kind": "pptx", "title": "Deck"}]})
103
+ return
104
+ if method == "GET" and path == "/api/computer/docs/doc-1":
105
+ self._send(200, {"id": "doc-1", "filename": "Deck.pptx", "kind": "pptx", "title": "Deck"})
106
+ return
107
+ if method == "POST" and path == "/api/computer/files" and "Deck.pptx" in body:
108
+ self._send(200, {"id": "doc-1", "filename": "Deck.pptx", "kind": "pptx", "title": "Deck"})
109
+ return
110
+ if method == "POST" and path == "/api/computer/docs/doc-1/open":
111
+ self._send(200, {"ok": True, "path": "/tmp/Deck.pptx"})
112
+ return
113
+ if method == "GET" and path == "/api/setup":
114
+ self._send(200, {"providers": [{"id": "grok", "installed": True, "signed_in": False}]})
115
+ return
116
+ if method == "POST" and path == "/api/setup/providers/grok/login":
117
+ self._send(202, {"id": "job-1", "state": "running", "action": "login"})
118
+ return
119
+ if method == "POST" and path == "/api/setup/providers/openrouter/key" and "api_key" in body:
120
+ self._send(200, {"ok": True, "configured": True})
121
+ return
80
122
  self._send(404, {"error": "no such route"})
81
123
 
82
124
  def _send(self, status: int, payload: object) -> None:
@@ -140,6 +182,28 @@ class ClientTest(unittest.TestCase):
140
182
  self.assertTrue(acted["ok"])
141
183
  self.assertEqual(acted["result"], "clicked Search")
142
184
 
185
+ self.assertTrue(tm.builtin_mcp_url().endswith("/mcp"))
186
+ servers = tm.mcp_servers()
187
+ self.assertEqual(servers[0]["name"], "linear")
188
+ self.assertTrue(servers[0]["enabled"])
189
+ saved = tm.connect_mcp("linear", "npx", args=["-y", "mcp-remote"])
190
+ self.assertEqual(saved["command"], "npx")
191
+ self.assertEqual(tm.disconnect_mcp("linear"), {"removed": True})
192
+ docs = tm.docs()
193
+ self.assertEqual(docs[0]["id"], "doc-1")
194
+ self.assertEqual(docs[0]["kind"], "pptx")
195
+ self.assertEqual(tm.doc("doc-1")["filename"], "Deck.pptx")
196
+ self.assertEqual(tm.upload_doc("Deck.pptx", "QQ==")["id"], "doc-1")
197
+ self.assertEqual(tm.open_doc("doc-1"), {"ok": True, "path": "/tmp/Deck.pptx"})
198
+ deck = tm.make_pptx("Q4 plan", "Three slides: goal, plan, ask")
199
+ self.assertEqual(deck["id"], "cs-doc")
200
+ self.assertIn("doc_create_pptx", deck["task"])
201
+ self.assertEqual(tm.make_docx("Notes")["id"], "cs-docx")
202
+ job = tm.connect_provider("grok")
203
+ self.assertEqual(job["id"], "job-1")
204
+ self.assertEqual(job["action"], "login")
205
+ self.assertTrue(tm.connect_provider("openrouter", api_key="sk-test")["configured"])
206
+
143
207
  tm.clear_token()
144
208
  with self.assertRaises(TaskmasterError) as missing:
145
209
  tm.runs()
File without changes
File without changes