@earendil-works/pi-mcp 0.99.2 → 1.0.1

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.
@@ -18,13 +18,17 @@ function requiredString(value, name) {
18
18
  throw new Error(`Invalid ${name}`);
19
19
  return value;
20
20
  }
21
+ /** Treats `null` and `""` as absent: servers send them for fields they have no value for, like `scope: ""`. */
22
+ function absent(value) {
23
+ return value === undefined || value === null || value === "";
24
+ }
21
25
  function optionalString(value, name) {
22
- if (value === undefined)
26
+ if (absent(value))
23
27
  return undefined;
24
28
  return requiredString(value, name);
25
29
  }
26
30
  function optionalStrings(value, name) {
27
- if (value === undefined)
31
+ if (value === undefined || value === null)
28
32
  return undefined;
29
33
  if (!Array.isArray(value) || value.some((item) => typeof item !== "string"))
30
34
  throw new Error(`Invalid ${name}`);
@@ -32,13 +36,16 @@ function optionalStrings(value, name) {
32
36
  }
33
37
  function safeUrl(value, name) {
34
38
  const text = requiredString(value, name);
39
+ // URL parsing throws a `TypeError`, which discovery reserves for network failures.
40
+ if (!URL.canParse(text))
41
+ throw new Error(`Invalid ${name}`);
35
42
  const url = new URL(text);
36
43
  if (["javascript:", "data:", "vbscript:"].includes(url.protocol))
37
44
  throw new Error(`Invalid ${name}`);
38
45
  return text;
39
46
  }
40
47
  function optionalUrl(value, name) {
41
- return value === undefined ? undefined : safeUrl(value, name);
48
+ return absent(value) ? undefined : safeUrl(value, name);
42
49
  }
43
50
  export function parseProtectedResourceMetadata(value) {
44
51
  const input = object(value, "OAuth protected resource metadata");
@@ -68,11 +75,15 @@ export function parseAuthorizationServerMetadata(value) {
68
75
  client_id_metadata_document_supported: typeof input.client_id_metadata_document_supported === "boolean"
69
76
  ? input.client_id_metadata_document_supported
70
77
  : undefined,
78
+ authorization_response_iss_parameter_supported: typeof input.authorization_response_iss_parameter_supported === "boolean"
79
+ ? input.authorization_response_iss_parameter_supported
80
+ : undefined,
71
81
  });
72
82
  }
