feat(mcp): the remote door and the sign-in behind it (P15 B1, D-83, D-86)
A second HTTP listener in the books server, on 127.0.0.1 only, off until the app's admin request (RemoteStart) names the one public address. Every connection begins with the relay's PROXY v2 header, whose address is the caller's (never an HTTP header); the door speaks stateless plain-JSON MCP for one company per path, and is its own OAuth 2.1 server: metadata at every place products look, client ID metadata documents, dynamic registration and a typed client id and secret, PKCE S256, exact redirects, single-use short codes, rotated refresh tokens (a reused one ends its family), short access tokens, the issuer pinned. /authorize never approves: it parks the request and only the owner-only admin socket turns it into a code. An approval is one principals token (so A4's list and revoke see it) plus a record naming the product, which survives the product registering again. Read and draft by default; posting raised per approval. Every table is bounded and expires; secrets are kept as SHA-256 only. A stranger's unsigned request is a 401 with the metadata pointer and is counted, never written to the books' record. The access record gains an optional 'from' (the caller's address), kept as an IP when it is one (the TIN masking would turn it to dots). The tools a model reaches for first now carry the company's name and 'call books.start first' in their own descriptions (plan 3.4), local and remote. Dependencies: none new to the tree. reqwest (client documents, as ledger-host already uses it), subtle, getrandom and hyper-util (already pulled in by ledger-store and axum) are now declared by ledger-mcp; cargo deny and the notices check pass unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
eafd269ba0
commit
e00e52f2f3
15 files changed
+5839
-41
No files matched your search
@@ -1137,7 +1137,9 @@ fn context(
|
||||
sha256: String::new(),
|
||||
};
|
||||
let (mut parts, ()) = axum::http::Request::new(()).into_parts();
|
||||
parts.extensions.insert(crate::access::Caller { token });
|
||||
parts
|
||||
.extensions
|
||||
.insert(crate::access::Caller { token, from: None });
|
||||
cx.extensions.insert(parts);
|
||||
}
|
||||
cx
|
||||
@@ -1551,6 +1553,59 @@ fn a_tool_list_is_cached_only_for_its_caller() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Plan P15 3.4 (handbook.rs INVARIANT 7): the company's name and "call
|
||||
/// books.start first" are in the first 512 characters of the server's
|
||||
/// instructions AND in the description of books.start and the tools a model
|
||||
/// reaches for first, so a product that drops or cuts the instructions
|
||||
/// still delivers them. The same list is served to local and remote callers.
|
||||
#[test]
|
||||
fn the_company_and_the_entry_point_are_in_the_first_tools_too() {
|
||||
rt().block_on(async {
|
||||
let s = session("first-tools").await;
|
||||
let books = unit_dir("first-tools");
|
||||
let server = served(store(&books));
|
||||
let info = server.get_info();
|
||||
let instructions = info.instructions.unwrap();
|
||||
let lead: String = instructions.chars().take(handbook::CONNECT_LEAD).collect();
|
||||
assert!(lead.contains("books.start"), "{lead}");
|
||||
assert!(lead.contains("the double-entry books of"), "{lead}");
|
||||
let list = server
|
||||
.list_tools(None, context(&s.peer, Some(ALL)))
|
||||
.await
|
||||
.unwrap();
|
||||
let name = {
|
||||
let settings = server.settings();
|
||||
handbook::first_tools_lead(&settings)
|
||||
};
|
||||
assert!(name.contains("books.start") && name.starts_with("For the books of "));
|
||||
// The 700-character bound of a description (plan I-12) holds for
|
||||
// the tool's own text; the lead is the most this adds to it.
|
||||
assert!(name.chars().count() <= 160, "{name}");
|
||||
for first in handbook::FIRST_TOOLS {
|
||||
let tool = list
|
||||
.tools
|
||||
.iter()
|
||||
.find(|t| t.name == *first)
|
||||
.unwrap_or_else(|| panic!("{first} is not served"));
|
||||
let description = tool.description.as_deref().unwrap_or_default();
|
||||
assert!(description.starts_with(&name), "{first}: {description}");
|
||||
}
|
||||
// The others are left as they were.
|
||||
let chart = list
|
||||
.tools
|
||||
.iter()
|
||||
.find(|t| t.name == "books.trial_balance")
|
||||
.unwrap();
|
||||
assert!(
|
||||
!chart
|
||||
.description
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.starts_with("For the books of")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Plan 4.6 (P5 step 1): the envelope is put on every result in one
|
||||
/// place; a tool that can change the books answers with the journal's
|
||||
/// `head` and at least one next step, whatever it said itself, and the
|
||||
|
||||
Reference in new issue
Block a user