Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 53 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

A general-purpose Model Context Protocol interface for Urbit.

The `%mcp` desk ships as a single integrated control plane with three pieces:

1. **Native MCP server** at `/mcp` — runs Hoon-defined tools, prompts and
resources directly on your ship.
2. **MCP proxy** at `/apps/mcp/mcp` — aggregates the native server plus any
number of remote MCP / OpenAPI / Google Discovery upstreams behind a single
endpoint, with per-server tool filtering and OAuth 2.0 + PKCE token
management. OpenAPI and Discovery spec docs are dynamically converted
to MCP tool calls.
3. **Operator console** at `/apps/mcp/` — a web UI for configuring upstreams,
OAuth providers, the API key, and inspecting tools.
Comment on lines +9 to +15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint situation with /mcp and /apps/mcp is kind of weird now, clean layout might be:

  • /mcp - Urbit MCP endpoint
  • /apps/mcp - Urbit MCP UI
  • /mcp/servers - MCP proxy endpoint
  • /mcp/servers/{id} - endpoint for a single proxied MCP server


Both `/mcp` and `/apps/mcp/mcp` authenticate with the same `X-Api-Key` header.
A random key is generated on first install and can be regenerated, set, or
cleared from the operator console.

## Developer Setup

### 1. Build and Install
Expand All @@ -16,59 +32,71 @@ Create and mount the desk on your Urbit ship:
> |mount %mcp
```

In the `urbit-mcp` folder, run the [build script](build.sh). By default this will install dependencies into `/dist` in this folder. Use the `-p` argument to additionally copy the %mcp source and its dependencies into your ship's desk. This script will take a minute if it's your first time running it.
In the project folder, run the [build script](build.sh). By default this will
install dependencies into `/dist` in this folder. Use the `-p` argument to
additionally copy the source and its dependencies into your ship's desk. This
script will take a minute if it's your first time running it.

```bash
$ cd urbit-mcp
$ build.sh -p ~/path/to/zod/mcp
$ ./build.sh -p ~/path/to/zod/mcp
```

```dojo
> |commit %mcp
> |install our %mcp
```

### 2. Authentication Setup
This installs four agents on your ship:

Get your ship's web login code from the Dojo:
- `%mcp-server` — native MCP server bound to `/mcp`
- `%mcp-proxy` — aggregator bound to `/apps/mcp/api` and `/apps/mcp/mcp`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endpoint layout as above

- `%mcp-fileserver` — serves the operator UI at `/apps/mcp/`
- `%oauth` — OAuth 2.0 + PKCE provider/grant manager

```dojo
> +code
lidlut-tabwed-pillex-ridrup
~zod:dojo>
```
### 2. Open the operator console

Authenticate and get session cookie:
Visit `http://localhost:PORT/apps/mcp/`.

```bash
curl -i http://localhost:80/~/login -X POST -d "password=lidlut-tabwed-pillex-ridrup"
```
The console has three tabs:

Extract the cookie from the `set-cookie` header, which will look like this:

```
urbauth-~your-ship=0v3.j2062.1prp1.qne4e.goq3h.ksudm
```
- **Endpoint** — the proxy aggregate URL and your `X-Api-Key`. Buttons to
generate a random key, set a custom one, copy, or clear it. The page also
shows a `claude mcp add` snippet pre-filled with your ship name and key.
- **Upstreams** — configured remote servers. The native server is registered
automatically and tagged `BUILT-IN`. Add your own MCP servers, OpenAPI REST
APIs, or Google Discovery documents. Each upstream can be linked to an OAuth
provider for automatic token injection, and you can allow- or block-list
individual tools.
- **OAuth** — manage OAuth 2.0 + PKCE providers. Connect / disconnect grants,
edit endpoints, store client secrets (the secret is never returned to
the browser; leaving the field blank in an edit preserves the saved value).
OAuth providers can be assigned to upstreams and automatically renew
expired sessions.

### 3A. Register with Claude

Add the MCP server to Claude using HTTP transport:
In the **Endpoint** tab, click `GEN` to mint an API key (or `SET` to use your
own). Then copy the snippet shown under `CLAUDE CLI`, which will look like:

```bash
claude mcp add --transport http zod http://localhost:80/mcp --header "Cookie: urbauth-~your-ship=0v3.j2062.1prp1.qne4e.goq3h.ksudm" --scope user
claude mcp add --transport http zod \
http://localhost:8080/apps/mcp/mcp \
--header "X-Api-Key: <your-key>"
```