73
83
  export function parseOAuthTokens(value) {
74
84
  const input = object(value, "OAuth token response");
75
- const expires = input.expires_in === undefined ? undefined : Number(input.expires_in);
85
+ // `Number(null)` is 0, which would mark the token as expired at once.
86
+ const expires = absent(input.expires_in) ? undefined : Number(input.expires_in);
76
87
  if (expires !== undefined && !Number.isFinite(expires))
77
88
  throw new Error("Invalid expires_in");
78
89
  return compact({
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAiFlD,SAAS,MAAM,CAAC,KAAc,EAAE,IAAY;IAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,gGAAgG;AAChG,SAAS,OAAO,CAAmB,KAAQ;IAC1C,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAM,CAAC;AAChG,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,IAAY;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IACxF,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,IAAY;IACnD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,IAAY;IACpD,IAAI,KAAK,KAAK,SAAS;Q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Aa,EAAE,eAAe,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC,IAAI,EAAE;KAC1E,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Adapted from modelcontextprotocol/typescript-sdk v1.29.0.\n * Copyright (c) 2024 Anthropic, PBC. Licensed under MIT; see LICENSES/.\n * Modified to use dependency-free structural validation.\n */\n\nimport { isObject } from \"../protocol/jsonrpc.ts\";\n\nexport interface OAuthProtectedResourceMetadata {\n\tresource: string;\n\tauthorization_servers?: string[];\n\tscopes_supported?: string[];\n\t[key: string]: unknown;\n}\n\nexport interface AuthorizationServerMetadata {\n\tissuer: string;\n\tauthorization_endpoint: string;\n\ttoken_endpoint: string;\n\tregistration_endpoint?: string;\n\tscopes_supported?: string[];\n\tresponse_types_supported: string[];\n\tgrant_types_supported?: string[];\n\ttoken_endpoint_auth_methods_supported?: string[];\n\tcode_challenge_methods_supported?: string[];\n\tclient_id_metadata_document_supported?: boolean;\n\t[key: string]: unknown;\n}\n\nexport interface OAuthTokens {\n\taccess_token: string;\n\ttoken_type: string;\n\texpires_in?: number;\n\tscope?: string;\n\trefresh_token?: string;\n\tid_token?: string;\n}\n\nexport interface OAuthClientMetadata {\n\tredirect_uris: string[];\n\ttoken_endpoint_auth_method?: string;\n\tgrant_types?: string[];\n\tresponse_types?: string[];\n\tclient_name?: string;\n\tclient_uri?: string;\n\tlogo_uri?: string;\n\tscope?: string;\n\tcontacts?: string[];\n\ttos_uri?: string;\n\tpolicy_uri?: string;\n\tjwks_uri?: string;\n\tjwks?: unknown;\n\tsoftware_id?: string;\n\tsoftware_version?: string;\n\tsoftware_statement?: string;\n}\n\nexport interface OAuthClientInformation {\n\tclient_id: string;\n\tclient_secret?: string;\n\tclient_id_issued_at?: number;\n\tclient_secret_expires_at?: number;\n}\n\nexport type OAuthClientInformationFull = OAuthClientInformation & OAuthClientMetadata;\nexport type OAuthClientInformationMixed = OAuthClientInformation | OAuthClientInformationFull;\n\nexport interface OAuthDiscoveryState {\n\tauthorizationServerUrl: string;\n\tauthorizationServerMetadata?: AuthorizationServerMetadata;\n\tresourceMetadata?: OAuthProtectedResourceMetadata;\n\tresourceMetadataUrl?: string;\n}\n\nexport interface OAuthServerInfo {\n\tauthorizationServerUrl: string;\n\tauthorizationServerMetadata?: AuthorizationServerMetadata;\n\tresourceMetadata?: OAuthProtectedResourceMetadata;\n}\n\nexport interface OAuthChallenge {\n\tresourceMetadataUrl?: URL;\n\tscope?: string;\n\terror?: string;\n\terrorDescription?: string;\n}\n\nfunction object(value: unknown, name: string): Record<string, unknown> {\n\tif (!isObject(value)) throw new Error(`Invalid ${name}`);\n\treturn value;\n}\n\n/** Drops `undefined` values so optional fields are absent rather than present-but-undefined. */\nfunction compact<T extends object>(value: T): T {\n\treturn Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined)) as T;\n}\n\nfunction requiredString(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.length === 0) throw new Error(`Invalid ${name}`);\n\treturn value;\n}\n\nfunction optionalString(value: unknown, name: string): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requiredString(value, name);\n}\n\nfunction optionalStrings(value: unknown, name: string): string[] | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Array.isArray(value) || value.some((item) => typeof item !== \"string\")) throw new Error(`Invalid ${name}`);\n\treturn [...value];\n}\n\nfunction safeUrl(value: unknown, name: string): string {\n\tconst text = requiredString(value, name);\n\tconst url = new URL(text);\n\tif ([\"javascript:\", \"data:\", \"vbscript:\"].includes(url.protocol)) throw new Error(`Invalid ${name}`);\n\treturn text;\n}\n\nfunction optionalUrl(value: unknown, name: string): string | undefined {\n\treturn value === undefined ? undefined : safeUrl(value, name);\n}\n\nexport function parseProtectedResourceMetadata(value: unknown): OAuthProtectedResourceMetadata {\n\tconst input = object(value, \"OAuth protected resource metadata\");\n\treturn compact({\n\t\t...input,\n\t\tresource: safeUrl(input.resource, \"OAuth protected resource metadata resource\"),\n\t\tauthorization_servers: optionalStrings(input.authorization_servers, \"authorization_servers\")?.map((url) =>\n\t\t\tsafeUrl(url, \"authorization server URL\"),\n\t\t),\n\t\tscopes_supported: optionalStrings(input.scopes_supported, \"scopes_supported\"),\n\t});\n}\n\nexport function parseAuthorizationServerMetadata(value: unknown): AuthorizationServerMetadata {\n\tconst input = object(value, \"authorization server metadata\");\n\tconst responseTypes = optionalStrings(input.response_types_supported, \"response_types_supported\");\n\tif (!responseTypes) throw new Error(\"Invalid response_types_supported\");\n\treturn compact({\n\t\t...input,\n\t\tissuer: safeUrl(input.issuer, \"authorization server issuer\"),\n\t\tauthorization_endpoint: safeUrl(input.authorization_endpoint, \"authorization endpoint\"),\n\t\ttoken_endpoint: safeUrl(input.token_endpoint, \"token endpoint\"),\n\t\tregistration_endpoint: optionalUrl(input.registration_endpoint, \"registration endpoint\"),\n\t\tscopes_supported: optionalStrings(input.scopes_supported, \"scopes_supported\"),\n\t\tresponse_types_supported: responseTypes,\n\t\tgrant_types_supported: optionalStrings(input.grant_types_supported, \"grant_types_supported\"),\n\t\ttoken_endpoint_auth_methods_supported: optionalStrings(\n\t\t\tinput.token_endpoint_auth_methods_supported,\n\t\t\t\"token_endpoint_auth_methods_supported\",\n\t\t),\n\t\tcode_challenge_methods_supported: optionalStrings(\n\t\t\tinput.code_challenge_methods_supported,\n\t\t\t\"code_challenge_methods_supported\",\n\t\t),\n\t\tclient_id_metadata_document_supported:\n\t\t\ttypeof input.client_id_metadata_document_supported === \"boolean\"\n\t\t\t\t? input.client_id_metadata_document_supported\n\t\t\t\t: undefined,\n\t});\n}\n\nexport function parseOAuthTokens(value: unknown): OAuthTokens {\n\tconst input = object(value, \"OAuth token response\");\n\tconst expires = input.expires_in === undefined ? undefined : Number(input.expires_in);\n\tif (expires !== undefined && !Number.isFinite(expires)) throw new Error(\"Invalid expires_in\");\n\treturn compact({\n\t\taccess_token: requiredString(input.access_token, \"access_token\"),\n\t\ttoken_type: requiredString(input.token_type, \"token_type\"),\n\t\texpires_in: expires,\n\t\tscope: optionalString(input.scope, \"scope\"),\n\t\trefresh_token: optionalString(input.refresh_token, \"refresh_token\"),\n\t\tid_token: optionalString(input.id_token, \"id_token\"),\n\t});\n}\n\nexport function parseClientInformation(value: unknown): OAuthClientInformationFull {\n\tconst input = object(value, \"OAuth client registration response\");\n\treturn compact({\n\t\t...(input as unknown as OAuthClientMetadata),\n\t\tclient_id: requiredString(input.client_id, \"client_id\"),\n\t\tclient_secret: optionalString(input.client_secret, \"client_secret\"),\n\t\tclient_id_issued_at: typeof input.client_id_issued_at === \"number\" ? input.client_id_issued_at : undefined,\n\t\tclient_secret_expires_at:\n\t\t\ttypeof input.client_secret_expires_at === \"number\" ? input.client_secret_expires_at : undefined,\n\t\tredirect_uris: optionalStrings(input.redirect_uris, \"redirect_uris\") ?? [],\n\t});\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAmFlD,SAAS,MAAM,CAAC,KAAc,EAAE,IAAY;IAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,gGAAgG;AAChG,SAAS,OAAO,CAAmB,KAAQ;IAC1C,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAM,CAAC;AAChG,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,IAAY;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CA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K,EAAE,OAAO,CAAC;QAC3C,aAAa,EAAE,cAAc,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC;QACnE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC;KACpD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,oCAAoC,CAAC,CAAC;IAClE,OAAO,OAAO,CAAC;QACd,GAAI,KAAwC;QAC5C,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC;QACvD,aAAa,EAAE,cAAc,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC;QACnE,mBAAmB,EAAE,OAAO,KAAK,CAAC,mBAAmB,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS;QAC1G,wBAAwB,EACvB,OAAO,KAAK,CAAC,wBAAwB,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,SAAS;QAChG,aAAa,EAAE,eAAe,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC,IAAI,EAAE;KAC1E,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Adapted from modelcontextprotocol/typescript-sdk v1.29.0.\n * Copyright (c) 2024 Anthropic, PBC. Licensed under MIT; see LICENSES/.\n * Modified to use dependency-free structural validation.\n */\n\nimport { isObject } from \"../protocol/jsonrpc.ts\";\n\nexport interface OAuthProtectedResourceMetadata {\n\tresource: string;\n\tauthorization_servers?: string[];\n\tscopes_supported?: string[];\n\t[key: string]: unknown;\n}\n\nexport interface AuthorizationServerMetadata {\n\tissuer: string;\n\tauthorization_endpoint: string;\n\ttoken_endpoint: string;\n\tregistration_endpoint?: string;\n\tscopes_supported?: string[];\n\tresponse_types_supported: string[];\n\tgrant_types_supported?: string[];\n\ttoken_endpoint_auth_methods_supported?: string[];\n\tcode_challenge_methods_supported?: string[];\n\tclient_id_metadata_document_supported?: boolean;\n\t/** Whether authorization responses carry an `iss` parameter (RFC 9207). */\n\tauthorization_response_iss_parameter_supported?: boolean;\n\t[key: string]: unknown;\n}\n\nexport interface OAuthTokens {\n\taccess_token: string;\n\ttoken_type: string;\n\texpires_in?: number;\n\tscope?: string;\n\trefresh_token?: string;\n\tid_token?: string;\n}\n\nexport interface OAuthClientMetadata {\n\tredirect_uris: string[];\n\ttoken_endpoint_auth_method?: string;\n\tgrant_types?: string[];\n\tresponse_types?: string[];\n\tclient_name?: string;\n\tclient_uri?: string;\n\tlogo_uri?: string;\n\tscope?: string;\n\tcontacts?: string[];\n\ttos_uri?: string;\n\tpolicy_uri?: string;\n\tjwks_uri?: string;\n\tjwks?: unknown;\n\tsoftware_id?: string;\n\tsoftware_version?: string;\n\tsoftware_statement?: string;\n}\n\nexport interface OAuthClientInformation {\n\tclient_id: string;\n\tclient_secret?: string;\n\tclient_id_issued_at?: number;\n\tclient_secret_expires_at?: number;\n}\n\nexport type OAuthClientInformationFull = OAuthClientInformation & OAuthClientMetadata;\nexport type OAuthClientInformationMixed = OAuthClientInformation | OAuthClientInformationFull;\n\nexport interface OAuthDiscoveryState {\n\tauthorizationServerUrl: string;\n\tauthorizationServerMetadata?: AuthorizationServerMetadata;\n\tresourceMetadata?: OAuthProtectedResourceMetadata;\n\tresourceMetadataUrl?: string;\n}\n\nexport interface OAuthServerInfo {\n\tauthorizationServerUrl: string;\n\tauthorizationServerMetadata?: AuthorizationServerMetadata;\n\tresourceMetadata?: OAuthProtectedResourceMetadata;\n}\n\nexport interface OAuthChallenge {\n\tresourceMetadataUrl?: URL;\n\tscope?: string;\n\terror?: string;\n\terrorDescription?: string;\n}\n\nfunction object(value: unknown, name: string): Record<string, unknown> {\n\tif (!isObject(value)) throw new Error(`Invalid ${name}`);\n\treturn value;\n}\n\n/** Drops `undefined` values so optional fields are absent rather than present-but-undefined. */\nfunction compact<T extends object>(value: T): T {\n\treturn Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined)) as T;\n}\n\nfunction requiredString(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.length === 0) throw new Error(`Invalid ${name}`);\n\treturn value;\n}\n\n/** Treats `null` and `\"\"` as absent: servers send them for fields they have no value for, like `scope: \"\"`. */\nfunction absent(value: unknown): value is undefined | null | \"\" {\n\treturn value === undefined || value === null || value === \"\";\n}\n\nfunction optionalString(value: unknown, name: string): string | undefined {\n\tif (absent(value)) return undefined;\n\treturn requiredString(value, name);\n}\n\nfunction optionalStrings(value: unknown, name: string): string[] | undefined {\n\tif (value === undefined || value === null) return undefined;\n\tif (!Array.isArray(value) || value.some((item) => typeof item !== \"string\")) throw new Error(`Invalid ${name}`);\n\treturn [...value];\n}\n\nfunction safeUrl(value: unknown, name: string): string {\n\tconst text = requiredString(value, name);\n\t// URL parsing throws a `TypeError`, which discovery reserves for network failures.\n\tif (!URL.canParse(text)) throw new Error(`Invalid ${name}`);\n\tconst url = new URL(text);\n\tif ([\"javascript:\", \"data:\", \"vbscript:\"].includes(url.protocol)) throw new Error(`Invalid ${name}`);\n\treturn text;\n}\n\nfunction optionalUrl(value: unknown, name: string): string | undefined {\n\treturn absent(value) ? undefined : safeUrl(value, name);\n}\n\nexport function parseProtectedResourceMetadata(value: unknown): OAuthProtectedResourceMetadata {\n\tconst input = object(value, \"OAuth protected resource metadata\");\n\treturn compact({\n\t\t...input,\n\t\tresource: safeUrl(input.resource, \"OAuth protected resource metadata resource\"),\n\t\tauthorization_servers: optionalStrings(input.authorization_servers, \"authorization_servers\")?.map((url) =>\n\t\t\tsafeUrl(url, \"authorization server URL\"),\n\t\t),\n\t\tscopes_supported: optionalStrings(input.scopes_supported, \"scopes_supported\"),\n\t});\n}\n\nexport function parseAuthorizationServerMetadata(value: unknown): AuthorizationServerMetadata {\n\tconst input = object(value, \"authorization server metadata\");\n\tconst responseTypes = optionalStrings(input.response_types_supported, \"response_types_supported\");\n\tif (!responseTypes) throw new Error(\"Invalid response_types_supported\");\n\treturn compact({\n\t\t...input,\n\t\tissuer: safeUrl(input.issuer, \"authorization server issuer\"),\n\t\tauthorization_endpoint: safeUrl(input.authorization_endpoint, \"authorization endpoint\"),\n\t\ttoken_endpoint: safeUrl(input.token_endpoint, \"token endpoint\"),\n\t\tregistration_endpoint: optionalUrl(input.registration_endpoint, \"registration endpoint\"),\n\t\tscopes_supported: optionalStrings(input.scopes_supported, \"scopes_supported\"),\n\t\tresponse_types_supported: responseTypes,\n\t\tgrant_types_supported: optionalStrings(input.grant_types_supported, \"grant_types_supported\"),\n\t\ttoken_endpoint_auth_methods_supported: optionalStrings(\n\t\t\tinput.token_endpoint_auth_methods_supported,\n\t\t\t\"token_endpoint_auth_methods_supported\",\n\t\t),\n\t\tcode_challenge_methods_supported: optionalStrings(\n\t\t\tinput.code_challenge_methods_supported,\n\t\t\t\"code_challenge_methods_supported\",\n\t\t),\n\t\tclient_id_metadata_document_supported:\n\t\t\ttypeof input.client_id_metadata_document_supported === \"boolean\"\n\t\t\t\t? input.client_id_metadata_document_supported\n\t\t\t\t: undefined,\n\t\tauthorization_response_iss_parameter_supported:\n\t\t\ttypeof input.authorization_response_iss_parameter_supported === \"boolean\"\n\t\t\t\t? input.authorization_response_iss_parameter_supported\n\t\t\t\t: undefined,\n\t});\n}\n\nexport function parseOAuthTokens(value: unknown): OAuthTokens {\n\tconst input = object(value, \"OAuth token response\");\n\t// `Number(null)` is 0, which would mark the token as expired at once.\n\tconst expires = absent(input.expires_in) ? undefined : Number(input.expires_in);\n\tif (expires !== undefined && !Number.isFinite(expires)) throw new Error(\"Invalid expires_in\");\n\treturn compact({\n\t\taccess_token: requiredString(input.access_token, \"access_token\"),\n\t\ttoken_type: requiredString(input.token_type, \"token_type\"),\n\t\texpires_in: expires,\n\t\tscope: optionalString(input.scope, \"scope\"),\n\t\trefresh_token: optionalString(input.refresh_token, \"refresh_token\"),\n\t\tid_token: optionalString(input.id_token, \"id_token\"),\n\t});\n}\n\nexport function parseClientInformation(value: unknown): OAuthClientInformationFull {\n\tconst input = object(value, \"OAuth client registration response\");\n\treturn compact({\n\t\t...(input as unknown as OAuthClientMetadata),\n\t\tclient_id: requiredString(input.client_id, \"client_id\"),\n\t\tclient_secret: optionalString(input.client_secret, \"client_secret\"),\n\t\tclient_id_issued_at: typeof input.client_id_issued_at === \"number\" ? input.client_id_issued_at : undefined,\n\t\tclient_secret_expires_at:\n\t\t\ttypeof input.client_secret_expires_at === \"number\" ? input.client_secret_expires_at : undefined,\n\t\tredirect_uris: optionalStrings(input.redirect_uris, \"redirect_uris\") ?? [],\n\t});\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-mcp",
3
- "version": "0.99.2",
3
+ "version": "1.0.1",
4
4
  "description": "Standalone Model Context Protocol client for pi and other applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",