@creature-ai/sdk 0.1.14 → 0.1.15

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.
@@ -207,13 +207,13 @@ interface ToolContext {
207
207
  */
208
208
  instanceId: string;
209
209
  /**
210
- * Creature App Token for identity verification.
210
+ * Creature App Token for identity retrieval.
211
211
  * ONLY present when:
212
212
  * 1. App opted into Creature-managed auth (`auth: { creatureManaged: true }`)
213
213
  * 2. Tool call originated from Creature host
214
214
  *
215
- * Use `verifyCreatureToken(context.creatureToken)` to verify and extract
216
- * user identity for multi-tenant data access.
215
+ * Use `getIdentity(context.creatureToken)` to retrieve user identity
216
+ * for multi-tenant data access.
217
217
  *
218
218
  * @example
219
219
  * ```typescript
@@ -221,7 +221,7 @@ interface ToolContext {
221
221
  * if (!context.creatureToken) {
222
222
  * return { error: "Authentication required" };
223
223
  * }
224
- * const identity = await verifyCreatureToken(context.creatureToken);
224
+ * const identity = await getIdentity(context.creatureToken);
225
225
  * await db.notes.insert({
226
226
  * user_id: identity.user.id,
227
227
  * content,
@@ -715,7 +715,7 @@ declare function htmlLoader(htmlOrPath: string, basePath?: string): () => string
715
715
  declare function wrapServer<T extends McpServer>(server: T): T;
716
716
 
717
717
  /**
718
- * User identity from a verified Creature token.
718
+ * User identity from a Creature token.
719
719
  */
720
720
  interface CreatureUser {
721
721
  /** Unique, stable user identifier */
@@ -726,7 +726,7 @@ interface CreatureUser {
726
726
  name?: string;
727
727
  }
728
728
  /**
729
- * Organization context from a verified Creature token.
729
+ * Organization context from a Creature token.
730
730
  */
731
731
  interface CreatureOrganization {
732
732
  /** Unique organization identifier */
@@ -737,7 +737,7 @@ interface CreatureOrganization {
737
737
  slug: string;
738
738
  }
739
739
  /**
740
- * Project context from a verified Creature token.
740
+ * Project context from a Creature token.
741
741
  */
742
742
  interface CreatureProject {
743
743
  /** Unique project identifier */
@@ -746,15 +746,15 @@ interface CreatureProject {
746
746
  name: string;
747
747
  }
748
748
  /**
749
- * Session context from a verified Creature token.
749
+ * Session context from a Creature token.
750
750
  */
751
751
  interface CreatureSession {
752
752
  /** Unique session identifier */
753
753
  id: string;
754
754
  }
755
755
  /**
756
- * Verified identity claims from a Creature App Token.
757
- * Returned by verifyCreatureToken() on successful verification.
756
+ * Identity claims from a Creature App Token.
757
+ * Returned by getIdentity() on successful retrieval.
758
758
  */
759
759
  interface CreatureIdentity {
760
760
  /** User identity (always present for valid tokens) */
@@ -769,10 +769,10 @@ interface CreatureIdentity {
769
769
  expiresAt: string;
770
770
  }
771
771
  /**
772
- * Error thrown when token verification fails.
772
+ * Error thrown when identity retrieval fails.
773
773
  */
774
- declare class CreatureTokenError extends Error {
775
- /** Error code from the verification API */
774
+ declare class CreatureIdentityError extends Error {
775
+ /** Error code from the identity API */
776
776
  code: string;
777
777
  constructor({ code, message }: {
778
778
  code: string;
@@ -780,9 +780,9 @@ declare class CreatureTokenError extends Error {
780
780
  });
781
781
  }
782
782
  /**
783
- * Configuration for the Creature token verification API.
783
+ * Configuration for the Creature identity API.
784
784
  */
785
- interface VerifyConfig {
785
+ interface IdentityConfig {
786
786
  /**
787
787
  * Base URL for the Creature API.
788
788
  * Defaults to https://api.creature.run
@@ -791,43 +791,46 @@ interface VerifyConfig {
791
791
  apiUrl?: string;
792
792
  }
793
793
  /**
794
- * Verifies a Creature App Token and returns the identity claims.
794
+ * Retrieves user identity from a Creature App Token.
795
795
  *
796
- * Use this in your backend API to authenticate requests from your MCP App UI.
797
- * The token is provided to your UI via `hostContext.creature.token` when you
796
+ * Use this in your MCP App tool handlers to get the authenticated user's
797
+ * identity. The token is provided via `context.creatureToken` when you
798
798
  * opt into Creature-managed auth.
799
799
  *
800
- * @param tokenOrHeader - The App Token (raw) or Authorization header ("Bearer <token>")
800
+ * @param creatureToken - The App Token from context.creatureToken
801
801
  * @param config - Optional configuration (e.g., custom API URL)
802
- * @returns The verified identity claims
803
- * @throws {CreatureTokenError} If verification fails (invalid, expired, or malformed token)
802
+ * @returns The identity claims (user, organization, project, session)
803
+ * @throws {CreatureIdentityError} If the token is invalid, expired, or malformed
804
804
  *
805
805
  * @example
806
806
  * ```typescript
807
- * import { verifyCreatureToken } from "@creature-ai/sdk/server";
807
+ * import { getIdentity } from "@creature-ai/sdk/server";
808
+ *
809
+ * app.tool("save_note", { ... }, async ({ content }, context) => {
810
+ * if (!context.creatureToken) {
811
+ * return { text: "Authentication required", isError: true };
812
+ * }
808
813
  *
809
- * // In your Express/Hono/etc. API handler:
810
- * app.post("/api/notes", async (req, res) => {
811
814
  * try {
812
- * const identity = await verifyCreatureToken(req.headers.authorization);
815
+ * const identity = await getIdentity(context.creatureToken);
813
816
  *
814
817
  * // Use identity to scope data access
815
- * const notes = await db.notes.find({
818
+ * await db.notes.insert({
816
819
  * user_id: identity.user.id,
817
820
  * org_id: identity.organization?.id,
821
+ * content,
818
822
  * });
819
823
  *
820
- * res.json({ notes });
824
+ * return { text: "Note saved" };
821
825
  * } catch (err) {
822
- * if (err instanceof CreatureTokenError) {
823
- * res.status(401).json({ error: err.code, message: err.message });
824
- * } else {
825
- * res.status(500).json({ error: "internal_error" });
826
+ * if (err instanceof CreatureIdentityError) {
827
+ * return { text: err.message, isError: true };
826
828
  * }
829
+ * throw err;
827
830
  * }
828
831
  * });
829
832
  * ```
830
833
  */
831
- declare const verifyCreatureToken: (tokenOrHeader: string | undefined | null, config?: VerifyConfig) => Promise<CreatureIdentity>;
834
+ declare const getIdentity: (creatureToken: string | undefined | null, config?: IdentityConfig) => Promise<CreatureIdentity>;
832
835
 
833
- export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, type CreatureOrganization, type CreatureProject, type CreatureSession, CreatureTokenError, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, verifyCreatureToken, wrapServer };
836
+ export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, CreatureIdentityError, type CreatureOrganization, type CreatureProject, type CreatureSession, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, getIdentity, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, wrapServer };
@@ -14892,12 +14892,12 @@ function wrapServer(server) {
14892
14892
  }
14893
14893
 
14894
14894
  // src/server/auth.ts
14895
- var CreatureTokenError = class extends Error {
14896
- /** Error code from the verification API */
14895
+ var CreatureIdentityError = class extends Error {
14896
+ /** Error code from the identity API */
14897
14897
  code;
14898
14898
  constructor({ code, message }) {
14899
14899
  super(message);
14900
- this.name = "CreatureTokenError";
14900
+ this.name = "CreatureIdentityError";
14901
14901
  this.code = code;
14902
14902
  }
14903
14903
  };
@@ -14909,33 +14909,32 @@ var extractToken = (tokenOrHeader) => {
14909
14909
  }
14910
14910
  return trimmed;
14911
14911
  };
14912
- var verifyCreatureToken = async (tokenOrHeader, config) => {
14913
- if (!tokenOrHeader) {
14914
- throw new CreatureTokenError({
14912
+ var getIdentity = async (creatureToken, config) => {
14913
+ if (!creatureToken) {
14914
+ throw new CreatureIdentityError({
14915
14915
  code: "missing_token",
14916
- message: "No token provided. Expected Authorization header or raw token."
14916
+ message: "No token provided. Pass context.creatureToken to getIdentity()."
14917
14917
  });
14918
14918
  }
14919
- const token = extractToken(tokenOrHeader);
14919
+ const token = extractToken(creatureToken);
14920
14920
  if (!token) {
14921
- throw new CreatureTokenError({
14921
+ throw new CreatureIdentityError({
14922
14922
  code: "missing_token",
14923
- message: "Empty token after extraction from Authorization header."
14923
+ message: "Empty token after extraction."
14924
14924
  });
14925
14925
  }
14926
14926
  const apiUrl = config?.apiUrl || DEFAULT_API_URL;
14927
- const verifyUrl = `${apiUrl}/apps/v1/token/verify`;
14927
+ const identityUrl = `${apiUrl}/apps/v1/identity`;
14928
14928
  let response;
14929
14929
  try {
14930
- response = await fetch(verifyUrl, {
14931
- method: "POST",
14930
+ response = await fetch(identityUrl, {
14931
+ method: "GET",
14932
14932
  headers: {
14933
- Authorization: `Bearer ${token}`,
14934
- "Content-Type": "application/json"
14933
+ Authorization: `Bearer ${token}`
14935
14934
  }
14936
14935
  });
14937
14936
  } catch (err) {
14938
- throw new CreatureTokenError({
14937
+ throw new CreatureIdentityError({
14939
14938
  code: "network_error",
14940
14939
  message: `Failed to reach Creature API: ${err instanceof Error ? err.message : "Unknown error"}`
14941
14940
  });
@@ -14946,44 +14945,44 @@ var verifyCreatureToken = async (tokenOrHeader, config) => {
14946
14945
  errorData = await response.json();
14947
14946
  } catch {
14948
14947
  }
14949
- throw new CreatureTokenError({
14950
- code: errorData.error || "verification_failed",
14951
- message: errorData.error_description || `Token verification failed (HTTP ${response.status})`
14948
+ throw new CreatureIdentityError({
14949
+ code: errorData.error || "identity_error",
14950
+ message: errorData.error_description || `Identity request failed (HTTP ${response.status})`
14952
14951
  });
14953
14952
  }
14954
14953
  let data;
14955
14954
  try {
14956
14955
  data = await response.json();
14957
14956
  } catch {
14958
- throw new CreatureTokenError({
14957
+ throw new CreatureIdentityError({
14959
14958
  code: "invalid_response",
14960
14959
  message: "Invalid JSON response from Creature API"
14961
14960
  });
14962
14961
  }
14963
- if (!data.valid || !data.claims?.user) {
14964
- throw new CreatureTokenError({
14962
+ if (!data.user) {
14963
+ throw new CreatureIdentityError({
14965
14964
  code: "invalid_token",
14966
14965
  message: "Token is not valid"
14967
14966
  });
14968
14967
  }
14969
14968
  return {
14970
- user: data.claims.user,
14971
- organization: data.claims.organization,
14972
- project: data.claims.project,
14973
- session: data.claims.session,
14969
+ user: data.user,
14970
+ organization: data.organization,
14971
+ project: data.project,
14972
+ session: data.session,
14974
14973
  expiresAt: data.expires_at
14975
14974
  };
14976
14975
  };
14977
14976
  export {
14978
14977
  App,
14979
- CreatureTokenError,
14978
+ CreatureIdentityError,
14980
14979
  MIME_TYPES,
14981
14980
  createApp,
14981
+ getIdentity,
14982
14982
  htmlLoader,
14983
14983
  isHtmlContent,
14984
14984
  loadHtml,
14985
14985
  svgToDataUri,
14986
- verifyCreatureToken,
14987
14986
  wrapServer
14988
14987
  };
14989
14988
  //# sourceMappingURL=index.js.map