@osd-project/osd-cli 0.0.0 → 0.8.3

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.
Files changed (52) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +585 -4
  3. package/THIRD_PARTY_NOTICES.md +96 -0
  4. package/dist/auth-store.d.ts +38 -0
  5. package/dist/auth-store.js +239 -0
  6. package/dist/brand-catalog.d.ts +65 -0
  7. package/dist/brand-catalog.js +175 -0
  8. package/dist/connect-gate.d.ts +31 -0
  9. package/dist/connect-gate.js +82 -0
  10. package/dist/contracts.d.ts +61 -0
  11. package/dist/contracts.js +145 -0
  12. package/dist/exit-codes.d.ts +32 -0
  13. package/dist/exit-codes.js +40 -0
  14. package/dist/format.d.ts +71 -0
  15. package/dist/format.js +99 -0
  16. package/dist/generated/schemas.d.ts +2 -0
  17. package/dist/generated/schemas.js +1781 -0
  18. package/dist/guarded-fetch.d.ts +28 -0
  19. package/dist/guarded-fetch.js +252 -0
  20. package/dist/help.d.ts +27 -0
  21. package/dist/help.js +32 -0
  22. package/dist/http-fetch.d.ts +1 -0
  23. package/dist/http-fetch.js +17 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +821 -0
  26. package/dist/logout.d.ts +16 -0
  27. package/dist/logout.js +82 -0
  28. package/dist/mcp-auth.d.ts +70 -0
  29. package/dist/mcp-auth.js +603 -0
  30. package/dist/mcp-card.d.ts +23 -0
  31. package/dist/mcp-card.js +18 -0
  32. package/dist/mcp-client.d.ts +77 -0
  33. package/dist/mcp-client.js +193 -0
  34. package/dist/net-guard.d.ts +66 -0
  35. package/dist/net-guard.js +152 -0
  36. package/dist/proxy-config.d.ts +51 -0
  37. package/dist/proxy-config.js +147 -0
  38. package/dist/request.d.ts +32 -0
  39. package/dist/request.js +62 -0
  40. package/dist/resolve-endpoint.d.ts +62 -0
  41. package/dist/resolve-endpoint.js +172 -0
  42. package/dist/search.d.ts +39 -0
  43. package/dist/search.js +69 -0
  44. package/dist/skill.d.ts +155 -0
  45. package/dist/skill.js +320 -0
  46. package/dist/updates.d.ts +101 -0
  47. package/dist/updates.js +541 -0
  48. package/dist/verify.d.ts +92 -0
  49. package/dist/verify.js +379 -0
  50. package/package.json +51 -3
  51. package/skill/osd/SKILL.md +400 -0
  52. package/skill/osd/references/connect-mcp.md +48 -0
