archibase-mcp 0.0.0-stage → 0.1.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/README.md +67 -3
- package/dist/client.js +173 -0
- package/dist/index.js +162 -0
- package/package.json +49 -6
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# archibase-mcp
|
|
2
|
+
|
|
3
|
+
**The only structured, license-clean, machine-native floorplan corpus. Built for spatial AI, generative design, and architecture agents.** 📐🏗️
|
|
4
|
+
|
|
5
|
+
An [MCP](https://modelcontextprotocol.io) server that lets AI assistants (Claude, Cursor, and other MCP clients) search **Archibase**: real floor plans with room adjacency graphs and metric geometry. Calls are paid per use in USDC on Base through [x402](https://x402.org). There is no account, only a small wallet.
|
|
6
|
+
|
|
7
|
+
| Tool | Price | What it returns |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `search_floor_plans` | $0.02 | Up to 100 plans matching bedrooms, area (m²), built, source. Each has rooms (type, m², windows), connections (door, opening, entrance, window), bathrooms, provenance and licence |
|
|
10
|
+
| `get_floor_plan_geometry` | $0.10 | One plan's room polygons in metres, doors, windows and stair zones |
|
|
11
|
+
| `archibase_account` | free | Current prices, the wallet in use, and how much of the session budget is left |
|
|
12
|
+
|
|
13
|
+
The catalogue holds Swiss apartments (Swiss Dwellings, CC BY 4.0), South Asian homes and apartments (ResPlan, CC BY 4.0) and historic US houses (HABS, public domain). Repeated layouts are collapsed, and every result carries its source and the attribution to keep when you use it.
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
1. **Make a dedicated spending wallet.** Don't use your main wallet. Create a fresh one (for example in Coinbase Wallet or MetaMask), export its private key, and send it a few dollars of **USDC on Base**. Gas is not needed: x402 payments are signed authorisations that the facilitator submits.
|
|
18
|
+
2. **Add the server to your client.** For Claude Desktop, add this to `claude_desktop_config.json`; other clients take the same command and environment:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"archibase": {
|
|
24
|
+
"command": "npx",
|
|
25
|
+
"args": ["-y", "archibase-mcp"],
|
|
26
|
+
"env": {
|
|
27
|
+
"ARCHIBASE_PRIVATE_KEY": "0x…your spending wallet's key…",
|
|
28
|
+
"ARCHIBASE_BUDGET_USD": "2"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
For Claude Code: `claude mcp add archibase -e ARCHIBASE_PRIVATE_KEY=0x… -- npx -y archibase-mcp`
|
|
36
|
+
|
|
37
|
+
Without a wallet or key the server still runs: paid tools report what they would cost, and nothing is bought.
|
|
38
|
+
|
|
39
|
+
**No wallet?** Trials and partners can be issued an API key (write to the contact on [archibase.dev](https://archibase.dev)); use it instead. Set `ARCHIBASE_API_KEY=ak_…` in place of `ARCHIBASE_PRIVATE_KEY` (not both). The credit balance is the spending cap: calls fail with a top-up link when it runs out, and errors cost nothing.
|
|
40
|
+
|
|
41
|
+
## Spending limits
|
|
42
|
+
|
|
43
|
+
The assistant can't spend more than you allow:
|
|
44
|
+
|
|
45
|
+
| Variable | Default | Meaning |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `ARCHIBASE_API_KEY` | none | Prepaid-credits key instead of a wallet (see above) |
|
|
48
|
+
| `ARCHIBASE_BUDGET_USD` | `2` | Total spend per session with a wallet (each time the client starts the server) |
|
|
49
|
+
| `ARCHIBASE_MAX_PRICE_USD` | `0.25` | Refuse any single call priced above this |
|
|
50
|
+
| `ARCHIBASE_NETWORK` | `eip155:8453` | Base. Use `eip155:84532` with testnet USDC to try it free |
|
|
51
|
+
| `ARCHIBASE_API_URL` | Archibase mainnet | Point at another deployment |
|
|
52
|
+
| `ARCHIBASE_DEBUG` | off | `1` logs each request and status to stderr (never keys or signatures) |
|
|
53
|
+
|
|
54
|
+
The server checks the price before paying. Bad queries and unknown plans are answered free (400/404), and only USDC on the configured network can be paid.
|
|
55
|
+
|
|
56
|
+
## Development
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install && npm run build && npm test
|
|
60
|
+
# end-to-end on Base Sepolia with a funded test wallet file ({"privateKey": "0x…"}):
|
|
61
|
+
NODE_USE_ENV_PROXY=1 ARCHIBASE_NETWORK=eip155:84532 node scripts/e2e.mjs path/to/test-wallet.json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Publishing (maintainers)
|
|
65
|
+
|
|
66
|
+
1. `npm publish` (the package name is `archibase-mcp`; `package.json` carries `mcpName`).
|
|
67
|
+
2. List it in the official MCP Registry with [`mcp-publisher`](https://github.com/modelcontextprotocol/registry): `mcp-publisher login github` (as the `rekaiwena-sudo` GitHub account, which owns the `io.github.rekaiwena-sudo/*` namespace), then `mcp-publisher publish` from this folder, which reads `server.json`. Directories such as Glama, PulseMCP and mcp.so pick up registry entries.
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Archibase API client with x402 payments and hard spending limits.
|
|
3
|
+
*
|
|
4
|
+
* Every paid call is checked twice before any money moves:
|
|
5
|
+
* - per call: the price must be <= maxPriceUsd (x402 spend controls), and
|
|
6
|
+
* - per session: price + spent so far must be <= budgetUsd (a payment policy).
|
|
7
|
+
* Only USDC on the configured network can be paid, because that is the only scheme registered.
|
|
8
|
+
*/
|
|
9
|
+
import { decodePaymentResponseHeader, wrapFetchWithPaymentFromConfig } from "@x402/fetch";
|
|
10
|
+
import { ExactEvmScheme } from "@x402/evm/exact/client";
|
|
11
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
12
|
+
export const MAINNET = "eip155:8453";
|
|
13
|
+
export const TESTNET = "eip155:84532";
|
|
14
|
+
/** The Archibase wallet per network. The client refuses any challenge that pays anyone else (SEC-11). */
|
|
15
|
+
export const PINNED_PAY_TO = {
|
|
16
|
+
[MAINNET]: "0xcCEc3a1e65Cad6A6b62BC6bcE8b4284bD9D7815f",
|
|
17
|
+
[TESTNET]: "0xd69346e4f39dD3eEBc5bC9fba6E453EF83214878",
|
|
18
|
+
};
|
|
19
|
+
export const DEFAULT_API_URL = "https://api.archibase.dev";
|
|
20
|
+
const USDC_DECIMALS = 6;
|
|
21
|
+
export class ConfigError extends Error {
|
|
22
|
+
}
|
|
23
|
+
function usd(name, raw, fallback) {
|
|
24
|
+
if (raw === undefined || raw === "")
|
|
25
|
+
return fallback;
|
|
26
|
+
const n = Number(raw);
|
|
27
|
+
if (!Number.isFinite(n) || n < 0)
|
|
28
|
+
throw new ConfigError(`${name} must be a non-negative number of US dollars`);
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
export function loadConfig(env = process.env) {
|
|
32
|
+
const apiUrl = (env.ARCHIBASE_API_URL ?? DEFAULT_API_URL).replace(/\/$/, "");
|
|
33
|
+
if (!/^https:\/\//.test(apiUrl) && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(apiUrl)) {
|
|
34
|
+
throw new ConfigError("ARCHIBASE_API_URL must be https (or http://localhost for development)");
|
|
35
|
+
}
|
|
36
|
+
const network = env.ARCHIBASE_NETWORK ?? MAINNET;
|
|
37
|
+
if (network !== MAINNET && network !== TESTNET) {
|
|
38
|
+
throw new ConfigError(`ARCHIBASE_NETWORK must be ${MAINNET} (Base) or ${TESTNET} (Base Sepolia)`);
|
|
39
|
+
}
|
|
40
|
+
const key = env.ARCHIBASE_PRIVATE_KEY?.trim();
|
|
41
|
+
if (key && !/^0x[0-9a-fA-F]{64}$/.test(key))
|
|
42
|
+
throw new ConfigError("ARCHIBASE_PRIVATE_KEY must be a 0x-prefixed 32-byte hex key");
|
|
43
|
+
const apiKey = env.ARCHIBASE_API_KEY?.trim() || undefined;
|
|
44
|
+
if (apiKey && !/^ak_[A-Za-z0-9_-]{43}$/.test(apiKey))
|
|
45
|
+
throw new ConfigError("ARCHIBASE_API_KEY doesn't look like an Archibase key (ak_ followed by 43 characters)");
|
|
46
|
+
if (apiKey && key)
|
|
47
|
+
throw new ConfigError("Set ARCHIBASE_API_KEY (issued on request) or ARCHIBASE_PRIVATE_KEY (wallet), not both");
|
|
48
|
+
return {
|
|
49
|
+
apiUrl,
|
|
50
|
+
network,
|
|
51
|
+
apiKey,
|
|
52
|
+
privateKey: key ? key : undefined,
|
|
53
|
+
maxPriceUsd: usd("ARCHIBASE_MAX_PRICE_USD", env.ARCHIBASE_MAX_PRICE_USD, 0.25),
|
|
54
|
+
budgetUsd: usd("ARCHIBASE_BUDGET_USD", env.ARCHIBASE_BUDGET_USD, 2),
|
|
55
|
+
debug: env.ARCHIBASE_DEBUG === "1",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export const toAtomic = (dollars) => BigInt(Math.round(dollars * 10 ** USDC_DECIMALS));
|
|
59
|
+
export const fromAtomic = (atomic) => Number(atomic) / 10 ** USDC_DECIMALS;
|
|
60
|
+
export class ArchibaseClient {
|
|
61
|
+
cfg;
|
|
62
|
+
spent = 0n;
|
|
63
|
+
payFetch;
|
|
64
|
+
walletAddress;
|
|
65
|
+
baseFetch;
|
|
66
|
+
constructor(cfg, baseFetch = fetch) {
|
|
67
|
+
this.cfg = cfg;
|
|
68
|
+
this.baseFetch = cfg.debug ? debugFetch(baseFetch) : baseFetch;
|
|
69
|
+
baseFetch = this.baseFetch;
|
|
70
|
+
if (!cfg.privateKey)
|
|
71
|
+
return;
|
|
72
|
+
const account = privateKeyToAccount(cfg.privateKey);
|
|
73
|
+
this.walletAddress = account.address;
|
|
74
|
+
const budget = toAtomic(cfg.budgetUsd);
|
|
75
|
+
this.payFetch = wrapFetchWithPaymentFromConfig(baseFetch, {
|
|
76
|
+
schemes: [{ network: cfg.network, client: new ExactEvmScheme(account) }],
|
|
77
|
+
spendControls: { maxAmountPerPayment: `$${cfg.maxPriceUsd}` },
|
|
78
|
+
// Session budget: drop any option that would take total spend past the budget.
|
|
79
|
+
policies: [(_v, reqs) => reqs.filter((r) => this.spent + BigInt(r.amount) <= budget)],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
get spentUsd() {
|
|
83
|
+
return fromAtomic(this.spent);
|
|
84
|
+
}
|
|
85
|
+
get remainingUsd() {
|
|
86
|
+
return Math.max(0, this.cfg.budgetUsd - this.spentUsd);
|
|
87
|
+
}
|
|
88
|
+
/** Free: the discovery document (prices, schemas). */
|
|
89
|
+
async discovery() {
|
|
90
|
+
const res = await this.baseFetch(`${this.cfg.apiUrl}/.well-known/x402.json`, { signal: AbortSignal.timeout(15_000) });
|
|
91
|
+
if (!res.ok)
|
|
92
|
+
throw new Error(`discovery failed: HTTP ${res.status}`);
|
|
93
|
+
return res.json();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* GET a paid resource. Free errors (400/404) come back without paying. Without a wallet, a 402
|
|
97
|
+
* is returned as-is so the caller can explain what it would cost.
|
|
98
|
+
*/
|
|
99
|
+
async get(path) {
|
|
100
|
+
const url = `${this.cfg.apiUrl}${path}`;
|
|
101
|
+
if (this.cfg.apiKey) {
|
|
102
|
+
// Prepaid credits: the server deducts the price (and refunds on errors), so there is no 402 exchange.
|
|
103
|
+
const res = await this.baseFetch(url, { headers: { "X-API-Key": this.cfg.apiKey }, signal: AbortSignal.timeout(60_000) });
|
|
104
|
+
const left = res.headers.get("x-archibase-credits-remaining");
|
|
105
|
+
return { status: res.status, body: await res.json().catch(() => null), ...(left !== null && { creditsRemainingUsd: Number(left) }) };
|
|
106
|
+
}
|
|
107
|
+
// Ask unpaid first: validation errors and missing plans are free, and we learn the price.
|
|
108
|
+
const probe = await this.baseFetch(url, { signal: AbortSignal.timeout(30_000) });
|
|
109
|
+
if (probe.status !== 402)
|
|
110
|
+
return { status: probe.status, body: await probe.json().catch(() => null) };
|
|
111
|
+
const challenge = await probe.json().catch(() => null);
|
|
112
|
+
if (!this.payFetch)
|
|
113
|
+
return { status: 402, body: challenge };
|
|
114
|
+
// Payments are serialised: each call's budget check sees every earlier payment, so parallel
|
|
115
|
+
// calls cannot all pass the check before any of them is recorded (SEC-01).
|
|
116
|
+
return this.withPaymentLock(() => this.payForChallenge(url, challenge));
|
|
117
|
+
}
|
|
118
|
+
lock = Promise.resolve();
|
|
119
|
+
withPaymentLock(fn) {
|
|
120
|
+
const run = this.lock.then(fn, fn);
|
|
121
|
+
this.lock = run.catch(() => undefined);
|
|
122
|
+
return run;
|
|
123
|
+
}
|
|
124
|
+
async payForChallenge(url, challenge) {
|
|
125
|
+
const payFetch = this.payFetch;
|
|
126
|
+
if (!payFetch)
|
|
127
|
+
return { status: 402, body: challenge };
|
|
128
|
+
const pinned = PINNED_PAY_TO[this.cfg.network];
|
|
129
|
+
const offered = (challenge?.accepts ?? []).filter((a) => a.network === this.cfg.network);
|
|
130
|
+
if (pinned && offered.some((a) => (a.payTo ?? "").toLowerCase() !== pinned.toLowerCase())) {
|
|
131
|
+
throw new Error(`the API asks to be paid at a wallet other than Archibase's (${pinned}); nothing was paid`);
|
|
132
|
+
}
|
|
133
|
+
const price = cheapestAmount(challenge, this.cfg.network);
|
|
134
|
+
if (price === undefined) {
|
|
135
|
+
throw new Error(`the API does not accept USDC on ${this.cfg.network}; check ARCHIBASE_NETWORK and ARCHIBASE_API_URL`);
|
|
136
|
+
}
|
|
137
|
+
if (fromAtomic(price) > this.cfg.maxPriceUsd) {
|
|
138
|
+
throw new Error(`price $${fromAtomic(price)} is above ARCHIBASE_MAX_PRICE_USD ($${this.cfg.maxPriceUsd}); nothing was paid`);
|
|
139
|
+
}
|
|
140
|
+
if (this.spent + price > toAtomic(this.cfg.budgetUsd)) {
|
|
141
|
+
throw new Error(`this call costs $${fromAtomic(price)} but only $${this.remainingUsd.toFixed(2)} of the session budget ` +
|
|
142
|
+
`(ARCHIBASE_BUDGET_USD = $${this.cfg.budgetUsd}) is left; nothing was paid`);
|
|
143
|
+
}
|
|
144
|
+
const res = await payFetch(url, { signal: AbortSignal.timeout(60_000) });
|
|
145
|
+
const body = await res.json().catch(() => null);
|
|
146
|
+
const header = res.headers.get("payment-response") ?? res.headers.get("x-payment-response");
|
|
147
|
+
if (res.ok && header) {
|
|
148
|
+
const receipt = decodePaymentResponseHeader(header);
|
|
149
|
+
this.spent += price;
|
|
150
|
+
return { status: res.status, body, paid: { amountUsd: fromAtomic(price), transaction: receipt.transaction, network: receipt.network } };
|
|
151
|
+
}
|
|
152
|
+
return { status: res.status, body };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Lowest atomic amount the challenge accepts on `network`, if any. */
|
|
156
|
+
export function cheapestAmount(challenge, network) {
|
|
157
|
+
const accepts = challenge?.accepts ?? [];
|
|
158
|
+
const amounts = accepts.filter((a) => a.network === network && a.amount && /^\d+$/.test(a.amount)).map((a) => BigInt(a.amount));
|
|
159
|
+
return amounts.length ? amounts.reduce((a, b) => (b < a ? b : a)) : undefined;
|
|
160
|
+
}
|
|
161
|
+
function debugFetch(inner) {
|
|
162
|
+
return async (input, init) => {
|
|
163
|
+
const req = new Request(input, init);
|
|
164
|
+
const paying = req.headers.has("payment-signature") || req.headers.has("x-payment");
|
|
165
|
+
const res = await inner(req);
|
|
166
|
+
const path = new URL(req.url).pathname + new URL(req.url).search;
|
|
167
|
+
let detail = "";
|
|
168
|
+
if (res.status >= 400 && res.status !== 402)
|
|
169
|
+
detail = " " + (await res.clone().text().catch(() => "")).slice(0, 300);
|
|
170
|
+
console.error(`[archibase] ${req.method} ${path}${paying ? " (with payment)" : ""} -> ${res.status}${detail}`);
|
|
171
|
+
return res;
|
|
172
|
+
};
|
|
173
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Archibase MCP server (stdio). Gives an AI assistant three tools:
|
|
4
|
+
* - search_floor_plans paid search over real floor plans (room graphs, areas, provenance)
|
|
5
|
+
* - get_floor_plan_geometry paid metric geometry for one plan (room polygons, doors, windows, stairs)
|
|
6
|
+
* - archibase_account free: prices, wallet, and how much of the session budget is left
|
|
7
|
+
*
|
|
8
|
+
* Configuration (environment):
|
|
9
|
+
* ARCHIBASE_PRIVATE_KEY key of a dedicated spending wallet holding a little USDC on Base.
|
|
10
|
+
* Without it, paid tools report the price instead of paying.
|
|
11
|
+
* ARCHIBASE_BUDGET_USD max total spend per session (default 2)
|
|
12
|
+
* ARCHIBASE_MAX_PRICE_USD max price of any single call (default 0.25)
|
|
13
|
+
* ARCHIBASE_NETWORK eip155:8453 (Base, default) or eip155:84532 (Base Sepolia testnet)
|
|
14
|
+
* ARCHIBASE_API_URL API base URL
|
|
15
|
+
*/
|
|
16
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
17
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import { ArchibaseClient, loadConfig } from "./client.js";
|
|
20
|
+
const VERSION = "0.1.0";
|
|
21
|
+
const text = (value, isError = false) => ({
|
|
22
|
+
content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value) }],
|
|
23
|
+
...(isError && { isError: true }),
|
|
24
|
+
});
|
|
25
|
+
function describePaid(r, client) {
|
|
26
|
+
if (client.cfg.apiKey) {
|
|
27
|
+
const body = r.body;
|
|
28
|
+
if (r.status === 401)
|
|
29
|
+
return text("The API key was rejected. Check ARCHIBASE_API_KEY.", true);
|
|
30
|
+
if (r.status === 402 && body?.error === "insufficient_credits") {
|
|
31
|
+
return text(`Out of credits (balance $${body.balance_usd}). Nothing was charged. Ask the Archibase contact to top up the key.`, true);
|
|
32
|
+
}
|
|
33
|
+
if (r.status >= 400)
|
|
34
|
+
return text({ error: `HTTP ${r.status}`, details: r.body }, true);
|
|
35
|
+
return text({ ...r.body, credits: { remaining_usd: r.creditsRemainingUsd } });
|
|
36
|
+
}
|
|
37
|
+
if (r.status === 402 && client.walletAddress) {
|
|
38
|
+
const reason = r.body?.error ?? "unknown reason";
|
|
39
|
+
return text(`The payment was not accepted (${reason}). Nothing was charged. Check the wallet's USDC balance and network.`, true);
|
|
40
|
+
}
|
|
41
|
+
if (r.status === 402) {
|
|
42
|
+
const accepts = r.body?.accepts ?? [];
|
|
43
|
+
const price = accepts[0]?.amount ? `$${Number(accepts[0].amount) / 1e6} USDC` : "a small USDC payment";
|
|
44
|
+
return text(`This call costs ${price} on ${accepts[0]?.network ?? "Base"}, and no wallet is configured, so nothing was bought. ` +
|
|
45
|
+
"Set ARCHIBASE_PRIVATE_KEY to a dedicated spending wallet holding a little USDC on Base (see the archibase-mcp README).", true);
|
|
46
|
+
}
|
|
47
|
+
if (r.status >= 400)
|
|
48
|
+
return text({ error: `HTTP ${r.status}`, details: r.body }, true);
|
|
49
|
+
const out = { ...r.body };
|
|
50
|
+
if (r.paid) {
|
|
51
|
+
out.payment = { ...r.paid, session_spent_usd: client.spentUsd, session_remaining_usd: client.remainingUsd };
|
|
52
|
+
}
|
|
53
|
+
return text(out);
|
|
54
|
+
}
|
|
55
|
+
export function buildServer(client) {
|
|
56
|
+
const server = new McpServer({ name: "archibase", version: VERSION });
|
|
57
|
+
server.registerTool("search_floor_plans", {
|
|
58
|
+
title: "Search floor plans",
|
|
59
|
+
description: "Search the Archibase corpus of real, built residential floor plans (about 41,000 distinct layouts: Swiss apartments " +
|
|
60
|
+
"and South Asian homes and apartments, plus historic US houses). Each result has a room adjacency graph (rooms with " +
|
|
61
|
+
"type, m², window count; edges for doors, openings, entrances), bedroom and bathroom counts, provenance and licence. " +
|
|
62
|
+
"Costs $0.02 USDC per call, paid automatically from the configured wallet. Results are sorted by area, smallest first. " +
|
|
63
|
+
"Use get_floor_plan_geometry with a plan_id when you need the actual shapes.",
|
|
64
|
+
inputSchema: {
|
|
65
|
+
bedrooms: z.number().int().min(0).max(20).optional().describe("Exact number of bedrooms"),
|
|
66
|
+
m2_min: z.number().min(0).optional().describe("Minimum net interior area in m²"),
|
|
67
|
+
m2_max: z.number().min(0).optional().describe("Maximum net interior area in m²"),
|
|
68
|
+
built: z.boolean().optional().describe("true = only plans of buildings that were actually built"),
|
|
69
|
+
source: z.enum(["dataset", "habs", "commissioned", "synthetic", "ai_generated"]).optional().describe("Provenance filter; habs = historic US surveys"),
|
|
70
|
+
building_type: z
|
|
71
|
+
.enum(["residential", "office", "retail", "transport", "government", "sports", "hospitality", "healthcare", "cultural", "education", "industrial", "mixed", "other"])
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("What the building is used for. Non-residential plans are one floor each"),
|
|
74
|
+
include_duplicates: z.boolean().optional().describe("Return every copy of repeated layouts (default: one per layout)"),
|
|
75
|
+
units: z.enum(["metric", "imperial"]).optional().describe("imperial returns sqft instead of m²"),
|
|
76
|
+
limit: z.number().int().min(1).max(100).optional().describe("Max results (default 25)"),
|
|
77
|
+
},
|
|
78
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
79
|
+
}, async (args) => {
|
|
80
|
+
const q = new URLSearchParams();
|
|
81
|
+
for (const [k, v] of Object.entries(args))
|
|
82
|
+
if (v !== undefined)
|
|
83
|
+
q.set(k, String(v));
|
|
84
|
+
try {
|
|
85
|
+
return describePaid(await client.get(`/api/v1/plans/search?${q}`), client);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return text(err instanceof Error ? err.message : String(err), true);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
server.registerTool("get_floor_plan_geometry", {
|
|
92
|
+
title: "Get floor plan geometry",
|
|
93
|
+
description: "Buy one plan's vector geometry: room polygons in metres (ids match the search result's graph), doors, windows and " +
|
|
94
|
+
"stair zones. Costs $0.10 USDC. Only plans whose search result has a non-null vector_schema_url have geometry; " +
|
|
95
|
+
"an unknown plan returns a free 404.",
|
|
96
|
+
inputSchema: {
|
|
97
|
+
plan_id: z.string().regex(/^[a-z0-9][a-z0-9-]{2,79}$/).describe("plan_id from search_floor_plans"),
|
|
98
|
+
units: z.enum(["metric", "imperial"]).optional().describe("imperial returns feet"),
|
|
99
|
+
},
|
|
100
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
101
|
+
}, async ({ plan_id, units }) => {
|
|
102
|
+
try {
|
|
103
|
+
const q = units === "imperial" ? "?units=imperial" : "";
|
|
104
|
+
return describePaid(await client.get(`/api/v1/plans/${plan_id}/vector${q}`), client);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
return text(err instanceof Error ? err.message : String(err), true);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
server.registerTool("archibase_account", {
|
|
111
|
+
title: "Archibase prices and budget",
|
|
112
|
+
description: "Free. Current prices, the network and wallet in use, and how much of this session's spending budget is left.",
|
|
113
|
+
inputSchema: {},
|
|
114
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
115
|
+
}, async () => {
|
|
116
|
+
let prices = "unavailable";
|
|
117
|
+
try {
|
|
118
|
+
const d = (await client.discovery());
|
|
119
|
+
prices = (d.resources ?? []).map((r) => ({ resource: r.resource, price: r.price }));
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
prices = `could not fetch prices: ${err instanceof Error ? err.message : String(err)}`;
|
|
123
|
+
}
|
|
124
|
+
if (client.cfg.apiKey) {
|
|
125
|
+
// Prepaid credits: the balance, not a session budget, is the spending cap.
|
|
126
|
+
let balance = "unavailable";
|
|
127
|
+
try {
|
|
128
|
+
const res = await fetch(`${client.cfg.apiUrl}/api/v1/account`, { headers: { "X-API-Key": client.cfg.apiKey }, signal: AbortSignal.timeout(15_000) });
|
|
129
|
+
const body = (await res.json());
|
|
130
|
+
balance = res.ok ? body.balance_usd : `error: ${body.error ?? res.status}`;
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
balance = `could not fetch balance: ${err instanceof Error ? err.message : String(err)}`;
|
|
134
|
+
}
|
|
135
|
+
return text({ api: client.cfg.apiUrl, mode: "prepaid credits (API key)", credits_balance_usd: balance, prices });
|
|
136
|
+
}
|
|
137
|
+
return text({
|
|
138
|
+
api: client.cfg.apiUrl,
|
|
139
|
+
network: client.cfg.network,
|
|
140
|
+
mode: client.walletAddress ? "wallet (x402)" : "no payment method (paid tools only report prices)",
|
|
141
|
+
wallet: client.walletAddress ?? "not configured (paid tools will only report prices)",
|
|
142
|
+
max_price_per_call_usd: client.cfg.maxPriceUsd,
|
|
143
|
+
session_budget_usd: client.cfg.budgetUsd,
|
|
144
|
+
session_spent_usd: client.spentUsd,
|
|
145
|
+
session_remaining_usd: client.remainingUsd,
|
|
146
|
+
prices,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
return server;
|
|
150
|
+
}
|
|
151
|
+
async function main() {
|
|
152
|
+
const client = new ArchibaseClient(loadConfig());
|
|
153
|
+
await buildServer(client).connect(new StdioServerTransport());
|
|
154
|
+
// stdout carries the protocol; log to stderr only.
|
|
155
|
+
console.error(`archibase-mcp ${VERSION} on ${client.cfg.network}, wallet ${client.walletAddress ?? "none"}, budget $${client.cfg.budgetUsd}`);
|
|
156
|
+
}
|
|
157
|
+
if (process.argv[1] && /archibase-mcp|index\.(js|ts)$/.test(process.argv[1])) {
|
|
158
|
+
main().catch((err) => {
|
|
159
|
+
console.error(err instanceof Error ? err.message : err);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
});
|
|
162
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "archibase-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "archibase-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for Archibase: the structured, license-clean, machine-native floorplan corpus for spatial AI, generative design and architecture agents. Pay per call in USDC on Base via x402",
|
|
5
|
+
"mcpName": "io.github.rekaiwena-sudo/archibase",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"archibase-mcp": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"start": "node dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"mcp",
|
|
24
|
+
"x402",
|
|
25
|
+
"floor-plans",
|
|
26
|
+
"architecture",
|
|
27
|
+
"base",
|
|
28
|
+
"usdc"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/rekaiwena-sudo/archibase.git",
|
|
34
|
+
"directory": "mcp"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
38
|
+
"@x402/core": "~2.30.0",
|
|
39
|
+
"@x402/evm": "~2.30.0",
|
|
40
|
+
"@x402/fetch": "~2.30.0",
|
|
41
|
+
"viem": "^2.57.19",
|
|
42
|
+
"zod": "^4.6.7"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.20.5",
|
|
46
|
+
"typescript": "^7.0.2",
|
|
47
|
+
"vitest": "^5.1.0"
|
|
48
|
+
}
|
|
49
|
+
}
|