hulla-id-mcp 0.0.0-stage → 0.3.0
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.
- package/LICENSE +202 -0
- package/README.md +104 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +366 -0
- package/dist/state.d.ts +33 -0
- package/dist/state.js +123 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 numericalsAI Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hulla-id-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP server for [HULLA.ID](https://hulla.id) — give any AI agent a human-readable,
|
|
4
|
+
pronounceable identity (e.g. `red.mountain.wolf`) with a cryptographic key, an
|
|
5
|
+
optional responsible human owner, and a reachable email address.
|
|
6
|
+
|
|
7
|
+
Runs **locally** over stdio. Ed25519 private keys are generated and stored on your
|
|
8
|
+
machine (`~/.hulla-id/`, chmod 600) and are never shown to the model or sent anywhere.
|
|
9
|
+
|
|
10
|
+
## Setup (Claude Desktop / Claude Code / any MCP client)
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"mcpServers": {
|
|
15
|
+
"hulla-id": {
|
|
16
|
+
"command": "npx",
|
|
17
|
+
"args": ["-y", "hulla-id-mcp"]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Tools
|
|
24
|
+
|
|
25
|
+
| Tool | What it does |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `lookup` | Resolve a hulla id → public identity (type, owner, public key, KYC level) |
|
|
28
|
+
| `verify_message` | Authenticate another agent: check its signed message (JWS) against its current key, your audience, the expected purpose (required), expiry and replay |
|
|
29
|
+
| `signup` | **Start here.** One call: key made locally, confirmation mail (link + 6-digit code) to the user; returns the provisional name and a four-word key fingerprint |
|
|
30
|
+
| `signup_confirm` | With the code: confirm. Without: check once (pending / active / rejected / expired). Once active, the bot is ready under its **final** name |
|
|
31
|
+
| `connect` | Connect this agent to a bot ID made in the HULLA.id app, with the one-time code the app shows (`code`, e.g. `K7QM-3XPD`); new key made locally |
|
|
32
|
+
| `register_self` / `register_self_confirm` | Older path (prefer `signup`): an identity of the agent's own via an address it can read |
|
|
33
|
+
| `login_owner` / `login_owner_confirm` | Email-OTP login of a human owner, for bots that should belong to a person |
|
|
34
|
+
| `register_bot` | Create a bot identity under the logged-in owner; key stays local |
|
|
35
|
+
| `sign_message` | Sign a message as a local bot id → JWS bound to one audience and purpose, max. 15 min |
|
|
36
|
+
| `whoami` | Show stored session, local bot identities (each with a pending key change if someone ran `recover` for it) and unconfirmed signups |
|
|
37
|
+
|
|
38
|
+
`sign_message` never signs raw text and never returns a raw signature, so a prompt
|
|
39
|
+
cannot trick the agent into signing a HULLA.ID login or registration statement. It
|
|
40
|
+
also refuses HULLA-internal audiences (`hulla.id`, `*.hulla.id`) and purposes
|
|
41
|
+
(`cancel-recover`, anything starting with `hulla`), so an injected prompt cannot make
|
|
42
|
+
the agent act on its own identity at HULLA.ID (e.g. abort a key change). To
|
|
43
|
+
prove "I am this id" to someone, sign their nonce with `purpose: "challenge"`.
|
|
44
|
+
`verify_message` looks the signer's key up fresh on every call and fails closed when
|
|
45
|
+
the lookup fails. It takes the `purpose` you expect and rejects a token issued for any
|
|
46
|
+
other purpose (`bad_purpose`) — a `challenge` token is never accepted as an `order`.
|
|
47
|
+
|
|
48
|
+
**Pending key change.** If someone runs `recover` for one of the local bots, the server
|
|
49
|
+
reports `pendingKeyChange: { effectiveAt, newPublicKey, cancellable }` (key lookup and key
|
|
50
|
+
sign-in). `whoami` shows it per bot. Until `effectiveAt` the old key can cancel the change
|
|
51
|
+
(once in 30 days — after that `cancellable` is false and the next change lands after 72 h); in code
|
|
52
|
+
that is `HullaBot.cancelKeyChange()` from the `hulla-id` SDK (deliberately not an MCP tool
|
|
53
|
+
the model could be talked into or out of).
|
|
54
|
+
|
|
55
|
+
**Signup.** `signup` keeps the new key under `signups/<signupId>/` in the state directory
|
|
56
|
+
(directory 700, files 600) until the signup is active, then `signup_confirm` moves it to
|
|
57
|
+
`bots/<final id>/` — the user may pick another name on the confirmation page, so the final
|
|
58
|
+
id can differ from the first one. A rejected or expired signup's unused key is deleted. The
|
|
59
|
+
confirmation mail shows the same four key words as `key_fingerprint`; the agent tells the
|
|
60
|
+
user to confirm only if they match. `signup_confirm` never blocks: without a code it checks
|
|
61
|
+
once and returns.
|
|
62
|
+
|
|
63
|
+
## Connect a bot you created in the HULLA.id app
|
|
64
|
+
|
|
65
|
+
In the HULLA.id app, open the bot and tap **Connect your bot**. The app shows a one-time code
|
|
66
|
+
(`XXXX-XXXX`, valid 15 minutes, usable once) and a sentence to paste to your agent:
|
|
67
|
+
|
|
68
|
+
> **User:** Connect to HULLA.id with code K7QM-3XPD
|
|
69
|
+
> **Agent:** calls `connect("K7QM-3XPD")` → *"Done: I am `wise.robot.moon`, reachable at
|
|
70
|
+
> `wise.robot.moon@hulla.id`."*
|
|
71
|
+
|
|
72
|
+
`connect` makes a new Ed25519 key on this machine, sends only the public key with the code,
|
|
73
|
+
stores the key under `bots/<id>/` (directory 700, files 600) and signs in with it. One bot ID,
|
|
74
|
+
one agent: connecting again replaces the key, and the agent connected before stops working —
|
|
75
|
+
for two agents, create two bot IDs (e.g. `wise.robot.moon` and `calm.river.lamp`). If the code
|
|
76
|
+
is unknown, expired or already used, the tool says so: create a new one in the app.
|
|
77
|
+
|
|
78
|
+
## Typical conversation
|
|
79
|
+
|
|
80
|
+
> **User:** Get yourself a HULLA.id. My email is max@example.com.
|
|
81
|
+
> **Agent:** calls `signup("max@example.com", "research-agent")` → *"I'll be `gold.river.fox`.
|
|
82
|
+
> A mail went to max@example.com — please confirm only if it shows the key words
|
|
83
|
+
> `apple-river-stone-moon`."* → later `signup_confirm(signup_id)` → *"Done: I am
|
|
84
|
+
> `gold.river.fox`, reachable at `gold.river.fox@hulla.id`."*
|
|
85
|
+
|
|
86
|
+
For a bot that should belong to a person: `login_owner` → `login_owner_confirm` →
|
|
87
|
+
`register_bot("research-agent")`.
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
The server uses the SDK from `../sdk/js` (`file:` dependency, symlinked): build it first.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
(cd ../sdk/js && npm install && npm run build)
|
|
95
|
+
npm install
|
|
96
|
+
npm run build
|
|
97
|
+
npm test
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Environment
|
|
101
|
+
|
|
102
|
+
- `HULLA_ID_BASE_URL` — API base (default `https://hulla.id`)
|
|
103
|
+
- `HULLA_ID_HOME` — state directory (default `~/.hulla-id`)
|
|
104
|
+
|
|
105
|
+
License: Apache-2.0
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* hulla-id-mcp — MCP server that lets any MCP-capable agent get and use a
|
|
4
|
+
* HULLA.ID (human-readable 3-word identity, e.g. Red.Mountain.Wolf).
|
|
5
|
+
*
|
|
6
|
+
* Runs LOCALLY (stdio): Ed25519 private keys are generated and stored on
|
|
7
|
+
* this machine (~/.hulla-id/, chmod 600) and are never returned to the
|
|
8
|
+
* model or sent anywhere except as public keys during registration.
|
|
9
|
+
*
|
|
10
|
+
* Tools:
|
|
11
|
+
* lookup — resolve a hulla id → public identity (key, type, owner)
|
|
12
|
+
* verify_message — check a signed message (JWS) from another hulla id
|
|
13
|
+
* signup — one call: key made here, confirmation mail to the user
|
|
14
|
+
* signup_confirm — check the signup once, or confirm it with the mailed code
|
|
15
|
+
* connect — take over a bot ID made in the HULLA.id app, with the
|
|
16
|
+
* one-time code the app shows (new key made here)
|
|
17
|
+
* register_self — older path, step 1: send an OTP to the agent's OWN address
|
|
18
|
+
* register_self_confirm — older path, step 2: confirm it → own identity
|
|
19
|
+
* login_owner — step 1: send an email OTP to a human owner
|
|
20
|
+
* login_owner_confirm — step 2: confirm the OTP → session stored locally
|
|
21
|
+
* register_bot — create a bot identity under the logged-in owner
|
|
22
|
+
* sign_message — sign a message as JWS (audience + purpose + expiry);
|
|
23
|
+
* never signs raw text (Spec 014 §4C)
|
|
24
|
+
* whoami — show stored session + locally-stored bots, and any
|
|
25
|
+
* pending key change (recover) for them
|
|
26
|
+
*
|
|
27
|
+
* signup is the way to get an identity: one call, the user confirms the mail
|
|
28
|
+
* (or the agent reads the code itself). Pending signups are kept under
|
|
29
|
+
* signups/<signupId> and move to bots/<final id> once active — the user may
|
|
30
|
+
* pick another name on the confirmation page. Self-registration via
|
|
31
|
+
* register_self is the older two-step path; the owner path (login_owner →
|
|
32
|
+
* register_bot) still exists for bots that should belong to a person.
|
|
33
|
+
*/
|
|
34
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
35
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
36
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
37
|
+
import { join } from 'node:path';
|
|
38
|
+
import { z } from 'zod';
|
|
39
|
+
import { HullaApiError, HullaBot, HullaID, PendingSignup, saveBotIdentity, verifyMessage, verifyRequest } from 'hulla-id';
|
|
40
|
+
import { saveSession, loadSession, botDir, listBots, listSignups, promoteSignup, removeSignup, signupDir, connectingDir, promoteConnected, removeConnecting, } from './state.js';
|
|
41
|
+
const BASE_URL = process.env.HULLA_ID_BASE_URL ?? 'https://hulla.id';
|
|
42
|
+
// the real package version (dist/index.js and src/index.ts both sit one level below package.json)
|
|
43
|
+
const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8')).version;
|
|
44
|
+
const server = new McpServer({ name: 'hulla-id', version: VERSION });
|
|
45
|
+
function text(data) {
|
|
46
|
+
return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
|
|
47
|
+
}
|
|
48
|
+
function errorText(err) {
|
|
49
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
50
|
+
return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
|
|
51
|
+
}
|
|
52
|
+
server.tool('lookup', 'Look a HULLA.ID (e.g. red.mountain.wolf) up in the register: whether it exists and is active, whether it is a person or a bot (only if its owner shows that), its current public key (and when it last changed) and its @hulla.id mail address. The register never says who owns a name.', { hulla_id: z.string().describe('The 3-word id, e.g. red.mountain.wolf') }, async ({ hulla_id }) => {
|
|
53
|
+
try {
|
|
54
|
+
const identity = await new HullaID({ baseUrl: BASE_URL }).lookup(hulla_id);
|
|
55
|
+
return text(identity);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return errorText(err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
server.tool('verify_message', 'Verify a signed message (a JWS token from sign_message) from another HULLA.ID. Checks the signature against the signer\'s CURRENT key (fresh lookup, fails closed if the lookup fails), that the token is addressed to `audience`, was issued for exactly `purpose` (a token for another purpose is rejected with bad_purpose), is not expired, not replayed, and that `body` is exactly what was signed. Use it to authenticate another agent.', {
|
|
62
|
+
body: z.string().describe('The exact message text that was signed (byte for byte)'),
|
|
63
|
+
token: z.string().describe('The JWS token the signer sent along'),
|
|
64
|
+
audience: z.string().min(1).describe('Who you are — the audience the token must be addressed to (your HULLA-ID, domain or URL)'),
|
|
65
|
+
purpose: z.string().min(1).max(64).describe('The purpose you expect, e.g. "challenge" or "order" — the token must have been issued for exactly this'),
|
|
66
|
+
}, async ({ body, token, audience, purpose }) => {
|
|
67
|
+
const result = await verifyMessage(body, token, { audience, purpose, baseUrl: BASE_URL });
|
|
68
|
+
return text(result);
|
|
69
|
+
});
|
|
70
|
+
server.tool('signup', 'Get this agent its own HULLA.ID in one call — the recommended way. Generates an Ed25519 keypair locally (the private key is stored on this machine and never shown or transmitted) and mails a confirmation link + 6-digit code to the user\'s address. Returns the provisional name and a four-word key fingerprint. Afterwards call signup_confirm.', {
|
|
71
|
+
email: z.string().email().describe('The user\'s email address — the confirmation mail goes there'),
|
|
72
|
+
name: z.string().min(1).max(64).optional().describe('Name that goes into the three words, e.g. "research-agent" (default "bot")'),
|
|
73
|
+
}, async ({ email, name }) => {
|
|
74
|
+
try {
|
|
75
|
+
const pending = await HullaID.signup({ email, name, baseUrl: BASE_URL });
|
|
76
|
+
pending.save(signupDir(pending.signupId));
|
|
77
|
+
return text({
|
|
78
|
+
status: pending.state,
|
|
79
|
+
hulla_id: pending.hullaId,
|
|
80
|
+
signup_id: pending.signupId,
|
|
81
|
+
key_fingerprint: pending.keyFingerprint,
|
|
82
|
+
expires_at: pending.expiresAt,
|
|
83
|
+
instruction: `Tell the user: this agent's name will be ${pending.hullaId} (they may pick another suggestion when confirming). ` +
|
|
84
|
+
`A confirmation mail went to ${email}. They should confirm ONLY if the four key words in that mail are exactly ` +
|
|
85
|
+
`"${pending.keyFingerprint}" — if the words differ or they did not ask for this, they should click "That was not me". ` +
|
|
86
|
+
`Then call signup_confirm with signup_id (add the 6-digit code if you can read that mailbox yourself, or if the user tells it to you).`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
return errorText(err);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
server.tool('signup_confirm', 'Finish a signup started with signup. With the 6-digit code from the mail it confirms right away; without a code it checks once (no waiting) whether the user has confirmed via the link, and reports pending, active, rejected or expired. Once active the identity is ready for sign_message. The final name can differ from the one signup reported — always use the hulla_id returned here.', {
|
|
94
|
+
signup_id: z.string().regex(/^[0-9a-f]{32}$/).describe('The signup_id that signup returned'),
|
|
95
|
+
code: z.string().regex(/^\d{6}$/).optional().describe('The 6-digit code from the confirmation mail, if known'),
|
|
96
|
+
}, async ({ signup_id, code }) => {
|
|
97
|
+
try {
|
|
98
|
+
const dir = signupDir(signup_id, false);
|
|
99
|
+
if (!existsSync(dir)) {
|
|
100
|
+
return errorText(new Error('No pending signup with this id on this machine. If it was confirmed already, whoami lists the bot.'));
|
|
101
|
+
}
|
|
102
|
+
const pending = PendingSignup.load(dir, { baseUrl: BASE_URL });
|
|
103
|
+
let reason;
|
|
104
|
+
if (code) {
|
|
105
|
+
try {
|
|
106
|
+
await pending.confirm(code);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
// 410: no longer open — maybe confirmed via the link meanwhile
|
|
110
|
+
if (!(err instanceof HullaApiError) || err.status !== 410)
|
|
111
|
+
throw err;
|
|
112
|
+
({ reason } = await pending.status());
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
({ reason } = await pending.status());
|
|
117
|
+
}
|
|
118
|
+
if (pending.state === 'active') {
|
|
119
|
+
const hullaId = pending.hullaId;
|
|
120
|
+
const stored = promoteSignup(signup_id, hullaId);
|
|
121
|
+
return text({
|
|
122
|
+
status: 'active',
|
|
123
|
+
hulla_id: hullaId,
|
|
124
|
+
email: pending.emailProxy || `${hullaId}@hulla.id`,
|
|
125
|
+
owner: null,
|
|
126
|
+
keyStoredAt: join(stored, 'hulla-id-private.pem'),
|
|
127
|
+
note: 'This is the final name — use it from now on. The private key stays on this machine; use sign_message to prove control of it.',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (pending.state === 'rejected' || pending.state === 'expired') {
|
|
131
|
+
removeSignup(signup_id);
|
|
132
|
+
return text({
|
|
133
|
+
status: pending.state,
|
|
134
|
+
...(pending.state === 'rejected' ? { reason: reason ?? null } : {}),
|
|
135
|
+
note: pending.state === 'rejected'
|
|
136
|
+
? 'The signup was rejected (e.g. the mailbox owner clicked "That was not me"). The unused key was deleted. Ask the user before trying again.'
|
|
137
|
+
: 'The signup expired before it was confirmed. The unused key was deleted; call signup again if the user still wants it.',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return text({
|
|
141
|
+
status: pending.state,
|
|
142
|
+
hulla_id: pending.hullaId,
|
|
143
|
+
key_fingerprint: pending.keyFingerprint,
|
|
144
|
+
expires_at: pending.expiresAt,
|
|
145
|
+
next: 'Not confirmed yet. Remind the user to confirm the mail (only if the four key words match), then call signup_confirm again — do not poll in a tight loop.',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
return errorText(err);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
server.tool('connect', 'Connect this agent to a HULLA.id bot ID using the one-time code from the HULLA.id app.', {
|
|
153
|
+
code: z.string().min(1).max(32).describe('The one-time code the HULLA.id app shows, e.g. K7QM-3XPD (valid 15 minutes, single use)'),
|
|
154
|
+
}, async ({ code }) => {
|
|
155
|
+
const staging = connectingDir();
|
|
156
|
+
try {
|
|
157
|
+
const bot = await HullaBot.connect(code, { baseUrl: BASE_URL, dir: staging });
|
|
158
|
+
const stored = promoteConnected(staging, bot.hullaId);
|
|
159
|
+
return text({
|
|
160
|
+
status: 'connected',
|
|
161
|
+
hulla_id: bot.hullaId,
|
|
162
|
+
email: `${bot.hullaId}@hulla.id`,
|
|
163
|
+
keyStoredAt: join(stored, 'hulla-id-private.pem'),
|
|
164
|
+
note: 'This agent now holds the key of this bot ID and is signed in with it. Any agent connected to it before no longer works. The private key stays on this machine; use sign_message to prove control of it.',
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
// The code may be spent although signing in afterwards failed: keep the key.
|
|
169
|
+
try {
|
|
170
|
+
const saved = JSON.parse(readFileSync(join(staging, 'hulla-id.json'), 'utf-8'));
|
|
171
|
+
if (typeof saved?.hullaId === 'string' && saved.hullaId)
|
|
172
|
+
promoteConnected(staging, saved.hullaId);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
// nothing was saved
|
|
176
|
+
}
|
|
177
|
+
removeConnecting(staging);
|
|
178
|
+
return errorText(err);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
server.tool('register_self', 'Older path — prefer signup. Step 1 of self-registration: send a 6-digit code to an address THIS agent can read. No human owner is involved.', {
|
|
182
|
+
email: z.string().email().describe('An address this agent controls and can read mail at'),
|
|
183
|
+
}, async ({ email }) => {
|
|
184
|
+
try {
|
|
185
|
+
await new HullaID({ baseUrl: BASE_URL }).verifyEmail(email);
|
|
186
|
+
return text({
|
|
187
|
+
status: 'code_sent',
|
|
188
|
+
next: 'Read the 6-digit code from that mailbox, then call register_self_confirm with the same email.',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
return errorText(err);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
server.tool('register_self_confirm', 'Older path — prefer signup. Step 2 of self-registration: confirm the code and claim a 3-word HULLA.ID for this agent. Generates an Ed25519 keypair locally; the private key is stored on this machine and never shown or transmitted. The resulting identity has no owner.', {
|
|
196
|
+
email: z.string().email().describe('The same address register_self was called with'),
|
|
197
|
+
code: z.string().length(6).describe('The 6-digit code from that mailbox'),
|
|
198
|
+
bot_name: z.string().min(1).max(64).describe('Display name, e.g. "my-research-agent"'),
|
|
199
|
+
}, async ({ email, code, bot_name }) => {
|
|
200
|
+
try {
|
|
201
|
+
const client = new HullaID({ baseUrl: BASE_URL });
|
|
202
|
+
const { token } = await client.confirmEmail(email, code, 'register');
|
|
203
|
+
const bot = await client.createSelfRegisteredBot(token, bot_name, { email });
|
|
204
|
+
const paths = saveBotIdentity(bot, botDir(bot.hullaId));
|
|
205
|
+
return text({
|
|
206
|
+
status: 'registered',
|
|
207
|
+
hulla_id: bot.hullaId,
|
|
208
|
+
email: bot.emailProxy,
|
|
209
|
+
owner: null,
|
|
210
|
+
keyStoredAt: paths.privateKeyPath,
|
|
211
|
+
note: 'This identity belongs to no one but this agent. The private key stays on this machine — use sign_message to prove control of it.',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
return errorText(err);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
server.tool('login_owner', 'Step 1 of owner login: send a 6-digit code to a human\'s email, so bots can be registered under that person. Only needed when the identity should belong to someone — an agent that just wants its own id uses register_self.', { email: z.string().email().describe('The human owner\'s email registered with HULLA.ID') }, async ({ email }) => {
|
|
219
|
+
try {
|
|
220
|
+
await new HullaID({ baseUrl: BASE_URL }).verifyEmail(email);
|
|
221
|
+
return text({ status: 'code_sent', next: 'Ask the user for the 6-digit code, then call login_owner_confirm.' });
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
return errorText(err);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
server.tool('login_owner_confirm', 'Step 2 of owner login: confirm the emailed code. Stores the session locally (~/.hulla-id) for register_bot.', {
|
|
228
|
+
email: z.string().email(),
|
|
229
|
+
code: z.string().length(6).describe('The 6-digit code from the email'),
|
|
230
|
+
}, async ({ email, code }) => {
|
|
231
|
+
try {
|
|
232
|
+
const client = new HullaID({ baseUrl: BASE_URL });
|
|
233
|
+
const { token } = await client.confirmEmail(email, code, 'login');
|
|
234
|
+
const session = await client.login(token);
|
|
235
|
+
saveSession({
|
|
236
|
+
email,
|
|
237
|
+
hullaId: session.identity.hullaId,
|
|
238
|
+
sessionToken: session.sessionToken,
|
|
239
|
+
savedAt: new Date().toISOString(),
|
|
240
|
+
});
|
|
241
|
+
return text({ status: 'logged_in', owner: session.identity.hullaId });
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
return errorText(err);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
server.tool('register_bot', 'Create a new bot identity (3-word HULLA.ID) OWNED BY the logged-in human. Requires login_owner first. If the agent just wants an identity of its own, use register_self instead — that needs no human at all. Generates an Ed25519 keypair locally; the private key is stored on this machine and never shown.', { bot_name: z.string().min(1).max(64).describe('Display name for the bot, e.g. "my-research-agent"') }, async ({ bot_name }) => {
|
|
248
|
+
try {
|
|
249
|
+
const session = loadSession();
|
|
250
|
+
if (!session) {
|
|
251
|
+
return errorText(new Error('Not logged in as an owner. Either call login_owner first, or use register_self to get an identity that belongs to no one.'));
|
|
252
|
+
}
|
|
253
|
+
const client = new HullaID({ baseUrl: BASE_URL, sessionToken: session.sessionToken });
|
|
254
|
+
const bot = await client.createBot(bot_name, { ownerEmail: session.email });
|
|
255
|
+
const paths = saveBotIdentity(bot, botDir(bot.hullaId));
|
|
256
|
+
return text({
|
|
257
|
+
status: 'registered',
|
|
258
|
+
hulla_id: bot.hullaId,
|
|
259
|
+
email: bot.emailProxy || `${bot.hullaId}@hulla.id`,
|
|
260
|
+
owner: session.hullaId,
|
|
261
|
+
keyStoredAt: paths.privateKeyPath,
|
|
262
|
+
note: 'Private key stays on this machine. Use sign_message to prove this identity.',
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
return errorText(err);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
server.tool('sign_message', 'Sign a message as a locally-stored bot identity. Produces a JWS token bound to ONE audience and ONE purpose, valid for at most 15 minutes, that the recipient checks with verify_message. This tool never signs raw text and never returns a raw signature — so it cannot be used to forge a HULLA.ID login or registration. HULLA-internal audiences (hulla.id, *.hulla.id) and purposes (cancel-recover, anything starting with "hulla") are refused, so a message cannot talk it into acting on this identity at HULLA.ID itself. To prove "I am this id" to someone, use purpose "challenge" and put their nonce in the body.', {
|
|
270
|
+
hulla_id: z.string().describe('A bot id created on this machine via register_self or register_bot'),
|
|
271
|
+
body: z.string().describe('The message to sign; the recipient needs exactly this text too'),
|
|
272
|
+
audience: z.string().min(1).describe('Who the message is for: their HULLA-ID, domain or URL (never hulla.id itself)'),
|
|
273
|
+
purpose: z.string().min(1).max(64).describe('What it is for, e.g. "order", "challenge", "a2a" (not cancel-recover or hulla*)'),
|
|
274
|
+
ttl_seconds: z.number().int().min(1).max(900).optional().describe('Lifetime, default 300, max 900'),
|
|
275
|
+
}, async ({ hulla_id, body, audience, purpose, ttl_seconds }) => {
|
|
276
|
+
try {
|
|
277
|
+
const bot = HullaBot.fromSavedBot(botDir(hulla_id), { baseUrl: BASE_URL });
|
|
278
|
+
const token = bot.signMessage(body, { audience, purpose, ttlSeconds: ttl_seconds });
|
|
279
|
+
return text({ hulla_id: bot.hullaId, audience, purpose, token });
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
return errorText(err);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
server.tool('set_card', 'Publish the A2A Agent Card of a bot stored on this machine under its HULLA name (Spec 017). The card is signed with the bot key and served at https://a-b-c.hulla.id/.well-known/agent-card.json; anyone can check it against the register. Needs a bot with a responsible human (not an autonomous one). Endpoints must be https://. Endpoints are public — warn the user before publishing a home IP address.', {
|
|
286
|
+
hulla_id: z.string().describe('A bot id created on this machine'),
|
|
287
|
+
card: z.record(z.unknown()).describe('A2A 1.0 Agent Card: name, description, supportedInterfaces [{url, protocolBinding, protocolVersion}], version, capabilities, defaultInputModes, defaultOutputModes, skills [{id, name, description, tags}]. No signatures — they are added here.'),
|
|
288
|
+
}, async ({ hulla_id, card }) => {
|
|
289
|
+
try {
|
|
290
|
+
const bot = HullaBot.fromSavedBot(botDir(hulla_id), { baseUrl: BASE_URL });
|
|
291
|
+
return text(await bot.setCard(card));
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
return errorText(err);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
server.tool('sign_request', 'Sign an HTTP request to another agent as a bot stored on this machine (RFC 9421 HTTP Message Signatures, keyid = HULLA-ID, created + nonce, body bound by Content-Digest). Returns the headers to add; send the body byte for byte as given. Good for 300 s. The receiver checks it with verify_request. Requests to hulla.id itself are refused.', {
|
|
298
|
+
hulla_id: z.string().describe('A bot id created on this machine'),
|
|
299
|
+
method: z.string().min(1).describe('HTTP method, e.g. POST'),
|
|
300
|
+
url: z.string().url().describe('The full URL that will be called'),
|
|
301
|
+
body: z.string().optional().describe('The exact request body, if any'),
|
|
302
|
+
}, async ({ hulla_id, method, url, body }) => {
|
|
303
|
+
try {
|
|
304
|
+
const bot = HullaBot.fromSavedBot(botDir(hulla_id), { baseUrl: BASE_URL });
|
|
305
|
+
return text({ hulla_id: bot.hullaId, headers: bot.signRequest({ method, url, body }) });
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
return errorText(err);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
server.tool('verify_request', 'Verify an incoming HTTP request signed by another HULLA.ID (RFC 9421, from sign_request or the SDK). Checks the signature against the signer\'s CURRENT key in the register (fails closed if the lookup fails), that method, full URL and body are exactly what was signed, that it is at most 300 s old and not replayed. Returns ok and the signer\'s HULLA-ID, or a reason.', {
|
|
312
|
+
method: z.string().min(1),
|
|
313
|
+
url: z.string().url().describe('The full URL the caller used (scheme, host, path, query)'),
|
|
314
|
+
headers: z.record(z.string()).describe('The request headers — at least Signature-Input, Signature and, with a body, Content-Digest'),
|
|
315
|
+
body: z.string().optional().describe('The exact request body received, if any'),
|
|
316
|
+
}, async ({ method, url, headers, body }) => {
|
|
317
|
+
return text(await verifyRequest({ method, url, headers, body }, { baseUrl: BASE_URL }));
|
|
318
|
+
});
|
|
319
|
+
server.tool('delete_identity', 'Delete a bot identity stored on this machine (tasks/037). Its key stops working at once; for 30 days its owner can restore it in the HULLA.id app, then the data is gone for good and the three words are never given to anyone else. Only call this when the user has explicitly asked to delete exactly this id, and repeat the id in `confirm`. The local key files stay on disk but are useless afterwards.', {
|
|
320
|
+
hulla_id: z.string().describe('A bot id created on this machine'),
|
|
321
|
+
confirm: z.string().describe('The same id again, typed out — guards against deleting the wrong one'),
|
|
322
|
+
}, async ({ hulla_id, confirm }) => {
|
|
323
|
+
try {
|
|
324
|
+
if (confirm.trim().toLowerCase() !== hulla_id.trim().toLowerCase()) {
|
|
325
|
+
return errorText(new Error('confirm must repeat hulla_id exactly — nothing was deleted.'));
|
|
326
|
+
}
|
|
327
|
+
const bot = HullaBot.fromSavedBot(botDir(hulla_id), { baseUrl: BASE_URL });
|
|
328
|
+
const result = await bot.deleteIdentity();
|
|
329
|
+
return text({ status: 'deleted', ...result });
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
return errorText(err);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
server.tool('whoami', 'Show the locally stored owner session, bot identities and unconfirmed signups (finish those with signup_confirm) on this machine. For each bot it also reports a pending key change (someone ran recover for it; the new key takes effect at effectiveAt) — if the user did not start that, tell them right away. If cancellable is true the old key can still cancel it until then; if false it will happen anyway (this key already cancelled one in the last 30 days) and the owner\'s mailbox needs securing.', {}, async () => {
|
|
336
|
+
const session = loadSession();
|
|
337
|
+
const client = new HullaID({ baseUrl: BASE_URL });
|
|
338
|
+
// One public key lookup per bot; a failed lookup only means "unknown".
|
|
339
|
+
const bots = await Promise.all(listBots().map(async (hullaId) => {
|
|
340
|
+
try {
|
|
341
|
+
const record = await client.keys(hullaId);
|
|
342
|
+
return { hullaId, pendingKeyChange: record.pendingKeyChange ?? null };
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
return { hullaId, pendingKeyChange: 'unknown (key lookup failed)' };
|
|
346
|
+
}
|
|
347
|
+
}));
|
|
348
|
+
// Unconfirmed signups, from local state only (signup_confirm checks the server).
|
|
349
|
+
const signups = listSignups().flatMap((signupId) => {
|
|
350
|
+
try {
|
|
351
|
+
const p = PendingSignup.load(signupDir(signupId, false), { baseUrl: BASE_URL });
|
|
352
|
+
return [{ signupId, hullaId: p.hullaId, keyFingerprint: p.keyFingerprint, state: p.state, expiresAt: p.expiresAt }];
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return text({
|
|
359
|
+
owner: session ? { hullaId: session.hullaId, email: session.email, since: session.savedAt } : null,
|
|
360
|
+
bots,
|
|
361
|
+
pendingSignups: signups,
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
const transport = new StdioServerTransport();
|
|
365
|
+
await server.connect(transport);
|
|
366
|
+
console.error('[hulla-id-mcp] ready (stdio)');
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare function stateDir(): string;
|
|
2
|
+
export interface StoredSession {
|
|
3
|
+
email: string;
|
|
4
|
+
hullaId: string;
|
|
5
|
+
sessionToken: string;
|
|
6
|
+
savedAt: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function saveSession(s: StoredSession): void;
|
|
9
|
+
export declare function loadSession(): StoredSession | null;
|
|
10
|
+
export declare function botsDir(): string;
|
|
11
|
+
export declare function botDir(hullaId: string): string;
|
|
12
|
+
export declare function signupsDir(): string;
|
|
13
|
+
/** Path of a pending signup's directory; `create` makes it (0700). */
|
|
14
|
+
export declare function signupDir(signupId: string, create?: boolean): string;
|
|
15
|
+
export declare function listSignups(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Move an activated signup to bots/<hullaId>. Refuses to replace a bot that
|
|
18
|
+
* already has a key there. Returns the new directory.
|
|
19
|
+
*/
|
|
20
|
+
export declare function promoteSignup(signupId: string, hullaId: string): string;
|
|
21
|
+
/** Drop a signup that can no longer become an identity (rejected/expired). */
|
|
22
|
+
export declare function removeSignup(signupId: string): void;
|
|
23
|
+
/** A fresh, empty directory (0700) for a connect in progress. */
|
|
24
|
+
export declare function connectingDir(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Move a connected bot's key to bots/<hullaId>. Unlike promoteSignup this
|
|
27
|
+
* REPLACES a bot stored there: connect gave the id a new key on the server,
|
|
28
|
+
* so the old one no longer works. Returns the new directory.
|
|
29
|
+
*/
|
|
30
|
+
export declare function promoteConnected(from: string, hullaId: string): string;
|
|
31
|
+
/** Drop a connect directory that never got a key (connect failed). */
|
|
32
|
+
export declare function removeConnecting(dir: string): void;
|
|
33
|
+
export declare function listBots(): string[];
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local state for the MCP server — session token + bot key storage under
|
|
3
|
+
* ~/.hulla-id/. Private keys NEVER leave this directory; tool results only
|
|
4
|
+
* ever reference them by path. Everything sensitive is chmod 600.
|
|
5
|
+
*/
|
|
6
|
+
import { chmodSync, mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, renameSync, rmdirSync, rmSync, } from 'node:fs';
|
|
7
|
+
import { randomBytes } from 'node:crypto';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
export function stateDir() {
|
|
11
|
+
const dir = process.env.HULLA_ID_HOME ?? join(homedir(), '.hulla-id');
|
|
12
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
const sessionPath = () => join(stateDir(), 'session.json');
|
|
16
|
+
export function saveSession(s) {
|
|
17
|
+
writeFileSync(sessionPath(), JSON.stringify(s, null, 2), { mode: 0o600 });
|
|
18
|
+
// writeFileSync only applies the mode when it creates the file
|
|
19
|
+
chmodSync(sessionPath(), 0o600);
|
|
20
|
+
}
|
|
21
|
+
export function loadSession() {
|
|
22
|
+
if (!existsSync(sessionPath()))
|
|
23
|
+
return null;
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(readFileSync(sessionPath(), 'utf-8'));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function botsDir() {
|
|
32
|
+
const dir = join(stateDir(), 'bots');
|
|
33
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
34
|
+
return dir;
|
|
35
|
+
}
|
|
36
|
+
export function botDir(hullaId) {
|
|
37
|
+
// hulla ids are dot-separated words. Anything else — '..', '.', a slash —
|
|
38
|
+
// could point outside bots/ and is refused rather than rewritten.
|
|
39
|
+
const safe = hullaId.toLowerCase();
|
|
40
|
+
if (!/^[a-z0-9-]+(\.[a-z0-9-]+)*$/.test(safe))
|
|
41
|
+
throw new Error(`Not a HULLA-ID: ${JSON.stringify(hullaId)}`);
|
|
42
|
+
const dir = join(botsDir(), safe);
|
|
43
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
// Unconfirmed signups (Spec 013) live apart from bots/: the name may still
|
|
47
|
+
// change on the confirmation page, so the key moves to bots/<final id> only
|
|
48
|
+
// once the signup is active.
|
|
49
|
+
const SIGNUP_ID = /^[0-9a-f]{32}$/;
|
|
50
|
+
export function signupsDir() {
|
|
51
|
+
const dir = join(stateDir(), 'signups');
|
|
52
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
53
|
+
return dir;
|
|
54
|
+
}
|
|
55
|
+
/** Path of a pending signup's directory; `create` makes it (0700). */
|
|
56
|
+
export function signupDir(signupId, create = true) {
|
|
57
|
+
if (!SIGNUP_ID.test(signupId))
|
|
58
|
+
throw new Error(`Not a signup id: ${JSON.stringify(signupId)}`);
|
|
59
|
+
const dir = join(signupsDir(), signupId);
|
|
60
|
+
if (create)
|
|
61
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
62
|
+
return dir;
|
|
63
|
+
}
|
|
64
|
+
export function listSignups() {
|
|
65
|
+
return readdirSync(signupsDir(), { withFileTypes: true })
|
|
66
|
+
.filter((e) => e.isDirectory() && SIGNUP_ID.test(e.name))
|
|
67
|
+
.map((e) => e.name);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Move an activated signup to bots/<hullaId>. Refuses to replace a bot that
|
|
71
|
+
* already has a key there. Returns the new directory.
|
|
72
|
+
*/
|
|
73
|
+
export function promoteSignup(signupId, hullaId) {
|
|
74
|
+
const from = signupDir(signupId, false);
|
|
75
|
+
if (!existsSync(from))
|
|
76
|
+
throw new Error(`No pending signup ${signupId} on this machine.`);
|
|
77
|
+
const to = botDir(hullaId); // validates the id, creates bots/<id>
|
|
78
|
+
if (readdirSync(to).length > 0) {
|
|
79
|
+
throw new Error(`A bot ${hullaId} is already stored at ${to}; the new key stays at ${from}.`);
|
|
80
|
+
}
|
|
81
|
+
rmdirSync(to);
|
|
82
|
+
renameSync(from, to);
|
|
83
|
+
return to;
|
|
84
|
+
}
|
|
85
|
+
/** Drop a signup that can no longer become an identity (rejected/expired). */
|
|
86
|
+
export function removeSignup(signupId) {
|
|
87
|
+
rmSync(signupDir(signupId, false), { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
// connect (IMPROVEMENTS/015): the id is known only once the code is redeemed,
|
|
90
|
+
// so the new key is written to connecting/<random> first and then moved to
|
|
91
|
+
// bots/<id>.
|
|
92
|
+
/** A fresh, empty directory (0700) for a connect in progress. */
|
|
93
|
+
export function connectingDir() {
|
|
94
|
+
const parent = join(stateDir(), 'connecting');
|
|
95
|
+
mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
96
|
+
const dir = join(parent, randomBytes(8).toString('hex'));
|
|
97
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
98
|
+
return dir;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Move a connected bot's key to bots/<hullaId>. Unlike promoteSignup this
|
|
102
|
+
* REPLACES a bot stored there: connect gave the id a new key on the server,
|
|
103
|
+
* so the old one no longer works. Returns the new directory.
|
|
104
|
+
*/
|
|
105
|
+
export function promoteConnected(from, hullaId) {
|
|
106
|
+
if (!existsSync(join(from, 'hulla-id-private.pem')))
|
|
107
|
+
throw new Error(`No connected key in ${from}.`);
|
|
108
|
+
const to = botDir(hullaId); // validates the id, creates bots/<id>
|
|
109
|
+
rmSync(to, { recursive: true, force: true });
|
|
110
|
+
renameSync(from, to);
|
|
111
|
+
return to;
|
|
112
|
+
}
|
|
113
|
+
/** Drop a connect directory that never got a key (connect failed). */
|
|
114
|
+
export function removeConnecting(dir) {
|
|
115
|
+
rmSync(dir, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
export function listBots() {
|
|
118
|
+
if (!existsSync(botsDir()))
|
|
119
|
+
return [];
|
|
120
|
+
return readdirSync(botsDir(), { withFileTypes: true })
|
|
121
|
+
.filter((e) => e.isDirectory())
|
|
122
|
+
.map((e) => e.name);
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hulla-id-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "MCP server for HULLA.ID \u2014 give any AI agent a human-readable identity (Red.Mountain.Wolf)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"hulla-id-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc && chmod +x dist/index.js",
|
|
16
|
+
"start": "node dist/index.js",
|
|
17
|
+
"test": "node --import tsx --test src/state.test.ts src/signup-flow.test.ts src/connect-flow.test.ts"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
24
|
+
"hulla-id": "^0.3.0",
|
|
25
|
+
"zod": "^3.23.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"tsx": "^4.19.0",
|
|
30
|
+
"typescript": "^5.6.0"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"mcp",
|
|
34
|
+
"hulla",
|
|
35
|
+
"identity",
|
|
36
|
+
"agent",
|
|
37
|
+
"bot"
|
|
38
|
+
],
|
|
39
|
+
"author": "numericalsAI Inc.",
|
|
40
|
+
"license": "Apache-2.0"
|
|
41
|
+
}
|