@@ -0,0 +1,16 @@
1
+ import { AuthStore } from "./auth-store.js";
2
+ import type { ResolveOutcome } from "./resolve-endpoint.js";
3
+ interface LogoutOptions {
4
+ store?: AuthStore;
5
+ fetchFn?: typeof fetch;
6
+ warn?: (message: string) => void;
7
+ }
8
+ export declare function resolveLogoutTarget(target: string, resolved: ResolveOutcome): {
9
+ error: string;
10
+ } | {
11
+ endpoint: string;
12
+ warning?: string;
13
+ };
14
+ /** Local deletion never depends on the server. */
15
+ export declare function logout(endpoint?: string, options?: LogoutOptions): Promise<void>;
16
+ export {};
package/dist/logout.js ADDED
@@ -0,0 +1,82 @@
1
+ import { discoverOAuthServerInfo } from "@modelcontextprotocol/client";
2
+ import { AuthStore } from "./auth-store.js";
3
+ import { createGuardedFetch } from "./guarded-fetch.js";
4
+ export function resolveLogoutTarget(target, resolved) {
5
+ if (resolved.kind === "invalid")
6
+ return { error: resolved.message };
7
+ if (resolved.kind === "unreachable")
8
+ return { endpoint: target, warning: resolved.message };
9
+ return resolved.warning
10
+ ? { endpoint: resolved.url, warning: resolved.warning }
11
+ : { endpoint: resolved.url };
12
+ }
13
+ /** Local deletion never depends on the server. */
14
+ export async function logout(endpoint, options = {}) {
15
+ const store = options.store ?? new AuthStore();
16
+ const warn = options.warn ?? console.error;
17
+ if (endpoint === undefined) {
18
+ const removed = await store.deleteAll();
19
+ warn(removed ? "Removed cached OAuth credentials." : "No cached OAuth credentials.");
20
+ return;
21
+ }
22
+ const skipped = "Token revocation skipped or incomplete; local credentials removed.";
23
+ let record;
24
+ try {
25
+ record = await store.read(endpoint, { migrate: false });
26
+ }
27
+ catch {
28
+ // An unreadable vault must not prevent the local deletion attempt.
29
+ }
30
+ const removed = await store.delete(endpoint);
31
+ warn(removed ? "Removed cached OAuth credentials." : "No cached OAuth credentials.");
32
+ if (!removed)
33
+ return;
34
+ if (!record) {
35
+ warn(skipped);
36
+ return;
37
+ }
38
+ if (!record.tokens)
39
+ return;
40
+ const guarded = options.fetchFn ? undefined : createGuardedFetch();
41
+ const fetchFn = (input, init) => (options.fetchFn ?? guarded.fetchFn)(input, {
42
+ ...init, signal: AbortSignal.timeout(10_000),
43
+ });
44
+ try {
45
+ const { authorizationServerMetadata } = await discoverOAuthServerInfo(endpoint, { fetchFn });
46
+ const revocationEndpoint = authorizationServerMetadata && "revocation_endpoint" in authorizationServerMetadata
47
+ ? authorizationServerMetadata.revocation_endpoint
48
+ : undefined;
49
+ if (typeof revocationEndpoint !== "string" || !revocationEndpoint) {
50
+ warn(skipped);
51
+ return;
52
+ }
53
+ let failed = false;
54
+ for (const hint of ["refresh_token", "access_token"]) {
55
+ const token = record.tokens[hint];
56
+ if (!token)
57
+ continue;
58
+ const body = new URLSearchParams({ token, token_type_hint: hint });
59
+ if (record.clientInformation)
60
+ body.set("client_id", record.clientInformation.client_id);
61
+ try {
62
+ const response = await fetchFn(revocationEndpoint, {
63
+ method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body,
64
+ });
65
+ if (!response.ok)
66
+ failed = true;
67
+ await response.body?.cancel();
68
+ }
69
+ catch {
70
+ failed = true;
71
+ }
72
+ }
73
+ if (failed)
74
+ warn(skipped);
75
+ }
76
+ catch {
77
+ warn(skipped);
78
+ }
79
+ finally {
80
+ await guarded?.close().catch(() => undefined);
81
+ }
82
+ }
@@ -0,0 +1,70 @@
1
+ import type { OAuthClientProvider, OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/client";
2
+ import { AuthStore } from "./auth-store.js";
3
+ /**
4
+ * Whether a server-supplied authorization URL may be opened in the browser:
5
+ * https, or http on loopback (OAuth 2.1 §1.5). The SDK only rejects
6
+ * javascript:/data:/vbscript:, so without this a malicious server could make
7
+ * the CLI hand `file://...` or a custom app scheme to the OS URL handler.
8
+ */
9
+ export declare function isSafeAuthorizationUrl(url: URL): boolean;
10
+ /**
11
+ * Launches the system browser via the `open` package, which owns the
12
+ * per-platform mess: on Windows it uses PowerShell Start-Process with
13
+ * proper escaping (cmd /c start would re-parse & in the URL's query string
14
+ * as a command separator -- and the URL is server-controlled), on Linux it
15
+ * handles xdg-open detection and WSL. Resolves false when the launch
16
+ * fails; the caller prints the URL as a fallback either way.
17
+ */
18
+ export declare function openInBrowser(url: URL): Promise<boolean>;
19
+ export declare class CliOAuthProvider implements OAuthClientProvider {
20
+ private readonly endpoint;
21
+ private readonly onAuthorizationUrl;
22
+ private readonly store;
23
+ private record;
24
+ private verifier;
25
+ private readonly stateValue;
26
+ private redirect;
27
+ /** Set only during device polling; the SDK handles token parsing and client authentication. */
28
+ prepareTokenRequest?: OAuthClientProvider["prepareTokenRequest"];
29
+ private constructor();
30
+ /**
31
+ * Provider pre-loaded with whatever is cached for this endpoint.
32
+ * Attach it even for anonymous use: the transport only sends tokens when
33
+ * the cache holds some, and the SDK needs a provider present to attempt
34
+ * refreshes.
35
+ */
36
+ static fromStore(endpoint: string, onAuthorizationUrl: (url: URL) => void, store?: AuthStore): Promise<CliOAuthProvider>;
37
+ /** The loopback server may land on an ephemeral port; keep the redirect in sync. */
38
+ setRedirectUrl(redirect: string): void;
39
+ get redirectUrl(): string;
40
+ get clientMetadata(): OAuthClientMetadata;
41
+ state(): string;
42
+ clientInformation(): OAuthClientInformationMixed | undefined;
43
+ saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
44
+ /** Stage a device client in memory; saveTokens commits the new pair after approval. */
45
+ stageClientInformation(info: OAuthClientInformationMixed): () => void;
46
+ tokens(): OAuthTokens | undefined;
47
+ saveTokens(tokens: OAuthTokens): Promise<void>;
48
+ redirectToAuthorization(authorizationUrl: URL): void;
49
+ saveCodeVerifier(codeVerifier: string): void;
50
+ codeVerifier(): string;
51
+ invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
52
+ }
53
+ export interface AuthorizationHooks {
54
+ /** Progress for the human; goes to stderr so --json output stays clean. */
55
+ info(message: string): void;
56
+ }
57
+ export type AuthorizationOutcome = {
58
+ kind: "authorized";
59
+ } | {
60
+ kind: "failed";
61
+ message: string;
62
+ };
63
+ export interface AuthorizationDeps {
64
+ /** TEST SEAM ONLY: lets loopback mock authorization servers through the SSRF guard. Never set in production paths. */
65
+ allowLoopback?: boolean;
66
+ }
67
+ /** RFC 8628 sign-in for a public client, without a browser callback or loopback listener. */
68
+ export declare function authorizeDeviceMcpEndpoint(endpoint: string, provider: CliOAuthProvider, hooks: AuthorizationHooks, deps?: AuthorizationDeps): Promise<AuthorizationOutcome>;
69
+ /** Prefer the advertised device flow; retain browser authorization for other servers. */
70
+ export declare function authorizeMcpEndpoint(endpoint: string, provider: CliOAuthProvider, hooks: AuthorizationHooks, deps?: AuthorizationDeps): Promise<AuthorizationOutcome>;