@lostgradient/backchannel-mcp 0.1.0 → 0.2.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 +2 -0
- package/dist/velveteen.d.ts +11 -1
- package/dist/velveteen.js +24 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -46,3 +46,5 @@ export const handler = createOperationHandler({
|
|
|
46
46
|
The mount serves catalog tools and injected resources, including when its host runs on Cloudflare Workers. [`@lostgradient/bureau`](../bureau/README.md#mcp-adapter-cor-839-cor-910) is the consumer in this repository.
|
|
47
47
|
|
|
48
48
|
For a Velveteen application, `mountCatalog` from `@lostgradient/backchannel-mcp/velveteen` registers the catalog, MCP endpoint and discovery routes together. Supply `basePath`, `publicOrigin`, the catalog operations and host, the application's `authenticateApi` function, and `mcp.serverInfo` with an authorization profile. `externalOAuth` from `@lostgradient/mcp/oauth` accepts an issuer, token verifier and current-principal resolver; the resolver returns the Backchannel `principal` and its `delegableScopes`. `hostedOAuth` accepts the application's session callbacks, OAuth store, default scopes and descriptions, and configures its issuer when the catalog starts. The resource URL includes the application's base path; its protected-resource metadata is served at the public root. A missing grantable scope receives an OAuth challenge, while a permanent policy denial remains a catalog fault.
|
|
49
|
+
|
|
50
|
+
By default the MCP resource is `<base><basePath>/mcp`. Set `mcp.path` (for example `mcp: { serverInfo, authorization, path: '/mcp' }`) to serve it at a root-level path instead, such as `/mcp`, while the catalog stays mounted under its own `basePath`. The value is the full public path: it is not prefixed with the application base path, and it must have at least one segment, with no trailing slash, query, fragment, backslash, or `.` or `..` segment. Otherwise `mountCatalog` throws `TypeError('Invalid MCP resource path')`. The protected-resource metadata, the challenge and the audience a grant must carry follow it, so a grant for `/mcp` is accepted at `/mcp` and one for the old `<base><basePath>/mcp` is refused. In this mode MCP is served only at `path`, and the old `<base><basePath>/mcp` form answers 404. Velveteen refuses a path that overlaps another mount, the hosted issuer's `/oauth` routes or its reserved `/_remote` and `/_assets` paths when the application starts. The REST and JSON-RPC routes stay under `basePath`.
|
package/dist/velveteen.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ type CatalogOptions<Host> = Pick<OperationHandlerOptions<Host>, 'operations' | '
|
|
|
31
31
|
}): CatalogAuthority;
|
|
32
32
|
};
|
|
33
33
|
requiredScopes?: readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* The full public path of the MCP resource, such as `/mcp`. It is used verbatim and is not
|
|
36
|
+
* prefixed with the application's base path. When set, MCP is served only at this path, the
|
|
37
|
+
* protected-resource metadata and token audience follow it, and the default
|
|
38
|
+
* `<base><basePath>/mcp` form answers 404. When absent, the resource stays at
|
|
39
|
+
* `<base><basePath>/mcp`.
|
|
40
|
+
*/
|
|
41
|
+
path?: string;
|
|
34
42
|
};
|
|
35
43
|
};
|
|
36
44
|
/** Register one catalog service and its protected discovery routes with Velveteen. */
|
|
@@ -39,7 +47,9 @@ export declare function mountCatalog<Host>(options: CatalogOptions<Host>): {
|
|
|
39
47
|
machineFormPaths(): string[];
|
|
40
48
|
rootPaths(base: string): string[];
|
|
41
49
|
start(base: string): {
|
|
42
|
-
fetch: (request: Request
|
|
50
|
+
fetch: (request: Request, arrival?: {
|
|
51
|
+
root: boolean;
|
|
52
|
+
}) => Promise<Response>;
|
|
43
53
|
close: () => void;
|
|
44
54
|
};
|
|
45
55
|
};
|
package/dist/velveteen.js
CHANGED
|
@@ -28,8 +28,19 @@ function canonicalPath(path) {
|
|
|
28
28
|
})
|
|
29
29
|
.join('/');
|
|
30
30
|
}
|
|
31
|
+
function canonicalResourcePath(path) {
|
|
32
|
+
try {
|
|
33
|
+
if (!/^\/(?:[^/?#\\]+)(?:\/[^/?#\\]+)*$/.test(path))
|
|
34
|
+
throw new TypeError();
|
|
35
|
+
return canonicalPath(path);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new TypeError('Invalid MCP resource path');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
31
41
|
/** Register one catalog service and its protected discovery routes with Velveteen. */
|
|
32
42
|
export function mountCatalog(options) {
|
|
43
|
+
const rootResourcePath = options.mcp.path === undefined ? undefined : canonicalResourcePath(options.mcp.path);
|
|
33
44
|
const suppliedProfile = options.mcp.authorization;
|
|
34
45
|
const capturedProfile = 'configure' in suppliedProfile
|
|
35
46
|
? { configure: suppliedProfile.configure.bind(suppliedProfile) }
|
|
@@ -97,8 +108,9 @@ export function mountCatalog(options) {
|
|
|
97
108
|
: [];
|
|
98
109
|
},
|
|
99
110
|
rootPaths(base) {
|
|
100
|
-
const resourcePath = `${canonicalPath(base)}${options.basePath}/mcp`;
|
|
111
|
+
const resourcePath = rootResourcePath ?? `${canonicalPath(base)}${options.basePath}/mcp`;
|
|
101
112
|
return [
|
|
113
|
+
...(rootResourcePath === undefined ? [] : [rootResourcePath]),
|
|
102
114
|
`/.well-known/oauth-protected-resource${resourcePath}`,
|
|
103
115
|
...('configure' in profile || profile.handle
|
|
104
116
|
? [
|
|
@@ -109,7 +121,7 @@ export function mountCatalog(options) {
|
|
|
109
121
|
];
|
|
110
122
|
},
|
|
111
123
|
start(base) {
|
|
112
|
-
const resourcePath = `${canonicalPath(base)}${options.basePath}/mcp`;
|
|
124
|
+
const resourcePath = rootResourcePath ?? `${canonicalPath(base)}${options.basePath}/mcp`;
|
|
113
125
|
const authorization = 'configure' in profile
|
|
114
126
|
? profile.configure({ origin: options.publicOrigin, resourcePath, scopes })
|
|
115
127
|
: profile;
|
|
@@ -215,13 +227,21 @@ export function mountCatalog(options) {
|
|
|
215
227
|
},
|
|
216
228
|
});
|
|
217
229
|
let closed = false;
|
|
218
|
-
const fetch = async (request) => {
|
|
230
|
+
const fetch = async (request, arrival) => {
|
|
219
231
|
if (closed)
|
|
220
232
|
return new Response('Catalog disposed', { status: 503 });
|
|
221
233
|
const url = new URL(request.url);
|
|
222
234
|
if (url.pathname === metadataPath)
|
|
223
235
|
return protectedHttp(request);
|
|
224
|
-
if (
|
|
236
|
+
if (rootResourcePath !== undefined) {
|
|
237
|
+
if (url.pathname === rootResourcePath && arrival?.root === true)
|
|
238
|
+
return protectedHttp(request);
|
|
239
|
+
// Under the mount only the retired `<base><basePath>/mcp` is refused; any other path,
|
|
240
|
+
// including one that equals `rootResourcePath`, is a catalog route and falls through.
|
|
241
|
+
if (url.pathname === '/mcp' && arrival?.root !== true)
|
|
242
|
+
return new Response('Not found', { status: 404 });
|
|
243
|
+
}
|
|
244
|
+
else if (url.pathname === '/mcp') {
|
|
225
245
|
url.pathname = resourcePath;
|
|
226
246
|
return protectedHttp(new Request(url, request));
|
|
227
247
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lostgradient/backchannel-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The stateless HTTP MCP mount for Backchannel operation catalogs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lostgradient/backchannel": "0.1.
|
|
29
|
-
"@lostgradient/mcp": "0.
|
|
28
|
+
"@lostgradient/backchannel": "0.1.1",
|
|
29
|
+
"@lostgradient/mcp": "0.4.0",
|
|
30
30
|
"@modelcontextprotocol/server": "^2.4.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {}
|