### 3B. Register with Codex

Codex requires the `mcp-proxy` python package to function. Install with `uvx mcp-proxy`, then append this to your `~/.codex/config.toml`:
Codex needs the `mcp-proxy` python bridge. Install with `uvx mcp-proxy`, then
append to `~/.codex/config.toml`:

```toml
[mcp_servers.fen]
[mcp_servers.zod]
command = "uvx"
args = [
"mcp-proxy",
"--transport", "streamablehttp",
"--headers", "Cookie", "urbauth-~your-ship=0v2.20fhu.t7ki1.cftjr.3s8bv.d9i5l",
"http://localhost:80/mcp"
"--headers", "X-Api-Key", "<your-key>",
"http://localhost:8080/apps/mcp/mcp"
]
```

Expand Down
12 changes: 12 additions & 0 deletions desk/app/fileserver/config.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
|%
++ web-root ^- (list @t)
/apps/mcp
++ file-root ^- path
/web
++ index ^- $@(~ [~ path])
`/index/html
++ extension ^- ?(%need %path %fall)
%fall
++ auth ^- $@(? [? (list [path ?])])
&
--
243 changes: 243 additions & 0 deletions desk/app/mcp-fileserver.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
:: mcp-fileserver: serves the web UI from clay
::
:: copy of foo-fileserver pattern.
:: reads configuration from /app/fileserver/config.hoon.
::
/= config /app/fileserver/config
::
|%
++ web-root ^- (list @t) web-root:config
::
++ defaults
|%
++ file-root ^- path /web
++ tombstone ^- ? |
++ index ^- $@(~ [~ path]) `/index/html
++ extension ^- ?(%need %path %fall) %need
++ auth ^- $@(? [? (list [path ?])]) &
--
::
++ file-root ^- path
!@(file-root:config file-root:defaults file-root:config)
::
++ tombstone ^- ?
!@(tombstone:config tombstone:defaults tombstone:config)
::
++ index ^- $@(?(~ %apache) [~ u=path])
!@(index:config index:defaults index:config)
::
++ extension ^- ?(%need %path %fall)
!@(extension:config extension:defaults extension:config)
::
++ auth ^~ ^- (map path ?)
=/ val=$@(? [? (list [path ?])])
!@(auth:config auth:defaults auth:config)
?@ val (~(put by *(map path ?)) / val)
(~(gas by *(map path ?)) [/ -.val] +.val)
--
::
|%
+$ state-0
$: %0
foot=path
woot=path
cash=(set @t)
==
::
+$ card card:agent:gall
::
+$ cart $@(~ $^((lest card) $%([~ card] card)))
++ zang
|= a=(list cart)
^- (list card)
%- zing
%+ turn a
|= b=cart
^- (list card)
?~ b ~
?^ -.b b
?~ -.b [+.b]~
[b]~
::
++ store
|= [url=@t entry=(unit cache-entry:eyre)]
^- card
[%pass /eyre/cache %arvo %e %set-response url entry]
::
++ read-next
|= [[our=@p =desk now=@da] =path]
^- card
=; =task:clay
[%pass [%clay %next path] %arvo %c task]
[%warp our desk ~ %next %z da+now path]
::
++ set-norm
|= [[our=@p =desk] =path keep=?]
^- card
=; =task:clay
[%pass [%clay %norm path] %arvo %c task]
[%tomb %norm our desk (~(put of *norm:clay) path keep)]
::
++ run-tombstone
^- card
[%pass /clay/tomb %arvo %c %tomb %pick ~]
--
::
=| state-0
=* state -
::
^- agent:gall
|_ =bowl:gall
+* this .
::
++ on-init
^- (quip card _this)
=. foot file-root
=. woot web-root
:_ this
:+ [%pass /eyre/connect %arvo %e %connect [~ web-root] dap.bowl]
(read-next [our q.byk now]:bowl file-root)
?. tombstone ~
:~ (set-norm [our q.byk]:bowl file-root |)
run-tombstone
==
::
++ on-save
!>(state)
::
++ on-load
|= ole=vase
^- (quip card _this)
=/ old !<(state-0 ole)
:_ this(foot file-root, woot web-root, cash ~)
%- zang
:~ ?: =(foot.old file-root) ~
(read-next [our q.byk now]:bowl file-root)
::
?. tombstone
(set-norm [our q.byk]:bowl foot.old &)
:~ (set-norm [our q.byk]:bowl file-root |)
run-tombstone
==
::
(turn ~(tap in cash.old) (curr store ~))
::
?: =(woot.old web-root) ~
:~ [%pass /eyre/connect %arvo %e %connect [~ woot.old] dap.bowl]
[%pass /eyre/connect %arvo %e %disconnect [~ woot.old]]
[%pass /eyre/connect %arvo %e %connect [~ web-root] dap.bowl]
==
==
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
?: ?=(%dbug mark)
~& state=state
[~ this]
~| mark=mark
?> ?=(%handle-http-request mark)
=+ !<([rid=@ta inbound-request:eyre] vase)
::
=; [sav=$@(%| [%& auth=?]) pay=simple-payload:http]
=/ serve=(list card)
=? pay &(?=([%& %&] sav) !authenticated)
[[403 ~] `(as-octs:mimes:html 'unauthorized')]
=? data.pay ?=(%'HEAD' method.request)
~
=/ =path /http-response/[rid]
:~ [%give %fact ~[path] [%http-response-header !>(response-header.pay)]]
[%give %fact ~[path] [%http-response-data !>(data.pay)]]
[%give %kick ~[path] ~]
==
[serve this]
?. ?=(?(%'GET' %'HEAD') method.request)
[%| [405 ~] `(as-octs:mimes:html 'read-only resource')]
=+ ^- [[ext=(unit @ta) site=(list @t)] args=(list [key=@t value=@t])]
=- (fall - [[~ ~] ~])
(rush url.request ;~(plug apat:de-purl:html yque:de-purl:html))
?. =(web-root (scag (lent web-root) site))
[%| [500 ~] `(as-octs:mimes:html 'bad route')]
:: redirect /apps/mcp to /apps/mcp/
?: &(=(web-root site) ?=(~ ext))
[%| [301 ['location' (cat 3 (spat web-root) '/')]~] ~]
=. site (slag (lent web-root) site)
:- :- %&
|-
?: =(/ site) (~(got by auth) /)
%- (bond |.(^$(site (snip site))))
(~(get by auth) site)
=/ target=$@(?(~ %apache) [pax=path ext=@ta])
|-
?: &(?=(~ ext) ?=([%$ *] (flop site)))
=+ index=index
?@ index index
[(weld (snip site) u.index) (rear u.index)]
?^ ext [(snoc site u.ext) u.ext]
?- =<(. extension)
%need ~
%path [site (rear site)]
%fall $(site (snoc site %$))
==
?~ target
[[404 ~] `(as-octs:mimes:html 'not found')]
=/ bas=path
/(scot %p our.bowl)/[q.byk.bowl]/(scot %da now.bowl)
?^ target
=/ =path
:(weld bas file-root pax.target)
?. .^(? %cu path)
~& [dap.bowl %not-found path=path]
[[404 ~] `(as-octs:mimes:html 'not found')]
=+ .^(file=^vase %cr path)
=+ ~| [%no-mime-conversion from=ext.target]
.^(=tube:clay %cc (weld bas /[ext.target]/mime))
=+ !<(=mime (tube file))
:_ `q.mime
[200 ['content-type' (rsh 3^1 (spat p.mime))] ['cache-control' 'no-cache'] ~]
?> ?=(%apache target)
[[200 ['content-type' 'text/html;charset=UTF-8']~] `(as-octs:mimes:html 'directory listing not supported')]
::
++ on-watch
|= =path
^- (quip card _this)
?> ?=([%http-response @ ~] path)
[~ this]
::
++ on-arvo
|= [=wire sign=sign-arvo]
^- (quip card _this)
~| wire=wire
?+ wire !!
[%eyre %connect ~]
~| sign=+<.sign
?> ?=(%bound +<.sign)
~? !accepted.sign [dap.bowl %binding-rejected binding.sign]
[~ this]
::
[%eyre %cache ~]
~| sign=+<.sign
~| %did-not-expect-gift
!!
::
[%clay %next *]
?. =(t.t.wire file-root) [~ this]
~| sign=+<.sign
?> ?=(%writ +<.sign)
:_ this(cash ~)
%- zang
:+ ?:(tombstone ~ run-tombstone)
(read-next [our q.byk now]:bowl file-root)
(turn ~(tap in cash) (curr store ~))
==
::
++ on-leave |=(* [~ this])
++ on-agent |=(* [~ this])
++ on-peek |=(* ~)
::
++ on-fail
|= [=term =tang]
^- (quip card _this)
%- (slog (rap 3 dap.bowl ' +on-fail: ' term ~) tang)
[~ this]
--
Loading
Loading