agent-host-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.
- agent_host_mcp-0.1.0/.gitignore +16 -0
- agent_host_mcp-0.1.0/.python-version +1 -0
- agent_host_mcp-0.1.0/Makefile +48 -0
- agent_host_mcp-0.1.0/PKG-INFO +253 -0
- agent_host_mcp-0.1.0/README.md +242 -0
- agent_host_mcp-0.1.0/REFERENCE.md +756 -0
- agent_host_mcp-0.1.0/hatch_build.py +30 -0
- agent_host_mcp-0.1.0/package-lock.json +4460 -0
- agent_host_mcp-0.1.0/package.json +12 -0
- agent_host_mcp-0.1.0/pyproject.toml +54 -0
- agent_host_mcp-0.1.0/scripts/agent-host-mcp +6 -0
- agent_host_mcp-0.1.0/scripts/test_mcp.py +120 -0
- agent_host_mcp-0.1.0/src/agent_mcp/__init__.py +1 -0
- agent_host_mcp-0.1.0/src/agent_mcp/actions.py +194 -0
- agent_host_mcp-0.1.0/src/agent_mcp/auth.py +84 -0
- agent_host_mcp-0.1.0/src/agent_mcp/catalog.py +47 -0
- agent_host_mcp-0.1.0/src/agent_mcp/cell_worker.py +107 -0
- agent_host_mcp-0.1.0/src/agent_mcp/database.py +33 -0
- agent_host_mcp-0.1.0/src/agent_mcp/execution.py +93 -0
- agent_host_mcp-0.1.0/src/agent_mcp/knowledge.py +154 -0
- agent_host_mcp-0.1.0/src/agent_mcp/knowledge_sdk.py +133 -0
- agent_host_mcp-0.1.0/src/agent_mcp/knowledge_store.py +142 -0
- agent_host_mcp-0.1.0/src/agent_mcp/landing.html +95 -0
- agent_host_mcp-0.1.0/src/agent_mcp/models.py +53 -0
- agent_host_mcp-0.1.0/src/agent_mcp/openwiki_export.mjs +5 -0
- agent_host_mcp-0.1.0/src/agent_mcp/openwiki_retrieve.mjs +10 -0
- agent_host_mcp-0.1.0/src/agent_mcp/paths.py +23 -0
- agent_host_mcp-0.1.0/src/agent_mcp/runner.py +111 -0
- agent_host_mcp-0.1.0/src/agent_mcp/scheduler.py +125 -0
- agent_host_mcp-0.1.0/src/agent_mcp/server.py +496 -0
- agent_host_mcp-0.1.0/src/agent_mcp/session_delete.py +76 -0
- agent_host_mcp-0.1.0/src/agent_mcp/session_metadata.py +54 -0
- agent_host_mcp-0.1.0/src/agent_mcp/sessions.py +158 -0
- agent_host_mcp-0.1.0/src/agent_mcp/skills/upload-files/SKILL.md +82 -0
- agent_host_mcp-0.1.0/src/agent_mcp/tokens.py +120 -0
- agent_host_mcp-0.1.0/src/agent_mcp/upload_routes.py +71 -0
- agent_host_mcp-0.1.0/src/agent_mcp/upload_skill.py +21 -0
- agent_host_mcp-0.1.0/src/agent_mcp/uploads.py +98 -0
- agent_host_mcp-0.1.0/src/agent_mcp/version.py +39 -0
- agent_host_mcp-0.1.0/src/agent_mcp/wiki.py +144 -0
- agent_host_mcp-0.1.0/src/agent_mcp/wiki_routes.py +101 -0
- agent_host_mcp-0.1.0/src/agent_mcp/wiki_tools.py +165 -0
- agent_host_mcp-0.1.0/tests/conftest.py +7 -0
- agent_host_mcp-0.1.0/tests/test_action_http.py +71 -0
- agent_host_mcp-0.1.0/tests/test_actions.py +177 -0
- agent_host_mcp-0.1.0/tests/test_auth.py +75 -0
- agent_host_mcp-0.1.0/tests/test_catalog.py +98 -0
- agent_host_mcp-0.1.0/tests/test_curl_auth.py +52 -0
- agent_host_mcp-0.1.0/tests/test_execution.py +242 -0
- agent_host_mcp-0.1.0/tests/test_knowledge.py +236 -0
- agent_host_mcp-0.1.0/tests/test_knowledge_sdk.py +180 -0
- agent_host_mcp-0.1.0/tests/test_knowledge_store.py +76 -0
- agent_host_mcp-0.1.0/tests/test_models.py +83 -0
- agent_host_mcp-0.1.0/tests/test_paths.py +50 -0
- agent_host_mcp-0.1.0/tests/test_runner.py +194 -0
- agent_host_mcp-0.1.0/tests/test_scheduler.py +68 -0
- agent_host_mcp-0.1.0/tests/test_scheduler_lifecycle.py +83 -0
- agent_host_mcp-0.1.0/tests/test_server.py +169 -0
- agent_host_mcp-0.1.0/tests/test_session_delete.py +91 -0
- agent_host_mcp-0.1.0/tests/test_session_metadata.py +70 -0
- agent_host_mcp-0.1.0/tests/test_sessions.py +76 -0
- agent_host_mcp-0.1.0/tests/test_tokens.py +94 -0
- agent_host_mcp-0.1.0/tests/test_upload_routes.py +109 -0
- agent_host_mcp-0.1.0/tests/test_upload_skill.py +84 -0
- agent_host_mcp-0.1.0/tests/test_uploads.py +89 -0
- agent_host_mcp-0.1.0/tests/test_version.py +52 -0
- agent_host_mcp-0.1.0/tests/test_wiki.py +75 -0
- agent_host_mcp-0.1.0/tests/test_wiki_routes.py +105 -0
- agent_host_mcp-0.1.0/tests/test_wiki_tools.py +52 -0
- agent_host_mcp-0.1.0/uv.lock +904 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12.13
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.DEFAULT_GOAL := build
|
|
2
|
+
|
|
3
|
+
UV ?= uv
|
|
4
|
+
NPM ?= npm
|
|
5
|
+
PYTHON_VERSION := $(shell cat .python-version)
|
|
6
|
+
UV_DIR := $(CURDIR)/.uv
|
|
7
|
+
export UV_CACHE_DIR := $(UV_DIR)/cache
|
|
8
|
+
export UV_PYTHON_INSTALL_DIR := $(UV_DIR)/python
|
|
9
|
+
export UV_PROJECT_ENVIRONMENT := $(UV_DIR)/dev
|
|
10
|
+
export UV_MANAGED_PYTHON := true
|
|
11
|
+
export npm_config_cache := $(CURDIR)/.tools/npm-cache
|
|
12
|
+
unexport VIRTUAL_ENV
|
|
13
|
+
|
|
14
|
+
PORT ?= 7081
|
|
15
|
+
HOST ?= 0.0.0.0
|
|
16
|
+
TEST_HOST ?= 127.0.0.1
|
|
17
|
+
|
|
18
|
+
.PHONY: python wiki-deps build run test check
|
|
19
|
+
|
|
20
|
+
python:
|
|
21
|
+
$(UV) python install --no-bin $(PYTHON_VERSION)
|
|
22
|
+
$(UV) python find --managed-python --system $(PYTHON_VERSION) > .uv/python-path
|
|
23
|
+
@case "$$(cat .uv/python-path)" in "$(UV_PYTHON_INSTALL_DIR)"/*) ;; *) echo "Expected a project-local Python under .uv/python" >&2; exit 1 ;; esac
|
|
24
|
+
|
|
25
|
+
wiki-deps: node_modules/.package-lock.json
|
|
26
|
+
|
|
27
|
+
node_modules/.package-lock.json: package.json package-lock.json
|
|
28
|
+
$(NPM) ci --no-audit --no-fund
|
|
29
|
+
|
|
30
|
+
build: python wiki-deps
|
|
31
|
+
$(UV) build --python "$$(cat .uv/python-path)" --out-dir build
|
|
32
|
+
$(UV) export --frozen --no-dev --no-emit-project --output-file build/requirements.txt
|
|
33
|
+
$(UV) venv --allow-existing --python "$$(cat .uv/python-path)" .uv/venv
|
|
34
|
+
$(UV) pip uninstall --python .uv/venv/bin/python agent-mcp
|
|
35
|
+
$(UV) pip install --python .uv/venv/bin/python --reinstall-package agent-host-mcp -r build/requirements.txt $$(ls -t build/agent_host_mcp-*.whl | head -n 1)
|
|
36
|
+
cp scripts/agent-host-mcp build/agent-host-mcp
|
|
37
|
+
chmod +x build/agent-host-mcp
|
|
38
|
+
./.uv/venv/bin/python -m agent_mcp.catalog build/tool-catalog.json
|
|
39
|
+
|
|
40
|
+
run: build
|
|
41
|
+
./build/agent-host-mcp --port $(PORT) --host $(HOST)
|
|
42
|
+
|
|
43
|
+
test:
|
|
44
|
+
./.uv/venv/bin/python scripts/test_mcp.py http://$(TEST_HOST):$(PORT)/mcp
|
|
45
|
+
|
|
46
|
+
check: python wiki-deps
|
|
47
|
+
$(UV) run --frozen --python "$$(cat .uv/python-path)" pytest -q
|
|
48
|
+
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: agent-host-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Connect Codex sessions, remote execution, and project knowledge to MCP clients.
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: mcp<2,>=1.12
|
|
7
|
+
Requires-Dist: openai-codex>=0.167.0
|
|
8
|
+
Requires-Dist: python-dotenv<2,>=1
|
|
9
|
+
Requires-Dist: python-multipart<1,>=0.0.33
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Agent Host MCP
|
|
13
|
+
|
|
14
|
+
**Turn your agent on the host into an MCP server.**
|
|
15
|
+
|
|
16
|
+
Agent Host MCP lets your assistant work with the development environment on your
|
|
17
|
+
Linux machine. Read project files, execute Python or shell commands, ask a remote
|
|
18
|
+
Codex agent to carry out a task, and reuse knowledge from past sessions—all
|
|
19
|
+
through one MCP connection.
|
|
20
|
+
|
|
21
|
+
Use it when your code lives on a remote host and you want your assistant to
|
|
22
|
+
inspect that environment directly instead of copying files and terminal output
|
|
23
|
+
into a conversation.
|
|
24
|
+
|
|
25
|
+
## What you can do
|
|
26
|
+
|
|
27
|
+
- **Understand a project:** read contributor guidance, inspect files, and find
|
|
28
|
+
saved Codex sessions.
|
|
29
|
+
- **Get work done:** run notebook-style Python cells or shell scripts, or delegate
|
|
30
|
+
a task to Codex in a new or existing session.
|
|
31
|
+
- **Keep useful context:** build topic knowledge from sessions, then browse it in
|
|
32
|
+
OpenWiki or search it from your assistant.
|
|
33
|
+
- **Manage the host workflow:** transfer files, label sessions, and inspect
|
|
34
|
+
recorded token usage.
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
### 1. Start Agent Host MCP on your host
|
|
39
|
+
|
|
40
|
+
You need a **Linux host**, uv, make, Node.js **22.22.0 or newer**, and npm. Run the
|
|
41
|
+
server as the account whose Codex sessions you want to use, with that account’s
|
|
42
|
+
existing Codex login and configuration. Set `CODEX_HOME` if they live outside
|
|
43
|
+
`~/.codex`. A separate API key is not required by Agent Host MCP.
|
|
44
|
+
|
|
45
|
+
From a source checkout or an unpacked source release:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
make build
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Create a `.env` file in the directory from which you will start the server:
|
|
52
|
+
|
|
53
|
+
```dotenv
|
|
54
|
+
MCP_TOKEN=replace-with-a-long-random-secret
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Replace the placeholder with a long, randomly generated token. Restrict access:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
chmod 600 .env
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Keep an existing `.env` when upgrading. Keep the token private and provide the
|
|
64
|
+
same value to your client.
|
|
65
|
+
|
|
66
|
+
Start the server:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
make run HOST=0.0.0.0 PORT=7081
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The CLI is **`agent-host-mcp`**. After building, you can also start it directly:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
./build/agent-host-mcp --host 0.0.0.0 --port 7081
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Use the source-release setup above for all features, including OpenWiki.
|
|
79
|
+
Installing the Python wheel alone does not set up the knowledge viewer.
|
|
80
|
+
|
|
81
|
+
### 2. Add it to your Codex client
|
|
82
|
+
|
|
83
|
+
On the machine where you use Codex, set `MCP_TOKEN` to your server’s token. For
|
|
84
|
+
example, in Bash you can enter it without placing its value in shell history:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
read -rsp 'Agent Host MCP token: ' MCP_TOKEN
|
|
88
|
+
export MCP_TOKEN
|
|
89
|
+
printf '\n'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Register the server, replacing `https://YOUR_HOST` with your server’s HTTPS URL:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
codex mcp add remotecodex \
|
|
96
|
+
--url https://YOUR_HOST/mcp \
|
|
97
|
+
--bearer-token-env-var MCP_TOKEN
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Start your Codex client from an environment where `MCP_TOKEN` is available.
|
|
101
|
+
Other MCP clients can use **Streamable HTTP** at `/mcp` with
|
|
102
|
+
`Authorization: Bearer <MCP_TOKEN>`.
|
|
103
|
+
|
|
104
|
+
### 3. Ask your assistant to use it
|
|
105
|
+
|
|
106
|
+
Try requests such as:
|
|
107
|
+
|
|
108
|
+
> Use remotecodex to read AGENTS.md in my project directory and summarize its guidance.
|
|
109
|
+
>
|
|
110
|
+
> Run a Python cell that calculates 6 * 7 on the remote host.
|
|
111
|
+
>
|
|
112
|
+
> Start a new Codex session in my project and ask it to investigate the failing tests.
|
|
113
|
+
>
|
|
114
|
+
> Search my saved knowledge for deployment hints.
|
|
115
|
+
|
|
116
|
+
Replace “my project directory” with the actual host path. The client discovers
|
|
117
|
+
available tools and their parameters through `tools/list`.
|
|
118
|
+
|
|
119
|
+
## Choose the right execution tool
|
|
120
|
+
|
|
121
|
+
| Task | Tool | What to expect |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| Run code directly | `execute(string, path="~")` | A persistent Python namespace per directory. Variables, imports and functions carry over between cells. |
|
|
124
|
+
| Run a shell script | `execute` with a cell beginning with `!` or `%` | The whole remaining cell runs through `/bin/sh` in the chosen directory. |
|
|
125
|
+
| Delegate work to Codex | `run(path, prompt, session_id=None)` | Omit the ID for a new saved session; supply one to resume that exact session. |
|
|
126
|
+
|
|
127
|
+
`execute` defaults to the server account’s home directory. `run` requires an
|
|
128
|
+
existing working directory. Use `create_path` to create an absolute directory
|
|
129
|
+
and its missing parents first.
|
|
130
|
+
|
|
131
|
+
`execute` uses the server’s installed Python packages and normal account
|
|
132
|
+
permissions; it is not a security sandbox. Python variables last until the runtime
|
|
133
|
+
or server restarts. Shell environment/directory changes do not carry over to later
|
|
134
|
+
cells. `run` uses your saved Codex login and configured defaults for new sessions.
|
|
135
|
+
A saved session must be closed in its current Codex client before resuming it here.
|
|
136
|
+
|
|
137
|
+
### Collect a long-running result
|
|
138
|
+
|
|
139
|
+
`run`, `execute`, `build_knowledge`, and `delete_session` return an **`action_id`**
|
|
140
|
+
immediately. Save it, then repeat the same tool and original arguments with that
|
|
141
|
+
ID until its status becomes `completed`, `failed`, or `interrupted`.
|
|
142
|
+
|
|
143
|
+
For example, start a cell:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{"string":"6 * 7"}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Then call `execute` again with the returned ID:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{"string":"6 * 7","action_id":"returned-action-id","wait_seconds":20}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Omitting the ID starts new work. Reconnecting never reruns the original task.
|
|
156
|
+
Keep an omitted `path` or `session_id` omitted when reconnecting. Inspect the
|
|
157
|
+
nested `result.status` too: a completed action may contain a failed cell or turn.
|
|
158
|
+
|
|
159
|
+
A gateway timeout or disconnected client leaves the job running. Each reconnect
|
|
160
|
+
waits at most 20 seconds. SSE carries progress and the final result, rather than
|
|
161
|
+
live stdout or model tokens. Server shutdown interrupts active jobs; they are
|
|
162
|
+
not automatically rerun. Completed results are retained for up to 24 hours,
|
|
163
|
+
subject to a 256-action capacity.
|
|
164
|
+
|
|
165
|
+
## Build and use your knowledge
|
|
166
|
+
|
|
167
|
+
Ask your assistant to call `list_models`, choose a supported model and depth,
|
|
168
|
+
then call `build_knowledge`. Supply `session_id` to target one session, or omit it
|
|
169
|
+
for an incremental batch. Unchanged, verified context is reused.
|
|
170
|
+
|
|
171
|
+
Browse the results at **`/knowledge`** and sign in with your MCP token. The
|
|
172
|
+
OpenWiki page and `wiki_list_pages`, `wiki_search`, and `wiki_read` tools use the
|
|
173
|
+
same saved knowledge. Viewing or searching it does not call a model. Browser
|
|
174
|
+
visualization needs access to OpenWiki’s pinned external library/font CDNs.
|
|
175
|
+
|
|
176
|
+
While the server runs, it also checks for new or changed session context every
|
|
177
|
+
30 minutes. When idle, it runs a daily maintenance pass that still skips unchanged
|
|
178
|
+
context. Builds use your Codex login and can make model calls.
|
|
179
|
+
|
|
180
|
+
**Session retirement:** knowledge builds may delete sessions whose working
|
|
181
|
+
directories have been removed, after saving and verifying their knowledge.
|
|
182
|
+
Sessions with existing working directories are preserved by automatic builds.
|
|
183
|
+
`delete_session` explicitly deletes a selected session, including one whose
|
|
184
|
+
working directory exists, only after its current knowledge is verified. Active or changed sessions, and sessions with remaining descendants, are kept.
|
|
185
|
+
|
|
186
|
+
## Available tools
|
|
187
|
+
|
|
188
|
+
The server exposes thirteen tools. See the [detailed reference](REFERENCE.md)
|
|
189
|
+
for schemas, limits, outputs and failure handling.
|
|
190
|
+
|
|
191
|
+
| Tool | Use it to |
|
|
192
|
+
| --- | --- |
|
|
193
|
+
| `list_sessions` | Find saved session IDs, models, depths, working directories and descriptions. |
|
|
194
|
+
| `update_session` | Set a client-managed description; blank text clears it. |
|
|
195
|
+
| `list_models` | Discover supported models and reasoning depths. |
|
|
196
|
+
| `create_path` | Create an absolute host directory and missing parents. |
|
|
197
|
+
| `execute` | Execute Python cells or prefixed shell scripts. |
|
|
198
|
+
| `run` | Start or resume a Codex session and submit a prompt. |
|
|
199
|
+
| `build_knowledge` | Extract reusable knowledge from changed or selected sessions; may retire missing-directory sessions. |
|
|
200
|
+
| `delete_session` | Delete a session only after its current knowledge is saved and verified. |
|
|
201
|
+
| `token_count` | Inspect recorded host/session usage and cache-hit ratios; retired usage appears in `others`. |
|
|
202
|
+
| `get_upload_skill` | Get instructions for authenticated HTTP file uploads. |
|
|
203
|
+
| `wiki_list_pages` | Browse knowledge topic pages with pagination. |
|
|
204
|
+
| `wiki_search` | Find relevant knowledge sections. |
|
|
205
|
+
| `wiki_read` | Read selected sections and their source provenance. |
|
|
206
|
+
|
|
207
|
+
To transfer a local file, read `get_upload_skill` first. Uploads use a separate
|
|
208
|
+
HTTP `POST /upload` with the same Bearer token, the actual file bytes, and a
|
|
209
|
+
client-selected absolute destination directory. Missing parents are created;
|
|
210
|
+
existing files are never overwritten. The file limit is 100 MiB. Native MCP auth
|
|
211
|
+
does not automatically expose the credential to an agent’s separate HTTP client.
|
|
212
|
+
|
|
213
|
+
Token usage is recorded session usage, not an exact billing report. Cached and
|
|
214
|
+
reasoning counters are subsets, and `cache_hit_ratio` is cached input divided by
|
|
215
|
+
input; unknown coverage is reported.
|
|
216
|
+
|
|
217
|
+
## Access and upgrades
|
|
218
|
+
|
|
219
|
+
The landing page at `/` is public. MCP calls, uploads and knowledge content
|
|
220
|
+
require authentication. Signing in to the knowledge browser does not authorize
|
|
221
|
+
MCP calls or uploads. Connect only clients you trust with the host account’s access.
|
|
222
|
+
|
|
223
|
+
The server reads `.env` from its working directory; an exported `MCP_TOKEN`
|
|
224
|
+
overrides the file. Restart the server after changing its token.
|
|
225
|
+
|
|
226
|
+
Keep your `.env`, Codex login and saved sessions when upgrading. Extracted
|
|
227
|
+
knowledge is saved under `~/.agent-mcp/knowledge`; preserve it and the other
|
|
228
|
+
Agent Host MCP data described in the [backup reference](REFERENCE.md#long-running-tool-actions-and-sse).
|
|
229
|
+
Stop the previous service before starting its replacement on the same port,
|
|
230
|
+
then refresh your client’s MCP connection to discover updated tools.
|
|
231
|
+
|
|
232
|
+
## Check your setup
|
|
233
|
+
|
|
234
|
+
With the server running and curl installed:
|
|
235
|
+
|
|
236
|
+
```sh
|
|
237
|
+
make test PORT=7081
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
This checks the advertised tools, session/model discovery, token accounting and
|
|
241
|
+
wiki retrieval. It does not submit model turns or delete real sessions. It prints
|
|
242
|
+
session and model results, so keep that output private.
|
|
243
|
+
|
|
244
|
+
| Symptom | What to check |
|
|
245
|
+
| --- | --- |
|
|
246
|
+
| Unauthorized or startup token error | Match the server’s token and the client’s `MCP_TOKEN` environment variable. |
|
|
247
|
+
| Port 7081 is already in use | Stop the intended previous process yourself, or choose another `PORT`. |
|
|
248
|
+
| Session has an active writer | Close its owning Codex session normally before resuming it, or omit the ID to create a separate session. |
|
|
249
|
+
| OpenWiki unavailable | Run `make build` from the source directory and check Node dependencies and browser CDN access. |
|
|
250
|
+
| Client still shows old tools | Refresh/reconnect the client after restarting the updated server; a new conversation alone may not refresh its cache. |
|
|
251
|
+
| Public gateway cannot be reached | Check gateway routing and any IP allowlist separately from the local server. |
|
|
252
|
+
|
|
253
|
+
For detailed usage, limits and troubleshooting, see [REFERENCE.md](REFERENCE.md).
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Agent Host MCP
|
|
2
|
+
|
|
3
|
+
**Turn your agent on the host into an MCP server.**
|
|
4
|
+
|
|
5
|
+
Agent Host MCP lets your assistant work with the development environment on your
|
|
6
|
+
Linux machine. Read project files, execute Python or shell commands, ask a remote
|
|
7
|
+
Codex agent to carry out a task, and reuse knowledge from past sessions—all
|
|
8
|
+
through one MCP connection.
|
|
9
|
+
|
|
10
|
+
Use it when your code lives on a remote host and you want your assistant to
|
|
11
|
+
inspect that environment directly instead of copying files and terminal output
|
|
12
|
+
into a conversation.
|
|
13
|
+
|
|
14
|
+
## What you can do
|
|
15
|
+
|
|
16
|
+
- **Understand a project:** read contributor guidance, inspect files, and find
|
|
17
|
+
saved Codex sessions.
|
|
18
|
+
- **Get work done:** run notebook-style Python cells or shell scripts, or delegate
|
|
19
|
+
a task to Codex in a new or existing session.
|
|
20
|
+
- **Keep useful context:** build topic knowledge from sessions, then browse it in
|
|
21
|
+
OpenWiki or search it from your assistant.
|
|
22
|
+
- **Manage the host workflow:** transfer files, label sessions, and inspect
|
|
23
|
+
recorded token usage.
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
### 1. Start Agent Host MCP on your host
|
|
28
|
+
|
|
29
|
+
You need a **Linux host**, uv, make, Node.js **22.22.0 or newer**, and npm. Run the
|
|
30
|
+
server as the account whose Codex sessions you want to use, with that account’s
|
|
31
|
+
existing Codex login and configuration. Set `CODEX_HOME` if they live outside
|
|
32
|
+
`~/.codex`. A separate API key is not required by Agent Host MCP.
|
|
33
|
+
|
|
34
|
+
From a source checkout or an unpacked source release:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
make build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Create a `.env` file in the directory from which you will start the server:
|
|
41
|
+
|
|
42
|
+
```dotenv
|
|
43
|
+
MCP_TOKEN=replace-with-a-long-random-secret
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Replace the placeholder with a long, randomly generated token. Restrict access:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
chmod 600 .env
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Keep an existing `.env` when upgrading. Keep the token private and provide the
|
|
53
|
+
same value to your client.
|
|
54
|
+
|
|
55
|
+
Start the server:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
make run HOST=0.0.0.0 PORT=7081
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The CLI is **`agent-host-mcp`**. After building, you can also start it directly:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
./build/agent-host-mcp --host 0.0.0.0 --port 7081
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use the source-release setup above for all features, including OpenWiki.
|
|
68
|
+
Installing the Python wheel alone does not set up the knowledge viewer.
|
|
69
|
+
|
|
70
|
+
### 2. Add it to your Codex client
|
|
71
|
+
|
|
72
|
+
On the machine where you use Codex, set `MCP_TOKEN` to your server’s token. For
|
|
73
|
+
example, in Bash you can enter it without placing its value in shell history:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
read -rsp 'Agent Host MCP token: ' MCP_TOKEN
|
|
77
|
+
export MCP_TOKEN
|
|
78
|
+
printf '\n'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Register the server, replacing `https://YOUR_HOST` with your server’s HTTPS URL:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
codex mcp add remotecodex \
|
|
85
|
+
--url https://YOUR_HOST/mcp \
|
|
86
|
+
--bearer-token-env-var MCP_TOKEN
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Start your Codex client from an environment where `MCP_TOKEN` is available.
|
|
90
|
+
Other MCP clients can use **Streamable HTTP** at `/mcp` with
|
|
91
|
+
`Authorization: Bearer <MCP_TOKEN>`.
|
|
92
|
+
|
|
93
|
+
### 3. Ask your assistant to use it
|
|
94
|
+
|
|
95
|
+
Try requests such as:
|
|
96
|
+
|
|
97
|
+
> Use remotecodex to read AGENTS.md in my project directory and summarize its guidance.
|
|
98
|
+
>
|
|
99
|
+
> Run a Python cell that calculates 6 * 7 on the remote host.
|
|
100
|
+
>
|
|
101
|
+
> Start a new Codex session in my project and ask it to investigate the failing tests.
|
|
102
|
+
>
|
|
103
|
+
> Search my saved knowledge for deployment hints.
|
|
104
|
+
|
|
105
|
+
Replace “my project directory” with the actual host path. The client discovers
|
|
106
|
+
available tools and their parameters through `tools/list`.
|
|
107
|
+
|
|
108
|
+
## Choose the right execution tool
|
|
109
|
+
|
|
110
|
+
| Task | Tool | What to expect |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| Run code directly | `execute(string, path="~")` | A persistent Python namespace per directory. Variables, imports and functions carry over between cells. |
|
|
113
|
+
| Run a shell script | `execute` with a cell beginning with `!` or `%` | The whole remaining cell runs through `/bin/sh` in the chosen directory. |
|
|
114
|
+
| Delegate work to Codex | `run(path, prompt, session_id=None)` | Omit the ID for a new saved session; supply one to resume that exact session. |
|
|
115
|
+
|
|
116
|
+
`execute` defaults to the server account’s home directory. `run` requires an
|
|
117
|
+
existing working directory. Use `create_path` to create an absolute directory
|
|
118
|
+
and its missing parents first.
|
|
119
|
+
|
|
120
|
+
`execute` uses the server’s installed Python packages and normal account
|
|
121
|
+
permissions; it is not a security sandbox. Python variables last until the runtime
|
|
122
|
+
or server restarts. Shell environment/directory changes do not carry over to later
|
|
123
|
+
cells. `run` uses your saved Codex login and configured defaults for new sessions.
|
|
124
|
+
A saved session must be closed in its current Codex client before resuming it here.
|
|
125
|
+
|
|
126
|
+
### Collect a long-running result
|
|
127
|
+
|
|
128
|
+
`run`, `execute`, `build_knowledge`, and `delete_session` return an **`action_id`**
|
|
129
|
+
immediately. Save it, then repeat the same tool and original arguments with that
|
|
130
|
+
ID until its status becomes `completed`, `failed`, or `interrupted`.
|
|
131
|
+
|
|
132
|
+
For example, start a cell:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{"string":"6 * 7"}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Then call `execute` again with the returned ID:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{"string":"6 * 7","action_id":"returned-action-id","wait_seconds":20}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Omitting the ID starts new work. Reconnecting never reruns the original task.
|
|
145
|
+
Keep an omitted `path` or `session_id` omitted when reconnecting. Inspect the
|
|
146
|
+
nested `result.status` too: a completed action may contain a failed cell or turn.
|
|
147
|
+
|
|
148
|
+
A gateway timeout or disconnected client leaves the job running. Each reconnect
|
|
149
|
+
waits at most 20 seconds. SSE carries progress and the final result, rather than
|
|
150
|
+
live stdout or model tokens. Server shutdown interrupts active jobs; they are
|
|
151
|
+
not automatically rerun. Completed results are retained for up to 24 hours,
|
|
152
|
+
subject to a 256-action capacity.
|
|
153
|
+
|
|
154
|
+
## Build and use your knowledge
|
|
155
|
+
|
|
156
|
+
Ask your assistant to call `list_models`, choose a supported model and depth,
|
|
157
|
+
then call `build_knowledge`. Supply `session_id` to target one session, or omit it
|
|
158
|
+
for an incremental batch. Unchanged, verified context is reused.
|
|
159
|
+
|
|
160
|
+
Browse the results at **`/knowledge`** and sign in with your MCP token. The
|
|
161
|
+
OpenWiki page and `wiki_list_pages`, `wiki_search`, and `wiki_read` tools use the
|
|
162
|
+
same saved knowledge. Viewing or searching it does not call a model. Browser
|
|
163
|
+
visualization needs access to OpenWiki’s pinned external library/font CDNs.
|
|
164
|
+
|
|
165
|
+
While the server runs, it also checks for new or changed session context every
|
|
166
|
+
30 minutes. When idle, it runs a daily maintenance pass that still skips unchanged
|
|
167
|
+
context. Builds use your Codex login and can make model calls.
|
|
168
|
+
|
|
169
|
+
**Session retirement:** knowledge builds may delete sessions whose working
|
|
170
|
+
directories have been removed, after saving and verifying their knowledge.
|
|
171
|
+
Sessions with existing working directories are preserved by automatic builds.
|
|
172
|
+
`delete_session` explicitly deletes a selected session, including one whose
|
|
173
|
+
working directory exists, only after its current knowledge is verified. Active or changed sessions, and sessions with remaining descendants, are kept.
|
|
174
|
+
|
|
175
|
+
## Available tools
|
|
176
|
+
|
|
177
|
+
The server exposes thirteen tools. See the [detailed reference](REFERENCE.md)
|
|
178
|
+
for schemas, limits, outputs and failure handling.
|
|
179
|
+
|
|
180
|
+
| Tool | Use it to |
|
|
181
|
+
| --- | --- |
|
|
182
|
+
| `list_sessions` | Find saved session IDs, models, depths, working directories and descriptions. |
|
|
183
|
+
| `update_session` | Set a client-managed description; blank text clears it. |
|
|
184
|
+
| `list_models` | Discover supported models and reasoning depths. |
|
|
185
|
+
| `create_path` | Create an absolute host directory and missing parents. |
|
|
186
|
+
| `execute` | Execute Python cells or prefixed shell scripts. |
|
|
187
|
+
| `run` | Start or resume a Codex session and submit a prompt. |
|
|
188
|
+
| `build_knowledge` | Extract reusable knowledge from changed or selected sessions; may retire missing-directory sessions. |
|
|
189
|
+
| `delete_session` | Delete a session only after its current knowledge is saved and verified. |
|
|
190
|
+
| `token_count` | Inspect recorded host/session usage and cache-hit ratios; retired usage appears in `others`. |
|
|
191
|
+
| `get_upload_skill` | Get instructions for authenticated HTTP file uploads. |
|
|
192
|
+
| `wiki_list_pages` | Browse knowledge topic pages with pagination. |
|
|
193
|
+
| `wiki_search` | Find relevant knowledge sections. |
|
|
194
|
+
| `wiki_read` | Read selected sections and their source provenance. |
|
|
195
|
+
|
|
196
|
+
To transfer a local file, read `get_upload_skill` first. Uploads use a separate
|
|
197
|
+
HTTP `POST /upload` with the same Bearer token, the actual file bytes, and a
|
|
198
|
+
client-selected absolute destination directory. Missing parents are created;
|
|
199
|
+
existing files are never overwritten. The file limit is 100 MiB. Native MCP auth
|
|
200
|
+
does not automatically expose the credential to an agent’s separate HTTP client.
|
|
201
|
+
|
|
202
|
+
Token usage is recorded session usage, not an exact billing report. Cached and
|
|
203
|
+
reasoning counters are subsets, and `cache_hit_ratio` is cached input divided by
|
|
204
|
+
input; unknown coverage is reported.
|
|
205
|
+
|
|
206
|
+
## Access and upgrades
|
|
207
|
+
|
|
208
|
+
The landing page at `/` is public. MCP calls, uploads and knowledge content
|
|
209
|
+
require authentication. Signing in to the knowledge browser does not authorize
|
|
210
|
+
MCP calls or uploads. Connect only clients you trust with the host account’s access.
|
|
211
|
+
|
|
212
|
+
The server reads `.env` from its working directory; an exported `MCP_TOKEN`
|
|
213
|
+
overrides the file. Restart the server after changing its token.
|
|
214
|
+
|
|
215
|
+
Keep your `.env`, Codex login and saved sessions when upgrading. Extracted
|
|
216
|
+
knowledge is saved under `~/.agent-mcp/knowledge`; preserve it and the other
|
|
217
|
+
Agent Host MCP data described in the [backup reference](REFERENCE.md#long-running-tool-actions-and-sse).
|
|
218
|
+
Stop the previous service before starting its replacement on the same port,
|
|
219
|
+
then refresh your client’s MCP connection to discover updated tools.
|
|
220
|
+
|
|
221
|
+
## Check your setup
|
|
222
|
+
|
|
223
|
+
With the server running and curl installed:
|
|
224
|
+
|
|
225
|
+
```sh
|
|
226
|
+
make test PORT=7081
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
This checks the advertised tools, session/model discovery, token accounting and
|
|
230
|
+
wiki retrieval. It does not submit model turns or delete real sessions. It prints
|
|
231
|
+
session and model results, so keep that output private.
|
|
232
|
+
|
|
233
|
+
| Symptom | What to check |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| Unauthorized or startup token error | Match the server’s token and the client’s `MCP_TOKEN` environment variable. |
|
|
236
|
+
| Port 7081 is already in use | Stop the intended previous process yourself, or choose another `PORT`. |
|
|
237
|
+
| Session has an active writer | Close its owning Codex session normally before resuming it, or omit the ID to create a separate session. |
|
|
238
|
+
| OpenWiki unavailable | Run `make build` from the source directory and check Node dependencies and browser CDN access. |
|
|
239
|
+
| Client still shows old tools | Refresh/reconnect the client after restarting the updated server; a new conversation alone may not refresh its cache. |
|
|
240
|
+
| Public gateway cannot be reached | Check gateway routing and any IP allowlist separately from the local server. |
|
|
241
|
+
|
|
242
|
+
For detailed usage, limits and troubleshooting, see [REFERENCE.md](REFERENCE.md).
|